Datasheet

VS1053b Datasheet
10 OPERATION
If you know beforehand how much you are going to record, you may fill in the complete header
before any actual data. However, if you don’t know how much you are going to record, you have
to fill in the header size datas F and D after finishing recording.
The PCM data is read from SCI_HDAT0 and written into file as follows. The low 8 bits of
SCI_HDAT0 should be written as the first byte to a file, then the high 8 bits (little-endian order).
Note that this is different from how ADPCM data is written to a file (see Chapter 10.8.4).
Below is an example of a valid header for a 44.1 kHz mono PCM file that has a final length of
1798768 (0x1B7270) bytes:
0000 52 49 46 46 68 72 1b 00 57 41 56 45 66 6d 74 20 |RIFFhr..WAVEfmt |
0010 10 00 00 00 01 00 01 00 80 bb 00 00 00 77 01 00 |.............w..|
0020 02 00 10 00 64 61 74 61 44 72 1b 00 |....dataDr......|
10.8.4 Adding an IMA ADPCM RIFF Header
To make your IMA ADPCM 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 0x14 0x0 0x0 0x0 20
20 AudioFormat 2 0x11 0x0 0x11 for IMA ADPCM
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 0xfd7 for 8 kHz mono
32 BlockAlign 2 0x00 0x01 256 for mono, 512 for stereo
34 BitsPerSample 2 0x04 0x00 4-bit ADPCM
36 ByteExtraData 2 0x02 0x00 2
38 ExtraData 2 0xf9 0x01 Samples per block (505)
40 SubChunk2ID 4 "fact"
44 SubChunk2Size 4 0x4 0x0 0x0 0x0 4
48 NumOfSamples 4 S0 S1 S2 S3
52 SubChunk3ID 4 "data"
56 SubChunk3Size 4 D0 D1 D2 D3 Data size (File Size-60)
60 Block1 256 First ADPCM block, 512 bytes for stereo
316 . . . More ADPCM data blocks
If we have n audio blocks, the values in the table are as follows:
F = n × C × 256 + 52
R = F
s
(see Chapter 10.8.1 to see how to calculate F
s
)
B =
F
s
×C×256
505
S = n × 505. D = n × C × 256
Version: 1.22, 2014-12-19 56