[sdlsound] pcm data from sample.buffer
Peter Jensen
skruedims at yahoo.dk
Wed Oct 26 09:06:39 EDT 2011
Hi,
I'm trying to get the raw PCM data, from a decoded mp3 file.
I'm only interested in the raw pcm data, and not to output it to eg. sdl-audio.But if try to look into the sample.buffer after decoding, the buffer seems empty. (See below).
But if i modify eg. playsound_simple.c, in the audio callback function there are data in the buffer.
It looks like SDL_OpenAudio does something to the data?
Is it possible to somehow get the raw pcm data without using eg. SDL_OpenAudio?
Best Regards
Peter
int main()
{
if (!Sound_Init())
{
cout << "\nFailed init" << endl;
exit(1);
}
Sound_Sample *sample = Sound_NewSampleFromFile("data/musik.mp3", NULL, 65536);
if (!sample)
{
cout << "Error opening file:" << Sound_GetError();
exit(1);
}
Uint32 br = Sound_DecodeAll(sample);
Uint8 *decoded = (Uint8*)sample->buffer;
if ((sample->flags & SOUND_SAMPLEFLAG_EOF))
{
cout << "\nDecoded number of bytes:" << br << endl;
for (Uint32 i=0; i<br; i++)
{
Uint8 f = decoded[i];
cout << (float)f << ",";
}
}
Sound_FreeSample(sample);
Sound_Quit();
return 0;
}
More information about the sdlsound
mailing list