Using Speex in NXP's LPC175x/6x MCU Family: Rev. 2 - 5 March 2012 Application Note
Using Speex in NXP's LPC175x/6x MCU Family: Rev. 2 - 5 March 2012 Application Note
Using Speex in NXP's LPC175x/6x MCU Family: Rev. 2 - 5 March 2012 Application Note
Application note
Document information
Info
Content
Keywords
Abstract
AN11085
NXP Semiconductors
Revision history
Rev
Date
Description
20120305
20110616
Initial version.
Contact information
For more information, please visit: http://www.nxp.com
For sales office addresses, please send an email to: [email protected]
AN11085
Application note
2 of 17
AN11085
NXP Semiconductors
1. Introduction
1.1 Overview
Once designed to be a free alternative to expensive speech codecs, Speex is an Open
Source / Free software patent-free audio compression format designed for speech.
Speex is part of the GNU project and this application note provides information regarding
the usage of this library on NXPs LPC175x/6x microcontrollers (based on Cortex-M3).
1.1.2 Applications
The Speex library can be used in various applications, such as VoIP, internet audio
streaming, data archiving (e.g., voice mail), and audio books.
AN11085
Application note
3 of 17
AN11085
NXP Semiconductors
I2S (Inter-IC Sound) interface for digital audio input or output, with fractional rate
control. The I2S interface can be used with the GPDMA. The I2S interface supports 3wire data transmit and receive or 4-wire combined transmit and receive connections,
as well as master clock output.
AN11085
Application note
4 of 17
AN11085
NXP Semiconductors
Fig 1.
2. Application
2.1 Vocoder overview
The application proposed is a Vocoder using LPC1768. Vocoders are analysis and
processing systems mostly used for voice applications. It treats the audio signal
enhancing the bandpass related to the voice spectrum frequencies, encoding, decoding,
filtering and finally amplifying it.
The application software processes Speex data, capturing data either from ADC or I2S
and to deliver it either to DAC or I2S. The application allows usage of ADC and DAC
converters in case of I2S codec is not available:
Fig 2.
AN11085
Application note
Functional diagram of Speex application in LPC17XX using (a) NXP I2S Codec
and (b) using ADC and DAC converters
All information provided in this document is subject to legal disclaimers.
5 of 17
AN11085
NXP Semiconductors
Memory usage
IDE
Keil RVMDK
49900
10120
IAR EWARM
36346
18196
LPCXpresso[1]
86676
18272
[1]
LPCXpresso code size includes the UDA1380 Library and is also not optimized.
AN11085
Application note
6 of 17
AN11085
NXP Semiconductors
and up to 4.5 ms for decoding 1. This makes the LPC175x/6x suitable for real-time
encoding or decoding.
SPX_CODEC_CFG_Type spx_config;
/* Speex CODEC configuration */
spx_config.quality
= 4;
spx_config.complexity = 1;
spx_config.vbr
= SPX_VBR_DISABLED;
spx_config.enh
= SPX_ENHANCER_ENABLED;
spx_Init(&spx_config);
Fig 3.
1.
AN11085
Application note
/*
/*
/*
/*
Encoder
Encoder
Encoder
Decoder
parameter
parameter
parameter
parameter
*/
*/
*/
*/
Only during encoding or decoding, P0_25 is set to a high level providing a simple approach for time
measurement.
All information provided in this document is subject to legal disclaimers.
7 of 17
AN11085
NXP Semiconductors
Fig 4.
Speex initialization
AN11085
Application note
8 of 17
AN11085
NXP Semiconductors
Start encoding
IN_Buffer[1]
Start encoding
IN_Buffer[0]
Stop encoding
IN_Buffer[0]
Start encoding
IN_Buffer[0]
Stop encoding
IN_Buffer[1]
Start recording
Start capturing to
IN_Buffer[0]
Fig 5.
AN11085
Application note
IN_Buffer[0]
completed
Start capturing to
IN_Buffer[1]
IN_Buffer[1]
completed
Start capturing to
IN_Buffer[0]
IN_Buffer[0]
completed
Start capturing to
IN_Buffer[1]
Encoding scheme
9 of 17
AN11085
NXP Semiconductors
Record
Sampler start(1)
Init recording
parameters
Capture a sample
All frames
encoded
No
Yes
Toggle buffer
index
No
New frame
available
No
New frame
available for
encoding
Yes
Encode frame
End
Disable audio
input
End
(1) Depending on the board, Sampler can be TIMER0 or I2S Interrupt Handler
Fig 6.
Encoding flowchart
AN11085
Application note
10 of 17
AN11085
NXP Semiconductors
Record
Init playing
parameters
OUTPUT start(1)
Yes
All frames
decoded
Output a sample
No
Free
OUT_Buffer
available
No
No
All samples
delivered
Yes
Yes
#frames
encoded == 1
Free current
OUT_Buffer
No
Active next
OUT_Buffer for
output
Yes
Free next buffer
for decoding
End
Enable audio
output
Disable audio
output
End
(1) Depending on the board, OUTPUT can be TIMER0 or I2S Interrupt Handler
Fig 7.
AN11085
Application note
Decoding flowchart
11 of 17
AN11085
NXP Semiconductors
OUT_Buffer[1]
available
Start to send
OUT_Buffer[1]
20ms
20ms
20ms
Fig 8.
Stop decoding
4th frame
Stop decoding
3rd frame
Stop decoding
2nd frame
OUT_Buffer[0]
available
Start to send
OUT_Buffer[0]
Start decoding
4th frame
Start decoding
3rd frame
Start decoding
2nd frame
OUT_Buffer[0]
available
Start to send
OUT_Buffer[0]
Bit clock = 16 kHz (resulting in 8 k samples per second, as the UDA1380 will
always transfer stereo data);
The UDA1380 sends data according to WS and BCK signals generated by LPC1768.
Because the microphone signal is MONO, the same value is sent as RIGHT and LEFT
data.
When configured for 16-bit word, the 32 bits RX FIFO contains two consecutive 16-bit
samples after a complete WS cycle. The RX FIFO contents and I2S bus format sent by
UDA1380 are shown in Fig 9 and Fig 10. An oscilloscope screen of a transition is shown
in Fig 11.
Fig 9.
Fig 10. I2S bus format for UDA1380 for transferring 1 mono sample
AN11085
Application note
12 of 17
AN11085
NXP Semiconductors
Fig 11. Oscilloscope screen of an I2S signal received by the LPC1768. Yellow
(I2SRX_WS), blue (I2SRX_CLK) and magenta (I2SRX_SDA)
Note: On the CodeRed RDB1768 board the microphone is not working properly by
default due to a hardware bug, as there is no power supplied to the microphone. This can
easily be fixed by connecting a 10 k resistor from the microphone to the analog power
supply of the UDA1380. Fig 12 shows the required patch.
Fig 12. Hardware fix required when connecting an electret microphone to the RDB1768
board
Application note
13 of 17
AN11085
NXP Semiconductors
but it contains a speaker that is used by the application to play a sample audio that
comes with the software.
3. Conclusion
We can see in this application note that the LPC175x/6x is suitable for Vocoder
applications using the Speex Codec. Even using no optimization methods, this
microcontroller can perform real-time Speex encoding/decoding satisfactorily. Users also
can implement some Preprocessor functions available by the Speex software library,
such as Resampler, Echo Cancellation, etc.
AN11085
Application note
14 of 17
AN11085
NXP Semiconductors
4. References
Speex manual, http://speex.org/docs/
Speex API Reference Manual, http://speex.org/docs/
LPC17xx user manual (UM10360), http://www.nxp.com
AN11085
Application note
15 of 17
AN11085
NXP Semiconductors
5. Legal information
5.1 Definitions
Draft The document is a draft version only. The content is still under
internal review and subject to formal approval, which may result in
modifications or additions. NXP Semiconductors does not give any
representations or warranties as to the accuracy or completeness of
information included herein and shall have no liability for the consequences
of use of such information.
5.2 Disclaimers
Limited warranty and liability Information in this document is believed to
be accurate and reliable. However, NXP Semiconductors does not give any
representations or warranties, expressed or implied, as to the accuracy or
completeness of such information and shall have no liability for the
consequences of use of such information. NXP Semiconductors takes no
responsibility for the content in this document if provided by an information
source outside of NXP Semiconductors.
In no event shall NXP Semiconductors be liable for any indirect, incidental,
punitive, special or consequential damages (including - without limitation lost profits, lost savings, business interruption, costs related to the removal
or replacement of any products or rework charges) whether or not such
damages are based on tort (including negligence), warranty, breach of
contract or any other legal theory.
Notwithstanding any damages that customer might incur for any reason
whatsoever, NXP Semiconductors aggregate and cumulative liability
towards customer for the products described herein shall be limited in
accordance with the Terms and conditions of commercial sale of NXP
Semiconductors.
Right to make changes NXP Semiconductors reserves the right to make
changes to information published in this document, including without
limitation specifications and product descriptions, at any time and without
notice. This document supersedes and replaces all information supplied prior
to the publication hereof.
Suitability for use NXP Semiconductors products are not designed,
authorized or warranted to be suitable for use in life support, life-critical or
safety-critical systems or equipment, nor in applications where failure or
malfunction of an NXP Semiconductors product can reasonably be expected
to result in personal injury, death or severe property or environmental
damage. NXP Semiconductors and its suppliers accept no liability for
inclusion and/or use of NXP Semiconductors products in such equipment or
applications and therefore such inclusion and/or use is at the customers
own risk.
Applications Applications that are described herein for any of these
products are for illustrative purposes only. NXP Semiconductors makes no
representation or warranty that such applications will be suitable for the
specified use without further testing or modification.
5.3 Trademarks
Notice: All referenced brands, product names, service names and
trademarks are property of their respective owners.
Customers are responsible for the design and operation of their applications
and products using NXP Semiconductors products, and NXP
AN11085
Application note
16 of 17
AN11085
NXP Semiconductors
6. Contents
1.
1.1
1.1.1
1.1.2
1.1.3
1.2
1.3
Introduction ......................................................... 3
Overview ............................................................ 3
Speex features ................................................... 3
Applications ........................................................ 3
About this document .......................................... 3
LPC175x/6x features .......................................... 4
About Code Reds RBD1768 development board
........................................................................... 4
2.
Application ........................................................... 5
2.1
Vocoder overview............................................... 5
2.2
Memory requirements ........................................ 6
2.3
Speex application implementation ...................... 6
2.3.1
Codec settings ................................................... 6
2.3.1.1
Sampling rate ..................................................... 6
2.3.1.2
Speex Parameters ............................................. 6
2.3.2
Environment features and requirements ............ 6
2.3.3
Using libSpeex ................................................... 7
2.4
Application description ....................................... 8
2.4.1
Record process .................................................. 8
2.4.2
Playback process ............................................. 10
2.4.3
Audio input/output for RDB1768 board ............ 12
2.4.4
User Interface................................................... 13
3.
Conclusion ......................................................... 14
4.
References ......................................................... 15
5.
Legal information .............................................. 16
5.1
Definitions ........................................................ 16
5.2
Disclaimers....................................................... 16
5.3
Trademarks ...................................................... 16
6.
Contents ............................................................. 17
Please be aware that important notices concerning this document and the product(s)
described herein, have been included in the section 'Legal information'.