Browse Source

cleanup: reduce code duplication with a new function

StatusCreateTerminatedMsg.

This is not covered by current tests.
master
Juho Hiltunen 2 years ago
parent
commit
8021528f5e
1 changed files with 25 additions and 32 deletions
  1. 25
    32
      src/libespeak-ng/speech.c

+ 25
- 32
src/libespeak-ng/speech.c View File

@@ -63,6 +63,8 @@
#include "voice.h" // for FreeVoiceList, VoiceReset, current_...
#include "wavegen.h" // for WavegenFill, WavegenInit, WcmdqUsed

static espeak_ng_STATUS StatusCreateTerminatedMsg(t_espeak_command *c1, unsigned int *unique_identifier, void *user_data);

unsigned char *outbuf = NULL;
int outbuf_size = 0;
unsigned char *out_start;
@@ -686,22 +688,7 @@ espeak_ng_Synthesize(const void *text, size_t size,
*unique_identifier = c1->u.my_text.unique_identifier;
}

// Create the "terminated msg" command (same uid)
t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data);

// Try to add these 2 commands (single transaction)
if (c1 && c2) {
espeak_ng_STATUS status = fifo_add_commands(c1, c2);
if (status != ENS_OK) {
delete_espeak_command(c1);
delete_espeak_command(c2);
}
return status;
}

delete_espeak_command(c1);
delete_espeak_command(c2);
return ENOMEM;
return StatusCreateTerminatedMsg(c1, unique_identifier, user_data);
#else
return sync_espeak_Synth(0, text, position, position_type, end_position, flags, user_data);
#endif
@@ -736,22 +723,7 @@ espeak_ng_SynthesizeMark(const void *text,
*unique_identifier = c1->u.my_mark.unique_identifier;
}

// Create the "terminated msg" command (same uid)
t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data);

// Try to add these 2 commands (single transaction)
if (c1 && c2) {
espeak_ng_STATUS status = fifo_add_commands(c1, c2);
if (status != ENS_OK) {
delete_espeak_command(c1);
delete_espeak_command(c2);
}
return status;
}

delete_espeak_command(c1);
delete_espeak_command(c2);
return ENOMEM;
return StatusCreateTerminatedMsg(c1, unique_identifier, user_data);
#else
return sync_espeak_Synth_Mark(0, text, index_mark, end_position, flags, user_data);
#endif
@@ -964,4 +936,25 @@ ESPEAK_API const char *espeak_Info(const char **ptr)
return version_string;
}


#pragma GCC visibility pop


static espeak_ng_STATUS StatusCreateTerminatedMsg(t_espeak_command *c1, unsigned int *unique_identifier, void *user_data) {
// Create the "terminated msg" command (same uid)
t_espeak_command *c2 = create_espeak_terminated_msg(*unique_identifier, user_data);

// Try to add these 2 commands (single transaction)
if (c1 && c2) {
espeak_ng_STATUS status = fifo_add_commands(c1, c2);
if (status != ENS_OK) {
delete_espeak_command(c1);
delete_espeak_command(c2);
}
return status;
}

delete_espeak_command(c1);
delete_espeak_command(c2);
return ENOMEM;
}

Loading…
Cancel
Save