Hi All,
I've got some questions about the behaviour of the AudioPlayMemory object, and how it expects the array containing the samples to be laid out.
I've read the old documentation here: https://www.pjrc.com/teensy/td_libs_AudioPlayMemory.html as well as the AudioPlayMemory page in the teensy audio tool.
and some comments here:
https://forum.pjrc.com/threads/29121-Recording-audio-to-buffer?highlight=2's+complement
and looked at the source code for "wav2sketch".
And I think I've mostly wrapped my head around it, but I can't reconcile some things with the numbers I see in the example sketches.
Here's my understanding of the layout of AudioPlayMemory, please let me know if I've gotten anything wrong:
1) The data is stored as an array of "const unsigned int", each element of which is 32-bits (4 bytes) in size.
2) The data of each sample is _signed_ in a 2's complement form.
3) Different sample rates (44100, 22050, 11025 Hz) can be selected,
4) Samples can be in either an 8-bit compressed format, or uncompressed 16-bit PCM. (16-bit samples are stored in little-endian format, with low-byte containting the least-significant bits)
5) The high 8-bits of the first word of the array specify the format of the compression, and the low 24-bits specifies the length of the samples. According to the documentation the length is specified in bytes, but I suspect it is actually specified in samples.
Here's my diagram:
The problem is when I look at example sketches and see how other people have used the AudioPlayMemory objects, I get different numbers for array size than what I'd predict based on the length specification in the header.
Specifically the numbers are wrong for all the 16-bit formats if I assume the units of length are bytes:
If I assume the units of length are samples, then it looks much better, but some of the files still don't match the pattern:
Is what I'm seeing just a bug in wav2sketch (or the files "guitar_a2_note" and "guitar_b3_note" in the example sketches), or have I made a mistake somewhere?
Cheers,
Gavin
I've got some questions about the behaviour of the AudioPlayMemory object, and how it expects the array containing the samples to be laid out.
I've read the old documentation here: https://www.pjrc.com/teensy/td_libs_AudioPlayMemory.html as well as the AudioPlayMemory page in the teensy audio tool.
and some comments here:
https://forum.pjrc.com/threads/29121-Recording-audio-to-buffer?highlight=2's+complement
and looked at the source code for "wav2sketch".
And I think I've mostly wrapped my head around it, but I can't reconcile some things with the numbers I see in the example sketches.
Here's my understanding of the layout of AudioPlayMemory, please let me know if I've gotten anything wrong:
1) The data is stored as an array of "const unsigned int", each element of which is 32-bits (4 bytes) in size.
2) The data of each sample is _signed_ in a 2's complement form.
3) Different sample rates (44100, 22050, 11025 Hz) can be selected,
4) Samples can be in either an 8-bit compressed format, or uncompressed 16-bit PCM. (16-bit samples are stored in little-endian format, with low-byte containting the least-significant bits)
5) The high 8-bits of the first word of the array specify the format of the compression, and the low 24-bits specifies the length of the samples. According to the documentation the length is specified in bytes, but I suspect it is actually specified in samples.
Here's my diagram:
The problem is when I look at example sketches and see how other people have used the AudioPlayMemory objects, I get different numbers for array size than what I'd predict based on the length specification in the header.
Specifically the numbers are wrong for all the 16-bit formats if I assume the units of length are bytes:
If I assume the units of length are samples, then it looks much better, but some of the files still don't match the pattern:
Is what I'm seeing just a bug in wav2sketch (or the files "guitar_a2_note" and "guitar_b3_note" in the example sketches), or have I made a mistake somewhere?
Cheers,
Gavin