ST AN3225 Application note

AN3225

Application note

Audio software codec for the STM8L15xxx

Introduction

This application note describes a simple and easy-to-use solution to help design and develop products with an audio output, for example, toys, alarms, door bells, and white goods.

Audio data generally require the storage of a lot of memory. However, the memory space needed to preserve such data can be reduced by compressing the audio data via a specified compression method. Processing these data is usually a complex task requiring powerful microcontrollers such as DSP or audio chip. Normally, 8-bit microcontrolles do not offer either a large memory or a high computing performance.

The software solution offered in this application note reconstructs audio signals from compressed samples. A simple audio codec based on an adaptive differential pulse coded modulation (ADPCM) algorithm is used and advantage is taken of the advanced STM8L core with its 3-staged pipeline and 16 MIPS peak performance.

The digital samples are converted to an analog signal by an on-chip, 12-bit, digital-to-analog converter (DAC). This offers good overall audio quality, yet is a cost-effective solution for 8- bit microcontroller applications.

The battery-powered application benefits from the ultra low-power consumption of STM8L microcontrollers.

The example firmware and application hardware design are provided with this application note to enable easy porting of the offered solution to the final application.

December 2010

Doc ID 17566 Rev 2

1/13

www.st.com

Contents

AN3225

 

 

Contents

1

ADPCM codec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

 

1.1

Adaptive differential pulse coded modulation (ADPCM) . . . . . . . . . . . . . . .

3

 

1.2

Interactive multimedia association (IMA) ADPCM . . . . . . . . . . . . . . . . . . .

3

 

1.3

IMA ADPCM decompression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

 

1.4

IMA ADPCM compression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

2

Audio data encoding and storing . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 6

 

2.1

Internal Flash memory used for audio data storing . . . . . . . . . . . . . . . . . .

6

 

2.2

External memory used for audio data storing . . . . . . . . . . . . . . . . . . . . . .

8

3

STM8L audio output using on-chip 12-bit DAC . . . . . . . . . . . . . . . . . . .

9

4

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

5

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

6

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12

2/13

Doc ID 17566 Rev 2

AN3225

ADPCM codec

 

 

1 ADPCM codec

1.1Adaptive differential pulse coded modulation (ADPCM)

ADPCM is a fixed length codeword audio codec which reduces redundant information from audio waveforms. The information core is separated from the correlated waveform samples by encoding differences between the current samples and the predicted ones. As the correlation between consecutive audio samples is generally high, this method is reasonably effective and preserves good audio quality. The ADPCM codec, which is based on coding waveforms in time domains, is much less complex than codecs based on voice perception (vocoders) that operate in frequency domains. For these reasons, the ADPCM codec is the best choice for the audio output on 8-bit microcontrollers.

The ADPCM algorithm has been developed for speech coding. It is implemented in several steps and is used in telephone systems like ITU-T G.726 (covering CCITT G.721 and G.723 standards). G.726 and similar telecommunication codecs, offer several advanced features which are necessary for successful transmission and streaming. Such features include synchronous coding adjustment, tone detection to carry data modem signals, adaptated speed control, and recovery from transmission error conditions. These features lead to additional algorithm complexity which either requires the use of a digital signal processor (DSP) or lowering the encoding/decoding sample rate. Such features do not bring many additional benefits to the microcontroller for coding/decoding the audio or speech signals. Less complex alternatives can be found.

1.2Interactive multimedia association (IMA) ADPCM

The IMA(a) ADPCM codec is one such alternative solution. This codec is widely used across different computers platforms, for example in Microsoft® Sound Recorder or Apple® QuickTime® player. It was originally offered by Intel/DVI® as an open standard for use by the IMA. The reference algorithms and recommended formats were initially developed by the digital audio technical working group (DATWG) and refined by the digital audio focus group (DAFG) of the IMA. These groups are no longer active.

The IMA DATWG reference algorithm is less complex than the G.726 algorithm. The number of encoding/decoding CPU cycles needed is reduced by using fixed prediction and by replacing complex floating point mathematical operations by look-up tables. The implementation of the ADPCM codec presented in this application note is compatible with the IMA reference algorithm published by the IMA DATWG/DAFG in the “Recommended Practices for Enhancing Digital Audio Compatibility in Multimedia Systems”, revision 3.00 (see References).

a.IMA is a computer/audio/video industry trade association that has worked to promote multimedia application development.

Doc ID 17566 Rev 2

3/13

ST AN3225 Application note

ADPCM codec

AN3225

 

 

1.3IMA ADPCM decompression

The IMA ADPCM decompression algorithm compresses samples which are stored as 4-bit signed two’s complement values. The result is decompressed samples in linear 16-bit two’s complement format.

The input sample (Sq) is dequantized using an inverse quantizer with an adapted step (q) to obtain a difference (Sd). The step size is adapted by using a lookup table approximating to an exponential function. The vector pointing to the lookup table is adjusted according to the magnitude of Sq. To reduce quantization errors, one half of the step size is always added or subtracted to Sd. The resulting decompressed linear sample is the sum of Sd and the predicted sample (Sp). As Sp is a simple zero order hold function, Sd is simply added to the previous output value. The decoder preconditions are that Sp is cleared and that the quantization step is set to the smallest one.

Figure 1. ADPCM decoder

3Q

3D

 

3,

 

)NVERSE QUANTIZER

 

 

 

 

 

 

 

 

 

 

 

Q

3P

 

3TEP SIZEEADAPTOR

 

0REDICTOR

 

 

 

 

 

AI

4/13

Doc ID 17566 Rev 2

Loading...
+ 9 hidden pages