Hi first time poster, long time reader.
I have been trying to figure out how to use the PSP Audio library so that I can use Speex to play some encoded file back. So far I have managed to get the library to compile and install into the SDK, modified a couple of the encoding and decoding sample programs to work on the PSP. These just take a wav file encode to spx and decode back to wav, no problems so I know my library works. However I just cannot seem to get the PSP to play back any audio, and since I have looked at every PSP Audio example I can find I cannot seem to get it to work. I guess I am missing something fundamental as most of the samples talk about using 1024 bits, whereas on average mine is producing 320 bits per callback, so I guess the sample rate is too low, but I cannot figure out what I am doing wrong.
You can download my libSpeex here http://users.on.net/~nirving/psp/libspeex-psp.zip and the sample code I have written here http://users.on.net/~nirving/psp/speexClient.zip . Here is a sample encoded file for playback http://users.on.net/~nirving/psp/test-encode.spx
I would be grateful for any feedback, suggestions ideas etc.
Thanks
libSpeex and playback
Okay I have made some progress, and managed to get some code to output the sample. Currently I am having to output each bit I have 3 times to get anything of value, by this I mean it was too fast before, so am trying to find out how to convert (interpolate) the 8bit mono @ 8000 to 16 bit stereo @ 44100. People are mentioning some code to do this but I am not sure where to look, any idea?
You can convert from 8000 Hz to 44100 Hz with something like this:
I used this technique in Ruckus to shift pitch, which is the same operation as adjusting the sample rate. This doesn't do any interpolation or other fanciness, but that wouldn't be hard to add. Note that you still have to figure out how to write scale_sample, which I've left as an exercise because I'm lazy. :-) This code assumes that scale_sample will take an 8-bit mono sample and scale it to 16-bit stereo.
Code: Select all
u8 srcSamples[320];
u32 dstSamples[1764];
u32 srcIndex = 0; // fixed-point -- divide by 10000000 to get integer portion
u32 dstIndex;
for (dstIndex = 0; dstIndex < 1764; dstIndex++)
{
dstSamples[dstIndex] = scale_sample(srcSamples[srcIndex / 10000000]);
srcIndex += 1814059;
}