Datasheet

VS1053b Datasheet
10 OPERATION
10.8.2 Reading PCM / IMA ADPCM Data
After PCM / IMA ADPCM recording has been activated, registers SCI_HDAT0 and SCI_HDAT1
have new functions.
The PCM / IMA ADPCM sample buffer is 1024 16-bit words. The fill status of the buffer can
be read from SCI_HDAT1. If SCI_HDAT1 is greater than 0, you can read as many 16-bit words
from SCI_HDAT0. If the data is not read fast enough, the buffer overflows and returns to empty
state.
Note: if SCI_HDAT1 768, it may be better to wait for the buffer to overflow and clear before
reading samples. That way you may avoid buffer aliasing.
In IMA ADPCM mode each mono IMA ADPCM block is 128 words, i.e. 256 bytes, and stereo
IMA ADPCM block is 256 words, i.e. 512 bytes. If you wish to interrupt reading data and
possibly continue later, please stop at the boundary. This way complete compression blocks
are skipped and the encoded stream stays valid.
10.8.3 Adding a PCM RIFF Header
To make your PCM file a RIFF / WAV file, you have to add a header to the data. The following
shows a header for a mono file. Note that 2- and 4-byte values are little-endian (lowest byte
first).
File Offset Field Name Size Bytes Description
0 ChunkID 4 "RIFF"
4 ChunkSize 4 F0 F1 F2 F3 File size - 8
8 Format 4 "WAVE"
12 SubChunk1ID 4 "fmt "
16 SubChunk1Size 4 0x10 0x0 0x0 0x0 20
20 AudioFormat 2 0x01 0x0 0x1 for PCM
22 NumOfChannels 2 C0 C1 1 for mono, 2 for stereo
24 SampleRate 4 R0 R1 R2 R3 0x1f40 for 8 kHz
28 ByteRate 4 B0 B1 B2 B3 0x3e80 for 8 kHz mono
32 BlockAlign 2 0x02 0x00 2 for mono, 4 for stereo
34 BitsPerSample 2 0x10 0x00 16 bits / sample
36 SubChunk3ID 4 "data"
40 SubChunk3Size 4 D0 D1 D2 D3 Data size (File Size-36)
44 Samples... Audio samples
The values in the table are calculated as follows:
R = F
s
(see Chapter 10.8.1 to see how to calculate F
s
)
B = 2 × F
s
× C
Version: 1.22, 2014-12-19 55