SDL Audio Functions

Hi,

I’m trying to do some experiments with RAW audio using SDL,
but I’m not understanding it’s documentation.

Anyone have a sample on loading RAW audio data and playing ?

I need to play very large files… and must be the basic RAW
audio functions (not 3rdparty libs like SDL_mixer, please).

Thanks,

Herbert

Hi,

I’m trying to do some experiments with RAW audio using SDL,
but I’m not understanding it’s documentation.

Anyone have a sample on loading RAW audio data and playing ?

I need to play very large files… and must be the basic RAW
audio functions (not 3rdparty libs like SDL_mixer, please).

Have you looked at loopwave.c in the test subdirectory of the source archive?
To stream, just load the data yourself and feed it in the audio callback.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Thanks!

Another question… did you have some URL or document
that explains in detail the 44100,16,Stereo RAW
format ?

[]s,

Herbert

Sam Lantinga wrote:>>Hi,

I’m trying to do some experiments with RAW audio using SDL,
but I’m not understanding it’s documentation.

Anyone have a sample on loading RAW audio data and playing ?

I need to play very large files… and must be the basic RAW
audio functions (not 3rdparty libs like SDL_mixer, please).

Have you looked at loopwave.c in the test subdirectory of the source archive?
To stream, just load the data yourself and feed it in the audio callback.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Can you tell me what is wrong on this ??

I’m not understanding how there functions work…

Sam Lantinga wrote:

Hi,

I’m trying to do some experiments with RAW audio using SDL,
but I’m not understanding it’s documentation.

Anyone have a sample on loading RAW audio data and playing ?

I need to play very large files… and must be the basic RAW
audio functions (not 3rdparty libs like SDL_mixer, please).

Have you looked at loopwave.c in the test subdirectory of the source archive?
To stream, just load the data yourself and feed it in the audio callback.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: main.cpp
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030814/9fd9dae2/attachment.asc

Forget this… I did it…

H. G. Fischer wrote:> Can you tell me what is wrong on this ??

I’m not understanding how there functions work…

Sam Lantinga wrote:

Hi,

I’m trying to do some experiments with RAW audio using SDL,
but I’m not understanding it’s documentation.

Anyone have a sample on loading RAW audio data and playing ?

I need to play very large files… and must be the basic RAW
audio functions (not 3rdparty libs like SDL_mixer, please).

Have you looked at loopwave.c in the test subdirectory of the source
archive?
To stream, just load the data yourself and feed it in the audio callback.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


#include <SDL/SDL.h>
#include <stdlib.h>
#include <string.h>

void fill_audio(void *udata, Uint8 *stream, int len);

static Uint8 *audio_chunk;
static Uint32 audio_len;
static Uint8 *audio_pos;

int main (int argc, char* argv[])
{
printf(“Initializing SDL.\n”);

if (( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1 ))
{
printf(“Could not initialize SDL: %s.\n”, SDL_GetError());
return -1;
}
else
{
atexit(SDL_Quit);
}

SDL_AudioSpec wanted;

wanted.freq = 44100;
wanted.format = AUDIO_S16;
wanted.channels = 2;
wanted.samples = 1024;
wanted.callback = fill_audio;
wanted.userdata = NULL;

if ( SDL_OpenAudio(&wanted, NULL) < 0 )
{
fprintf(stderr, “Couldn’t open audio: %s\n”, SDL_GetError());
return -1;
}

FILE* f = fopen(“EdMotta/van.raw”, “r”);
if (f == NULL)
{
fprintf(stderr, “Couldn’t open file: %s\n”, strerror(errno));
return -1;
}
fseek(f, 0, SEEK_END);
audio_len = ftell(f);
fseek(f, 0, SEEK_SET);
printf("%ul\n", audio_len);

audio_chunk = (Uint8 *)calloc(1, audio_len);
fread(audio_chunk, 1, audio_len, f);
fclose(f);

audio_pos = audio_chunk;

SDL_PauseAudio(0);

while ( audio_len > 0 )
{
SDL_Delay(100);
}

SDL_CloseAudio();

return 0;
}

void fill_audio(void *udata, Uint8 *stream, int len)
{
if ( audio_len == 0 )
return;

len = ( len > audio_len ? audio_len : len );
SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
audio_pos += len;
audio_len -= len;
}