diff options
Diffstat (limited to 'src/gc_sound/src')
-rw-r--r-- | src/gc_sound/src/gc-sound-item.c | 12 | ||||
-rw-r--r-- | src/gc_sound/src/gc-sound-mixer-SDL.c | 45 | ||||
-rw-r--r-- | src/gc_sound/src/gc-sound-object.c | 2 | ||||
-rw-r--r-- | src/gc_sound/src/test_gc_sound.c | 22 |
4 files changed, 48 insertions, 33 deletions
diff --git a/src/gc_sound/src/gc-sound-item.c b/src/gc_sound/src/gc-sound-item.c index d6aaebe..275a90f 100644 --- a/src/gc_sound/src/gc-sound-item.c +++ b/src/gc_sound/src/gc-sound-item.c @@ -166,6 +166,9 @@ gboolean gc_sound_item_play (GcSoundItem *self) void gc_sound_item_set_filename (GcSoundItem *self, gchar *filename) { + if (self->filename) + g_free (self->filename); + if (filename) { self->filename = g_strdup(filename); @@ -180,7 +183,7 @@ void gc_sound_item_set_filename (GcSoundItem *self, gchar *filename) gchar * gc_sound_item_get_filename (GcSoundItem *self) { - return self->filename; + return g_strdup(self->filename); } static void @@ -319,6 +322,13 @@ gc_sound_item_class_init(GcSoundItemClass* self_class) "The channel where this channel stand", GC_TYPE_SOUND_CHANNEL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property(go_class, + PROP_FILENAME, + g_param_spec_string ("filename", + "File to play", + "The sound file to play", + NULL, + G_PARAM_READWRITE)); /* signals */ /* enum { */ diff --git a/src/gc_sound/src/gc-sound-mixer-SDL.c b/src/gc_sound/src/gc-sound-mixer-SDL.c index 1edb622..64727da 100644 --- a/src/gc_sound/src/gc-sound-mixer-SDL.c +++ b/src/gc_sound/src/gc-sound-mixer-SDL.c @@ -70,7 +70,7 @@ gc_sound_mixer_sdl_open_audio (GcSoundMixer* mixer) return FALSE; } - self->audio_opened = FALSE; + self->audio_opened = TRUE; // print out some info on the audio device and stream Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); @@ -108,6 +108,13 @@ gc_sound_mixer_sdl_close_audio (GcSoundMixer * mixer) static void reset_channel_number(GcSoundChannel *channel, gboolean stopped, gpointer data) { channel->channel_number = GPOINTER_TO_INT(data); + GcSoundMixerSdl *self = GC_SOUND_MIXER_SDL(GC_SOUND_OBJECT(channel)->parent); + + /* if this channel is last in list, we can now reset numbers of channel */ + if (self->channels->len == channel->channel_number + 1){ + Mix_AllocateChannels(channel->channel_number + 1); + g_warning ("Numbers of channels allocated is now %d", Mix_AllocateChannels(-1)); + } } static void channel_destroyed(GcSoundChannel *channel, gpointer data) @@ -121,9 +128,8 @@ static void channel_destroyed(GcSoundChannel *channel, gpointer data) // not be finalized before it get this signal. gc_sound_mixer_halt_channel (GC_SOUND_MIXER(self), channel); } - + g_ptr_array_remove_index (self->channels, channel->channel_number); - g_object_unref (channel); /* channel reorganisation */ for (i = 0; i < self->channels->len; i++) { @@ -136,6 +142,15 @@ static void channel_destroyed(GcSoundChannel *channel, gpointer data) reset_channel_number ( i_channel, FALSE, GINT_TO_POINTER(i)); } } + + /* destroyed channel is last one */ + if (self->channels->len == channel->channel_number){ + Mix_AllocateChannels(channel->channel_number + 1); + g_warning ("Numbers of channels allocated is now %d", Mix_AllocateChannels(-1)); + } + + g_object_unref (channel); + } static GcSoundChannel *gc_sound_mixer_sdl_new_channel (GcSoundMixer * mixer) @@ -351,9 +366,8 @@ gc_sound_mixer_sdl_init (GcSoundMixerSdl* self) } /* like GtkWindow */ - g_object_ref_sink (self); + g_object_ref_sink (G_OBJECT(self)); self->has_user_ref_count = TRUE; - } enum { @@ -368,19 +382,10 @@ gc_sound_mixer_sdl_finalize (GObject* object) { GcSoundMixerSdl * self = GC_SOUND_MIXER_SDL(object); - running_mixer = NULL; - g_ptr_array_free (self->channels, TRUE); g_hash_table_destroy (self->samples); - if (self->audio_opened) - Mix_CloseAudio(); - - SDL_Quit(); - - g_warning("SDL audio closed"); - G_OBJECT_CLASS(parent_class)->finalize (object); } @@ -396,6 +401,18 @@ gc_sound_mixer_sdl_destroy (GcSoundObject *object) gc_sound_object_destroy (GC_SOUND_OBJECT(g_ptr_array_index(self->channels,i))); g_object_unref(G_OBJECT(g_ptr_array_index(self->channels,i))); } + + running_mixer = NULL; + + if (self->audio_opened){ + Mix_CloseAudio(); + self->audio_opened = FALSE; + g_warning ("SDL audio closed"); + } else + g_warning("mixer destroy: SDL audio was closed !"); + + SDL_Quit(); + if (self->has_user_ref_count) { diff --git a/src/gc_sound/src/gc-sound-object.c b/src/gc_sound/src/gc-sound-object.c index 67fad8f..f313cf6 100644 --- a/src/gc_sound/src/gc-sound-object.c +++ b/src/gc_sound/src/gc-sound-object.c @@ -1,4 +1,4 @@ -/* gcompris - gc-sound-object.h +/* gcompris - gc-sound-object.c * * Copyright (C) 2006 Yves Combe * diff --git a/src/gc_sound/src/test_gc_sound.c b/src/gc_sound/src/test_gc_sound.c index 082caf0..afa36dd 100644 --- a/src/gc_sound/src/test_gc_sound.c +++ b/src/gc_sound/src/test_gc_sound.c @@ -23,28 +23,16 @@ main (int argc, char *argv) gcmix = gc_sound_mixer_sdl_new(); GC_SOUND_OBJECT(gcmix)->nick = "gcmix"; - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); - /* We open two chans to play simultaneously */ gcchan1 = gc_sound_mixer_new_channel(gcmix); - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); - gcchan2 = gc_sound_mixer_new_channel(gcmix); - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); GC_SOUND_OBJECT(gcchan1)->nick = "gcchan1"; GC_SOUND_OBJECT(gcchan2)->nick = "gcchan2"; - //GcSoundMixer *gcmix2; - - //g_object_get(G_OBJECT(gcchan2), "parent", &gcmix2, NULL); - /* Each chan has a root item, where we group the sounds to play in that channel*/ root1 = GC_SOUND_ITEM(gc_sound_channel_get_root(gcchan1)); - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); - root2 = GC_SOUND_ITEM(gc_sound_channel_get_root(gcchan2)); - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); GC_SOUND_OBJECT(root1)->nick="root1"; GC_SOUND_OBJECT(root2)->nick="root2"; @@ -57,8 +45,6 @@ main (int argc, char *argv) item1_2 = gc_sound_item_append_child (item1); - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); - GC_SOUND_OBJECT(item1)->nick = "item1"; GC_SOUND_OBJECT(item2)->nick = "item2"; GC_SOUND_OBJECT(item3)->nick = "item3"; @@ -114,16 +100,18 @@ main (int argc, char *argv) gc_sound_item_play(item3); //gc_sound_object_destroy(GC_SOUND_OBJECT(gcchan2)); + g_warning("destroying item1"); gc_sound_object_destroy(GC_SOUND_OBJECT(item1)); - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); + g_usleep(3000000); + g_warning("destroying root2"); gc_sound_object_destroy(GC_SOUND_OBJECT(root2)); - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); g_usleep(3000000); + g_warning("destroying gcmix"); gc_sound_object_destroy(GC_SOUND_OBJECT(gcmix)); - g_warning("mix ref_count %d", G_OBJECT(gcmix)->ref_count); + //gc_sound_object_destroy(GC_SOUND_OBJECT(gcmix2)); g_usleep(3000000); |