Playback audio stream

Hi all,

I am working at using SDL to playback network audio stream, but I don’t know
how to do it.
I found some tutorials and tried the following way,but it didn’t work.

The received audio data format is AFMT_S16_LE (OSS format), I store the data
in a buffer,
s_chAudioBuf[1024096], when the buffer is filled, I use SDL to play it.

the callback function is playit:
void SDLCALL playit(void *unused, Uint8 *stream, int len)
{
Uint32 amount = wave.soundlen - wave.soundpos;
if (amount > len)
amount = len;
SDL_MixAudio(stream, &wave.sound[wave.soundpos], amount, SDL_MIX_MAXVOLUME);
wave.soundpos += amount;
}

the main code here:
if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
perror(“Initializing”);
return false;
}
wave.wanted_spec.freq = 44100;
wave.wanted_spec.format = AUDIO_S16LSB;
wave.wanted_spec.channels = 1;
wave.wanted_spec.samples = 2048;
wave.wanted_spec.callback = playit;
wave.wanted_spec.userdata = s_chAudioBuf;
if(SDL_OpenAudio(&wave.wanted_spec, NULL) < 0)
{
printf(“SDL_OpenAudio failed!!”);
return -1;
}
SDL_PauseAudio(0);
SDL_Delay(1000);
SDL_CloseAudio();

I can’t here any sound using this way, can anyone help me to solve it?
Thanks.

Best regards,
Arthur

Does the loopwave test program in the SDL source archive work for you?
It basically does the same thing…On Wed, Sep 9, 2009 at 4:57 AM, Arthur Chen <zijian.ping at gmail.com> wrote:

Hi all,

I am working at using SDL to playback network audio stream, but I don’t know
how to do it.
I found some tutorials and tried the following way,but it didn’t work.
The received audio data format is AFMT_S16_LE (OSS format), I store the data
in a buffer,
s_chAudioBuf[1024096], when the buffer is filled, I use SDL to play it.
the callback function is playit:
void SDLCALL playit(void *unused, Uint8 *stream, int len)
{
Uint32 amount = wave.soundlen - wave.soundpos;
if (amount > len)
amount = len;
SDL_MixAudio(stream, &wave.sound[wave.soundpos], amount, SDL_MIX_MAXVOLUME);
wave.soundpos += amount;
}

the main code here:
if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
perror(“Initializing”);
return false;
}
wave.wanted_spec.freq = 44100;
wave.wanted_spec.format = AUDIO_S16LSB;
wave.wanted_spec.channels = 1;
wave.wanted_spec.samples = 2048;
wave.wanted_spec.callback = playit;
wave.wanted_spec.userdata = s_chAudioBuf;
if(SDL_OpenAudio(&wave.wanted_spec, NULL) < 0)
{
printf(“SDL_OpenAudio failed!!”);
return -1;
}
SDL_PauseAudio(0);
SDL_Delay(1000);
SDL_CloseAudio();
I can’t here any sound using this way, can anyone help me to solve it?
Thanks.
Best regards,
Arthur


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC