Back to index

gcompris  8.2.2
Classes | Defines | Typedefs | Enumerations | Functions | Variables
soundutil.h File Reference
#include <stdio.h>
#include "gcompris.h"
#include <glib-object.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _GcomprisSound
struct  _GcomprisSoundClass

Defines

#define MAX_QUEUE_LENGTH   5
#define MAX_SOUND_FILES   20
#define GCOMPRIS_SOUND_TYPE   (gc_sound_get_type ())
#define GCOMPRIS_SOUND(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCOMPRIS_SOUND_TYPE, GcomprisSound))
#define GCOMPRIS_SOUND_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), GCOMPRIS_SOUND_TYPE, GcomprisSoundClass))
#define GCOMPRIS_SOUND_IS(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCOMPRIS_SOUND_TYPE))
#define GCOMPRIS_SOUND_IS_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GCOMPRIS_SOUND_TYPE))
#define GCOMPRIS_SOUND_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GCOMPRIS_SOUND_TYPE, GcomprisSoundClass))

Typedefs

typedef void(* GcomprisSoundCallback )(gchar *)
typedef struct _GcomprisSound
typedef struct _GcomprisSoundClass
typedef struct _GcomprisSoundPrivate

Enumerations

enum  SoundPolicy { PLAY_ONLY_IF_IDLE = 0, PLAY_AFTER_CURRENT = 1, PLAY_AND_INTERRUPT = 2 }

Functions

void gc_sound_play_ogg (const gchar *,...)
void gc_sound_play_ogg_cb (const gchar *, GcomprisSoundCallback)
void gc_sound_play_ogg_list (GList *files)
void gc_sound_policy_set (int)
int gc_sound_policy_get (void)
void gc_sound_init (void)
void gc_sound_reopen (void)
void gc_sound_close (void)
void gc_sound_pause (void)
void gc_sound_resume (void)
int decode_ogg_file (char *infile)
void display_ao_devices ()
int sdlplayer_init ()
void sdlplayer_close ()
void sdlplayer_reopen ()
int sdlplayer_music (char *filename, int volume)
void sdlplayer_halt_music ()
void sdlplayer_pause_music ()
void sdlplayer_resume_music ()
void sdlplayer_halt_fx ()
void sdlplayer_resume_fx ()
int sdlplayer_fx (char *filename, int volume)
gchar * gc_sound_alphabet (gchar *chars)
 return a string representing a letter or number audio file get alphabet sound file name from gunichar
GType gc_sound_get_type (void)

Variables

GObject * gc_sound_controller

Class Documentation

struct _GcomprisSound

Definition at line 91 of file soundutil.h.

Class Members
GObject parent
GcomprisSoundPrivate * private

Define Documentation

#define GCOMPRIS_SOUND (   obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCOMPRIS_SOUND_TYPE, GcomprisSound))

Definition at line 81 of file soundutil.h.

#define GCOMPRIS_SOUND_CLASS (   klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GCOMPRIS_SOUND_TYPE, GcomprisSoundClass))

Definition at line 82 of file soundutil.h.

#define GCOMPRIS_SOUND_GET_CLASS (   obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GCOMPRIS_SOUND_TYPE, GcomprisSoundClass))

Definition at line 85 of file soundutil.h.

#define GCOMPRIS_SOUND_IS (   obj)    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCOMPRIS_SOUND_TYPE))

Definition at line 83 of file soundutil.h.

#define GCOMPRIS_SOUND_IS_CLASS (   klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), GCOMPRIS_SOUND_TYPE))

Definition at line 84 of file soundutil.h.

Definition at line 80 of file soundutil.h.

#define MAX_QUEUE_LENGTH   5

Definition at line 27 of file soundutil.h.

#define MAX_SOUND_FILES   20

Definition at line 28 of file soundutil.h.


Typedef Documentation

typedef struct _GcomprisSound

Definition at line 87 of file soundutil.h.

typedef struct _GcomprisSoundClass

Definition at line 88 of file soundutil.h.

typedef struct _GcomprisSoundPrivate

Definition at line 89 of file soundutil.h.

typedef void(* GcomprisSoundCallback)(gchar *)

Definition at line 37 of file soundutil.h.


Enumeration Type Documentation

Enumerator:
PLAY_ONLY_IF_IDLE 
PLAY_AFTER_CURRENT 
PLAY_AND_INTERRUPT 

Definition at line 30 of file soundutil.h.


Function Documentation

int decode_ogg_file ( char *  infile)
gchar* gc_sound_alphabet ( gchar *  chars)

return a string representing a letter or number audio file get alphabet sound file name from gunichar

the returned sound has the suffix .ogg

Returns:
a newly allocated string of the form U0033.ogg

Definition at line 454 of file soundutil.c.

{
  gchar *next, *str, *prev, *result;
  gint i;
  gint length;
  gunichar next_unichar;

  length = g_utf8_strlen(chars, -1);

  next = chars;
  result = NULL;

  for (i=0; i < length; i++) {
    next_unichar = g_utf8_get_char(next);
    str = g_strdup_printf("U%.4X",(gint32) g_unichar_tolower(next_unichar));
    prev = result;
    if (prev)
      result = g_strconcat( prev, str, NULL);
    else
      result = g_strdup(str);

    g_free(str);
    g_free(prev);
    next = g_utf8_next_char(next);
  }

  gchar *result2 = g_strdup_printf("%s.ogg",result);
  g_free(result);

  return result2;
}

Here is the caller graph for this function:

void gc_sound_close ( void  )

Definition at line 111 of file soundutil.c.

{
  if ( !sound_closed )
    {
      sdlplayer_halt_music();
      sdlplayer_halt_fx();
      g_mutex_lock(lock_fx);
      g_mutex_lock(lock_music);
      sdlplayer_close();
      sound_closed = TRUE;
      music_paused = FALSE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

GType gc_sound_get_type ( void  )

Definition at line 551 of file soundutil.c.

{
        static GType type = 0;
        if (type == 0) {
                static const GTypeInfo info = {
                        sizeof (GcomprisSoundClass),
                        NULL,   /* base_init */
                        NULL,   /* base_finalize */
                        gc_sound_class_init,   /* class_init */
                        NULL,   /* class_finalize */
                        NULL,   /* class_data */
                        sizeof (GcomprisSound),
                        0,      /* n_preallocs */
                        gc_sound_instance_init    /* instance_init */
                };
                type = g_type_register_static (G_TYPE_OBJECT,
                                               "GcomprisSoundType",
                                               &info, 0);
        }
        return type;
}

Here is the call graph for this function:

void gc_sound_init ( void  )

Definition at line 61 of file soundutil.c.

{

  /* Check to run the init once only */
  if(sound_init == 1)
    {
      if(sound_closed == TRUE)
       gc_sound_reopen();

         return;
    }
  sound_init = 1;

  gc_sound_controller = g_object_new (GCOMPRIS_SOUND_TYPE, NULL);

  g_signal_connect( gc_sound_controller,
                  "sound-played",
                  (GCallback) gc_sound_callback,
                  NULL);

  g_assert( gc_sound_controller != NULL );

  /* Initialize the thread system */
  if (!g_thread_supported ()) g_thread_init (NULL);

  lock = g_mutex_new ();
  lock_music = g_mutex_new ();
  lock_fx = g_mutex_new ();
  cond = g_cond_new ();

  sound_policy = PLAY_AFTER_CURRENT;

  if(sdlplayer_init()!=0) {
    /* Sound init failed. Desactivate the sound */
    gc_prop_get()->music = 0;
    gc_prop_get()->fx    = 0;
    return;
  }

  thread_scheduler_fx = g_thread_create((GThreadFunc)scheduler_fx, NULL, FALSE, NULL);
  if (thread_scheduler_fx == NULL)
    perror("create failed for fx scheduler");

  thread_scheduler_music = g_thread_create((GThreadFunc)scheduler_music, NULL, FALSE, NULL);
  if (thread_scheduler_music == NULL)
    perror("create failed for music scheduler");

}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_sound_pause ( void  )

Definition at line 139 of file soundutil.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_sound_play_ogg ( const gchar *  ,
  ... 
)

Definition at line 365 of file soundutil.c.

{
  va_list ap;
  char* tmp = NULL;
  GList* list = NULL;

  if(!sound || !gc_prop_get()->fx)
    return;

  list = g_list_append(list, (gpointer)sound);

  g_warning("Adding %s in the play list queue\n", sound);

  va_start( ap, sound);
  while( (tmp = va_arg (ap, char *)))
    {
      list = g_list_append(list, (gpointer)tmp);
    }
  va_end(ap);

  gc_sound_play_ogg_list( list );

  g_list_free(list);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_sound_play_ogg_cb ( const gchar *  ,
GcomprisSoundCallback   
)

Definition at line 338 of file soundutil.c.

{

  g_assert ( cb != NULL);

  /* g_intern_string is in 2.10 */
  const gchar *intern_file = g_quark_to_string( g_quark_from_string(file));

  if (!sound_callbacks)
    sound_callbacks = g_hash_table_new_full (g_str_hash,
                                       g_str_equal,
                                       NULL,
                                       NULL);

  /* i suppose there will not be two call of that function with same sound file before sound is played */
  g_hash_table_replace (sound_callbacks,
                     (gpointer)intern_file,
                     cb);
  gc_sound_play_ogg(intern_file, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_sound_play_ogg_list ( GList *  files)

Definition at line 402 of file soundutil.c.

{
  GList* list;
  char* tmpSound = NULL;

  if ( !gc_prop_get()->fx )
    return;

  if (        sound_policy == PLAY_ONLY_IF_IDLE &&
        g_list_length( pending_queue ) > 0 )
    return;

  if ( sound_policy == PLAY_AND_INTERRUPT ) {
    g_warning("halt music");
    while ( g_list_length(pending_queue) > 0 )
    {
      tmpSound = g_list_nth_data( pending_queue, 0 );
      pending_queue = g_list_remove( pending_queue, tmpSound );
      g_free(tmpSound);
    }
    sdlplayer_halt_fx();
  }

  g_mutex_lock (lock);

  list = g_list_first( files );
  while( list!=NULL )
    {
      if (g_list_length(pending_queue) < MAX_QUEUE_LENGTH)
       {
         pending_queue = g_list_append(pending_queue, g_strdup( (gchar*)(list->data) ));
       }
      list = g_list_next(list);
    }

  g_mutex_unlock (lock);

  // Tell the scheduler to check for new sounds to play
  g_warning("Tell the scheduler to check for new sounds to play\n");
  g_cond_signal (cond);

}

Here is the call graph for this function:

Here is the caller graph for this function:

int gc_sound_policy_get ( void  )

Definition at line 170 of file soundutil.c.

{
  return sound_policy;
}

Here is the caller graph for this function:

void gc_sound_policy_set ( int  )

Definition at line 156 of file soundutil.c.

Here is the caller graph for this function:

void gc_sound_reopen ( void  )

Definition at line 126 of file soundutil.c.

{
  if (sound_closed)
    {
      sdlplayer_reopen();
      g_mutex_unlock(lock_fx);
      g_mutex_unlock(lock_music);
      sound_closed = FALSE;
      music_paused = FALSE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_sound_resume ( void  )

Definition at line 146 of file soundutil.c.

Here is the call graph for this function:

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:

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

Definition at line 53 of file soundutil.c.