Enlightenment CVS committal Author : kwo Project : e16 Module : e
Dir : e16/e/src Modified Files: Makefile.am edebug.h ipc.c sound.c sound.h sound_esd.c Added Files: sound_load.c Log Message: Sound - Split loading and playing. =================================================================== RCS file: /cvs/e/e16/e/src/Makefile.am,v retrieving revision 1.98 retrieving revision 1.99 diff -u -3 -r1.98 -r1.99 --- Makefile.am 15 Dec 2007 12:33:43 -0000 1.98 +++ Makefile.am 28 Jan 2008 21:20:09 -0000 1.99 @@ -180,7 +180,7 @@ else -MODULE_SRCS = sound_esd.c ttfont.c text_xft.c text_pango.c +MODULE_SRCS = sound_esd.c sound_load.c ttfont.c text_xft.c text_pango.c MODULE_LIBS = $(ESD_LIBS) $(PANGO_LIBS) $(XFT_LIBS) MODULE_CFLAGS = $(ESD_CFLAGS) $(PANGO_CFLAGS) $(XFT_CFLAGS) =================================================================== RCS file: /cvs/e/e16/e/src/edebug.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- edebug.h 26 Jan 2008 11:43:12 -0000 1.6 +++ edebug.h 28 Jan 2008 21:20:09 -0000 1.7 @@ -51,6 +51,7 @@ #define EDBUG_TYPE_DBUS 149 #define EDBUG_TYPE_TIMERS 150 #define EDBUG_TYPE_IDLERS 151 +#define EDBUG_TYPE_SOUND 152 #define EDBUG_TYPE_COMPMGR 161 #define EDBUG_TYPE_COMPMGR2 162 =================================================================== RCS file: /cvs/e/e16/e/src/ipc.c,v retrieving revision 1.305 retrieving revision 1.306 diff -u -3 -r1.305 -r1.306 --- ipc.c 21 Dec 2007 22:04:54 -0000 1.305 +++ ipc.c 28 Jan 2008 21:20:09 -0000 1.306 @@ -1415,8 +1415,15 @@ #if !USE_COMPOSITE else if (!strcmp(param1, "cm")) { - DialogOKstr(_("Message"), - _("Enlightenment was built without composite support")); + DialogOK(_("Message"), _("e16 was built without %s support"), + _("composite")); + } +#endif +#if !HAVE_SOUND + else if (!strcmp(param1, "sound")) + { + DialogOK(_("Message"), _("e16 was built without %s support"), + _("sound")); } #endif else =================================================================== RCS file: /cvs/e/e16/e/src/sound.c,v retrieving revision 1.57 retrieving revision 1.58 diff -u -3 -r1.57 -r1.58 --- sound.c 4 Sep 2007 21:15:21 -0000 1.57 +++ sound.c 28 Jan 2008 21:20:09 -0000 1.58 @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2007 Kim Woelders + * Copyright (C) 2004-2008 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -36,6 +36,8 @@ Sample *sample; } SoundClass; +#define SC_NAME(sc) ((sc) ? (sc)->name : "(none)") + static struct { char enable; @@ -47,9 +49,11 @@ #if USE_MODULES static const SoundOps *ops = NULL; #else +#if defined(HAVE_SOUND_ESD) extern const SoundOps SoundOps_esd; static const SoundOps *ops = &SoundOps_esd; #endif +#endif static void _SclassSampleDestroy(void *data, void *user_data __UNUSED__) @@ -59,7 +63,7 @@ if (!sclass || !sclass->sample) return; - if (ops && ops->SampleDestroy) + if (ops) ops->SampleDestroy(sclass->sample); sclass->sample = NULL; } @@ -105,7 +109,7 @@ if (!sclass || !Conf_sound.enable) return; - if (!sclass->sample && ops && ops->SampleLoad) + if (!sclass->sample) { char *file; @@ -115,21 +119,20 @@ sclass->sample = ops->SampleLoad(file); Efree(file); } - else + if (!sclass->sample) { DialogOK(_("Error finding sound file"), _("Warning! Enlightenment was unable to load the\n" "following sound file:\n%s\n" "Enlightenment will continue to operate, but you\n" "may wish to check your configuration settings.\n"), - file); + sclass->file); + SclassDestroy(sclass); + return; } } - if (sclass->sample && ops && ops->SamplePlay) - ops->SamplePlay(sclass->sample); - else - SclassDestroy(sclass); + ops->SamplePlay(sclass->sample); } static int @@ -156,6 +159,10 @@ return; sclass = SclassFind(name); + + if (EDebug(EDBUG_TYPE_SOUND)) + Eprintf("%s: %s file=%s\n", "SclassApply", name, SC_NAME(sclass)); + SclassApply(sclass); } @@ -201,7 +208,7 @@ { ecore_list_for_each(sound_list, _SclassSampleDestroy, NULL); - if (ops && ops->Exit) + if (ops) ops->Exit(); Conf_sound.enable = 0; @@ -300,18 +307,10 @@ DialogItemTableSetOptions(table, 2, 0, 0, 0); -#ifdef HAVE_LIBESD di = DialogAddItem(table, DITEM_CHECKBUTTON); DialogItemSetColSpan(di, 2); DialogItemSetText(di, _("Enable sounds")); DialogItemCheckButtonSetPtr(di, &tmp_audio); -#else - di = DialogAddItem(table, DITEM_TEXT); - DialogItemSetColSpan(di, 2); - DialogItemSetText(di, - _("Audio not available since EsounD was not\n" - "present at the time of compilation.")); -#endif } const DialogDef DlgSound = { =================================================================== RCS file: /cvs/e/e16/e/src/sound.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- sound.h 23 Aug 2007 18:48:21 -0000 1.1 +++ sound.h 28 Jan 2008 21:20:09 -0000 1.2 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007 Kim Woelders + * Copyright (C) 2004-2008 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -25,6 +25,15 @@ #include "config.h" +typedef struct +{ + unsigned int channels; + unsigned int bit_per_sample; + unsigned int rate; + void *data; + unsigned int size; /* N. bytes in data */ +} SoundSampleData; + typedef struct _sample Sample; typedef struct @@ -42,5 +51,7 @@ #else #define SoundPlay(name) do{}while(0) #endif + +int SoundSampleGetData(const char *file, SoundSampleData * ssd); #endif /* _SOUND_H_ */ =================================================================== RCS file: /cvs/e/e16/e/src/sound_esd.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- sound_esd.c 12 Sep 2007 21:33:50 -0000 1.3 +++ sound_esd.c 28 Jan 2008 21:20:09 -0000 1.4 @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2007 Kim Woelders + * Copyright (C) 2004-2008 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -22,10 +22,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "E.h" -#if defined(HAVE_SOUND) && defined(HAVE_LIBESD) +#if defined(HAVE_SOUND) && defined(HAVE_SOUND_ESD) #include "sound.h" #include <esd.h> -#include <audiofile.h> #ifdef USE_MODULES #define Estrdup strdup @@ -33,75 +32,68 @@ struct _sample { - char *file; /* We should not need this */ - int rate; - int format; - int samples; - unsigned char *data; + SoundSampleData ssd; int id; }; static int sound_fd = -1; static Sample * -_esd_Load(const char *file) +_sound_esd_Load(const char *file) { - AFfilehandle in_file; Sample *s; - int in_format, in_width, in_channels, frame_count; - int bytes_per_frame, frames_read; - double in_rate; + int err, format; - in_file = afOpenFile(file, "r", NULL); - if (!in_file) + if (sound_fd < 0) return NULL; - s = EMALLOC(Sample, 1); + s = ECALLOC(Sample, 1); if (!s) + return NULL; + + err = SoundSampleGetData(file, &s->ssd); + if (err) { - afCloseFile(in_file); + Efree(s); return NULL; } - frame_count = afGetFrameCount(in_file, AF_DEFAULT_TRACK); - in_channels = afGetChannels(in_file, AF_DEFAULT_TRACK); - in_rate = afGetRate(in_file, AF_DEFAULT_TRACK); - afGetSampleFormat(in_file, AF_DEFAULT_TRACK, &in_format, &in_width); -#ifdef WORDS_BIGENDIAN - afSetVirtualByteOrder(in_file, AF_DEFAULT_TRACK, AF_BYTEORDER_BIGENDIAN); -#else - afSetVirtualByteOrder(in_file, AF_DEFAULT_TRACK, AF_BYTEORDER_LITTLEENDIAN); -#endif - s->file = Estrdup(file); - s->rate = 44100; - s->format = ESD_STREAM | ESD_PLAY; - s->samples = 0; - s->data = NULL; - s->id = 0; - - if (in_width == 8) - s->format |= ESD_BITS8; - else if (in_width == 16) - s->format |= ESD_BITS16; - bytes_per_frame = (in_width * in_channels) / 8; - if (in_channels == 1) - s->format |= ESD_MONO; - else if (in_channels == 2) - s->format |= ESD_STEREO; - s->rate = (int)in_rate; + format = ESD_STREAM | ESD_PLAY; + if (s->ssd.bit_per_sample == 8) + format |= ESD_BITS8; + else if (s->ssd.bit_per_sample == 16) + format |= ESD_BITS16; + if (s->ssd.channels == 1) + format |= ESD_MONO; + else if (s->ssd.channels == 2) + format |= ESD_STEREO; - s->samples = frame_count * bytes_per_frame; - s->data = EMALLOC(unsigned char, frame_count * bytes_per_frame); + s->id = esd_sample_getid(sound_fd, file); + if (s->id < 0) + { + int confirm; + + s->id = esd_sample_cache(sound_fd, format, s->ssd.rate, s->ssd.size, + file); + write(sound_fd, s->ssd.data, s->ssd.size); + confirm = esd_confirm_sample_cache(sound_fd); + if (confirm != s->id) + s->id = 0; + } - frames_read = afReadFrames(in_file, AF_DEFAULT_TRACK, s->data, frame_count); - afCloseFile(in_file); + _EFREE(s->ssd.data); + if (s->id <= 0) + _EFREE(s); return s; } static void -_esd_Destroy(Sample * s) +_sound_esd_Destroy(Sample * s) { + if (!s) + return; + if (s->id && sound_fd >= 0) { /* Why the hell is this symbol not in esd? */ @@ -109,44 +101,22 @@ /* esd_sample_kill(sound_fd,s->id); */ esd_sample_free(sound_fd, s->id); } - if (s->data) - Efree(s->data); - if (s->file) - Efree(s->file); - if (s) - Efree(s); + _EFREE(s->ssd.data); + Efree(s); } static void -_esd_Play(Sample * s) +_sound_esd_Play(Sample * s) { - int size, confirm = 0; - if (sound_fd < 0 || !s) return; - if (!s->id && s->data) - { - size = s->samples; - s->id = esd_sample_getid(sound_fd, s->file); - if (s->id < 0) - { - s->id = - esd_sample_cache(sound_fd, s->format, s->rate, size, s->file); - write(sound_fd, s->data, size); - confirm = esd_confirm_sample_cache(sound_fd); - if (confirm != s->id) - s->id = 0; - } - Efree(s->data); - s->data = NULL; - } if (s->id > 0) esd_sample_play(sound_fd, s->id); } static int -_esd_Init(void) +_sound_esd_Init(void) { if (sound_fd >= 0) return 0; @@ -157,7 +127,7 @@ } static void -_esd_Exit(void) +_sound_esd_Exit(void) { if (sound_fd < 0) return; @@ -168,7 +138,8 @@ __EXPORT__ extern const SoundOps SoundOps_esd; const SoundOps SoundOps_esd = { - _esd_Init, _esd_Exit, _esd_Load, _esd_Destroy, _esd_Play, + _sound_esd_Init, _sound_esd_Exit, _sound_esd_Load, _sound_esd_Destroy, + _sound_esd_Play, }; #endif /* HAVE_SOUND && HAVE_LIBESD */ ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs