libSpeex and playback

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
nirving
Posts: 12
Joined: Wed Sep 20, 2006 6:35 am

libSpeex and playback

Post by nirving »

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
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Doesn't speex work on 320 samples per frame? Perhaps that's your problem?
nirving
Posts: 12
Joined: Wed Sep 20, 2006 6:35 am

Post by nirving »

I am not sure, the example I have created seems to be 320 samples per frame. Does this mean I have to use use each sample 4 times to get anything out?
nirving
Posts: 12
Joined: Wed Sep 20, 2006 6:35 am

Post by nirving »

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?
User avatar
dsn
Posts: 47
Joined: Wed Nov 09, 2005 11:48 am
Location: Indianapolis, Indiana, USA

Post by dsn »

You can convert from 8000 Hz to 44100 Hz with something like this:

Code: Select all

u8 srcSamples[320];
u32 dstSamples[1764];
u32 srcIndex = 0;      // fixed-point -- divide by 10000000 to get integer portion
u32 dstIndex;

for &#40;dstIndex = 0; dstIndex < 1764; dstIndex++&#41;
&#123;
	dstSamples&#91;dstIndex&#93; = scale_sample&#40;srcSamples&#91;srcIndex / 10000000&#93;&#41;;
	srcIndex += 1814059;
&#125;
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.
Post Reply