SDL sound help

Could anyone please link me to other SDL sound tutorials. I can’t get the
one on the sdl site to work. I get no error messages but theres no sound.
heres the code:

struct sounds {
Uint8 *data;
Uint32 dpos;
Uint32 dlen;
};

sounds sndwelcome;

void LoadSounds()
{
int index;
SDL_AudioSpec wave;
Uint8 *data;
Uint32 dlen;
SDL_AudioCVT cvt;

char file[60];
/* Load the sound file and convert it to 16-bit stereo at 22kHz */
sprintf(file, "chimes.wav");

if ( SDL_LoadWAV(file, &wave, &data, &dlen) == NULL ) {
fprintf(stderr, “Couldn’t load %s: %s\n”, file, SDL_GetError());
return;
}

SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq,

AUDIO_S16, 2, 22050);
cvt.buf = (Uint8*)malloc(dlencvt.len_mult); // I had to add (Uint8)
or else it wouldnt compile. If this is the problem would anyone know
how to fix it?

memcpy(cvt.buf, data, dlen);
cvt.len = dlen;
SDL_ConvertAudio(&cvt);
SDL_FreeWAV(data);

/* Put the sound data in the slot (it starts playing immediately) */
if ( sndwelcome.data ) {
    free(sndwelcome.data);
}
SDL_LockAudio();
sndwelcome.data = cvt.buf;
sndwelcome.dlen = cvt.len_cvt;
sndwelcome.dpos = 0;
SDL_UnlockAudio();

}

Hello norco,

Sunday, April 23, 2006, 3:49:53 AM, you wrote:

ntan> Could anyone please link me to other SDL sound tutorials. I can’t get the
ntan> one on the sdl site to work. I get no error messages but theres no sound.
ntan> heres the code:

Check how you are opening the sound library for a start.

http://www.libsdl.org/intro/usingsound.html

Also, if what you want is to play multiple sounds or play sound in a
"fire and forget" manner, you should use SDL_mixer instead.

The re-cast on malloc() is normal - C++ specifies that all void *
returning functions must now have an appropriate cast.–
Best regards,
Peter mailto:@Peter_Mulholland