QUOTE(Doron @ Dec 26 2006, 06:04)

Hi.
I am using wavpack (as a library linked with my code) to compress 16 bit PCM data on a powerpc machine.
Since I get my buffers from another place already in memory, I don't use a real file, so wavpack actually reads the samples from a buffer in memory (i've implemented the needed callbacks for this).
My question:
1. I pass wavpack a buffer of int's. How should the samples be arranged inside the buffer?
Should I put each 16 bit sample in one int? Should it be aligned to the right or shifted to the left?
2. How should I configure wavpack? I use 16 bit for config->bits_per_sample, but what should i use for config->bytes_per_sample (and what does it mean)?
3. I tried using the following:
bits_per_sample=16
bytes_per_sample=4
Each int in the buffer was holding one 16 bit sample aligned to the right.
This yielded *bad* results (most of the buffers actually inflated).
4. When I am decompressing, wavpack writes data to a buffer. What is the format of the buffer. Is it 2 samples in each int or one sample aligned to the left/right?
5. One last thing, I am doing all this on a power pc cpu.
Again, I remind that I'm not letting wavpack read from a file but from a buffer in memory.
Thanks for any help,
Doron
First, I assume you have read
this. It covers this but I realize it's not super clear and I plan to update it soon.
For both packing and unpacking, WavPack always takes buffers of 32-bit signed integers, even if you're only passing in 8-bit or 16-bit values. This is done because WavPack always works in 32-bit internally. Assuming that the number of bits is a multiple of 8, then the values are right justified in the 32-bit integer. So, if your values are 16-bit ints, then you would simply cast them to a 32-bit int and pass them in (-32768 to +32767). Note that this means that the values
must be signed-extended into the high bytes (I think this might be why your buffers were inflating). On decoding, the values are passed back exactly like they are passed in during encode.
For this example you would set bits_per_sample to 16 and bytes_per_sample to 2 (because the original samples fit in 2 bytes). The bytes_per_sample information is stored in the WavPack file so that during decoding the decoder will know how big the samples can be so that it can quickly detect errors (and it's also used for clipping in lossy mode).
There should not be any endian issue with the power pc. The samples are always passed in and out in the native endian mode of the processor, so you should not have to deal with this at all (unless you want to calculate md5 sums).
Hope this helps and let me know if you have more questions...