From 7ffd31ba2584359996e04cd3d4d92f810d651066 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Thu, 19 May 2011 12:58:09 +0100 Subject: Break dependency between pico and the audio system. The TTS engine should use only TTS defined constants, and not constants from the audiosystem. This happened to work because PCM_16_BIT in native was the same as DEFAULT in java, which happened to be PCM_16_BIT. Change-Id: I0f43a46afff8c45d1eb18c1beaab62dce87b8055 --- pico/compat/include/TtsEngine.h | 18 +++++++++++++----- pico/compat/jni/com_android_tts_compat_SynthProxy.cpp | 5 +++++ pico/compat/jni/tts.h | 5 ++++- pico/tts/com_svox_picottsengine.cpp | 13 ++++++------- 4 files changed, 28 insertions(+), 13 deletions(-) (limited to 'pico') diff --git a/pico/compat/include/TtsEngine.h b/pico/compat/include/TtsEngine.h index 916118c..ed1a178 100644 --- a/pico/compat/include/TtsEngine.h +++ b/pico/compat/include/TtsEngine.h @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include // This header defines the interface used by the Android platform // to access Text-To-Speech functionality in shared libraries that implement @@ -42,6 +41,15 @@ enum tts_callback_status { TTS_CALLBACK_CONTINUE = 1 }; +// NOTE: This is duplicated in compat/jni/tts.h. Please +// make changes there as well. +enum tts_audio_format { + TTS_AUDIO_FORMAT_INVALID = -1, + TTS_AUDIO_FORMAT_DEFAULT = 0, + TTS_AUDIO_FORMAT_PCM_16_BIT = 1, + TTS_AUDIO_FORMAT_PCM_8_BIT = 2, +}; + // The callback is used by the implementation of this interface to notify its // client, the Android TTS service, that the last requested synthesis has been // completed. // TODO reword @@ -49,7 +57,7 @@ enum tts_callback_status { // @param [inout] void *& - The userdata pointer set in the original // synth call // @param [in] uint32_t - Track sampling rate in Hz -// @param [in] uint32_t - The audio format +// @param [in] tts_audio_format - The audio format // @param [in] int - The number of channels // @param [inout] int8_t *& - A buffer of audio data only valid during the // execution of the callback @@ -60,7 +68,7 @@ enum tts_callback_status { // TTS_CALLBACK_CONTINUE to indicate the synthesis must continue if // there is more data to produce. typedef tts_callback_status (synthDoneCB_t)(void *&, uint32_t, - uint32_t, int, int8_t *&, size_t&, tts_synth_status); + tts_audio_format, int, int8_t *&, size_t&, tts_synth_status); class TtsEngine; extern "C" TtsEngine* getTtsEngine(); @@ -83,6 +91,7 @@ enum tts_support_result { TTS_LANG_NOT_SUPPORTED = -2 }; + class TtsEngine { public: @@ -159,7 +168,7 @@ public: // @param[inout] channels in: the desired number of audio channels // out: the number of channels used by the TTS engine // @return TTS_SUCCESS, or TTS_FAILURE - virtual tts_result setAudioFormat(audio_format_t& encoding, uint32_t& rate, + virtual tts_result setAudioFormat(tts_audio_format& encoding, uint32_t& rate, int& channels); // Set a property for the the TTS engine @@ -229,4 +238,3 @@ public: }; } // namespace android - diff --git a/pico/compat/jni/com_android_tts_compat_SynthProxy.cpp b/pico/compat/jni/com_android_tts_compat_SynthProxy.cpp index c9c38c4..f410ee5 100644 --- a/pico/compat/jni/com_android_tts_compat_SynthProxy.cpp +++ b/pico/compat/jni/com_android_tts_compat_SynthProxy.cpp @@ -40,6 +40,11 @@ #define FILTER_GAIN 5.5f // linear gain // android.media.AudioFormat.ENCODING_ values +// +// Note that these constants are different from those +// defined in the native code (system/audio.h and others). +// We use them because we use a Java AudioTrack to play +// back our data. #define AUDIO_FORMAT_ENCODING_DEFAULT 1 #define AUDIO_FORMAT_ENCODING_PCM_16_BIT 2 #define AUDIO_FORMAT_ENCODING_PCM_8_BIT 3 diff --git a/pico/compat/jni/tts.h b/pico/compat/jni/tts.h index fb15108..9e05c9d 100644 --- a/pico/compat/jni/tts.h +++ b/pico/compat/jni/tts.h @@ -14,7 +14,7 @@ * limitations under the License. */ #ifndef ANDROID_TTS_H -#define ANDROID_TTS_H +#define ANDROID_TTS_H // This header defines the interface used by the Android platform // to access Text-To-Speech functionality in shared libraries that implement @@ -62,6 +62,9 @@ typedef enum { } android_tts_callback_status_t; // Supported audio formats +// +// NOTE: This is duplicated in compat/include/TtsEngine.h +// Please make changes there as well. typedef enum { ANDROID_TTS_AUDIO_FORMAT_INVALID = -1, ANDROID_TTS_AUDIO_FORMAT_DEFAULT = 0, diff --git a/pico/tts/com_svox_picottsengine.cpp b/pico/tts/com_svox_picottsengine.cpp index 885429f..bafd300 100644 --- a/pico/tts/com_svox_picottsengine.cpp +++ b/pico/tts/com_svox_picottsengine.cpp @@ -43,7 +43,6 @@ #include #include -#include #include #include @@ -1291,11 +1290,11 @@ tts_result TtsEngine::getLanguage(char *language, char *country, char *variant) * @channels - reference to number of channels * return tts_result * */ -tts_result TtsEngine::setAudioFormat(audio_format_t& encoding, uint32_t& rate, +tts_result TtsEngine::setAudioFormat(tts_audio_format& encoding, uint32_t& rate, int& channels) { // ignore the input parameters, the enforced audio parameters are fixed here - encoding = AUDIO_FORMAT_PCM_16_BIT; + encoding = TTS_AUDIO_FORMAT_PCM_16_BIT; rate = 16000; channels = 1; return TTS_SUCCESS; @@ -1586,7 +1585,7 @@ tts_result TtsEngine::synthesizeText( const char * text, int8_t * buffer, size_t bufused += bytes_recv; } else { /* The buffer filled; pass this on to the callback function. */ - cbret = picoSynthDoneCBPtr(userdata, 16000, AUDIO_FORMAT_PCM_16_BIT, 1, buffer, + cbret = picoSynthDoneCBPtr(userdata, 16000, TTS_AUDIO_FORMAT_PCM_16_BIT, 1, buffer, bufused, TTS_SYNTH_PENDING); if (cbret == TTS_CALLBACK_HALT) { LOGI("Halt requested by caller. Halting."); @@ -1604,7 +1603,7 @@ tts_result TtsEngine::synthesizeText( const char * text, int8_t * buffer, size_t /* This chunk of synthesis is finished; pass the remaining samples. Use 16 KHz, 16-bit samples. */ if (!picoSynthAbort) { - picoSynthDoneCBPtr( userdata, 16000, AUDIO_FORMAT_PCM_16_BIT, 1, buffer, bufused, + picoSynthDoneCBPtr( userdata, 16000, TTS_AUDIO_FORMAT_PCM_16_BIT, 1, buffer, bufused, TTS_SYNTH_PENDING); } picoSynthAbort = 0; @@ -1617,7 +1616,7 @@ tts_result TtsEngine::synthesizeText( const char * text, int8_t * buffer, size_t free(local_text); } LOGV("Synth loop: sending TTS_SYNTH_DONE after error"); - picoSynthDoneCBPtr( userdata, 16000, AUDIO_FORMAT_PCM_16_BIT, 1, buffer, bufused, + picoSynthDoneCBPtr( userdata, 16000, TTS_AUDIO_FORMAT_PCM_16_BIT, 1, buffer, bufused, TTS_SYNTH_DONE); pico_resetEngine( picoEngine, PICO_RESET_SOFT ); return TTS_FAILURE; @@ -1626,7 +1625,7 @@ tts_result TtsEngine::synthesizeText( const char * text, int8_t * buffer, size_t /* Synthesis is done; notify the caller */ LOGV("Synth loop: sending TTS_SYNTH_DONE after all done, or was asked to stop"); - picoSynthDoneCBPtr( userdata, 16000, AUDIO_FORMAT_PCM_16_BIT, 1, buffer, bufused, + picoSynthDoneCBPtr( userdata, 16000, TTS_AUDIO_FORMAT_PCM_16_BIT, 1, buffer, bufused, TTS_SYNTH_DONE); if (local_text) { -- cgit v1.1