[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] remove duplicate implementations of a function
From: |
Trevor Saunders |
Subject: |
[PATCH] remove duplicate implementations of a function |
Date: |
Thu, 2 Sep 2010 02:43:36 -0400 |
espeak, ibmtts, and ivona all had there own <module_name>_play_file()
function replace them with a single implementation in module_utils.c
---
src/modules/espeak.c | 73 +-----------------------------------------
src/modules/ibmtts.c | 74 +-----------------------------------------
src/modules/ivona_client.c | 77 +-------------------------------------------
src/modules/module_utils.c | 71 ++++++++++++++++++++++++++++++++++++++++
src/modules/module_utils.h | 1 +
5 files changed, 75 insertions(+), 221 deletions(-)
diff --git a/src/modules/espeak.c b/src/modules/espeak.c
index be96cd2..e9a90ef 100644
--- a/src/modules/espeak.c
+++ b/src/modules/espeak.c
@@ -175,7 +175,6 @@ static gboolean espeak_add_mark_to_playback_queue(const
char *markId);
static gboolean espeak_add_flag_to_playback_queue(EPlaybackQueueEntryType
type);
static void espeak_delete_playback_queue_entry(TPlaybackQueueEntry
*playback_queue_entry);
static gboolean espeak_send_to_audio(TPlaybackQueueEntry
*playback_queue_entry);
-static gboolean espeak_play_file(char *filename);
/* Miscellaneous internal function prototypes. */
static gboolean is_thread_busy(pthread_mutex_t *suspended_mutex);
@@ -1091,7 +1090,7 @@ _espeak_play(void* nothing)
pthread_mutex_unlock(&espeak_state_mutex);
break;
case ESPEAK_QET_SOUND_ICON:
-
espeak_play_file(playback_queue_entry->data.sound_icon_filename);
+
utils_play_file(playback_queue_entry->data.sound_icon_filename);
break;
case ESPEAK_QET_BEGIN:
{
@@ -1129,76 +1128,6 @@ _espeak_play(void* nothing)
return 0;
}
-/* Plays the specified audio file. */
-static gboolean
-espeak_play_file(char *filename)
-{
- gboolean result = TRUE;
-#if HAVE_SNDFILE
- int subformat;
- sf_count_t items;
- sf_count_t readcount;
- SNDFILE* sf;
- SF_INFO sfinfo;
-
- DBG("Espeak: Playing |%s|", filename);
- memset (&sfinfo, 0, sizeof (sfinfo));
- sf = sf_open(filename, SFM_READ, &sfinfo);
- subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
- items = sfinfo.channels * sfinfo.frames;
- DBG("Espeak: frames = %ld, channels = %d", sfinfo.frames,
sfinfo.channels);
- DBG("Espeak: samplerate = %i, items = %Ld", sfinfo.samplerate, (long
long) items);
- DBG("Espeak: major format = 0x%08X, subformat = 0x%08X, endian =
0x%08X",
- sfinfo.format & SF_FORMAT_TYPEMASK, subformat, sfinfo.format &
SF_FORMAT_ENDMASK);
- if (sfinfo.channels < 1 || sfinfo.channels > 2) {
- DBG("Espeak: ERROR: channels = %d.\n", sfinfo.channels);
- result = FALSE;
- goto cleanup1;
- }
- if (sfinfo.frames > 0x7FFFFFFF) {
- DBG("Espeak: ERROR: Unknown number of frames.");
- result = FALSE;
- goto cleanup1;
- }
- if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE) {
- /* Set scaling for float to integer conversion. */
- sf_command (sf, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
- }
- AudioTrack track;
- track.num_samples = sfinfo.frames;
- track.num_channels = sfinfo.channels;
- track.sample_rate = sfinfo.samplerate;
- track.bits = 16;
- track.samples = malloc(items * sizeof(short));
- if (NULL == track.samples) {
- DBG("Espeak: ERROR: Cannot allocate audio buffer.");
- result = FALSE;
- goto cleanup1;
- }
- readcount = sf_read_short(sf, (short *) track.samples, items);
- DBG("Espeak: read %Ld items from audio file.", (long long) readcount);
-
- if (readcount > 0) {
- track.num_samples = readcount / sfinfo.channels;
- DBG("Espeak: Sending %i samples to audio.", track.num_samples);
- /* Volume is controlled by the synthesizer. Always play at
normal on audio device. */
- spd_audio_set_volume(module_audio_id, EspeakSoundIconVolume);
- int ret = spd_audio_play(module_audio_id, track, SPD_AUDIO_LE);
- if (ret < 0) {
- DBG("ERROR: Can't play track for unknown reason.");
- result = FALSE;
- goto cleanup2;
- }
- DBG("Espeak: Sent to audio.");
- }
- cleanup2:
- xfree(track.samples);
- cleanup1:
- sf_close(sf);
-#endif
- return result;
-}
-
static VoiceDescription**
espeak_list_synthesis_voices()
{
diff --git a/src/modules/ibmtts.c b/src/modules/ibmtts.c
index 45a30f6..f9a88c7 100644
--- a/src/modules/ibmtts.c
+++ b/src/modules/ibmtts.c
@@ -278,7 +278,6 @@ static TIbmttsBool ibmtts_add_mark_to_playback_queue(long
markId);
static TIbmttsBool ibmtts_add_flag_to_playback_queue(EPlaybackQueueEntryType
type);
static void ibmtts_delete_playback_queue_entry(TPlaybackQueueEntry
*playback_queue_entry);
static TIbmttsBool ibmtts_send_to_audio(TPlaybackQueueEntry
*playback_queue_entry);
-static TIbmttsBool ibmtts_play_file(char *filename);
/* Miscellaneous internal function prototypes. */
static TIbmttsBool is_thread_busy(pthread_mutex_t *suspended_mutex);
@@ -1469,7 +1468,7 @@ _ibmtts_play(void* nothing)
}
break;
case IBMTTS_QET_SOUND_ICON:
-
ibmtts_play_file(playback_queue_entry->data.sound_icon_filename);
+
utils_play_file(playback_queue_entry->data.sound_icon_filename);
break;
case IBMTTS_QET_BEGIN:
module_report_event_begin();
@@ -1572,77 +1571,6 @@ ibmtts_search_for_sound_icon(const char *icon_name)
return fn;
}
-/* Plays the specified audio file. */
-static TIbmttsBool
-ibmtts_play_file(char *filename)
-{
- TIbmttsBool result = IBMTTS_TRUE;
-#if HAVE_SNDFILE
- int subformat;
- sf_count_t items;
- sf_count_t readcount;
- SNDFILE* sf;
- SF_INFO sfinfo;
-
- DBG("Ibmtts: Playing |%s|", filename);
- memset (&sfinfo, 0, sizeof (sfinfo));
- sf = sf_open(filename, SFM_READ, &sfinfo);
- subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
- items = sfinfo.channels * sfinfo.frames;
- DBG("Ibmtts: frames = %ld, channels = %d", (long) sfinfo.frames,
sfinfo.channels);
- DBG("Ibmtts: samplerate = %i, items = %Ld", sfinfo.samplerate, items);
- DBG("Ibmtts: major format = 0x%08X, subformat = 0x%08X, endian = 0x%08X",
- sfinfo.format & SF_FORMAT_TYPEMASK, subformat, sfinfo.format &
SF_FORMAT_ENDMASK);
- if (sfinfo.channels < 1 || sfinfo.channels > 2) {
- DBG("Ibmtts: ERROR: channels = %d.\n", sfinfo.channels);
- result = IBMTTS_FALSE;
- goto cleanup1;
- }
- if (sfinfo.frames > 0x7FFFFFFF) {
- DBG("Ibmtts: ERROR: Unknown number of frames.");
- result = IBMTTS_FALSE;
- goto cleanup1;
- }
- if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE) {
- /* Set scaling for float to integer conversion. */
- sf_command (sf, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
- }
- AudioTrack track;
- track.num_samples = sfinfo.frames;
- track.num_channels = sfinfo.channels;
- track.sample_rate = sfinfo.samplerate;
- track.bits = 16;
- track.samples = xmalloc(items * sizeof(short));
- if (NULL == track.samples) {
- DBG("Ibmtts: ERROR: Cannot allocate audio buffer.");
- result = IBMTTS_FALSE;
- goto cleanup1;
- }
- readcount = sf_read_short(sf, (short *) track.samples, items);
- DBG("Ibmtts: read %Ld items from audio file.", readcount);
-
- if (readcount > 0) {
- track.num_samples = readcount / sfinfo.channels;
- DBG("Ibmtts: Sending %i samples to audio.", track.num_samples);
- /* Volume is controlled by the synthesizer. Always play at normal on
audio device. */
- spd_audio_set_volume(module_audio_id, 0);
- int ret = spd_audio_play(module_audio_id, track, SPD_AUDIO_LE);
- if (ret < 0) {
- DBG("ERROR: Can't play track for unknown reason.");
- result = IBMTTS_FALSE;
- goto cleanup2;
- }
- DBG("Ibmtts: Sent to audio.");
- }
-cleanup2:
- xfree(track.samples);
-cleanup1:
- sf_close(sf);
-#endif
- return result;
-}
-
-
void
alloc_voice_list()
{
diff --git a/src/modules/ivona_client.c b/src/modules/ivona_client.c
index ab7423c..559f08a 100644
--- a/src/modules/ivona_client.c
+++ b/src/modules/ivona_client.c
@@ -262,86 +262,11 @@ char *ivona_get_wave(char *to_say,int *nsamples,int
*offset)
return s;
}
-
-
-
-/* Plays the specified audio file - from ibmtts/espeak module */
-
-static gboolean
-ivona_play_file(char *filename)
-{
- gboolean result = TRUE;
-#if HAVE_SNDFILE
- int subformat;
- sf_count_t items;
- sf_count_t readcount;
- SNDFILE* sf;
- SF_INFO sfinfo;
-
- DBG("Ivona: Playing |%s|", filename);
- memset (&sfinfo, 0, sizeof (sfinfo));
- sf = sf_open(filename, SFM_READ, &sfinfo);
- subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
- items = sfinfo.channels * sfinfo.frames;
- DBG("Ivona: frames = %ld, channels = %d", (long) sfinfo.frames,
sfinfo.channels);
- DBG("Ivona: samplerate = %i, items = %Ld", sfinfo.samplerate, (long
long) items);
- DBG("Ivona: major format = 0x%08X, subformat = 0x%08X, endian = 0x%08X",
- sfinfo.format & SF_FORMAT_TYPEMASK, subformat, sfinfo.format &
SF_FORMAT_ENDMASK);
- if (sfinfo.channels < 1 || sfinfo.channels > 2) {
- DBG("Ivona: ERROR: channels = %d.\n", sfinfo.channels);
- result = FALSE;
- goto cleanup1;
- }
- if (sfinfo.frames > 0x7FFFFFFF) {
- DBG("Ivona: ERROR: Unknown number of frames.");
- result = FALSE;
- goto cleanup1;
- }
- if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE) {
- /* Set scaling for float to integer conversion. */
- sf_command (sf, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
- }
- AudioTrack track;
- track.num_samples = sfinfo.frames;
- track.num_channels = sfinfo.channels;
- track.sample_rate = sfinfo.samplerate;
- track.bits = 16;
- track.samples = malloc(items * sizeof(short));
- if (NULL == track.samples) {
- DBG("Ivona: ERROR: Cannot allocate audio buffer.");
- result = FALSE;
- goto cleanup1;
- }
- readcount = sf_read_short(sf, (short *) track.samples, items);
- DBG("Ivona: read %Ld items from audio file.", (long long) readcount);
-
- if (readcount > 0) {
- track.num_samples = readcount / sfinfo.channels;
- DBG("Ivona: Sending %i samples to audio.", track.num_samples);
- /* Volume is controlled by the synthesizer. Always play at
normal on audio device. */
- //spd_audio_set_volume(module_audio_id, IvonaSoundIconVolume);
- int ret = spd_audio_play(module_audio_id, track, SPD_AUDIO_LE);
- if (ret < 0) {
- DBG("ERROR: Can't play track for unknown reason.");
- result = FALSE;
- goto cleanup2;
- }
- DBG("Ivona: Sent to audio.");
- }
- cleanup2:
- xfree(track.samples);
- cleanup1:
- sf_close(sf);
-#endif
- return result;
-}
-
-
void play_icon(char *name)
{
char buf[256];
sprintf(buf,"%s%s",IvonaSoundIconPath,name);
- ivona_play_file(buf);
+ utils_play_file(buf);
}
#define IVONA_CACHE_SIZE 256
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index 99167e6..e78f53f 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -1137,3 +1137,74 @@ module_audio_init_spd(char **status_info)
return -1;
}
+
+/* Plays the specified audio file. */
+gboolean
+utils_play_file(char *filename)
+{
+ gboolean result = TRUE;
+#if HAVE_SNDFILE
+ int subformat;
+ sf_count_t items;
+ sf_count_t readcount;
+ SNDFILE* sf;
+ SF_INFO sfinfo;
+
+ DBG("Espeak: Playing |%s|", filename);
+ memset (&sfinfo, 0, sizeof (sfinfo));
+ sf = sf_open(filename, SFM_READ, &sfinfo);
+ subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
+ items = sfinfo.channels * sfinfo.frames;
+ DBG("Espeak: frames = %ld, channels = %d", sfinfo.frames,
sfinfo.channels);
+ DBG("Espeak: samplerate = %i, items = %Ld", sfinfo.samplerate, (long
long) items);
+ DBG("Espeak: major format = 0x%08X, subformat = 0x%08X, endian =
0x%08X",
+ sfinfo.format & SF_FORMAT_TYPEMASK, subformat, sfinfo.format &
SF_FORMAT_ENDMASK);
+ if (sfinfo.channels < 1 || sfinfo.channels > 2) {
+ DBG("Espeak: ERROR: channels = %d.\n", sfinfo.channels);
+ result = FALSE;
+ goto cleanup1;
+ }
+ if (sfinfo.frames > 0x7FFFFFFF) {
+ DBG("Espeak: ERROR: Unknown number of frames.");
+ result = FALSE;
+ goto cleanup1;
+ }
+ if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE) {
+ /* Set scaling for float to integer conversion. */
+ sf_command (sf, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
+ }
+ AudioTrack track;
+ track.num_samples = sfinfo.frames;
+ track.num_channels = sfinfo.channels;
+ track.sample_rate = sfinfo.samplerate;
+ track.bits = 16;
+ track.samples = malloc(items * sizeof(short));
+ if (NULL == track.samples) {
+ DBG("Espeak: ERROR: Cannot allocate audio buffer.");
+ result = FALSE;
+ goto cleanup1;
+ }
+ readcount = sf_read_short(sf, (short *) track.samples, items);
+ DBG("Espeak: read %Ld items from audio file.", (long long) readcount);
+
+ if (readcount > 0) {
+ track.num_samples = readcount / sfinfo.channels;
+ DBG("Espeak: Sending %i samples to audio.", track.num_samples);
+ /* Volume is controlled by the synthesizer. Always play at
normal on audio device. */
+ spd_audio_set_volume(module_audio_id, EspeakSoundIconVolume);
+ int ret = spd_audio_play(module_audio_id, track, SPD_AUDIO_LE);
+ if (ret < 0) {
+ DBG("ERROR: Can't play track for unknown reason.");
+ result = FALSE;
+ goto cleanup2;
+ }
+ DBG("Espeak: Sent to audio.");
+ }
+ cleanup2:
+ xfree(track.samples);
+ cleanup1:
+ sf_close(sf);
+#endif
+ return result;
+}
+
diff --git a/src/modules/module_utils.h b/src/modules/module_utils.h
index e2b20e4..48a0e35 100644
--- a/src/modules/module_utils.h
+++ b/src/modules/module_utils.h
@@ -411,6 +411,7 @@ void module_report_event_pause(void);
pthread_mutex_t module_stdout_mutex;
int module_utils_init(void);
+gboolean utils_play_file(char *file);
int module_audio_init_spd(char **status_info);
int module_audio_init(char **status_info);
--
1.7.1
- [PATCH] remove duplicate implementations of a function,
Trevor Saunders <=