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();
}