Back to index

gcompris  8.2.2
Functions | Variables
sdlplayer.c File Reference
#include "SDL.h"
#include "SDL_thread.h"
#include "SDL_mixer.h"
#include "SDL_audio.h"
#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>

Go to the source code of this file.

Functions

void errorv (char *str, va_list ap)
int cleanExit (char *str,...)
int sdlplayer_init ()
int sdlplayer_quit (Mix_Music *music)
int sdlplayer_music (char *filename, int volume)
int sdlplayer_fx (char *filename, int volume)
void sdlplayer_pause_music ()
void sdlplayer_halt_music ()
void sdlplayer_halt_fx ()
void sdlplayer_resume_music ()
void sdlplayer_resume_fx ()
void sdlplayer_close ()
void sdlplayer_reopen ()

Variables

Sint16 stream [2][4096]
int len = 4096
int bits = 0
int which = 0
int audio_buffers = 2048
static gboolean sound_closed = FALSE

Function Documentation

int cleanExit ( char *  str,
  ... 
)

Definition at line 60 of file sdlplayer.c.

{
  va_list ap;
  va_start(ap, str);
  errorv(str,ap);
  va_end(ap);
  Mix_CloseAudio();
  SDL_Quit();
  return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void errorv ( char *  str,
va_list  ap 
)

Definition at line 46 of file sdlplayer.c.

{
  vfprintf(stderr,str,ap);

  if(strcmp(Mix_GetError(), "Unrecognized file type (not VOC)")==0) {
    fprintf(stderr,"*** You need a version of \"SDL_mixer\" with OGG Vorbis supported ***\n");
    exit(EXIT_FAILURE);
  }

  fprintf(stderr,": %s.\n", Mix_GetError());
  fprintf(stderr,": %s.\n", SDL_GetError());

}

Here is the caller graph for this function:

void sdlplayer_close ( )

Definition at line 194 of file sdlplayer.c.

{
  sound_closed = TRUE;
  Mix_HaltMusic();
  Mix_HaltChannel(-1);
  Mix_CloseAudio();
}

Here is the caller graph for this function:

int sdlplayer_fx ( char *  filename,
int  volume 
)

Definition at line 131 of file sdlplayer.c.

{
  Mix_Chunk *sample;
  static int channel;

  g_warning("sdlplayer %s\n", filename);

  sample=Mix_LoadWAV_RW(SDL_RWFromFile(filename, "rb"), 1);
  if(!sample) {
    return(cleanExit("Mix_LoadWAV_RW"));
    // handle error
  }

  Mix_VolumeChunk(sample, MIX_MAX_VOLUME);

  if((channel=Mix_PlayChannel(-1, sample, 0))==-1) {
    return(cleanExit("Mix_LoadChannel(0x%p,1)",channel));
  }

  while(Mix_Playing(channel))
    {
      SDL_Delay(50);
    }

  // free the sample
  // Mix_Chunk *sample;
  Mix_FreeChunk(sample);

  g_warning("sdlplayer complete playing of %s\n", filename);

  return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 176 of file sdlplayer.c.

{
  if(!sound_closed)
    Mix_HaltChannel(-1);
}

Here is the caller graph for this function:

Definition at line 170 of file sdlplayer.c.

{
  if(!sound_closed)
    Mix_HaltMusic();
}

Here is the caller graph for this function:

int sdlplayer_init ( )

Definition at line 73 of file sdlplayer.c.

{
  int audio_rate,audio_channels;
  Uint16 audio_format;

  // initialize SDL for audio
  if(SDL_Init(SDL_INIT_AUDIO)<0)
    return(cleanExit("SDL_Init"));

  // initialize sdl mixer, open up the audio device
  if(Mix_OpenAudio(44100,MIX_DEFAULT_FORMAT,2,audio_buffers)<0)
    return(cleanExit("Mix_OpenAudio"));

  // print out some info on the audio device and stream
  Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
  bits=audio_format&0xFF;
  g_warning("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate,
           bits, audio_channels>1?"stereo":"mono", audio_buffers );

  return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int sdlplayer_music ( char *  filename,
int  volume 
)

Definition at line 106 of file sdlplayer.c.

{
  Mix_Music *music;

  g_warning("sdlplayer_bg %s\n", filename);

  // load the song
  if(!(music=Mix_LoadMUS(filename)))
    return(cleanExit("Mix_LoadMUS(\"%s\")",filename));

  if(Mix_PlayMusic(music, 1)==-1) {
    return(cleanExit("Mix_LoadMUS(0x%p,1)",music));
  }

  Mix_VolumeMusic(volume);

  // wait for the music to complete
  while(Mix_PlayingMusic() || Mix_PausedMusic())
    {
      SDL_Delay(50);
    }

  return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 164 of file sdlplayer.c.

{
  if(!sound_closed && Mix_PlayingMusic())
    Mix_PauseMusic();
}

Here is the caller graph for this function:

int sdlplayer_quit ( Mix_Music *  music)

Definition at line 95 of file sdlplayer.c.

{
  // free & close
  Mix_FreeMusic(music);
  Mix_CloseAudio();
  g_warning("SDL PLAYER SDL_Quit\n");
  SDL_Quit();

  return 0;
}
void sdlplayer_reopen ( )

Definition at line 201 of file sdlplayer.c.

{
  Mix_OpenAudio(44100,MIX_DEFAULT_FORMAT,2,audio_buffers);
  sound_closed = FALSE;
  Mix_ResumeMusic();
  Mix_Resume(-1);
}

Here is the caller graph for this function:

Definition at line 188 of file sdlplayer.c.

{
  if(!sound_closed)
    Mix_Resume(-1);
}

Here is the caller graph for this function:

Definition at line 182 of file sdlplayer.c.

{
  if(!sound_closed)
    Mix_ResumeMusic();
}

Here is the caller graph for this function:


Variable Documentation

int audio_buffers = 2048

Definition at line 39 of file sdlplayer.c.

int bits = 0

Definition at line 35 of file sdlplayer.c.

int len = 4096

Definition at line 35 of file sdlplayer.c.

gboolean sound_closed = FALSE [static]

Definition at line 41 of file sdlplayer.c.

Sint16 stream[2][4096]

Definition at line 34 of file sdlplayer.c.

int which = 0

Definition at line 35 of file sdlplayer.c.