[SDL] No Sound Output

Rasmus Neckelmann neckelmann at gmail.com
Tue Nov 1 11:30:11 PST 2005


On 11/1/05, Timm Murray <tmurray-sdl at wumpus-cave.net> wrote:
> I have a simple program for playing wav files:
>
> ----
> #include <stdio.h>
> #include <SDL.h>
> #include <SDL_mixer.h>
>
>
> int main(int argc, char **argv)
> {
> char *file = argv[1];
> int done = 0;
> Mix_Chunk *wav;
> int ret;
>
> SDL_Init( SDL_INIT_AUDIO );
>
> ret = Mix_OpenAudio( 44100, AUDIO_S16SYS, 2, 4096 );
> if( 0 > ret ) {
>  printf( "Error opening audio: %s\n", Mix_GetError() );
>  exit(1);
> }
>
> printf( "Playing file: %s\n", file );
> wav = Mix_LoadWAV( file );
> ret = Mix_PlayChannel( -1, wav, -1 );
> if( 0 > ret ) {
>  printf( "Error playing audio: %s\n", Mix_GetError() );
> }
> else {
>  printf( "Played on channel %i\n", ret );
> }
> SDL_Delay( 50 );
>
> Mix_FreeChunk( wav );
> Mix_CloseAudio();
> SDL_Quit();
> return 0;
> }
> ----
>
> [snip]
> However, nothing comes out of the speakers. I hear the sound when using
> wavplay, so sound works fine on my system. This is on Linux w/ALSA, running
> SDL 1.2.6 and SDL_mixer 1.2.6.

You only gives your program 50 millisecs to play the sound before you quit.
Try with a  while(Mix_Playing(-1) > 0);  instead of the delay and see
what happens.

--
Regards,
Rasmus Neckelmann




More information about the SDL mailing list