ST AN3143 Application note

AN3143

Application note

Audio software codec for the STM8S

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, white goods, washing machines, and alarms.

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 a complex task requiring powerful microcontrollers such as DSP or audio chip. Usually, 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 STM8S core with its 3-staged pipeline and 16 or 24 MIPS peak performance.

The digital samples are usually converted to an analog signal by some external or onchip digital-to-analog converter (DAC). There are a lot of applications where the high fidelity audio output is not a priority and/or the use of an external DAC is not a suitable costeffective solution for 8-bit microcontrollers. To reduce costs and to offer a good quality audio, an ideal solution is to generate an audio signal using pulse width modulation (PWM).

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.

March 2010

Doc ID 17011 Rev 1

1/13

www.st.com

Contents

AN3143

 

 

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

STM8S audio output hardware overview . . . . . . . . . . . . . . . . . . . . . . . .

9

4

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

11

5

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

11

6

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

12

2/13

Doc ID 17011 Rev 1

AN3143

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. Fortunately, 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®. 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 17011 Rev 1

3/13

ST AN3143 Application note

ADPCM codec

AN3143

 

 

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). To reduce quantization errors, one half of the step size is added 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 step size is adapted according to Sq. The decoder preconditions are that Sp is cleared and that the quantization step is set to smallest one.

Figure 1. ADPCM decoder

3Q

3D

 

3,

 

)NVERSE QUANTIZER

 

 

 

 

 

 

 

 

 

 

 

Q

3P

 

3TEP SIZEEADAPTOR

 

0REDICTOR

 

 

 

 

 

AI

4/13

Doc ID 17011 Rev 1

Loading...
+ 9 hidden pages