Generating and playing waves

I’m messing around with SDL and generating wave files. It works fine and I get
some nice tones. Now, I want to skip writing the file and just write the wav
to a buffer and have the audio callback function use that buffer to playback
the sound. However, I am having difficulties.

What I am currently doing is generating the wav and putting it in a buffer that
is used in the general fill_audio() callback function. But the call to
SDL_MixAudio() generates an error (could not read memory at 0x00000001).

Does the wav_buffer need to also have the header information, or does it only
need the samples? How is the wav_buffer allocated? I’m using 16-bit stereo
audio. I’ve tried allocating a 1-dim array and filling it sequentially. I’ve
tried allocating a 2-dim array (total number of samples * 2 bytes per sample).
Both of them give the same error. I tried looking in the source, but I
couldn’t find anything I could understand. If I tack on the header and write
the whole thing to a file, it plays fine. I just can’t get it to go through
SDL_MixAudio().

Any suggestions?

I believe David Olofson has some code that does this:

http://olofson.net/mixed.html

Check out speaker.tar.gz. It support other outputs for sound in
addition to SDL, but if you ignore that part you can see how he is
doing it with SDL for the generated sounds.

ChrisOn Thu, 4 Nov 2004 05:55:04 +0000 (UTC), Luke wrote:

I’m messing around with SDL and generating wave files. It works fine and I get
some nice tones. Now, I want to skip writing the file and just write the wav
to a buffer and have the audio callback function use that buffer to playback
the sound. However, I am having difficulties.


Chris Nystrom
http://www.newio.org/~ccn
AIM: nystromchris

Just out of curiosity, would it be possible for me to see
the source of this project?

Thanks,

Paul LoweOn Wednesday 03 November 2004 09:55 pm, Luke wrote:

I’m messing around with SDL and generating wave files.
It works fine and I get some nice tones. Now, I want to
skip writing the file and just write the wav to a buffer
and have the audio callback function use that buffer to
playback the sound. However, I am having difficulties.

What I am currently doing is generating the wav and
putting it in a buffer that is used in the general
fill_audio() callback function. But the call to
SDL_MixAudio() generates an error (could not read memory
at 0x00000001).

Does the wav_buffer need to also have the header
information, or does it only need the samples? How is
the wav_buffer allocated? I’m using 16-bit stereo audio.
I’ve tried allocating a 1-dim array and filling it
sequentially. I’ve tried allocating a 2-dim array (total
number of samples * 2 bytes per sample). Both of them
give the same error. I tried looking in the source, but
I couldn’t find anything I could understand. If I tack
on the header and write the whole thing to a file, it
plays fine. I just can’t get it to go through
SDL_MixAudio().

Any suggestions?


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