DanieleC88
12-01-2005, 23:49
Come posso riprodurre un file Wave usando SDL? Sto usando questo codice:
Dichiarazione:
SDL_AudioSpec sdl_desired = {
22050, /* frequency */
AUDIO_S16, /* format */
0, /* channels */
0, /* not used (computed by SDL) */
1024, /* samples */
0, /* not used (computed by SDL) */
0, /* not used (computed by SDL) */
mix_sound, /* callback function */
NULL /* not used (user data that we don't need) */
};
SDL_AudioSpec wav_audiospec;
unsigned char * wav_buffer = NULL;
unsigned int wav_length = 0;
unsigned int wav_position = 0;
Inizializzazione:
if (!SDL_OpenAudio(&sdl_desired, NULL))
{
fprintf(stderr, "Cannot open audio device (\"%s\").\n", SDL_GetError());
exit(ERROR);
}
else
{
if (!SDL_LoadWAV("data/background.wav", &wav_audiospec, &wav_buffer, &wav_length))
{
fprintf(stderr, "Cannot open audio file (\"%s\").\n", SDL_GetError());
exit(ERROR);
}
else
{
SDL_PauseAudio(FALSE);
}
}
Funzione di mixaggio:
void mix_sound(void * data, unsigned char * stream, int len)
{
SDL_MixAudio(stream, (wav_buffer+wav_position), len, SDL_MIX_MAXVOLUME);
wav_position += len;
wav_length -= len;
return;
}
Quando eseguo il codice non sento alcun suono. Dove sbaglio?
Dichiarazione:
SDL_AudioSpec sdl_desired = {
22050, /* frequency */
AUDIO_S16, /* format */
0, /* channels */
0, /* not used (computed by SDL) */
1024, /* samples */
0, /* not used (computed by SDL) */
0, /* not used (computed by SDL) */
mix_sound, /* callback function */
NULL /* not used (user data that we don't need) */
};
SDL_AudioSpec wav_audiospec;
unsigned char * wav_buffer = NULL;
unsigned int wav_length = 0;
unsigned int wav_position = 0;
Inizializzazione:
if (!SDL_OpenAudio(&sdl_desired, NULL))
{
fprintf(stderr, "Cannot open audio device (\"%s\").\n", SDL_GetError());
exit(ERROR);
}
else
{
if (!SDL_LoadWAV("data/background.wav", &wav_audiospec, &wav_buffer, &wav_length))
{
fprintf(stderr, "Cannot open audio file (\"%s\").\n", SDL_GetError());
exit(ERROR);
}
else
{
SDL_PauseAudio(FALSE);
}
}
Funzione di mixaggio:
void mix_sound(void * data, unsigned char * stream, int len)
{
SDL_MixAudio(stream, (wav_buffer+wav_position), len, SDL_MIX_MAXVOLUME);
wav_position += len;
wav_length -= len;
return;
}
Quando eseguo il codice non sento alcun suono. Dove sbaglio?