first commit
This commit is contained in:
508
3rdparty/hts_engine_API/lib/HTS_audio.c
vendored
Normal file
508
3rdparty/hts_engine_API/lib/HTS_audio.c
vendored
Normal file
@@ -0,0 +1,508 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_AUDIO_C
|
||||
#define HTS_AUDIO_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_AUDIO_C_START extern "C" {
|
||||
#define HTS_AUDIO_C_END }
|
||||
#else
|
||||
#define HTS_AUDIO_C_START
|
||||
#define HTS_AUDIO_C_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_AUDIO_C_START;
|
||||
|
||||
#if !defined(AUDIO_PLAY_WIN32) && !defined(AUDIO_PLAY_PORTAUDIO) && !defined(AUDIO_PLAY_NONE)
|
||||
#if defined(__WINCE__) || defined(_WINCE) || defined(_WINCE) || defined(__WINCE) || defined(__WIN32__) || defined(__WIN32) || defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
|
||||
#define AUDIO_PLAY_WIN32
|
||||
#else
|
||||
#define AUDIO_PLAY_NONE
|
||||
#endif /* __WINCE__ || _WINCE || _WINCE || __WINCE || __WIN32__ || __WIN32 || _WIN32 || WIN32 || __CYGWIN__ || __MINGW32__ */
|
||||
#endif /* !AUDIO_PLAY_WIN32 && !AUDIO_PLAY_PORTAUDIO && !AUDIO_PLAY_NONE */
|
||||
|
||||
/* hts_engine libralies */
|
||||
#include "HTS_hidden.h"
|
||||
|
||||
#ifdef AUDIO_PLAY_WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#define AUDIO_WAIT_BUFF_MS 10 /* wait time (0.01 sec) */
|
||||
#define AUDIO_CHANNEL 1 /* monaural */
|
||||
#ifdef _M_X64
|
||||
#define AUDIO_POINTER_TYPE DWORD_PTR
|
||||
#else
|
||||
#define AUDIO_POINTER_TYPE DWORD
|
||||
#endif
|
||||
|
||||
/* HTS_Audio: audio interface for Windows */
|
||||
typedef struct _HTS_AudioInterface {
|
||||
HWAVEOUT hwaveout; /* audio device handle */
|
||||
WAVEFORMATEX waveformatex; /* wave formatex */
|
||||
unsigned char which_buff; /* double buffering flag */
|
||||
HTS_Boolean now_buff_1; /* double buffering flag */
|
||||
HTS_Boolean now_buff_2; /* double buffering flag */
|
||||
WAVEHDR buff_1; /* buffer */
|
||||
WAVEHDR buff_2; /* buffer */
|
||||
} HTS_AudioInterface;
|
||||
|
||||
/* HTS_AudioInterface_callback_function: callback function from audio device */
|
||||
static void CALLBACK HTS_AudioInterface_callback_function(HWAVEOUT hwaveout, UINT msg, AUDIO_POINTER_TYPE user_data, AUDIO_POINTER_TYPE param1, AUDIO_POINTER_TYPE param2)
|
||||
{
|
||||
WAVEHDR *wavehdr = (WAVEHDR *) param1;
|
||||
HTS_AudioInterface *audio_interface = (HTS_AudioInterface *) user_data;
|
||||
|
||||
if (msg == MM_WOM_DONE && wavehdr && (wavehdr->dwFlags & WHDR_DONE)) {
|
||||
if (audio_interface->now_buff_1 == TRUE && wavehdr == &(audio_interface->buff_1)) {
|
||||
audio_interface->now_buff_1 = FALSE;
|
||||
} else if (audio_interface->now_buff_2 == TRUE && wavehdr == &(audio_interface->buff_2)) {
|
||||
audio_interface->now_buff_2 = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_AudioInterface_write: send buffer to audio device */
|
||||
static HTS_Boolean HTS_AudioInterface_write(HTS_AudioInterface * audio_interface, const short *buff, size_t buff_size)
|
||||
{
|
||||
MMRESULT result;
|
||||
|
||||
if (audio_interface->which_buff == 1) {
|
||||
while (audio_interface->now_buff_1 == TRUE)
|
||||
Sleep(AUDIO_WAIT_BUFF_MS);
|
||||
audio_interface->now_buff_1 = TRUE;
|
||||
audio_interface->which_buff = 2;
|
||||
memcpy(audio_interface->buff_1.lpData, buff, buff_size * sizeof(short));
|
||||
audio_interface->buff_1.dwBufferLength = (DWORD) buff_size *sizeof(short);
|
||||
result = waveOutWrite(audio_interface->hwaveout, &(audio_interface->buff_1), sizeof(WAVEHDR));
|
||||
} else {
|
||||
while (audio_interface->now_buff_2 == TRUE)
|
||||
Sleep(AUDIO_WAIT_BUFF_MS);
|
||||
audio_interface->now_buff_2 = TRUE;
|
||||
audio_interface->which_buff = 1;
|
||||
memcpy(audio_interface->buff_2.lpData, buff, buff_size * sizeof(short));
|
||||
audio_interface->buff_2.dwBufferLength = (DWORD) buff_size *sizeof(short);
|
||||
result = waveOutWrite(audio_interface->hwaveout, &(audio_interface->buff_2), sizeof(WAVEHDR));
|
||||
}
|
||||
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
HTS_error(0, "hts_engine: Cannot send datablocks to your output audio device to play waveform.\n");
|
||||
|
||||
return (result == MMSYSERR_NOERROR) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/* HTS_AudioInterface_close: close audio device */
|
||||
static void HTS_AudioInterface_close(HTS_AudioInterface * audio_interface)
|
||||
{
|
||||
MMRESULT result;
|
||||
|
||||
/* stop audio */
|
||||
result = waveOutReset(audio_interface->hwaveout);
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
HTS_error(0, "hts_engine: Cannot stop and reset your output audio device.\n");
|
||||
/* unprepare */
|
||||
result = waveOutUnprepareHeader(audio_interface->hwaveout, &(audio_interface->buff_1), sizeof(WAVEHDR));
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
HTS_error(0, "hts_engine: Cannot cleanup the audio datablocks to play waveform.\n");
|
||||
result = waveOutUnprepareHeader(audio_interface->hwaveout, &(audio_interface->buff_2), sizeof(WAVEHDR));
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
HTS_error(0, "hts_engine: Cannot cleanup the audio datablocks to play waveform.\n");
|
||||
/* close */
|
||||
result = waveOutClose(audio_interface->hwaveout);
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
HTS_error(0, "hts_engine: Failed to close your output audio device.\n");
|
||||
if (audio_interface->buff_1.lpData != NULL)
|
||||
HTS_free(audio_interface->buff_1.lpData);
|
||||
if (audio_interface->buff_2.lpData != NULL)
|
||||
HTS_free(audio_interface->buff_2.lpData);
|
||||
|
||||
HTS_free(audio_interface);
|
||||
}
|
||||
|
||||
static HTS_AudioInterface *HTS_AudioInterface_open(size_t sampling_frequency, size_t max_buff_size)
|
||||
{
|
||||
HTS_AudioInterface *audio_interface;
|
||||
MMRESULT result;
|
||||
|
||||
/* make audio interface */
|
||||
audio_interface = (HTS_AudioInterface *) HTS_calloc(1, sizeof(HTS_AudioInterface));
|
||||
|
||||
audio_interface->hwaveout = 0;
|
||||
audio_interface->which_buff = 1;
|
||||
audio_interface->now_buff_1 = FALSE;
|
||||
audio_interface->now_buff_2 = FALSE;
|
||||
|
||||
/* format */
|
||||
audio_interface->waveformatex.wFormatTag = WAVE_FORMAT_PCM;
|
||||
audio_interface->waveformatex.nChannels = AUDIO_CHANNEL;
|
||||
audio_interface->waveformatex.nSamplesPerSec = (DWORD) sampling_frequency;
|
||||
audio_interface->waveformatex.wBitsPerSample = sizeof(short) * 8;
|
||||
audio_interface->waveformatex.nBlockAlign = AUDIO_CHANNEL * audio_interface->waveformatex.wBitsPerSample / 8;
|
||||
audio_interface->waveformatex.nAvgBytesPerSec = (DWORD) sampling_frequency *audio_interface->waveformatex.nBlockAlign;
|
||||
/* open */
|
||||
result = waveOutOpen(&audio_interface->hwaveout, WAVE_MAPPER, &audio_interface->waveformatex, (AUDIO_POINTER_TYPE) HTS_AudioInterface_callback_function, (AUDIO_POINTER_TYPE) audio_interface, CALLBACK_FUNCTION);
|
||||
if (result != MMSYSERR_NOERROR) {
|
||||
HTS_error(0, "hts_engine: Failed to open your output audio_interface device to play waveform.\n");
|
||||
HTS_free(audio_interface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* prepare */
|
||||
audio_interface->buff_1.lpData = (LPSTR) HTS_calloc(max_buff_size, sizeof(short));
|
||||
audio_interface->buff_1.dwBufferLength = (DWORD) max_buff_size *sizeof(short);
|
||||
audio_interface->buff_1.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP;
|
||||
audio_interface->buff_1.dwLoops = 1;
|
||||
audio_interface->buff_1.lpNext = 0;
|
||||
audio_interface->buff_1.reserved = 0;
|
||||
result = waveOutPrepareHeader(audio_interface->hwaveout, &(audio_interface->buff_1), sizeof(WAVEHDR));
|
||||
if (result != MMSYSERR_NOERROR) {
|
||||
HTS_error(0, "hts_engine: Cannot initialize audio_interface datablocks to play waveform.\n");
|
||||
HTS_free(audio_interface->buff_1.lpData);
|
||||
HTS_free(audio_interface);
|
||||
return NULL;
|
||||
}
|
||||
audio_interface->buff_2.lpData = (LPSTR) HTS_calloc(max_buff_size, sizeof(short));
|
||||
audio_interface->buff_2.dwBufferLength = (DWORD) max_buff_size *sizeof(short);
|
||||
audio_interface->buff_2.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP;
|
||||
audio_interface->buff_2.dwLoops = 1;
|
||||
audio_interface->buff_2.lpNext = 0;
|
||||
audio_interface->buff_2.reserved = 0;
|
||||
result = waveOutPrepareHeader(audio_interface->hwaveout, &(audio_interface->buff_2), sizeof(WAVEHDR));
|
||||
if (result != MMSYSERR_NOERROR) {
|
||||
HTS_error(0, "hts_engine: Cannot initialize audio_interface datablocks to play waveform.\n");
|
||||
HTS_free(audio_interface->buff_1.lpData);
|
||||
HTS_free(audio_interface->buff_2.lpData);
|
||||
HTS_free(audio_interface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return audio_interface;
|
||||
}
|
||||
|
||||
/* HTS_Audio_initialize: initialize audio */
|
||||
void HTS_Audio_initialize(HTS_Audio * audio)
|
||||
{
|
||||
if (audio == NULL)
|
||||
return;
|
||||
|
||||
audio->sampling_frequency = 0;
|
||||
audio->max_buff_size = 0;
|
||||
audio->buff = NULL;
|
||||
audio->buff_size = 0;
|
||||
audio->audio_interface = NULL;
|
||||
}
|
||||
|
||||
/* HTS_Audio_set_parameter: set parameters for audio */
|
||||
void HTS_Audio_set_parameter(HTS_Audio * audio, size_t sampling_frequency, size_t max_buff_size)
|
||||
{
|
||||
if (audio == NULL)
|
||||
return;
|
||||
|
||||
if (audio->sampling_frequency == sampling_frequency && audio->max_buff_size == max_buff_size)
|
||||
return;
|
||||
|
||||
HTS_Audio_clear(audio);
|
||||
|
||||
if (sampling_frequency == 0 || max_buff_size == 0)
|
||||
return;
|
||||
|
||||
audio->audio_interface = HTS_AudioInterface_open(sampling_frequency, max_buff_size);
|
||||
if (audio->audio_interface == NULL)
|
||||
return;
|
||||
|
||||
audio->sampling_frequency = sampling_frequency;
|
||||
audio->max_buff_size = max_buff_size;
|
||||
audio->buff = (short *) HTS_calloc(max_buff_size, sizeof(short));
|
||||
audio->buff_size = 0;
|
||||
}
|
||||
|
||||
/* HTS_Audio_write: send data to audio */
|
||||
void HTS_Audio_write(HTS_Audio * audio, short data)
|
||||
{
|
||||
if (audio == NULL || audio->audio_interface == NULL)
|
||||
return;
|
||||
|
||||
audio->buff[audio->buff_size++] = data;
|
||||
|
||||
if (audio->buff_size >= audio->max_buff_size) {
|
||||
if (HTS_AudioInterface_write((HTS_AudioInterface *) audio->audio_interface, audio->buff, audio->buff_size) != TRUE) {
|
||||
HTS_Audio_clear(audio);
|
||||
return;
|
||||
}
|
||||
audio->buff_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Audio_flush: flush remain data */
|
||||
void HTS_Audio_flush(HTS_Audio * audio)
|
||||
{
|
||||
HTS_AudioInterface *audio_interface;
|
||||
|
||||
if (audio == NULL || audio->audio_interface == NULL)
|
||||
return;
|
||||
|
||||
audio_interface = (HTS_AudioInterface *) audio->audio_interface;
|
||||
if (audio->buff_size > 0) {
|
||||
if (HTS_AudioInterface_write(audio_interface, audio->buff, audio->buff_size) != TRUE) {
|
||||
HTS_Audio_clear(audio);
|
||||
return;
|
||||
}
|
||||
audio->buff_size = 0;
|
||||
}
|
||||
while (audio_interface->now_buff_1 == TRUE || audio_interface->now_buff_2 == TRUE)
|
||||
Sleep(AUDIO_WAIT_BUFF_MS);
|
||||
}
|
||||
|
||||
/* HTS_Audio_clear: free audio */
|
||||
void HTS_Audio_clear(HTS_Audio * audio)
|
||||
{
|
||||
HTS_AudioInterface *audio_interface;
|
||||
|
||||
if (audio == NULL || audio->audio_interface == NULL)
|
||||
return;
|
||||
|
||||
audio_interface = (HTS_AudioInterface *) audio->audio_interface;
|
||||
HTS_AudioInterface_close(audio_interface);
|
||||
if (audio->buff != NULL)
|
||||
free(audio->buff);
|
||||
HTS_Audio_initialize(audio);
|
||||
}
|
||||
|
||||
#endif /* AUDIO_PLAY_WIN32 */
|
||||
|
||||
#ifdef AUDIO_PLAY_PORTAUDIO
|
||||
|
||||
#include "portaudio.h"
|
||||
|
||||
/* HTS_AudioInterface: audio output for PortAudio */
|
||||
typedef struct _HTS_AudioInterface {
|
||||
PaStreamParameters parameters; /* parameters for output stream */
|
||||
PaStream *stream; /* output stream */
|
||||
} HTS_AudioInterface;
|
||||
|
||||
/* HTS_AudioInterface_write: send data to audio device */
|
||||
static void HTS_AudioInterface_write(HTS_AudioInterface * audio_interface, const short *buff, size_t buff_size)
|
||||
{
|
||||
PaError err;
|
||||
|
||||
err = Pa_WriteStream(audio_interface->stream, buff, buff_size);
|
||||
if (err != paNoError && err != paOutputUnderflowed)
|
||||
HTS_error(0, "hts_engine: Cannot send datablocks to your output audio device to play waveform.\n");
|
||||
}
|
||||
|
||||
/* HTS_AudioInterface_close: close audio device */
|
||||
static void HTS_AudioInterface_close(HTS_AudioInterface * audio_interface)
|
||||
{
|
||||
PaError err;
|
||||
|
||||
err = Pa_StopStream(audio_interface->stream);
|
||||
if (err != paNoError)
|
||||
HTS_error(0, "hts_engine: Cannot stop your output audio device.\n");
|
||||
err = Pa_CloseStream(audio_interface->stream);
|
||||
if (err != paNoError)
|
||||
HTS_error(0, "hts_engine: Failed to close your output audio device.\n");
|
||||
Pa_Terminate();
|
||||
|
||||
HTS_free(audio_interface);
|
||||
}
|
||||
|
||||
static HTS_AudioInterface *HTS_AudioInterface_open(size_t sampling_frequency, size_t max_buff_size)
|
||||
{
|
||||
HTS_AudioInterface *audio_interface;
|
||||
PaError err;
|
||||
|
||||
audio_interface = HTS_calloc(1, sizeof(HTS_AudioInterface));
|
||||
audio_interface->stream = NULL;
|
||||
|
||||
err = Pa_Initialize();
|
||||
if (err != paNoError) {
|
||||
HTS_error(0, "hts_engine: Failed to initialize your output audio device to play waveform.\n");
|
||||
HTS_free(audio_interface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
audio_interface->parameters.device = Pa_GetDefaultOutputDevice();
|
||||
audio_interface->parameters.channelCount = 1;
|
||||
audio_interface->parameters.sampleFormat = paInt16;
|
||||
audio_interface->parameters.suggestedLatency = Pa_GetDeviceInfo(audio_interface->parameters.device)->defaultLowOutputLatency;
|
||||
audio_interface->parameters.hostApiSpecificStreamInfo = NULL;
|
||||
|
||||
err = Pa_OpenStream(&audio_interface->stream, NULL, &audio_interface->parameters, sampling_frequency, max_buff_size, paClipOff, NULL, NULL);
|
||||
if (err != paNoError) {
|
||||
HTS_error(0, "hts_engine: Failed to open your output audio device to play waveform.\n");
|
||||
Pa_Terminate();
|
||||
HTS_free(audio_interface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = Pa_StartStream(audio_interface->stream);
|
||||
if (err != paNoError) {
|
||||
HTS_error(0, "hts_engine: Failed to start your output audio device to play waveform.\n");
|
||||
Pa_CloseStream(audio_interface->stream);
|
||||
Pa_Terminate();
|
||||
HTS_free(audio_interface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return audio_interface;
|
||||
}
|
||||
|
||||
/* HTS_Audio_initialize: initialize audio */
|
||||
void HTS_Audio_initialize(HTS_Audio * audio)
|
||||
{
|
||||
if (audio == NULL)
|
||||
return;
|
||||
|
||||
audio->sampling_frequency = 0;
|
||||
audio->max_buff_size = 0;
|
||||
audio->buff = NULL;
|
||||
audio->buff_size = 0;
|
||||
audio->audio_interface = NULL;
|
||||
}
|
||||
|
||||
/* HTS_Audio_set_parameter: set parameters for audio */
|
||||
void HTS_Audio_set_parameter(HTS_Audio * audio, size_t sampling_frequency, size_t max_buff_size)
|
||||
{
|
||||
if (audio == NULL)
|
||||
return;
|
||||
|
||||
if (audio->sampling_frequency == sampling_frequency && audio->max_buff_size == max_buff_size)
|
||||
return;
|
||||
|
||||
HTS_Audio_clear(audio);
|
||||
|
||||
if (sampling_frequency == 0 || max_buff_size == 0)
|
||||
return;
|
||||
|
||||
audio->audio_interface = HTS_AudioInterface_open(sampling_frequency, max_buff_size);
|
||||
if (audio->audio_interface == NULL)
|
||||
return;
|
||||
|
||||
audio->sampling_frequency = sampling_frequency;
|
||||
audio->max_buff_size = max_buff_size;
|
||||
audio->buff = (short *) HTS_calloc(max_buff_size, sizeof(short));
|
||||
audio->buff_size = 0;
|
||||
}
|
||||
|
||||
/* HTS_Audio_write: send data to audio device */
|
||||
void HTS_Audio_write(HTS_Audio * audio, short data)
|
||||
{
|
||||
if (audio == NULL)
|
||||
return;
|
||||
|
||||
audio->buff[audio->buff_size++] = data;
|
||||
|
||||
if (audio->buff_size >= audio->max_buff_size) {
|
||||
if (audio->audio_interface != NULL)
|
||||
HTS_AudioInterface_write((HTS_AudioInterface *) audio->audio_interface, audio->buff, audio->max_buff_size);
|
||||
audio->buff_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Audio_flush: flush remain data */
|
||||
void HTS_Audio_flush(HTS_Audio * audio)
|
||||
{
|
||||
HTS_AudioInterface *audio_interface;
|
||||
|
||||
if (audio == NULL || audio->audio_interface == NULL)
|
||||
return;
|
||||
|
||||
audio_interface = (HTS_AudioInterface *) audio->audio_interface;
|
||||
if (audio->buff_size > 0) {
|
||||
HTS_AudioInterface_write(audio_interface, audio->buff, audio->buff_size);
|
||||
audio->buff_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Audio_clear: free audio */
|
||||
void HTS_Audio_clear(HTS_Audio * audio)
|
||||
{
|
||||
HTS_AudioInterface *audio_interface;
|
||||
|
||||
if (audio == NULL || audio->audio_interface == NULL)
|
||||
return;
|
||||
audio_interface = (HTS_AudioInterface *) audio->audio_interface;
|
||||
|
||||
HTS_Audio_flush(audio);
|
||||
HTS_AudioInterface_close(audio_interface);
|
||||
if (audio->buff != NULL)
|
||||
HTS_free(audio->buff);
|
||||
HTS_Audio_initialize(audio);
|
||||
}
|
||||
|
||||
#endif /* AUDIO_PLAY_PORTAUDIO */
|
||||
|
||||
#ifdef AUDIO_PLAY_NONE
|
||||
|
||||
/* HTS_Audio_initialize: initialize audio */
|
||||
void HTS_Audio_initialize(HTS_Audio * audio)
|
||||
{
|
||||
}
|
||||
|
||||
/* HTS_Audio_set_parameter: set parameters for audio */
|
||||
void HTS_Audio_set_parameter(HTS_Audio * audio, size_t sampling_frequeny, size_t max_buff_size)
|
||||
{
|
||||
}
|
||||
|
||||
/* HTS_Audio_write: send data to audio */
|
||||
void HTS_Audio_write(HTS_Audio * audio, short data)
|
||||
{
|
||||
}
|
||||
|
||||
/* HTS_Audio_flush: flush remain data */
|
||||
void HTS_Audio_flush(HTS_Audio * audio)
|
||||
{
|
||||
}
|
||||
|
||||
/* HTS_Audio_clear: free audio */
|
||||
void HTS_Audio_clear(HTS_Audio * audio)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* AUDIO_PLAY_NONE */
|
||||
|
||||
HTS_AUDIO_C_END;
|
||||
|
||||
#endif /* !HTS_AUDIO_C */
|
||||
792
3rdparty/hts_engine_API/lib/HTS_engine.c
vendored
Normal file
792
3rdparty/hts_engine_API/lib/HTS_engine.c
vendored
Normal file
@@ -0,0 +1,792 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_ENGINE_C
|
||||
#define HTS_ENGINE_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_ENGINE_C_START extern "C" {
|
||||
#define HTS_ENGINE_C_END }
|
||||
#else
|
||||
#define HTS_ENGINE_C_START
|
||||
#define HTS_ENGINE_C_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_ENGINE_C_START;
|
||||
|
||||
#include <stdlib.h> /* for atof() */
|
||||
#include <string.h> /* for strcpy() */
|
||||
#include <math.h> /* for pow() */
|
||||
|
||||
/* hts_engine libraries */
|
||||
#include "HTS_hidden.h"
|
||||
|
||||
/* HTS_Engine_initialize: initialize engine */
|
||||
void HTS_Engine_initialize(HTS_Engine * engine)
|
||||
{
|
||||
/* global */
|
||||
engine->condition.sampling_frequency = 0;
|
||||
engine->condition.fperiod = 0;
|
||||
engine->condition.audio_buff_size = 0;
|
||||
engine->condition.stop = FALSE;
|
||||
engine->condition.volume = 1.0;
|
||||
engine->condition.msd_threshold = NULL;
|
||||
engine->condition.gv_weight = NULL;
|
||||
|
||||
/* duration */
|
||||
engine->condition.speed = 1.0;
|
||||
engine->condition.phoneme_alignment_flag = FALSE;
|
||||
|
||||
/* spectrum */
|
||||
engine->condition.stage = 0;
|
||||
engine->condition.use_log_gain = FALSE;
|
||||
engine->condition.alpha = 0.0;
|
||||
engine->condition.beta = 0.0;
|
||||
|
||||
/* log F0 */
|
||||
engine->condition.additional_half_tone = 0.0;
|
||||
|
||||
/* interpolation weights */
|
||||
engine->condition.duration_iw = NULL;
|
||||
engine->condition.parameter_iw = NULL;
|
||||
engine->condition.gv_iw = NULL;
|
||||
|
||||
/* initialize audio */
|
||||
HTS_Audio_initialize(&engine->audio);
|
||||
/* initialize model set */
|
||||
HTS_ModelSet_initialize(&engine->ms);
|
||||
/* initialize label list */
|
||||
HTS_Label_initialize(&engine->label);
|
||||
/* initialize state sequence set */
|
||||
HTS_SStreamSet_initialize(&engine->sss);
|
||||
/* initialize pstream set */
|
||||
HTS_PStreamSet_initialize(&engine->pss);
|
||||
/* initialize gstream set */
|
||||
HTS_GStreamSet_initialize(&engine->gss);
|
||||
}
|
||||
|
||||
/* HTS_Engine_load: load HTS voices */
|
||||
HTS_Boolean HTS_Engine_load(HTS_Engine * engine, char **voices, size_t num_voices)
|
||||
{
|
||||
size_t i, j;
|
||||
size_t nstream;
|
||||
double average_weight;
|
||||
const char *option, *find;
|
||||
|
||||
/* reset engine */
|
||||
HTS_Engine_clear(engine);
|
||||
|
||||
/* load voices */
|
||||
if (HTS_ModelSet_load(&engine->ms, voices, num_voices) != TRUE) {
|
||||
HTS_Engine_clear(engine);
|
||||
return FALSE;
|
||||
}
|
||||
nstream = HTS_ModelSet_get_nstream(&engine->ms);
|
||||
average_weight = 1.0 / num_voices;
|
||||
|
||||
/* global */
|
||||
engine->condition.sampling_frequency = HTS_ModelSet_get_sampling_frequency(&engine->ms);
|
||||
engine->condition.fperiod = HTS_ModelSet_get_fperiod(&engine->ms);
|
||||
engine->condition.msd_threshold = (double *) HTS_calloc(nstream, sizeof(double));
|
||||
for (i = 0; i < nstream; i++)
|
||||
engine->condition.msd_threshold[i] = 0.5;
|
||||
engine->condition.gv_weight = (double *) HTS_calloc(nstream, sizeof(double));
|
||||
for (i = 0; i < nstream; i++)
|
||||
engine->condition.gv_weight[i] = 1.0;
|
||||
|
||||
/* spectrum */
|
||||
option = HTS_ModelSet_get_option(&engine->ms, 0);
|
||||
find = strstr(option, "GAMMA=");
|
||||
if (find != NULL)
|
||||
engine->condition.stage = (size_t) atoi(&find[strlen("GAMMA=")]);
|
||||
find = strstr(option, "LN_GAIN=");
|
||||
if (find != NULL)
|
||||
engine->condition.use_log_gain = atoi(&find[strlen("LN_GAIN=")]) == 1 ? TRUE : FALSE;
|
||||
find = strstr(option, "ALPHA=");
|
||||
if (find != NULL)
|
||||
engine->condition.alpha = atof(&find[strlen("ALPHA=")]);
|
||||
|
||||
/* interpolation weights */
|
||||
engine->condition.duration_iw = (double *) HTS_calloc(num_voices, sizeof(double));
|
||||
for (i = 0; i < num_voices; i++)
|
||||
engine->condition.duration_iw[i] = average_weight;
|
||||
engine->condition.parameter_iw = (double **) HTS_calloc(num_voices, sizeof(double *));
|
||||
for (i = 0; i < num_voices; i++) {
|
||||
engine->condition.parameter_iw[i] = (double *) HTS_calloc(nstream, sizeof(double));
|
||||
for (j = 0; j < nstream; j++)
|
||||
engine->condition.parameter_iw[i][j] = average_weight;
|
||||
}
|
||||
engine->condition.gv_iw = (double **) HTS_calloc(num_voices, sizeof(double *));
|
||||
for (i = 0; i < num_voices; i++) {
|
||||
engine->condition.gv_iw[i] = (double *) HTS_calloc(nstream, sizeof(double));
|
||||
for (j = 0; j < nstream; j++)
|
||||
engine->condition.gv_iw[i][j] = average_weight;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_sampling_frequency: set sampling frequency */
|
||||
void HTS_Engine_set_sampling_frequency(HTS_Engine * engine, size_t i)
|
||||
{
|
||||
if (i < 1)
|
||||
i = 1;
|
||||
engine->condition.sampling_frequency = i;
|
||||
HTS_Audio_set_parameter(&engine->audio, engine->condition.sampling_frequency, engine->condition.audio_buff_size);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_sampling_frequency: get sampling frequency */
|
||||
size_t HTS_Engine_get_sampling_frequency(HTS_Engine * engine)
|
||||
{
|
||||
return engine->condition.sampling_frequency;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_fperiod: set frame period */
|
||||
void HTS_Engine_set_fperiod(HTS_Engine * engine, size_t i)
|
||||
{
|
||||
if (i < 1)
|
||||
i = 1;
|
||||
engine->condition.fperiod = i;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_fperiod: get frame period */
|
||||
size_t HTS_Engine_get_fperiod(HTS_Engine * engine)
|
||||
{
|
||||
return engine->condition.fperiod;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_audio_buff_size: set audio buffer size */
|
||||
void HTS_Engine_set_audio_buff_size(HTS_Engine * engine, size_t i)
|
||||
{
|
||||
engine->condition.audio_buff_size = i;
|
||||
HTS_Audio_set_parameter(&engine->audio, engine->condition.sampling_frequency, engine->condition.audio_buff_size);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_audio_buff_size: get audio buffer size */
|
||||
size_t HTS_Engine_get_audio_buff_size(HTS_Engine * engine)
|
||||
{
|
||||
return engine->condition.audio_buff_size;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_stop_flag: set stop flag */
|
||||
void HTS_Engine_set_stop_flag(HTS_Engine * engine, HTS_Boolean b)
|
||||
{
|
||||
engine->condition.stop = b;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_stop_flag: get stop flag */
|
||||
HTS_Boolean HTS_Engine_get_stop_flag(HTS_Engine * engine)
|
||||
{
|
||||
return engine->condition.stop;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_volume: set volume in db */
|
||||
void HTS_Engine_set_volume(HTS_Engine * engine, double f)
|
||||
{
|
||||
engine->condition.volume = exp(f * DB);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_volume: get volume in db */
|
||||
double HTS_Engine_get_volume(HTS_Engine * engine)
|
||||
{
|
||||
return log(engine->condition.volume) / DB;
|
||||
}
|
||||
|
||||
/* HTS_Egnine_set_msd_threshold: set MSD threshold */
|
||||
void HTS_Engine_set_msd_threshold(HTS_Engine * engine, size_t stream_index, double f)
|
||||
{
|
||||
if (f < 0.0)
|
||||
f = 0.0;
|
||||
if (f > 1.0)
|
||||
f = 1.0;
|
||||
engine->condition.msd_threshold[stream_index] = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_msd_threshold: get MSD threshold */
|
||||
double HTS_Engine_get_msd_threshold(HTS_Engine * engine, size_t stream_index)
|
||||
{
|
||||
return engine->condition.msd_threshold[stream_index];
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_gv_weight: set GV weight */
|
||||
void HTS_Engine_set_gv_weight(HTS_Engine * engine, size_t stream_index, double f)
|
||||
{
|
||||
if (f < 0.0)
|
||||
f = 0.0;
|
||||
engine->condition.gv_weight[stream_index] = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_gv_weight: get GV weight */
|
||||
double HTS_Engine_get_gv_weight(HTS_Engine * engine, size_t stream_index)
|
||||
{
|
||||
return engine->condition.gv_weight[stream_index];
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_speed: set speech speed */
|
||||
void HTS_Engine_set_speed(HTS_Engine * engine, double f)
|
||||
{
|
||||
if (f < 1.0E-06)
|
||||
f = 1.0E-06;
|
||||
engine->condition.speed = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_phoneme_alignment_flag: set flag for using phoneme alignment in label */
|
||||
void HTS_Engine_set_phoneme_alignment_flag(HTS_Engine * engine, HTS_Boolean b)
|
||||
{
|
||||
engine->condition.phoneme_alignment_flag = b;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_alpha: set alpha */
|
||||
void HTS_Engine_set_alpha(HTS_Engine * engine, double f)
|
||||
{
|
||||
if (f < 0.0)
|
||||
f = 0.0;
|
||||
if (f > 1.0)
|
||||
f = 1.0;
|
||||
engine->condition.alpha = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_alpha: get alpha */
|
||||
double HTS_Engine_get_alpha(HTS_Engine * engine)
|
||||
{
|
||||
return engine->condition.alpha;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_beta: set beta */
|
||||
void HTS_Engine_set_beta(HTS_Engine * engine, double f)
|
||||
{
|
||||
if (f < 0.0)
|
||||
f = 0.0;
|
||||
if (f > 1.0)
|
||||
f = 1.0;
|
||||
engine->condition.beta = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_beta: get beta */
|
||||
double HTS_Engine_get_beta(HTS_Engine * engine)
|
||||
{
|
||||
return engine->condition.beta;
|
||||
}
|
||||
|
||||
/* HTS_Engine_add_half_tone: add half tone */
|
||||
void HTS_Engine_add_half_tone(HTS_Engine * engine, double f)
|
||||
{
|
||||
engine->condition.additional_half_tone = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_duration_interpolation_weight: set interpolation weight for duration */
|
||||
void HTS_Engine_set_duration_interpolation_weight(HTS_Engine * engine, size_t voice_index, double f)
|
||||
{
|
||||
engine->condition.duration_iw[voice_index] = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_duration_interpolation_weight: get interpolation weight for duration */
|
||||
double HTS_Engine_get_duration_interpolation_weight(HTS_Engine * engine, size_t voice_index)
|
||||
{
|
||||
return engine->condition.duration_iw[voice_index];
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_parameter_interpolation_weight: set interpolation weight for parameter */
|
||||
void HTS_Engine_set_parameter_interpolation_weight(HTS_Engine * engine, size_t voice_index, size_t stream_index, double f)
|
||||
{
|
||||
engine->condition.parameter_iw[voice_index][stream_index] = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_parameter_interpolation_weight: get interpolation weight for parameter */
|
||||
double HTS_Engine_get_parameter_interpolation_weight(HTS_Engine * engine, size_t voice_index, size_t stream_index)
|
||||
{
|
||||
return engine->condition.parameter_iw[voice_index][stream_index];
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_gv_interpolation_weight: set interpolation weight for GV */
|
||||
void HTS_Engine_set_gv_interpolation_weight(HTS_Engine * engine, size_t voice_index, size_t stream_index, double f)
|
||||
{
|
||||
engine->condition.gv_iw[voice_index][stream_index] = f;
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_gv_interpolation_weight: get interpolation weight for GV */
|
||||
double HTS_Engine_get_gv_interpolation_weight(HTS_Engine * engine, size_t voice_index, size_t stream_index)
|
||||
{
|
||||
return engine->condition.gv_iw[voice_index][stream_index];
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_total_state: get total number of state */
|
||||
size_t HTS_Engine_get_total_state(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_SStreamSet_get_total_state(&engine->sss);
|
||||
}
|
||||
|
||||
/* HTS_Engine_set_state_mean: set mean value of state */
|
||||
void HTS_Engine_set_state_mean(HTS_Engine * engine, size_t stream_index, size_t state_index, size_t vector_index, double f)
|
||||
{
|
||||
HTS_SStreamSet_set_mean(&engine->sss, stream_index, state_index, vector_index, f);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_state_mean: get mean value of state */
|
||||
double HTS_Engine_get_state_mean(HTS_Engine * engine, size_t stream_index, size_t state_index, size_t vector_index)
|
||||
{
|
||||
return HTS_SStreamSet_get_mean(&engine->sss, stream_index, state_index, vector_index);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_state_duration: get state duration */
|
||||
size_t HTS_Engine_get_state_duration(HTS_Engine * engine, size_t state_index)
|
||||
{
|
||||
return HTS_SStreamSet_get_duration(&engine->sss, state_index);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_nvoices: get number of voices */
|
||||
size_t HTS_Engine_get_nvoices(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_ModelSet_get_nvoices(&engine->ms);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_nstream: get number of stream */
|
||||
size_t HTS_Engine_get_nstream(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_ModelSet_get_nstream(&engine->ms);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_nstate: get number of state */
|
||||
size_t HTS_Engine_get_nstate(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_ModelSet_get_nstate(&engine->ms);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_fullcontext_label_format: get full context label format */
|
||||
const char *HTS_Engine_get_fullcontext_label_format(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_ModelSet_get_fullcontext_label_format(&engine->ms);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_fullcontext_label_version: get full context label version */
|
||||
const char *HTS_Engine_get_fullcontext_label_version(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_ModelSet_get_fullcontext_label_version(&engine->ms);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_total_frame: get total number of frame */
|
||||
size_t HTS_Engine_get_total_frame(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_GStreamSet_get_total_frame(&engine->gss);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_nsamples: get number of samples */
|
||||
size_t HTS_Engine_get_nsamples(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_GStreamSet_get_total_nsamples(&engine->gss);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_generated_parameter: output generated parameter */
|
||||
double HTS_Engine_get_generated_parameter(HTS_Engine * engine, size_t stream_index, size_t frame_index, size_t vector_index)
|
||||
{
|
||||
return HTS_GStreamSet_get_parameter(&engine->gss, stream_index, frame_index, vector_index);
|
||||
}
|
||||
|
||||
/* HTS_Engine_get_generated_speech: output generated speech */
|
||||
double HTS_Engine_get_generated_speech(HTS_Engine * engine, size_t index)
|
||||
{
|
||||
return HTS_GStreamSet_get_speech(&engine->gss, index);
|
||||
}
|
||||
|
||||
/* HTS_Engine_generate_state_sequence: genereate state sequence (1st synthesis step) */
|
||||
static HTS_Boolean HTS_Engine_generate_state_sequence(HTS_Engine * engine)
|
||||
{
|
||||
size_t i, state_index, model_index;
|
||||
double f;
|
||||
|
||||
if (HTS_SStreamSet_create(&engine->sss, &engine->ms, &engine->label, engine->condition.phoneme_alignment_flag, engine->condition.speed, engine->condition.duration_iw, engine->condition.parameter_iw, engine->condition.gv_iw) != TRUE) {
|
||||
HTS_Engine_refresh(engine);
|
||||
return FALSE;
|
||||
}
|
||||
if (engine->condition.additional_half_tone != 0.0) {
|
||||
state_index = 0;
|
||||
model_index = 0;
|
||||
for (i = 0; i < HTS_Engine_get_total_state(engine); i++) {
|
||||
f = HTS_Engine_get_state_mean(engine, 1, i, 0);
|
||||
f += engine->condition.additional_half_tone * HALF_TONE;
|
||||
if (f < MIN_LF0)
|
||||
f = MIN_LF0;
|
||||
else if (f > MAX_LF0)
|
||||
f = MAX_LF0;
|
||||
HTS_Engine_set_state_mean(engine, 1, i, 0, f);
|
||||
state_index++;
|
||||
if (state_index >= HTS_Engine_get_nstate(engine)) {
|
||||
state_index = 0;
|
||||
model_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_Engine_generate_state_sequence_from_fn: genereate state sequence from file name (1st synthesis step) */
|
||||
HTS_Boolean HTS_Engine_generate_state_sequence_from_fn(HTS_Engine * engine, const char *fn)
|
||||
{
|
||||
HTS_Engine_refresh(engine);
|
||||
HTS_Label_load_from_fn(&engine->label, engine->condition.sampling_frequency, engine->condition.fperiod, fn);
|
||||
return HTS_Engine_generate_state_sequence(engine);
|
||||
}
|
||||
|
||||
/* HTS_Engine_generate_state_sequence_from_strings: generate state sequence from strings (1st synthesis step) */
|
||||
HTS_Boolean HTS_Engine_generate_state_sequence_from_strings(HTS_Engine * engine, char **lines, size_t num_lines)
|
||||
{
|
||||
HTS_Engine_refresh(engine);
|
||||
HTS_Label_load_from_strings(&engine->label, engine->condition.sampling_frequency, engine->condition.fperiod, lines, num_lines);
|
||||
return HTS_Engine_generate_state_sequence(engine);
|
||||
}
|
||||
|
||||
/* HTS_Engine_generate_parameter_sequence: generate parameter sequence (2nd synthesis step) */
|
||||
HTS_Boolean HTS_Engine_generate_parameter_sequence(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_PStreamSet_create(&engine->pss, &engine->sss, engine->condition.msd_threshold, engine->condition.gv_weight);
|
||||
}
|
||||
|
||||
/* HTS_Engine_generate_sample_sequence: generate sample sequence (3rd synthesis step) */
|
||||
HTS_Boolean HTS_Engine_generate_sample_sequence(HTS_Engine * engine)
|
||||
{
|
||||
return HTS_GStreamSet_create(&engine->gss, &engine->pss, engine->condition.stage, engine->condition.use_log_gain, engine->condition.sampling_frequency, engine->condition.fperiod, engine->condition.alpha, engine->condition.beta, &engine->condition.stop, engine->condition.volume, engine->condition.audio_buff_size > 0 ? &engine->audio : NULL);
|
||||
}
|
||||
|
||||
/* HTS_Engine_synthesize: synthesize speech */
|
||||
static HTS_Boolean HTS_Engine_synthesize(HTS_Engine * engine)
|
||||
{
|
||||
if (HTS_Engine_generate_state_sequence(engine) != TRUE) {
|
||||
HTS_Engine_refresh(engine);
|
||||
return FALSE;
|
||||
}
|
||||
if (HTS_Engine_generate_parameter_sequence(engine) != TRUE) {
|
||||
HTS_Engine_refresh(engine);
|
||||
return FALSE;
|
||||
}
|
||||
if (HTS_Engine_generate_sample_sequence(engine) != TRUE) {
|
||||
HTS_Engine_refresh(engine);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_Engine_synthesize_from_fn: synthesize speech from file name */
|
||||
HTS_Boolean HTS_Engine_synthesize_from_fn(HTS_Engine * engine, const char *fn)
|
||||
{
|
||||
HTS_Engine_refresh(engine);
|
||||
HTS_Label_load_from_fn(&engine->label, engine->condition.sampling_frequency, engine->condition.fperiod, fn);
|
||||
return HTS_Engine_synthesize(engine);
|
||||
}
|
||||
|
||||
/* HTS_Engine_synthesize_from_strings: synthesize speech from strings */
|
||||
HTS_Boolean HTS_Engine_synthesize_from_strings(HTS_Engine * engine, char **lines, size_t num_lines)
|
||||
{
|
||||
HTS_Engine_refresh(engine);
|
||||
HTS_Label_load_from_strings(&engine->label, engine->condition.sampling_frequency, engine->condition.fperiod, lines, num_lines);
|
||||
return HTS_Engine_synthesize(engine);
|
||||
}
|
||||
|
||||
/* HTS_Engine_save_information: save trace information */
|
||||
void HTS_Engine_save_information(HTS_Engine * engine, FILE * fp)
|
||||
{
|
||||
size_t i, j, k, l, m, n;
|
||||
double temp;
|
||||
HTS_Condition *condition = &engine->condition;
|
||||
HTS_ModelSet *ms = &engine->ms;
|
||||
HTS_Label *label = &engine->label;
|
||||
HTS_SStreamSet *sss = &engine->sss;
|
||||
HTS_PStreamSet *pss = &engine->pss;
|
||||
|
||||
/* global parameter */
|
||||
fprintf(fp, "[Global parameter]\n");
|
||||
fprintf(fp, "Sampring frequency -> %8lu(Hz)\n", (unsigned long) condition->sampling_frequency);
|
||||
fprintf(fp, "Frame period -> %8lu(point)\n", (unsigned long) condition->fperiod);
|
||||
fprintf(fp, " %8.5f(msec)\n", 1e+3 * condition->fperiod / condition->sampling_frequency);
|
||||
fprintf(fp, "All-pass constant -> %8.5f\n", (float) condition->alpha);
|
||||
fprintf(fp, "Gamma -> %8.5f\n", (float) (condition->stage == 0 ? 0.0 : -1.0 / condition->stage));
|
||||
if (condition->stage != 0) {
|
||||
if (condition->use_log_gain == TRUE)
|
||||
fprintf(fp, "Log gain flag -> TRUE\n");
|
||||
else
|
||||
fprintf(fp, "Log gain flag -> FALSE\n");
|
||||
}
|
||||
fprintf(fp, "Postfiltering coefficient -> %8.5f\n", (float) condition->beta);
|
||||
fprintf(fp, "Audio buffer size -> %8lu(sample)\n", (unsigned long) condition->audio_buff_size);
|
||||
fprintf(fp, "\n");
|
||||
|
||||
/* duration parameter */
|
||||
fprintf(fp, "[Duration parameter]\n");
|
||||
fprintf(fp, "Number of states -> %8lu\n", (unsigned long) HTS_ModelSet_get_nstate(ms));
|
||||
fprintf(fp, " Interpolation size -> %8lu\n", (unsigned long) HTS_ModelSet_get_nvoices(ms));
|
||||
/* check interpolation */
|
||||
for (i = 0, temp = 0.0; i < HTS_ModelSet_get_nvoices(ms); i++)
|
||||
temp += condition->duration_iw[i];
|
||||
for (i = 0; i < HTS_ModelSet_get_nvoices(ms); i++)
|
||||
if (condition->duration_iw[i] != 0.0)
|
||||
condition->duration_iw[i] /= temp;
|
||||
for (i = 0; i < HTS_ModelSet_get_nvoices(ms); i++)
|
||||
fprintf(fp, " Interpolation weight[%2lu] -> %8.0f(%%)\n", (unsigned long) i, (float) (100 * condition->duration_iw[i]));
|
||||
fprintf(fp, "\n");
|
||||
|
||||
fprintf(fp, "[Stream parameter]\n");
|
||||
for (i = 0; i < HTS_ModelSet_get_nstream(ms); i++) {
|
||||
/* stream parameter */
|
||||
fprintf(fp, "Stream[%2lu] vector length -> %8lu\n", (unsigned long) i, (unsigned long) HTS_ModelSet_get_vector_length(ms, i));
|
||||
fprintf(fp, " Dynamic window size -> %8lu\n", (unsigned long) HTS_ModelSet_get_window_size(ms, i));
|
||||
/* interpolation */
|
||||
fprintf(fp, " Interpolation size -> %8lu\n", (unsigned long) HTS_ModelSet_get_nvoices(ms));
|
||||
for (j = 0, temp = 0.0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
temp += condition->parameter_iw[j][i];
|
||||
for (j = 0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
if (condition->parameter_iw[j][i] != 0.0)
|
||||
condition->parameter_iw[j][i] /= temp;
|
||||
for (j = 0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
fprintf(fp, " Interpolation weight[%2lu] -> %8.0f(%%)\n", (unsigned long) j, (float) (100 * condition->parameter_iw[j][i]));
|
||||
/* MSD */
|
||||
if (HTS_ModelSet_is_msd(ms, i)) { /* for MSD */
|
||||
fprintf(fp, " MSD flag -> TRUE\n");
|
||||
fprintf(fp, " MSD threshold -> %8.5f\n", condition->msd_threshold[i]);
|
||||
} else { /* for non MSD */
|
||||
fprintf(fp, " MSD flag -> FALSE\n");
|
||||
}
|
||||
/* GV */
|
||||
if (HTS_ModelSet_use_gv(ms, i)) {
|
||||
fprintf(fp, " GV flag -> TRUE\n");
|
||||
fprintf(fp, " GV weight -> %8.0f(%%)\n", (float) (100 * condition->gv_weight[i]));
|
||||
fprintf(fp, " GV interpolation size -> %8lu\n", (unsigned long) HTS_ModelSet_get_nvoices(ms));
|
||||
/* interpolation */
|
||||
for (j = 0, temp = 0.0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
temp += condition->gv_iw[j][i];
|
||||
for (j = 0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
if (condition->gv_iw[j][i] != 0.0)
|
||||
condition->gv_iw[j][i] /= temp;
|
||||
for (j = 0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
fprintf(fp, " GV interpolation weight[%2lu] -> %8.0f(%%)\n", (unsigned long) j, (float) (100 * condition->gv_iw[j][i]));
|
||||
} else {
|
||||
fprintf(fp, " GV flag -> FALSE\n");
|
||||
}
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
|
||||
/* generated sequence */
|
||||
fprintf(fp, "[Generated sequence]\n");
|
||||
fprintf(fp, "Number of HMMs -> %8lu\n", (unsigned long) HTS_Label_get_size(label));
|
||||
fprintf(fp, "Number of stats -> %8lu\n", (unsigned long) HTS_Label_get_size(label) * HTS_ModelSet_get_nstate(ms));
|
||||
fprintf(fp, "Length of this speech -> %8.3f(sec)\n", (float) ((double) HTS_PStreamSet_get_total_frame(pss) * condition->fperiod / condition->sampling_frequency));
|
||||
fprintf(fp, " -> %8lu(frames)\n", (unsigned long) HTS_PStreamSet_get_total_frame(pss) * condition->fperiod);
|
||||
|
||||
for (i = 0; i < HTS_Label_get_size(label); i++) {
|
||||
fprintf(fp, "HMM[%2lu]\n", (unsigned long) i);
|
||||
fprintf(fp, " Name -> %s\n", HTS_Label_get_string(label, i));
|
||||
fprintf(fp, " Duration\n");
|
||||
for (j = 0; j < HTS_ModelSet_get_nvoices(ms); j++) {
|
||||
fprintf(fp, " Interpolation[%2lu]\n", (unsigned long) j);
|
||||
HTS_ModelSet_get_duration_index(ms, j, HTS_Label_get_string(label, i), &k, &l);
|
||||
fprintf(fp, " Tree index -> %8lu\n", (unsigned long) k);
|
||||
fprintf(fp, " PDF index -> %8lu\n", (unsigned long) l);
|
||||
}
|
||||
for (j = 0; j < HTS_ModelSet_get_nstate(ms); j++) {
|
||||
fprintf(fp, " State[%2lu]\n", (unsigned long) j + 2);
|
||||
fprintf(fp, " Length -> %8lu(frames)\n", (unsigned long) HTS_SStreamSet_get_duration(sss, i * HTS_ModelSet_get_nstate(ms) + j));
|
||||
for (k = 0; k < HTS_ModelSet_get_nstream(ms); k++) {
|
||||
fprintf(fp, " Stream[%2lu]\n", (unsigned long) k);
|
||||
if (HTS_ModelSet_is_msd(ms, k)) {
|
||||
if (HTS_SStreamSet_get_msd(sss, k, i * HTS_ModelSet_get_nstate(ms) + j) > condition->msd_threshold[k])
|
||||
fprintf(fp, " MSD flag -> TRUE\n");
|
||||
else
|
||||
fprintf(fp, " MSD flag -> FALSE\n");
|
||||
}
|
||||
for (l = 0; l < HTS_ModelSet_get_nvoices(ms); l++) {
|
||||
fprintf(fp, " Interpolation[%2lu]\n", (unsigned long) l);
|
||||
HTS_ModelSet_get_parameter_index(ms, l, k, j + 2, HTS_Label_get_string(label, i), &m, &n);
|
||||
fprintf(fp, " Tree index -> %8lu\n", (unsigned long) m);
|
||||
fprintf(fp, " PDF index -> %8lu\n", (unsigned long) n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Engine_save_label: save label with time */
|
||||
void HTS_Engine_save_label(HTS_Engine * engine, FILE * fp)
|
||||
{
|
||||
size_t i, j;
|
||||
size_t frame, state, duration;
|
||||
|
||||
HTS_Label *label = &engine->label;
|
||||
HTS_SStreamSet *sss = &engine->sss;
|
||||
size_t nstate = HTS_ModelSet_get_nstate(&engine->ms);
|
||||
double rate = engine->condition.fperiod * 1.0e+07 / engine->condition.sampling_frequency;
|
||||
|
||||
for (i = 0, state = 0, frame = 0; i < HTS_Label_get_size(label); i++) {
|
||||
for (j = 0, duration = 0; j < nstate; j++)
|
||||
duration += HTS_SStreamSet_get_duration(sss, state++);
|
||||
fprintf(fp, "%lu %lu %s\n", (unsigned long) (frame * rate), (unsigned long) ((frame + duration) * rate), HTS_Label_get_string(label, i));
|
||||
frame += duration;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Engine_save_generated_parameter: save generated parameter */
|
||||
void HTS_Engine_save_generated_parameter(HTS_Engine * engine, size_t stream_index, FILE * fp)
|
||||
{
|
||||
size_t i, j;
|
||||
float temp;
|
||||
HTS_GStreamSet *gss = &engine->gss;
|
||||
|
||||
for (i = 0; i < HTS_GStreamSet_get_total_frame(gss); i++)
|
||||
for (j = 0; j < HTS_GStreamSet_get_vector_length(gss, stream_index); j++) {
|
||||
temp = (float) HTS_GStreamSet_get_parameter(gss, stream_index, i, j);
|
||||
fwrite(&temp, sizeof(float), 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Engine_save_generated_speech: save generated speech */
|
||||
void HTS_Engine_save_generated_speech(HTS_Engine * engine, FILE * fp)
|
||||
{
|
||||
size_t i;
|
||||
double x;
|
||||
short temp;
|
||||
HTS_GStreamSet *gss = &engine->gss;
|
||||
|
||||
for (i = 0; i < HTS_GStreamSet_get_total_nsamples(gss); i++) {
|
||||
x = HTS_GStreamSet_get_speech(gss, i);
|
||||
if (x > 32767.0)
|
||||
temp = 32767;
|
||||
else if (x < -32768.0)
|
||||
temp = -32768;
|
||||
else
|
||||
temp = (short) x;
|
||||
fwrite(&temp, sizeof(short), 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Engine_save_riff: save RIFF format file */
|
||||
void HTS_Engine_save_riff(HTS_Engine * engine, FILE * fp)
|
||||
{
|
||||
size_t i;
|
||||
double x;
|
||||
short temp;
|
||||
|
||||
HTS_GStreamSet *gss = &engine->gss;
|
||||
char data_01_04[] = { 'R', 'I', 'F', 'F' };
|
||||
int data_05_08 = HTS_GStreamSet_get_total_nsamples(gss) * sizeof(short) + 36;
|
||||
char data_09_12[] = { 'W', 'A', 'V', 'E' };
|
||||
char data_13_16[] = { 'f', 'm', 't', ' ' };
|
||||
int data_17_20 = 16;
|
||||
short data_21_22 = 1; /* PCM */
|
||||
short data_23_24 = 1; /* monoral */
|
||||
int data_25_28 = engine->condition.sampling_frequency;
|
||||
int data_29_32 = engine->condition.sampling_frequency * sizeof(short);
|
||||
short data_33_34 = sizeof(short);
|
||||
short data_35_36 = (short) (sizeof(short) * 8);
|
||||
char data_37_40[] = { 'd', 'a', 't', 'a' };
|
||||
int data_41_44 = HTS_GStreamSet_get_total_nsamples(gss) * sizeof(short);
|
||||
|
||||
/* write header */
|
||||
HTS_fwrite_little_endian(data_01_04, sizeof(char), 4, fp);
|
||||
HTS_fwrite_little_endian(&data_05_08, sizeof(int), 1, fp);
|
||||
HTS_fwrite_little_endian(data_09_12, sizeof(char), 4, fp);
|
||||
HTS_fwrite_little_endian(data_13_16, sizeof(char), 4, fp);
|
||||
HTS_fwrite_little_endian(&data_17_20, sizeof(int), 1, fp);
|
||||
HTS_fwrite_little_endian(&data_21_22, sizeof(short), 1, fp);
|
||||
HTS_fwrite_little_endian(&data_23_24, sizeof(short), 1, fp);
|
||||
HTS_fwrite_little_endian(&data_25_28, sizeof(int), 1, fp);
|
||||
HTS_fwrite_little_endian(&data_29_32, sizeof(int), 1, fp);
|
||||
HTS_fwrite_little_endian(&data_33_34, sizeof(short), 1, fp);
|
||||
HTS_fwrite_little_endian(&data_35_36, sizeof(short), 1, fp);
|
||||
HTS_fwrite_little_endian(data_37_40, sizeof(char), 4, fp);
|
||||
HTS_fwrite_little_endian(&data_41_44, sizeof(int), 1, fp);
|
||||
/* write data */
|
||||
for (i = 0; i < HTS_GStreamSet_get_total_nsamples(gss); i++) {
|
||||
x = HTS_GStreamSet_get_speech(gss, i);
|
||||
if (x > 32767.0)
|
||||
temp = 32767;
|
||||
else if (x < -32768.0)
|
||||
temp = -32768;
|
||||
else
|
||||
temp = (short) x;
|
||||
HTS_fwrite_little_endian(&temp, sizeof(short), 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Engine_refresh: free model per one time synthesis */
|
||||
void HTS_Engine_refresh(HTS_Engine * engine)
|
||||
{
|
||||
/* free generated parameter stream set */
|
||||
HTS_GStreamSet_clear(&engine->gss);
|
||||
/* free parameter stream set */
|
||||
HTS_PStreamSet_clear(&engine->pss);
|
||||
/* free state stream set */
|
||||
HTS_SStreamSet_clear(&engine->sss);
|
||||
/* free label list */
|
||||
HTS_Label_clear(&engine->label);
|
||||
/* stop flag */
|
||||
engine->condition.stop = FALSE;
|
||||
}
|
||||
|
||||
/* HTS_Engine_clear: free engine */
|
||||
void HTS_Engine_clear(HTS_Engine * engine)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (engine->condition.msd_threshold != NULL)
|
||||
HTS_free(engine->condition.msd_threshold);
|
||||
if (engine->condition.duration_iw != NULL)
|
||||
HTS_free(engine->condition.duration_iw);
|
||||
if (engine->condition.gv_weight != NULL)
|
||||
HTS_free(engine->condition.gv_weight);
|
||||
if (engine->condition.parameter_iw != NULL) {
|
||||
for (i = 0; i < HTS_ModelSet_get_nvoices(&engine->ms); i++)
|
||||
HTS_free(engine->condition.parameter_iw[i]);
|
||||
HTS_free(engine->condition.parameter_iw);
|
||||
}
|
||||
if (engine->condition.gv_iw != NULL) {
|
||||
for (i = 0; i < HTS_ModelSet_get_nvoices(&engine->ms); i++)
|
||||
HTS_free(engine->condition.gv_iw[i]);
|
||||
HTS_free(engine->condition.gv_iw);
|
||||
}
|
||||
|
||||
HTS_ModelSet_clear(&engine->ms);
|
||||
HTS_Audio_clear(&engine->audio);
|
||||
HTS_Engine_initialize(engine);
|
||||
}
|
||||
|
||||
HTS_ENGINE_C_END;
|
||||
|
||||
#endif /* !HTS_ENGINE_C */
|
||||
203
3rdparty/hts_engine_API/lib/HTS_gstream.c
vendored
Normal file
203
3rdparty/hts_engine_API/lib/HTS_gstream.c
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_GSTREAM_C
|
||||
#define HTS_GSTREAM_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_GSTREAM_C_START extern "C" {
|
||||
#define HTS_GSTREAM_C_END }
|
||||
#else
|
||||
#define HTS_GSTREAM_C_START
|
||||
#define HTS_GSTREAM_C_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_GSTREAM_C_START;
|
||||
|
||||
/* hts_engine libraries */
|
||||
#include "HTS_hidden.h"
|
||||
|
||||
/* HTS_GStreamSet_initialize: initialize generated parameter stream set */
|
||||
void HTS_GStreamSet_initialize(HTS_GStreamSet * gss)
|
||||
{
|
||||
gss->nstream = 0;
|
||||
gss->total_frame = 0;
|
||||
gss->total_nsample = 0;
|
||||
gss->gstream = NULL;
|
||||
gss->gspeech = NULL;
|
||||
}
|
||||
|
||||
/* HTS_GStreamSet_create: generate speech */
|
||||
HTS_Boolean HTS_GStreamSet_create(HTS_GStreamSet * gss, HTS_PStreamSet * pss, size_t stage, HTS_Boolean use_log_gain, size_t sampling_rate, size_t fperiod, double alpha, double beta, HTS_Boolean * stop, double volume, HTS_Audio * audio)
|
||||
{
|
||||
size_t i, j, k;
|
||||
size_t msd_frame;
|
||||
HTS_Vocoder v;
|
||||
size_t nlpf = 0;
|
||||
double *lpf = NULL;
|
||||
|
||||
/* check */
|
||||
if (gss->gstream || gss->gspeech) {
|
||||
HTS_error(1, "HTS_GStreamSet_create: HTS_GStreamSet is not initialized.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* initialize */
|
||||
gss->nstream = HTS_PStreamSet_get_nstream(pss);
|
||||
gss->total_frame = HTS_PStreamSet_get_total_frame(pss);
|
||||
gss->total_nsample = fperiod * gss->total_frame;
|
||||
gss->gstream = (HTS_GStream *) HTS_calloc(gss->nstream, sizeof(HTS_GStream));
|
||||
for (i = 0; i < gss->nstream; i++) {
|
||||
gss->gstream[i].vector_length = HTS_PStreamSet_get_vector_length(pss, i);
|
||||
gss->gstream[i].par = (double **) HTS_calloc(gss->total_frame, sizeof(double *));
|
||||
for (j = 0; j < gss->total_frame; j++)
|
||||
gss->gstream[i].par[j] = (double *) HTS_calloc(gss->gstream[i].vector_length, sizeof(double));
|
||||
}
|
||||
gss->gspeech = (double *) HTS_calloc(gss->total_nsample, sizeof(double));
|
||||
|
||||
/* copy generated parameter */
|
||||
for (i = 0; i < gss->nstream; i++) {
|
||||
if (HTS_PStreamSet_is_msd(pss, i)) { /* for MSD */
|
||||
for (j = 0, msd_frame = 0; j < gss->total_frame; j++)
|
||||
if (HTS_PStreamSet_get_msd_flag(pss, i, j) == TRUE) {
|
||||
for (k = 0; k < gss->gstream[i].vector_length; k++)
|
||||
gss->gstream[i].par[j][k] = HTS_PStreamSet_get_parameter(pss, i, msd_frame, k);
|
||||
msd_frame++;
|
||||
} else
|
||||
for (k = 0; k < gss->gstream[i].vector_length; k++)
|
||||
gss->gstream[i].par[j][k] = HTS_NODATA;
|
||||
} else { /* for non MSD */
|
||||
for (j = 0; j < gss->total_frame; j++)
|
||||
for (k = 0; k < gss->gstream[i].vector_length; k++)
|
||||
gss->gstream[i].par[j][k] = HTS_PStreamSet_get_parameter(pss, i, j, k);
|
||||
}
|
||||
}
|
||||
|
||||
/* check */
|
||||
if (gss->nstream != 2 && gss->nstream != 3) {
|
||||
HTS_error(1, "HTS_GStreamSet_create: The number of streams should be 2 or 3.\n");
|
||||
HTS_GStreamSet_clear(gss);
|
||||
return FALSE;
|
||||
}
|
||||
if (HTS_PStreamSet_get_vector_length(pss, 1) != 1) {
|
||||
HTS_error(1, "HTS_GStreamSet_create: The size of lf0 static vector should be 1.\n");
|
||||
HTS_GStreamSet_clear(gss);
|
||||
return FALSE;
|
||||
}
|
||||
if (gss->nstream >= 3 && gss->gstream[2].vector_length % 2 == 0) {
|
||||
HTS_error(1, "HTS_GStreamSet_create: The number of low-pass filter coefficient should be odd numbers.");
|
||||
HTS_GStreamSet_clear(gss);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* synthesize speech waveform */
|
||||
HTS_Vocoder_initialize(&v, gss->gstream[0].vector_length - 1, stage, use_log_gain, sampling_rate, fperiod);
|
||||
if (gss->nstream >= 3)
|
||||
nlpf = gss->gstream[2].vector_length;
|
||||
for (i = 0; i < gss->total_frame && (*stop) == FALSE; i++) {
|
||||
j = i * fperiod;
|
||||
if (gss->nstream >= 3)
|
||||
lpf = &gss->gstream[2].par[i][0];
|
||||
HTS_Vocoder_synthesize(&v, gss->gstream[0].vector_length - 1, gss->gstream[1].par[i][0], &gss->gstream[0].par[i][0], nlpf, lpf, alpha, beta, volume, &gss->gspeech[j], audio);
|
||||
}
|
||||
HTS_Vocoder_clear(&v);
|
||||
if (audio)
|
||||
HTS_Audio_flush(audio);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_GStreamSet_get_total_nsamples: get total number of sample */
|
||||
size_t HTS_GStreamSet_get_total_nsamples(HTS_GStreamSet * gss)
|
||||
{
|
||||
return gss->total_nsample;
|
||||
}
|
||||
|
||||
/* HTS_GStreamSet_get_total_frame: get total number of frame */
|
||||
size_t HTS_GStreamSet_get_total_frame(HTS_GStreamSet * gss)
|
||||
{
|
||||
return gss->total_frame;
|
||||
}
|
||||
|
||||
/* HTS_GStreamSet_get_vector_length: get features length */
|
||||
size_t HTS_GStreamSet_get_vector_length(HTS_GStreamSet * gss, size_t stream_index)
|
||||
{
|
||||
return gss->gstream[stream_index].vector_length;
|
||||
}
|
||||
|
||||
/* HTS_GStreamSet_get_speech: get synthesized speech parameter */
|
||||
double HTS_GStreamSet_get_speech(HTS_GStreamSet * gss, size_t sample_index)
|
||||
{
|
||||
return gss->gspeech[sample_index];
|
||||
}
|
||||
|
||||
/* HTS_GStreamSet_get_parameter: get generated parameter */
|
||||
double HTS_GStreamSet_get_parameter(HTS_GStreamSet * gss, size_t stream_index, size_t frame_index, size_t vector_index)
|
||||
{
|
||||
return gss->gstream[stream_index].par[frame_index][vector_index];
|
||||
}
|
||||
|
||||
/* HTS_GStreamSet_clear: free generated parameter stream set */
|
||||
void HTS_GStreamSet_clear(HTS_GStreamSet * gss)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
if (gss->gstream) {
|
||||
for (i = 0; i < gss->nstream; i++) {
|
||||
if (gss->gstream[i].par != NULL) {
|
||||
for (j = 0; j < gss->total_frame; j++)
|
||||
HTS_free(gss->gstream[i].par[j]);
|
||||
HTS_free(gss->gstream[i].par);
|
||||
}
|
||||
}
|
||||
HTS_free(gss->gstream);
|
||||
}
|
||||
if (gss->gspeech)
|
||||
HTS_free(gss->gspeech);
|
||||
HTS_GStreamSet_initialize(gss);
|
||||
}
|
||||
|
||||
HTS_GSTREAM_C_END;
|
||||
|
||||
#endif /* !HTS_GSTREAM_C */
|
||||
510
3rdparty/hts_engine_API/lib/HTS_hidden.h
vendored
Normal file
510
3rdparty/hts_engine_API/lib/HTS_hidden.h
vendored
Normal file
@@ -0,0 +1,510 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_HIDDEN_H
|
||||
#define HTS_HIDDEN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_HIDDEN_H_START extern "C" {
|
||||
#define HTS_HIDDEN_H_END }
|
||||
#else
|
||||
#define HTS_HIDDEN_H_START
|
||||
#define HTS_HIDDEN_H_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_HIDDEN_H_START;
|
||||
|
||||
/* hts_engine libraries */
|
||||
#include "HTS_engine.h"
|
||||
|
||||
/* common ---------------------------------------------------------- */
|
||||
|
||||
#define HTS_MAXBUFLEN 1024
|
||||
|
||||
#if !defined(WORDS_BIGENDIAN) && !defined(WORDS_LITTLEENDIAN)
|
||||
#define WORDS_LITTLEENDIAN
|
||||
#endif /* !WORDS_BIGENDIAN && !WORDS_LITTLEENDIAN */
|
||||
#if defined(WORDS_BIGENDIAN) && defined(WORDS_LITTLEENDIAN)
|
||||
#undef WORDS_BIGENDIAN
|
||||
#endif /* WORDS_BIGENDIAN && WORDS_LITTLEENDIAN */
|
||||
|
||||
#define MAX_F0 20000.0
|
||||
#define MIN_F0 20.0
|
||||
#define MAX_LF0 9.9034875525361280454891979401956 /* log(20000.0) */
|
||||
#define MIN_LF0 2.9957322735539909934352235761425 /* log(20.0) */
|
||||
#define HALF_TONE 0.05776226504666210911810267678818 /* log(2.0) / 12.0 */
|
||||
#define DB 0.11512925464970228420089957273422 /* log(10.0) / 20.0 */
|
||||
|
||||
/* misc ------------------------------------------------------------ */
|
||||
|
||||
typedef struct _HTS_File {
|
||||
unsigned char type;
|
||||
void *pointer;
|
||||
} HTS_File;
|
||||
|
||||
/* HTS_fopen: wrapper for fopen */
|
||||
HTS_File *HTS_fopen_from_fn(const char *name, const char *opt);
|
||||
|
||||
/* HTS_fopen_from_fp: wrapper for fopen */
|
||||
HTS_File *HTS_fopen_from_fp(HTS_File * fp, size_t size);
|
||||
|
||||
/* HTS_fopen_from_data: wrapper for fopen */
|
||||
HTS_File *HTS_fopen_from_data(void *data, size_t size);
|
||||
|
||||
/* HTS_fclose: wrapper for fclose */
|
||||
void HTS_fclose(HTS_File * fp);
|
||||
|
||||
/* HTS_fgetc: wrapper for fgetc */
|
||||
int HTS_fgetc(HTS_File * fp);
|
||||
|
||||
/* HTS_feof: wrapper for feof */
|
||||
int HTS_feof(HTS_File * fp);
|
||||
|
||||
/* HTS_fseek: wrapper for fseek */
|
||||
int HTS_fseek(HTS_File * fp, long offset, int origin);
|
||||
|
||||
/* HTS_ftell: wrapper for ftell */
|
||||
size_t HTS_ftell(HTS_File * fp);
|
||||
|
||||
/* HTS_fread_big_endian: fread with byteswap */
|
||||
size_t HTS_fread_big_endian(void *buf, size_t size, size_t n, HTS_File * fp);
|
||||
|
||||
/* HTS_fread_little_endian: fread with byteswap */
|
||||
size_t HTS_fread_little_endian(void *buf, size_t size, size_t n, HTS_File * fp);
|
||||
|
||||
/* HTS_fwrite_little_endian: fwrite with byteswap */
|
||||
size_t HTS_fwrite_little_endian(const void *buf, size_t size, size_t n, FILE * fp);
|
||||
|
||||
/* HTS_get_pattern_token: get pattern token (single/double quote can be used) */
|
||||
HTS_Boolean HTS_get_pattern_token(HTS_File * fp, char *buff);
|
||||
|
||||
/* HTS_get_token: get token from file pointer (separators are space,tab,line break) */
|
||||
HTS_Boolean HTS_get_token_from_fp(HTS_File * fp, char *buff);
|
||||
|
||||
/* HTS_get_token: get token from file pointer with specified separator */
|
||||
HTS_Boolean HTS_get_token_from_fp_with_separator(HTS_File * fp, char *buff, char separator);
|
||||
|
||||
/* HTS_get_token_from_string: get token from string (separator are space,tab,line break) */
|
||||
HTS_Boolean HTS_get_token_from_string(const char *string, size_t * index, char *buff);
|
||||
|
||||
/* HTS_get_token_from_string_with_separator: get token from string with specified separator */
|
||||
HTS_Boolean HTS_get_token_from_string_with_separator(const char *str, size_t * index, char *buff, char separator);
|
||||
|
||||
/* HTS_calloc: wrapper for calloc */
|
||||
void *HTS_calloc(const size_t num, const size_t size);
|
||||
|
||||
/* HTS_strdup: wrapper for strdup */
|
||||
char *HTS_strdup(const char *string);
|
||||
|
||||
/* HTS_calloc_matrix: allocate double matrix */
|
||||
double **HTS_alloc_matrix(size_t x, size_t y);
|
||||
|
||||
/* HTS_free_matrix: free double matrix */
|
||||
void HTS_free_matrix(double **p, size_t x);
|
||||
|
||||
/* HTS_Free: wrapper for free */
|
||||
void HTS_free(void *p);
|
||||
|
||||
/* HTS_error: output error message */
|
||||
void HTS_error(int error, const char *message, ...);
|
||||
|
||||
/* audio ----------------------------------------------------------- */
|
||||
|
||||
/* HTS_Audio_initialize: initialize audio */
|
||||
void HTS_Audio_initialize(HTS_Audio * audio);
|
||||
|
||||
/* HTS_Audio_set_parameter: set parameters for audio */
|
||||
void HTS_Audio_set_parameter(HTS_Audio * audio, size_t sampling_frequency, size_t max_buff_size);
|
||||
|
||||
/* HTS_Audio_write: send data to audio */
|
||||
void HTS_Audio_write(HTS_Audio * audio, short data);
|
||||
|
||||
/* HTS_Audio_flush: flush remain data */
|
||||
void HTS_Audio_flush(HTS_Audio * audio);
|
||||
|
||||
/* HTS_Audio_clear: free audio */
|
||||
void HTS_Audio_clear(HTS_Audio * audio);
|
||||
|
||||
/* model ----------------------------------------------------------- */
|
||||
|
||||
/* HTS_ModelSet_initialize: initialize model set */
|
||||
void HTS_ModelSet_initialize(HTS_ModelSet * ms);
|
||||
|
||||
/* HTS_ModelSet_load: load HTS voices */
|
||||
HTS_Boolean HTS_ModelSet_load(HTS_ModelSet * ms, char **voices, size_t num_voices);
|
||||
|
||||
/* HTS_ModelSet_get_sampling_frequency: get sampling frequency of HTS voices */
|
||||
size_t HTS_ModelSet_get_sampling_frequency(HTS_ModelSet * ms);
|
||||
|
||||
/* HTS_ModelSet_get_fperiod: get frame period of HTS voices */
|
||||
size_t HTS_ModelSet_get_fperiod(HTS_ModelSet * ms);
|
||||
|
||||
/* HTS_ModelSet_get_fperiod: get stream option */
|
||||
const char *HTS_ModelSet_get_option(HTS_ModelSet * ms, size_t stream_index);
|
||||
|
||||
/* HTS_ModelSet_get_gv_flag: get GV flag */
|
||||
HTS_Boolean HTS_ModelSet_get_gv_flag(HTS_ModelSet * ms, const char *string);
|
||||
|
||||
/* HTS_ModelSet_get_nstate: get number of state */
|
||||
size_t HTS_ModelSet_get_nstate(HTS_ModelSet * ms);
|
||||
|
||||
/* HTS_Engine_get_fullcontext_label_format: get full-context label format */
|
||||
const char *HTS_ModelSet_get_fullcontext_label_format(HTS_ModelSet * ms);
|
||||
|
||||
/* HTS_Engine_get_fullcontext_label_version: get full-context label version */
|
||||
const char *HTS_ModelSet_get_fullcontext_label_version(HTS_ModelSet * ms);
|
||||
|
||||
/* HTS_ModelSet_get_nstream: get number of stream */
|
||||
size_t HTS_ModelSet_get_nstream(HTS_ModelSet * ms);
|
||||
|
||||
/* HTS_ModelSet_get_nvoices: get number of HTS voices */
|
||||
size_t HTS_ModelSet_get_nvoices(HTS_ModelSet * ms);
|
||||
|
||||
/* HTS_ModelSet_get_vector_length: get vector length */
|
||||
size_t HTS_ModelSet_get_vector_length(HTS_ModelSet * ms, size_t stream_index);
|
||||
|
||||
/* HTS_ModelSet_is_msd: get MSD flag */
|
||||
HTS_Boolean HTS_ModelSet_is_msd(HTS_ModelSet * ms, size_t stream_index);
|
||||
|
||||
/* HTS_ModelSet_get_window_size: get dynamic window size */
|
||||
size_t HTS_ModelSet_get_window_size(HTS_ModelSet * ms, size_t stream_index);
|
||||
|
||||
/* HTS_ModelSet_get_window_left_width: get left width of dynamic window */
|
||||
int HTS_ModelSet_get_window_left_width(HTS_ModelSet * ms, size_t stream_index, size_t window_index);
|
||||
|
||||
/* HTS_ModelSet_get_window_right_width: get right width of dynamic window */
|
||||
int HTS_ModelSet_get_window_right_width(HTS_ModelSet * ms, size_t stream_index, size_t window_index);
|
||||
|
||||
/* HTS_ModelSet_get_window_coefficient: get coefficient of dynamic window */
|
||||
double HTS_ModelSet_get_window_coefficient(HTS_ModelSet * ms, size_t stream_index, size_t window_index, size_t coefficient_index);
|
||||
|
||||
/* HTS_ModelSet_get_window_max_width: get max width of dynamic window */
|
||||
size_t HTS_ModelSet_get_window_max_width(HTS_ModelSet * ms, size_t stream_index);
|
||||
|
||||
/* HTS_ModelSet_use_gv: get GV flag */
|
||||
HTS_Boolean HTS_ModelSet_use_gv(HTS_ModelSet * ms, size_t stream_index);
|
||||
|
||||
/* HTS_ModelSet_get_duration_index: get index of duration tree and PDF */
|
||||
void HTS_ModelSet_get_duration_index(HTS_ModelSet * ms, size_t voice_index, const char *string, size_t * tree_index, size_t * pdf_index);
|
||||
|
||||
/* HTS_ModelSet_get_duration: get duration using interpolation weight */
|
||||
void HTS_ModelSet_get_duration(HTS_ModelSet * ms, const char *string, const double *iw, double *mean, double *vari);
|
||||
|
||||
/* HTS_ModelSet_get_parameter_index: get index of parameter tree and PDF */
|
||||
void HTS_ModelSet_get_parameter_index(HTS_ModelSet * ms, size_t voice_index, size_t stream_index, size_t state_index, const char *string, size_t * tree_index, size_t * pdf_index);
|
||||
|
||||
/* HTS_ModelSet_get_parameter: get parameter using interpolation weight */
|
||||
void HTS_ModelSet_get_parameter(HTS_ModelSet * ms, size_t stream_index, size_t state_index, const char *string, const double *const *iw, double *mean, double *vari, double *msd);
|
||||
|
||||
void HTS_ModelSet_get_gv_index(HTS_ModelSet * ms, size_t voice_index, size_t stream_index, const char *string, size_t * tree_index, size_t * pdf_index);
|
||||
|
||||
/* HTS_ModelSet_get_gv: get GV using interpolation weight */
|
||||
void HTS_ModelSet_get_gv(HTS_ModelSet * ms, size_t stream_index, const char *string, const double *const *iw, double *mean, double *vari);
|
||||
|
||||
/* HTS_ModelSet_clear: free model set */
|
||||
void HTS_ModelSet_clear(HTS_ModelSet * ms);
|
||||
|
||||
/* label ----------------------------------------------------------- */
|
||||
|
||||
/* HTS_Label_initialize: initialize label */
|
||||
void HTS_Label_initialize(HTS_Label * label);
|
||||
|
||||
/* HTS_Label_load_from_fn: load label from file name */
|
||||
void HTS_Label_load_from_fn(HTS_Label * label, size_t sampling_rate, size_t fperiod, const char *fn);
|
||||
|
||||
/* HTS_Label_load_from_strings: load label list from string list */
|
||||
void HTS_Label_load_from_strings(HTS_Label * label, size_t sampling_rate, size_t fperiod, char **lines, size_t num_lines);
|
||||
|
||||
/* HTS_Label_get_size: get number of label string */
|
||||
size_t HTS_Label_get_size(HTS_Label * label);
|
||||
|
||||
/* HTS_Label_get_string: get label string */
|
||||
const char *HTS_Label_get_string(HTS_Label * label, size_t index);
|
||||
|
||||
/* HTS_Label_get_start_frame: get start frame */
|
||||
double HTS_Label_get_start_frame(HTS_Label * label, size_t index);
|
||||
|
||||
/* HTS_Label_get_end_frame: get end frame */
|
||||
double HTS_Label_get_end_frame(HTS_Label * label, size_t index);
|
||||
|
||||
/* HTS_Label_clear: free label */
|
||||
void HTS_Label_clear(HTS_Label * label);
|
||||
|
||||
/* sstream --------------------------------------------------------- */
|
||||
|
||||
/* HTS_SStreamSet_initialize: initialize state stream set */
|
||||
void HTS_SStreamSet_initialize(HTS_SStreamSet * sss);
|
||||
|
||||
/* HTS_SStreamSet_create: parse label and determine state duration */
|
||||
HTS_Boolean HTS_SStreamSet_create(HTS_SStreamSet * sss, HTS_ModelSet * ms, HTS_Label * label, HTS_Boolean phoneme_alignment_flag, double speed, double *duration_iw, double **parameter_iw, double **gv_iw);
|
||||
|
||||
/* HTS_SStreamSet_get_nstream: get number of stream */
|
||||
size_t HTS_SStreamSet_get_nstream(HTS_SStreamSet * sss);
|
||||
|
||||
/* HTS_SStreamSet_get_vector_length: get vector length */
|
||||
size_t HTS_SStreamSet_get_vector_length(HTS_SStreamSet * sss, size_t stream_index);
|
||||
|
||||
/* HTS_SStreamSet_is_msd: get MSD flag */
|
||||
HTS_Boolean HTS_SStreamSet_is_msd(HTS_SStreamSet * sss, size_t stream_index);
|
||||
|
||||
/* HTS_SStreamSet_get_total_state: get total number of state */
|
||||
size_t HTS_SStreamSet_get_total_state(HTS_SStreamSet * sss);
|
||||
|
||||
/* HTS_SStreamSet_get_total_frame: get total number of frame */
|
||||
size_t HTS_SStreamSet_get_total_frame(HTS_SStreamSet * sss);
|
||||
|
||||
/* HTS_SStreamSet_get_msd: get msd parameter */
|
||||
double HTS_SStreamSet_get_msd(HTS_SStreamSet * sss, size_t stream_index, size_t state_index);
|
||||
|
||||
/* HTS_SStreamSet_window_size: get dynamic window size */
|
||||
size_t HTS_SStreamSet_get_window_size(HTS_SStreamSet * sss, size_t stream_index);
|
||||
|
||||
/* HTS_SStreamSet_get_window_left_width: get left width of dynamic window */
|
||||
int HTS_SStreamSet_get_window_left_width(HTS_SStreamSet * sss, size_t stream_index, size_t window_index);
|
||||
|
||||
/* HTS_SStreamSet_get_window_right_width: get right width of dynamic window */
|
||||
int HTS_SStreamSet_get_window_right_width(HTS_SStreamSet * sss, size_t stream_index, size_t window_index);
|
||||
|
||||
/* HTS_SStreamSet_get_window_coefficient: get coefficient of dynamic window */
|
||||
double HTS_SStreamSet_get_window_coefficient(HTS_SStreamSet * sss, size_t stream_index, size_t window_index, int coefficient_index);
|
||||
|
||||
/* HTS_SStreamSet_get_window_max_width: get max width of dynamic window */
|
||||
size_t HTS_SStreamSet_get_window_max_width(HTS_SStreamSet * sss, size_t stream_index);
|
||||
|
||||
/* HTS_SStreamSet_use_gv: get GV flag */
|
||||
HTS_Boolean HTS_SStreamSet_use_gv(HTS_SStreamSet * sss, size_t stream_index);
|
||||
|
||||
/* HTS_SStreamSet_get_duration: get state duration */
|
||||
size_t HTS_SStreamSet_get_duration(HTS_SStreamSet * sss, size_t state_index);
|
||||
|
||||
/* HTS_SStreamSet_get_mean: get mean parameter */
|
||||
double HTS_SStreamSet_get_mean(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, size_t vector_index);
|
||||
|
||||
/* HTS_SStreamSet_set_mean: set mean parameter */
|
||||
void HTS_SStreamSet_set_mean(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, size_t vector_index, double f);
|
||||
|
||||
/* HTS_SStreamSet_get_vari: get variance parameter */
|
||||
double HTS_SStreamSet_get_vari(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, size_t vector_index);
|
||||
|
||||
/* HTS_SStreamSet_set_vari: set variance parameter */
|
||||
void HTS_SStreamSet_set_vari(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, size_t vector_index, double f);
|
||||
|
||||
/* HTS_SStreamSet_get_gv_mean: get GV mean parameter */
|
||||
double HTS_SStreamSet_get_gv_mean(HTS_SStreamSet * sss, size_t stream_index, size_t vector_index);
|
||||
|
||||
/* HTS_SStreamSet_get_gv_mean: get GV variance parameter */
|
||||
double HTS_SStreamSet_get_gv_vari(HTS_SStreamSet * sss, size_t stream_index, size_t vector_index);
|
||||
|
||||
/* HTS_SStreamSet_set_gv_switch: set GV switch */
|
||||
void HTS_SStreamSet_set_gv_switch(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, HTS_Boolean i);
|
||||
|
||||
/* HTS_SStreamSet_get_gv_switch: get GV switch */
|
||||
HTS_Boolean HTS_SStreamSet_get_gv_switch(HTS_SStreamSet * sss, size_t stream_index, size_t state_index);
|
||||
|
||||
/* HTS_SStreamSet_clear: free state stream set */
|
||||
void HTS_SStreamSet_clear(HTS_SStreamSet * sss);
|
||||
|
||||
/* pstream --------------------------------------------------------- */
|
||||
|
||||
/* check variance in finv() */
|
||||
#define INFTY ((double) 1.0e+38)
|
||||
#define INFTY2 ((double) 1.0e+19)
|
||||
#define INVINF ((double) 1.0e-38)
|
||||
#define INVINF2 ((double) 1.0e-19)
|
||||
|
||||
/* GV */
|
||||
#define STEPINIT 0.1
|
||||
#define STEPDEC 0.5
|
||||
#define STEPINC 1.2
|
||||
#define W1 1.0
|
||||
#define W2 1.0
|
||||
#define GV_MAX_ITERATION 5
|
||||
|
||||
/* HTS_PStreamSet_initialize: initialize parameter stream set */
|
||||
void HTS_PStreamSet_initialize(HTS_PStreamSet * pss);
|
||||
|
||||
/* HTS_PStreamSet_create: parameter generation using GV weight */
|
||||
HTS_Boolean HTS_PStreamSet_create(HTS_PStreamSet * pss, HTS_SStreamSet * sss, double *msd_threshold, double *gv_weight);
|
||||
|
||||
/* HTS_PStreamSet_get_nstream: get number of stream */
|
||||
size_t HTS_PStreamSet_get_nstream(HTS_PStreamSet * pss);
|
||||
|
||||
/* HTS_PStreamSet_get_static_length: get features length */
|
||||
size_t HTS_PStreamSet_get_vector_length(HTS_PStreamSet * pss, size_t stream_index);
|
||||
|
||||
/* HTS_PStreamSet_get_total_frame: get total number of frame */
|
||||
size_t HTS_PStreamSet_get_total_frame(HTS_PStreamSet * pss);
|
||||
|
||||
/* HTS_PStreamSet_get_parameter: get parameter */
|
||||
double HTS_PStreamSet_get_parameter(HTS_PStreamSet * pss, size_t stream_index, size_t frame_index, size_t vector_index);
|
||||
|
||||
/* HTS_PStreamSet_get_parameter_vector: get parameter vector */
|
||||
double *HTS_PStreamSet_get_parameter_vector(HTS_PStreamSet * pss, size_t stream_index, size_t frame_index);
|
||||
|
||||
/* HTS_PStreamSet_get_msd_flag: get generated MSD flag per frame */
|
||||
HTS_Boolean HTS_PStreamSet_get_msd_flag(HTS_PStreamSet * pss, size_t stream_index, size_t frame_index);
|
||||
|
||||
/* HTS_PStreamSet_is_msd: get MSD flag */
|
||||
HTS_Boolean HTS_PStreamSet_is_msd(HTS_PStreamSet * pss, size_t stream_index);
|
||||
|
||||
/* HTS_PStreamSet_clear: free parameter stream set */
|
||||
void HTS_PStreamSet_clear(HTS_PStreamSet * pss);
|
||||
|
||||
/* gstream --------------------------------------------------------- */
|
||||
|
||||
/* HTS_GStreamSet_initialize: initialize generated parameter stream set */
|
||||
void HTS_GStreamSet_initialize(HTS_GStreamSet * gss);
|
||||
|
||||
/* HTS_GStreamSet_create: generate speech */
|
||||
HTS_Boolean HTS_GStreamSet_create(HTS_GStreamSet * gss, HTS_PStreamSet * pss, size_t stage, HTS_Boolean use_log_gain, size_t sampling_rate, size_t fperiod, double alpha, double beta, HTS_Boolean * stop, double volume, HTS_Audio * audio);
|
||||
|
||||
/* HTS_GStreamSet_get_total_nsamples: get total number of sample */
|
||||
size_t HTS_GStreamSet_get_total_nsamples(HTS_GStreamSet * gss);
|
||||
|
||||
/* HTS_GStreamSet_get_total_frame: get total number of frame */
|
||||
size_t HTS_GStreamSet_get_total_frame(HTS_GStreamSet * gss);
|
||||
|
||||
/* HTS_GStreamSet_get_static_length: get features length */
|
||||
size_t HTS_GStreamSet_get_vector_length(HTS_GStreamSet * gss, size_t stream_index);
|
||||
|
||||
/* HTS_GStreamSet_get_speech: get synthesized speech parameter */
|
||||
double HTS_GStreamSet_get_speech(HTS_GStreamSet * gss, size_t sample_index);
|
||||
|
||||
/* HTS_GStreamSet_get_parameter: get generated parameter */
|
||||
double HTS_GStreamSet_get_parameter(HTS_GStreamSet * gss, size_t stream_index, size_t frame_index, size_t vector_index);
|
||||
|
||||
/* HTS_GStreamSet_clear: free generated parameter stream set */
|
||||
void HTS_GStreamSet_clear(HTS_GStreamSet * gss);
|
||||
|
||||
/* vocoder --------------------------------------------------------- */
|
||||
|
||||
#ifndef LZERO
|
||||
#define LZERO (-1.0e+10) /* ~log(0) */
|
||||
#endif /* !LZERO */
|
||||
|
||||
#ifndef ZERO
|
||||
#define ZERO (1.0e-10) /* ~(0) */
|
||||
#endif /* !ZERO */
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.14159265358979323846
|
||||
#endif /* !PI */
|
||||
|
||||
#ifndef PI2
|
||||
#define PI2 6.28318530717958647692
|
||||
#endif /* !PI2 */
|
||||
|
||||
#define RANDMAX 32767
|
||||
|
||||
#define SEED 1
|
||||
#define B0 0x00000001
|
||||
#define B28 0x10000000
|
||||
#define B31 0x80000000
|
||||
#define B31_ 0x7fffffff
|
||||
#define Z 0x00000000
|
||||
|
||||
#ifdef HTS_EMBEDDED
|
||||
#define GAUSS FALSE
|
||||
#define PADEORDER 4 /* pade order (for MLSA filter) */
|
||||
#define IRLENG 384 /* length of impulse response */
|
||||
#else
|
||||
#define GAUSS TRUE
|
||||
#define PADEORDER 5
|
||||
#define IRLENG 576
|
||||
#endif /* HTS_EMBEDDED */
|
||||
|
||||
#define CHECK_LSP_STABILITY_MIN 0.25
|
||||
#define CHECK_LSP_STABILITY_NUM 4
|
||||
|
||||
/* for MGLSA filter */
|
||||
#define NORMFLG1 TRUE
|
||||
#define NORMFLG2 FALSE
|
||||
#define MULGFLG1 TRUE
|
||||
#define MULGFLG2 FALSE
|
||||
#define NGAIN FALSE
|
||||
|
||||
/* HTS_Vocoder: structure for setting of vocoder */
|
||||
typedef struct _HTS_Vocoder {
|
||||
HTS_Boolean is_first;
|
||||
size_t stage; /* Gamma=-1/stage: if stage=0 then Gamma=0 */
|
||||
double gamma; /* Gamma */
|
||||
HTS_Boolean use_log_gain; /* log gain flag (for LSP) */
|
||||
size_t fprd; /* frame shift */
|
||||
unsigned long next; /* temporary variable for random generator */
|
||||
HTS_Boolean gauss; /* flag to use Gaussian noise */
|
||||
double rate; /* sampling rate */
|
||||
double pitch_of_curr_point; /* used in excitation generation */
|
||||
double pitch_counter; /* used in excitation generation */
|
||||
double pitch_inc_per_point; /* used in excitation generation */
|
||||
double *excite_ring_buff; /* used in excitation generation */
|
||||
size_t excite_buff_size; /* used in excitation generation */
|
||||
size_t excite_buff_index; /* used in excitation generation */
|
||||
unsigned char sw; /* switch used in random generator */
|
||||
int x; /* excitation signal */
|
||||
double *freqt_buff; /* used in freqt */
|
||||
size_t freqt_size; /* buffer size for freqt */
|
||||
double *spectrum2en_buff; /* used in spectrum2en */
|
||||
size_t spectrum2en_size; /* buffer size for spectrum2en */
|
||||
double r1, r2, s; /* used in random generator */
|
||||
double *postfilter_buff; /* used in postfiltering */
|
||||
size_t postfilter_size; /* buffer size for postfiltering */
|
||||
double *c, *cc, *cinc, *d1; /* used in the MLSA/MGLSA filter */
|
||||
double *lsp2lpc_buff; /* used in lsp2lpc */
|
||||
size_t lsp2lpc_size; /* buffer size of lsp2lpc */
|
||||
double *gc2gc_buff; /* used in gc2gc */
|
||||
size_t gc2gc_size; /* buffer size for gc2gc */
|
||||
} HTS_Vocoder;
|
||||
|
||||
/* HTS_Vocoder_initialize: initialize vocoder */
|
||||
void HTS_Vocoder_initialize(HTS_Vocoder * v, size_t m, size_t stage, HTS_Boolean use_log_gain, size_t rate, size_t fperiod);
|
||||
|
||||
/* HTS_Vocoder_synthesize: pulse/noise excitation and MLSA/MGLSA filster based waveform synthesis */
|
||||
void HTS_Vocoder_synthesize(HTS_Vocoder * v, size_t m, double lf0, double *spectrum, size_t nlpf, double *lpf, double alpha, double beta, double volume, double *rawdata, HTS_Audio * audio);
|
||||
|
||||
/* HTS_Vocoder_clear: clear vocoder */
|
||||
void HTS_Vocoder_clear(HTS_Vocoder * v);
|
||||
|
||||
HTS_HIDDEN_H_END;
|
||||
|
||||
#endif /* !HTS_HIDDEN_H */
|
||||
263
3rdparty/hts_engine_API/lib/HTS_label.c
vendored
Normal file
263
3rdparty/hts_engine_API/lib/HTS_label.c
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_LABEL_C
|
||||
#define HTS_LABEL_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_LABEL_C_START extern "C" {
|
||||
#define HTS_LABEL_C_END }
|
||||
#else
|
||||
#define HTS_LABEL_C_START
|
||||
#define HTS_LABEL_C_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_LABEL_C_START;
|
||||
|
||||
#include <stdlib.h> /* for atof() */
|
||||
#include <ctype.h> /* for isgraph(),isdigit() */
|
||||
|
||||
/* hts_engine libraries */
|
||||
#include "HTS_hidden.h"
|
||||
|
||||
static HTS_Boolean isdigit_string(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (sscanf(str, "%d", &i) == 1)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* HTS_Label_initialize: initialize label */
|
||||
void HTS_Label_initialize(HTS_Label * label)
|
||||
{
|
||||
label->head = NULL;
|
||||
label->size = 0;
|
||||
}
|
||||
|
||||
/* HTS_Label_check_time: check label */
|
||||
static void HTS_Label_check_time(HTS_Label * label)
|
||||
{
|
||||
HTS_LabelString *lstring = label->head;
|
||||
HTS_LabelString *next = NULL;
|
||||
|
||||
if (lstring)
|
||||
lstring->start = 0.0;
|
||||
while (lstring) {
|
||||
next = lstring->next;
|
||||
if (!next)
|
||||
break;
|
||||
if (lstring->end < 0.0 && next->start >= 0.0)
|
||||
lstring->end = next->start;
|
||||
else if (lstring->end >= 0.0 && next->start < 0.0)
|
||||
next->start = lstring->end;
|
||||
if (lstring->start < 0.0)
|
||||
lstring->start = -1.0;
|
||||
if (lstring->end < 0.0)
|
||||
lstring->end = -1.0;
|
||||
lstring = next;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Label_load: load label */
|
||||
static void HTS_Label_load(HTS_Label * label, size_t sampling_rate, size_t fperiod, HTS_File * fp)
|
||||
{
|
||||
char buff[HTS_MAXBUFLEN];
|
||||
HTS_LabelString *lstring = NULL;
|
||||
double start, end;
|
||||
const double rate = (double) sampling_rate / ((double) fperiod * 1e+7);
|
||||
|
||||
if (label->head || label->size != 0) {
|
||||
HTS_error(1, "HTS_Label_load_from_fp: label is not initialized.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* parse label file */
|
||||
while (HTS_get_token_from_fp(fp, buff)) {
|
||||
if (!isgraph((int) buff[0]))
|
||||
break;
|
||||
label->size++;
|
||||
|
||||
if (lstring) {
|
||||
lstring->next = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
|
||||
lstring = lstring->next;
|
||||
} else { /* first time */
|
||||
lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
|
||||
label->head = lstring;
|
||||
}
|
||||
if (isdigit_string(buff)) { /* has frame infomation */
|
||||
start = atof(buff);
|
||||
HTS_get_token_from_fp(fp, buff);
|
||||
end = atof(buff);
|
||||
HTS_get_token_from_fp(fp, buff);
|
||||
lstring->start = rate * start;
|
||||
lstring->end = rate * end;
|
||||
} else {
|
||||
lstring->start = -1.0;
|
||||
lstring->end = -1.0;
|
||||
}
|
||||
lstring->next = NULL;
|
||||
lstring->name = HTS_strdup(buff);
|
||||
}
|
||||
HTS_Label_check_time(label);
|
||||
}
|
||||
|
||||
/* HTS_Label_load_from_fn: load label from file name */
|
||||
void HTS_Label_load_from_fn(HTS_Label * label, size_t sampling_rate, size_t fperiod, const char *fn)
|
||||
{
|
||||
HTS_File *fp = HTS_fopen_from_fn(fn, "r");
|
||||
HTS_Label_load(label, sampling_rate, fperiod, fp);
|
||||
HTS_fclose(fp);
|
||||
}
|
||||
|
||||
/* HTS_Label_load_from_strings: load label from strings */
|
||||
void HTS_Label_load_from_strings(HTS_Label * label, size_t sampling_rate, size_t fperiod, char **lines, size_t num_lines)
|
||||
{
|
||||
char buff[HTS_MAXBUFLEN];
|
||||
HTS_LabelString *lstring = NULL;
|
||||
size_t i;
|
||||
size_t data_index;
|
||||
double start, end;
|
||||
const double rate = (double) sampling_rate / ((double) fperiod * 1e+7);
|
||||
|
||||
if (label->head || label->size != 0) {
|
||||
HTS_error(1, "HTS_Label_load_from_fp: label list is not initialized.\n");
|
||||
return;
|
||||
}
|
||||
/* copy label */
|
||||
for (i = 0; i < num_lines; i++) {
|
||||
if (!isgraph((int) lines[i][0]))
|
||||
break;
|
||||
label->size++;
|
||||
|
||||
if (lstring) {
|
||||
lstring->next = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
|
||||
lstring = lstring->next;
|
||||
} else { /* first time */
|
||||
lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
|
||||
label->head = lstring;
|
||||
}
|
||||
data_index = 0;
|
||||
if (isdigit_string(lines[i])) { /* has frame infomation */
|
||||
HTS_get_token_from_string(lines[i], &data_index, buff);
|
||||
start = atof(buff);
|
||||
HTS_get_token_from_string(lines[i], &data_index, buff);
|
||||
end = atof(buff);
|
||||
HTS_get_token_from_string(lines[i], &data_index, buff);
|
||||
lstring->name = HTS_strdup(buff);
|
||||
lstring->start = rate * start;
|
||||
lstring->end = rate * end;
|
||||
} else {
|
||||
lstring->start = -1.0;
|
||||
lstring->end = -1.0;
|
||||
lstring->name = HTS_strdup(lines[i]);
|
||||
}
|
||||
lstring->next = NULL;
|
||||
}
|
||||
HTS_Label_check_time(label);
|
||||
}
|
||||
|
||||
/* HTS_Label_get_size: get number of label string */
|
||||
size_t HTS_Label_get_size(HTS_Label * label)
|
||||
{
|
||||
return label->size;
|
||||
}
|
||||
|
||||
/* HTS_Label_get_string: get label string */
|
||||
const char *HTS_Label_get_string(HTS_Label * label, size_t index)
|
||||
{
|
||||
size_t i;
|
||||
HTS_LabelString *lstring = label->head;
|
||||
|
||||
for (i = 0; i < index && lstring; i++)
|
||||
lstring = lstring->next;
|
||||
if (!lstring)
|
||||
return NULL;
|
||||
return lstring->name;
|
||||
}
|
||||
|
||||
/* HTS_Label_get_start_frame: get start frame */
|
||||
double HTS_Label_get_start_frame(HTS_Label * label, size_t index)
|
||||
{
|
||||
size_t i;
|
||||
HTS_LabelString *lstring = label->head;
|
||||
|
||||
for (i = 0; i < index && lstring; i++)
|
||||
lstring = lstring->next;
|
||||
if (!lstring)
|
||||
return -1.0;
|
||||
return lstring->start;
|
||||
}
|
||||
|
||||
/* HTS_Label_get_end_frame: get end frame */
|
||||
double HTS_Label_get_end_frame(HTS_Label * label, size_t index)
|
||||
{
|
||||
size_t i;
|
||||
HTS_LabelString *lstring = label->head;
|
||||
|
||||
for (i = 0; i < index && lstring; i++)
|
||||
lstring = lstring->next;
|
||||
if (!lstring)
|
||||
return -1.0;
|
||||
return lstring->end;
|
||||
}
|
||||
|
||||
/* HTS_Label_clear: free label */
|
||||
void HTS_Label_clear(HTS_Label * label)
|
||||
{
|
||||
HTS_LabelString *lstring, *next_lstring;
|
||||
|
||||
for (lstring = label->head; lstring; lstring = next_lstring) {
|
||||
next_lstring = lstring->next;
|
||||
HTS_free(lstring->name);
|
||||
HTS_free(lstring);
|
||||
}
|
||||
HTS_Label_initialize(label);
|
||||
}
|
||||
|
||||
HTS_LABEL_C_END;
|
||||
|
||||
#endif /* !HTS_LABEL_C */
|
||||
649
3rdparty/hts_engine_API/lib/HTS_misc.c
vendored
Executable file
649
3rdparty/hts_engine_API/lib/HTS_misc.c
vendored
Executable file
@@ -0,0 +1,649 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_MISC_C
|
||||
#define HTS_MISC_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_MISC_C_START extern "C" {
|
||||
#define HTS_MISC_C_END }
|
||||
#else
|
||||
#define HTS_MISC_C_START
|
||||
#define HTS_MISC_C_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_MISC_C_START;
|
||||
|
||||
#include <stdlib.h> /* for exit(),calloc(),free() */
|
||||
#include <stdarg.h> /* for va_list */
|
||||
#include <string.h> /* for strcpy(),strlen() */
|
||||
|
||||
/* hts_engine libraries */
|
||||
#include "HTS_hidden.h"
|
||||
|
||||
#ifdef FESTIVAL
|
||||
#include "EST_walloc.h"
|
||||
#endif /* FESTIVAL */
|
||||
|
||||
#define HTS_FILE 0
|
||||
#define HTS_DATA 1
|
||||
|
||||
typedef struct _HTS_Data {
|
||||
unsigned char *data;
|
||||
size_t size;
|
||||
size_t index;
|
||||
} HTS_Data;
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define MAX_PATH_SIZE 8192
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
||||
|
||||
// Encode 'path' which is assumed UTF-8 string, into UNICODE string.
|
||||
// wbuf and wbuf_len is a target buffer and its length.
|
||||
static void to_wchar(const char *path, wchar_t *wbuf, size_t wbuf_len) {
|
||||
char buf[MAX_PATH_SIZE * 2], buf2[MAX_PATH_SIZE * 2], *p;
|
||||
|
||||
strncpy(buf, path, sizeof(buf));
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
|
||||
// Trim trailing slashes. Leave backslash for paths like "X:\"
|
||||
p = buf + strlen(buf) - 1;
|
||||
while (p > buf && p[-1] != ':' && (p[0] == '\\' || p[0] == '/')) *p-- = '\0';
|
||||
|
||||
// Convert to Unicode and back. If doubly-converted string does not
|
||||
// match the original, something is fishy, reject.
|
||||
memset(wbuf, 0, wbuf_len * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int) wbuf_len);
|
||||
WideCharToMultiByte(CP_UTF8, 0, wbuf, (int) wbuf_len, buf2, sizeof(buf2),
|
||||
NULL, NULL);
|
||||
if (strcmp(buf, buf2) != 0) {
|
||||
wbuf[0] = L'\0';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* HTS_fopen_from_fn: wrapper for fopen */
|
||||
HTS_File *HTS_fopen_from_fn(const char *name, const char *opt)
|
||||
{
|
||||
HTS_File *fp = (HTS_File *) HTS_calloc(1, sizeof(HTS_File));
|
||||
|
||||
fp->type = HTS_FILE;
|
||||
#if defined(_WIN32)
|
||||
wchar_t wpath[MAX_PATH_SIZE], wmode[10];
|
||||
to_wchar(name, wpath, ARRAY_SIZE(wpath));
|
||||
to_wchar(opt, wmode, ARRAY_SIZE(wmode));
|
||||
fp->pointer = (void*) _wfopen(wpath, wmode);
|
||||
#else
|
||||
fp->pointer = (void *) fopen(name, opt);
|
||||
#endif
|
||||
if (fp->pointer == NULL) {
|
||||
HTS_error(0, "HTS_fopen: Cannot open %s.\n", name);
|
||||
HTS_free(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
/* HTS_fopen_from_fp: wrapper for fopen */
|
||||
HTS_File *HTS_fopen_from_fp(HTS_File * fp, size_t size)
|
||||
{
|
||||
if (fp == NULL || size == 0)
|
||||
return NULL;
|
||||
else if (fp->type == HTS_FILE) {
|
||||
HTS_Data *d;
|
||||
HTS_File *f;
|
||||
d = (HTS_Data *) HTS_calloc(1, sizeof(HTS_Data));
|
||||
d->data = (unsigned char *) HTS_calloc(size, sizeof(unsigned char));
|
||||
d->size = size;
|
||||
d->index = 0;
|
||||
if (fread(d->data, sizeof(unsigned char), size, (FILE *) fp->pointer) != size) {
|
||||
free(d->data);
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
f = (HTS_File *) HTS_calloc(1, sizeof(HTS_File));
|
||||
f->type = HTS_DATA;
|
||||
f->pointer = (void *) d;
|
||||
return f;
|
||||
} else if (fp->type == HTS_DATA) {
|
||||
HTS_File *f;
|
||||
HTS_Data *tmp1, *tmp2;
|
||||
tmp1 = (HTS_Data *) fp->pointer;
|
||||
if (tmp1->index + size > tmp1->size)
|
||||
return NULL;
|
||||
tmp2 = (HTS_Data *) HTS_calloc(1, sizeof(HTS_Data));
|
||||
tmp2->data = (unsigned char *) HTS_calloc(size, sizeof(unsigned char));
|
||||
tmp2->size = size;
|
||||
tmp2->index = 0;
|
||||
memcpy(tmp2->data, &tmp1->data[tmp1->index], size);
|
||||
tmp1->index += size;
|
||||
f = (HTS_File *) HTS_calloc(1, sizeof(HTS_File));
|
||||
f->type = HTS_DATA;
|
||||
f->pointer = (void *) tmp2;
|
||||
return f;
|
||||
}
|
||||
|
||||
HTS_error(0, "HTS_fopen_from_fp: Unknown file type.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* HTS_fopen_from_data: wrapper for fopen */
|
||||
HTS_File *HTS_fopen_from_data(void *data, size_t size)
|
||||
{
|
||||
HTS_Data *d;
|
||||
HTS_File *f;
|
||||
|
||||
if (data == NULL || size == 0)
|
||||
return NULL;
|
||||
|
||||
d = (HTS_Data *) HTS_calloc(1, sizeof(HTS_Data));
|
||||
d->data = (unsigned char *) HTS_calloc(size, sizeof(unsigned char));
|
||||
d->size = size;
|
||||
d->index = 0;
|
||||
|
||||
memcpy(d->data, data, size);
|
||||
|
||||
f = (HTS_File *) HTS_calloc(1, sizeof(HTS_File));
|
||||
f->type = HTS_DATA;
|
||||
f->pointer = (void *) d;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* HTS_fclose: wrapper for fclose */
|
||||
void HTS_fclose(HTS_File * fp)
|
||||
{
|
||||
if (fp == NULL) {
|
||||
return;
|
||||
} else if (fp->type == HTS_FILE) {
|
||||
if (fp->pointer != NULL)
|
||||
fclose((FILE *) fp->pointer);
|
||||
HTS_free(fp);
|
||||
return;
|
||||
} else if (fp->type == HTS_DATA) {
|
||||
if (fp->pointer != NULL) {
|
||||
HTS_Data *d = (HTS_Data *) fp->pointer;
|
||||
if (d->data != NULL)
|
||||
HTS_free(d->data);
|
||||
HTS_free(d);
|
||||
}
|
||||
HTS_free(fp);
|
||||
return;
|
||||
}
|
||||
HTS_error(0, "HTS_fclose: Unknown file type.\n");
|
||||
}
|
||||
|
||||
/* HTS_fgetc: wrapper for fgetc */
|
||||
int HTS_fgetc(HTS_File * fp)
|
||||
{
|
||||
if (fp == NULL) {
|
||||
return EOF;
|
||||
} else if (fp->type == HTS_FILE) {
|
||||
return fgetc((FILE *) fp->pointer);
|
||||
} else if (fp->type == HTS_DATA) {
|
||||
HTS_Data *d = (HTS_Data *) fp->pointer;
|
||||
if (d->size <= d->index)
|
||||
return EOF;
|
||||
return (int) d->data[d->index++];
|
||||
}
|
||||
HTS_error(0, "HTS_fgetc: Unknown file type.\n");
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* HTS_feof: wrapper for feof */
|
||||
int HTS_feof(HTS_File * fp)
|
||||
{
|
||||
if (fp == NULL) {
|
||||
return 1;
|
||||
} else if (fp->type == HTS_FILE) {
|
||||
return feof((FILE *) fp->pointer);
|
||||
} else if (fp->type == HTS_DATA) {
|
||||
HTS_Data *d = (HTS_Data *) fp->pointer;
|
||||
return d->size <= d->index ? 1 : 0;
|
||||
}
|
||||
HTS_error(0, "HTS_feof: Unknown file type.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* HTS_fseek: wrapper for fseek */
|
||||
int HTS_fseek(HTS_File * fp, long offset, int origin)
|
||||
{
|
||||
if (fp == NULL) {
|
||||
return 1;
|
||||
} else if (fp->type == HTS_FILE) {
|
||||
return fseek((FILE *) fp->pointer, offset, origin);
|
||||
} else if (fp->type == HTS_DATA) {
|
||||
HTS_Data *d = (HTS_Data *) fp->pointer;
|
||||
if (origin == SEEK_SET) {
|
||||
d->index = (size_t) offset;
|
||||
} else if (origin == SEEK_CUR) {
|
||||
d->index += offset;
|
||||
} else if (origin == SEEK_END) {
|
||||
d->index = d->size + offset;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
HTS_error(0, "HTS_fseek: Unknown file type.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* HTS_ftell: rapper for ftell */
|
||||
size_t HTS_ftell(HTS_File * fp)
|
||||
{
|
||||
if (fp == NULL) {
|
||||
return 0;
|
||||
} else if (fp->type == HTS_FILE) {
|
||||
fpos_t pos;
|
||||
fgetpos((FILE *) fp->pointer, &pos);
|
||||
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__ANDROID__) || defined(__OpenBSD__)
|
||||
return (size_t) pos;
|
||||
#else
|
||||
return (size_t) pos.__pos;
|
||||
#endif /* _WIN32 || __CYGWIN__ || __APPLE__ || __ANDROID__ */
|
||||
} else if (fp->type == HTS_DATA) {
|
||||
HTS_Data *d = (HTS_Data *) fp->pointer;
|
||||
return d->index;
|
||||
}
|
||||
HTS_error(0, "HTS_ftell: Unknown file type.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* HTS_fread: wrapper for fread */
|
||||
static size_t HTS_fread(void *buf, size_t size, size_t n, HTS_File * fp)
|
||||
{
|
||||
if (fp == NULL || size == 0 || n == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (fp->type == HTS_FILE) {
|
||||
return fread(buf, size, n, (FILE *) fp->pointer);
|
||||
} else if (fp->type == HTS_DATA) {
|
||||
HTS_Data *d = (HTS_Data *) fp->pointer;
|
||||
size_t i, length = size * n;
|
||||
unsigned char *c = (unsigned char *) buf;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (d->index < d->size)
|
||||
c[i] = d->data[d->index++];
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (i == 0)
|
||||
return 0;
|
||||
else
|
||||
return i / size;
|
||||
}
|
||||
HTS_error(0, "HTS_fread: Unknown file type.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* HTS_byte_swap: byte swap */
|
||||
static void HTS_byte_swap(void *p, size_t size, size_t block)
|
||||
{
|
||||
char *q, tmp;
|
||||
size_t i, j;
|
||||
|
||||
q = (char *) p;
|
||||
|
||||
for (i = 0; i < block; i++) {
|
||||
for (j = 0; j < (size / 2); j++) {
|
||||
tmp = *(q + j);
|
||||
*(q + j) = *(q + (size - 1 - j));
|
||||
*(q + (size - 1 - j)) = tmp;
|
||||
}
|
||||
q += size;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_fread_big_endian: fread with byteswap */
|
||||
size_t HTS_fread_big_endian(void *buf, size_t size, size_t n, HTS_File * fp)
|
||||
{
|
||||
size_t block = HTS_fread(buf, size, n, fp);
|
||||
|
||||
#ifdef WORDS_LITTLEENDIAN
|
||||
HTS_byte_swap(buf, size, block);
|
||||
#endif /* WORDS_LITTLEENDIAN */
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
/* HTS_fread_little_endian: fread with byteswap */
|
||||
size_t HTS_fread_little_endian(void *buf, size_t size, size_t n, HTS_File * fp)
|
||||
{
|
||||
size_t block = HTS_fread(buf, size, n, fp);
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
HTS_byte_swap(buf, size, block);
|
||||
#endif /* WORDS_BIGENDIAN */
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
/* HTS_fwrite_little_endian: fwrite with byteswap */
|
||||
size_t HTS_fwrite_little_endian(const void *buf, size_t size, size_t n, FILE * fp)
|
||||
{
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
HTS_byte_swap(buf, size, n * size);
|
||||
#endif /* WORDS_BIGENDIAN */
|
||||
return fwrite(buf, size, n, fp);
|
||||
}
|
||||
|
||||
/* HTS_get_pattern_token: get pattern token (single/double quote can be used) */
|
||||
HTS_Boolean HTS_get_pattern_token(HTS_File * fp, char *buff)
|
||||
{
|
||||
char c;
|
||||
size_t i;
|
||||
HTS_Boolean squote = FALSE, dquote = FALSE;
|
||||
|
||||
if (fp == NULL || HTS_feof(fp))
|
||||
return FALSE;
|
||||
c = HTS_fgetc(fp);
|
||||
|
||||
while (c == ' ' || c == '\n') {
|
||||
if (HTS_feof(fp))
|
||||
return FALSE;
|
||||
c = HTS_fgetc(fp);
|
||||
}
|
||||
|
||||
if (c == '\'') { /* single quote case */
|
||||
if (HTS_feof(fp))
|
||||
return FALSE;
|
||||
c = HTS_fgetc(fp);
|
||||
squote = TRUE;
|
||||
}
|
||||
|
||||
if (c == '\"') { /*double quote case */
|
||||
if (HTS_feof(fp))
|
||||
return FALSE;
|
||||
c = HTS_fgetc(fp);
|
||||
dquote = TRUE;
|
||||
}
|
||||
|
||||
if (c == ',') { /*special character ',' */
|
||||
strcpy(buff, ",");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (1) {
|
||||
buff[i++] = c;
|
||||
c = HTS_fgetc(fp);
|
||||
if (squote && c == '\'')
|
||||
break;
|
||||
if (dquote && c == '\"')
|
||||
break;
|
||||
if (!squote && !dquote) {
|
||||
if (c == ' ')
|
||||
break;
|
||||
if (c == '\n')
|
||||
break;
|
||||
if (HTS_feof(fp))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
buff[i] = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_get_token: get token from file pointer (separators are space, tab, and line break) */
|
||||
HTS_Boolean HTS_get_token_from_fp(HTS_File * fp, char *buff)
|
||||
{
|
||||
char c;
|
||||
size_t i;
|
||||
|
||||
if (fp == NULL || HTS_feof(fp))
|
||||
return FALSE;
|
||||
c = HTS_fgetc(fp);
|
||||
while (c == ' ' || c == '\n' || c == '\t') {
|
||||
if (HTS_feof(fp))
|
||||
return FALSE;
|
||||
c = HTS_fgetc(fp);
|
||||
if (c == EOF)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; c != ' ' && c != '\n' && c != '\t';) {
|
||||
buff[i++] = c;
|
||||
if (HTS_feof(fp))
|
||||
break;
|
||||
c = HTS_fgetc(fp);
|
||||
if (c == EOF)
|
||||
break;
|
||||
}
|
||||
|
||||
buff[i] = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_get_token_with_separator: get token from file pointer with specified separator */
|
||||
HTS_Boolean HTS_get_token_from_fp_with_separator(HTS_File * fp, char *buff, char separator)
|
||||
{
|
||||
char c;
|
||||
size_t i;
|
||||
|
||||
if (fp == NULL || HTS_feof(fp))
|
||||
return FALSE;
|
||||
c = HTS_fgetc(fp);
|
||||
while (c == separator) {
|
||||
if (HTS_feof(fp))
|
||||
return FALSE;
|
||||
c = HTS_fgetc(fp);
|
||||
if (c == EOF)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; c != separator;) {
|
||||
buff[i++] = c;
|
||||
if (HTS_feof(fp))
|
||||
break;
|
||||
c = HTS_fgetc(fp);
|
||||
if (c == EOF)
|
||||
break;
|
||||
}
|
||||
|
||||
buff[i] = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_get_token_from_string: get token from string (separators are space, tab, and line break) */
|
||||
HTS_Boolean HTS_get_token_from_string(const char *string, size_t * index, char *buff)
|
||||
{
|
||||
char c;
|
||||
size_t i;
|
||||
|
||||
c = string[(*index)];
|
||||
if (c == '\0')
|
||||
return FALSE;
|
||||
c = string[(*index)++];
|
||||
if (c == '\0')
|
||||
return FALSE;
|
||||
while (c == ' ' || c == '\n' || c == '\t') {
|
||||
if (c == '\0')
|
||||
return FALSE;
|
||||
c = string[(*index)++];
|
||||
}
|
||||
for (i = 0; c != ' ' && c != '\n' && c != '\t' && c != '\0'; i++) {
|
||||
buff[i] = c;
|
||||
c = string[(*index)++];
|
||||
}
|
||||
|
||||
buff[i] = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_get_token_from_string_with_separator: get token from string with specified separator */
|
||||
HTS_Boolean HTS_get_token_from_string_with_separator(const char *str, size_t * index, char *buff, char separator)
|
||||
{
|
||||
char c;
|
||||
size_t len = 0;
|
||||
|
||||
if (str == NULL)
|
||||
return FALSE;
|
||||
|
||||
c = str[(*index)];
|
||||
if (c == '\0')
|
||||
return FALSE;
|
||||
while (c == separator) {
|
||||
if (c == '\0')
|
||||
return FALSE;
|
||||
(*index)++;
|
||||
c = str[(*index)];
|
||||
}
|
||||
while (c != separator && c != '\0') {
|
||||
buff[len++] = c;
|
||||
(*index)++;
|
||||
c = str[(*index)];
|
||||
}
|
||||
if (c != '\0')
|
||||
(*index)++;
|
||||
|
||||
buff[len] = '\0';
|
||||
|
||||
if (len > 0)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* HTS_calloc: wrapper for calloc */
|
||||
void *HTS_calloc(const size_t num, const size_t size)
|
||||
{
|
||||
size_t n = num * size;
|
||||
void *mem;
|
||||
|
||||
if (n == 0)
|
||||
return NULL;
|
||||
|
||||
#ifdef FESTIVAL
|
||||
mem = (void *) safe_wcalloc(n);
|
||||
#else
|
||||
mem = (void *) malloc(n);
|
||||
#endif /* FESTIVAL */
|
||||
if (mem == NULL) {
|
||||
HTS_error(1, "HTS_calloc: Cannot allocate memory.\n");
|
||||
}
|
||||
|
||||
memset(mem, 0, n);
|
||||
return mem;
|
||||
}
|
||||
|
||||
/* HTS_Free: wrapper for free */
|
||||
void HTS_free(void *ptr)
|
||||
{
|
||||
#ifdef FESTIVAL
|
||||
wfree(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif /* FESTIVAL */
|
||||
}
|
||||
|
||||
/* HTS_strdup: wrapper for strdup */
|
||||
char *HTS_strdup(const char *string)
|
||||
{
|
||||
#ifdef FESTIVAL
|
||||
return (wstrdup(string));
|
||||
#else
|
||||
char *buff = (char *) HTS_calloc(strlen(string) + 1, sizeof(char));
|
||||
strcpy(buff, string);
|
||||
return buff;
|
||||
#endif /* FESTIVAL */
|
||||
}
|
||||
|
||||
/* HTS_alloc_matrix: allocate double matrix */
|
||||
double **HTS_alloc_matrix(size_t x, size_t y)
|
||||
{
|
||||
size_t i;
|
||||
double **p;
|
||||
|
||||
if (x == 0 || y == 0)
|
||||
return NULL;
|
||||
|
||||
p = (double **) HTS_calloc(x, sizeof(double *));
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
p[i] = (double *) HTS_calloc(y, sizeof(double));
|
||||
return p;
|
||||
}
|
||||
|
||||
/* HTS_free_matrix: free double matrix */
|
||||
void HTS_free_matrix(double **p, size_t x)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
HTS_free(p[i]);
|
||||
HTS_free(p);
|
||||
}
|
||||
|
||||
/* HTS_error: output error message */
|
||||
void HTS_error(int error, const char *message, ...)
|
||||
{
|
||||
va_list arg;
|
||||
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
if (error > 0)
|
||||
fprintf(stderr, "\nError: ");
|
||||
else
|
||||
fprintf(stderr, "\nWarning: ");
|
||||
|
||||
va_start(arg, message);
|
||||
vfprintf(stderr, message, arg);
|
||||
va_end(arg);
|
||||
|
||||
fflush(stderr);
|
||||
|
||||
if (error > 0)
|
||||
exit(error);
|
||||
}
|
||||
|
||||
HTS_MISC_C_END;
|
||||
|
||||
#endif /* !HTS_MISC_C */
|
||||
1695
3rdparty/hts_engine_API/lib/HTS_model.c
vendored
Normal file
1695
3rdparty/hts_engine_API/lib/HTS_model.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
524
3rdparty/hts_engine_API/lib/HTS_pstream.c
vendored
Normal file
524
3rdparty/hts_engine_API/lib/HTS_pstream.c
vendored
Normal file
@@ -0,0 +1,524 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_PSTREAM_C
|
||||
#define HTS_PSTREAM_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_PSTREAM_C_START extern "C" {
|
||||
#define HTS_PSTREAM_C_END }
|
||||
#else
|
||||
#define HTS_PSTREAM_C_START
|
||||
#define HTS_PSTREAM_C_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_PSTREAM_C_START;
|
||||
|
||||
#include <math.h> /* for sqrt() */
|
||||
|
||||
/* hts_engine libraries */
|
||||
#include "HTS_hidden.h"
|
||||
|
||||
/* HTS_finv: calculate 1.0/variance function */
|
||||
static double HTS_finv(const double x)
|
||||
{
|
||||
if (x >= INFTY2)
|
||||
return 0.0;
|
||||
if (x <= -INFTY2)
|
||||
return 0.0;
|
||||
if (x <= INVINF2 && x >= 0)
|
||||
return INFTY;
|
||||
if (x >= -INVINF2 && x < 0)
|
||||
return -INFTY;
|
||||
|
||||
return (1.0 / x);
|
||||
}
|
||||
|
||||
/* HTS_PStream_calc_wuw_and_wum: calcurate W'U^{-1}W and W'U^{-1}M */
|
||||
static void HTS_PStream_calc_wuw_and_wum(HTS_PStream * pst, size_t m)
|
||||
{
|
||||
size_t t, i, j;
|
||||
int shift;
|
||||
double wu;
|
||||
|
||||
for (t = 0; t < pst->length; t++) {
|
||||
/* initialize */
|
||||
pst->sm.wum[t] = 0.0;
|
||||
for (i = 0; i < pst->width; i++)
|
||||
pst->sm.wuw[t][i] = 0.0;
|
||||
|
||||
/* calc WUW & WUM */
|
||||
for (i = 0; i < pst->win_size; i++)
|
||||
for (shift = pst->win_l_width[i]; shift <= pst->win_r_width[i]; shift++)
|
||||
if (((int) t + shift >= 0) && ((int) t + shift < pst->length) && (pst->win_coefficient[i][-shift] != 0.0)) {
|
||||
wu = pst->win_coefficient[i][-shift] * pst->sm.ivar[t + shift][i * pst->vector_length + m];
|
||||
pst->sm.wum[t] += wu * pst->sm.mean[t + shift][i * pst->vector_length + m];
|
||||
for (j = 0; (j < pst->width) && (t + j < pst->length); j++)
|
||||
if (((int) j <= pst->win_r_width[i] + shift) && (pst->win_coefficient[i][j - shift] != 0.0))
|
||||
pst->sm.wuw[t][j] += wu * pst->win_coefficient[i][j - shift];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* HTS_PStream_ldl_factorization: Factorize W'*U^{-1}*W to L*D*L' (L: lower triangular, D: diagonal) */
|
||||
static void HTS_PStream_ldl_factorization(HTS_PStream * pst)
|
||||
{
|
||||
size_t t, i, j;
|
||||
|
||||
for (t = 0; t < pst->length; t++) {
|
||||
for (i = 1; (i < pst->width) && (t >= i); i++)
|
||||
pst->sm.wuw[t][0] -= pst->sm.wuw[t - i][i] * pst->sm.wuw[t - i][i] * pst->sm.wuw[t - i][0];
|
||||
|
||||
for (i = 1; i < pst->width; i++) {
|
||||
for (j = 1; (i + j < pst->width) && (t >= j); j++)
|
||||
pst->sm.wuw[t][i] -= pst->sm.wuw[t - j][j] * pst->sm.wuw[t - j][i + j] * pst->sm.wuw[t - j][0];
|
||||
pst->sm.wuw[t][i] /= pst->sm.wuw[t][0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_PStream_forward_substitution: forward subtitution for mlpg */
|
||||
static void HTS_PStream_forward_substitution(HTS_PStream * pst)
|
||||
{
|
||||
size_t t, i;
|
||||
|
||||
for (t = 0; t < pst->length; t++) {
|
||||
pst->sm.g[t] = pst->sm.wum[t];
|
||||
for (i = 1; (i < pst->width) && (t >= i); i++)
|
||||
pst->sm.g[t] -= pst->sm.wuw[t - i][i] * pst->sm.g[t - i];
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_PStream_backward_substitution: backward subtitution for mlpg */
|
||||
static void HTS_PStream_backward_substitution(HTS_PStream * pst, size_t m)
|
||||
{
|
||||
size_t rev, t, i;
|
||||
|
||||
for (rev = 0; rev < pst->length; rev++) {
|
||||
t = pst->length - 1 - rev;
|
||||
pst->par[t][m] = pst->sm.g[t] / pst->sm.wuw[t][0];
|
||||
for (i = 1; (i < pst->width) && (t + i < pst->length); i++)
|
||||
pst->par[t][m] -= pst->sm.wuw[t][i] * pst->par[t + i][m];
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_PStream_calc_gv: subfunction for mlpg using GV */
|
||||
static void HTS_PStream_calc_gv(HTS_PStream * pst, size_t m, double *mean, double *vari)
|
||||
{
|
||||
size_t t;
|
||||
|
||||
*mean = 0.0;
|
||||
for (t = 0; t < pst->length; t++)
|
||||
if (pst->gv_switch[t])
|
||||
*mean += pst->par[t][m];
|
||||
*mean /= pst->gv_length;
|
||||
*vari = 0.0;
|
||||
for (t = 0; t < pst->length; t++)
|
||||
if (pst->gv_switch[t])
|
||||
*vari += (pst->par[t][m] - *mean) * (pst->par[t][m] - *mean);
|
||||
*vari /= pst->gv_length;
|
||||
}
|
||||
|
||||
/* HTS_PStream_conv_gv: subfunction for mlpg using GV */
|
||||
static void HTS_PStream_conv_gv(HTS_PStream * pst, size_t m)
|
||||
{
|
||||
size_t t;
|
||||
double ratio;
|
||||
double mean;
|
||||
double vari;
|
||||
|
||||
HTS_PStream_calc_gv(pst, m, &mean, &vari);
|
||||
ratio = sqrt(pst->gv_mean[m] / vari);
|
||||
for (t = 0; t < pst->length; t++)
|
||||
if (pst->gv_switch[t])
|
||||
pst->par[t][m] = ratio * (pst->par[t][m] - mean) + mean;
|
||||
}
|
||||
|
||||
/* HTS_PStream_calc_derivative: subfunction for mlpg using GV */
|
||||
static double HTS_PStream_calc_derivative(HTS_PStream * pst, size_t m)
|
||||
{
|
||||
size_t t, i;
|
||||
double mean;
|
||||
double vari;
|
||||
double dv;
|
||||
double h;
|
||||
double gvobj;
|
||||
double hmmobj;
|
||||
double w = 1.0 / (pst->win_size * pst->length);
|
||||
|
||||
HTS_PStream_calc_gv(pst, m, &mean, &vari);
|
||||
gvobj = -0.5 * W2 * vari * pst->gv_vari[m] * (vari - 2.0 * pst->gv_mean[m]);
|
||||
dv = -2.0 * pst->gv_vari[m] * (vari - pst->gv_mean[m]) / pst->length;
|
||||
|
||||
for (t = 0; t < pst->length; t++) {
|
||||
pst->sm.g[t] = pst->sm.wuw[t][0] * pst->par[t][m];
|
||||
for (i = 1; i < pst->width; i++) {
|
||||
if (t + i < pst->length)
|
||||
pst->sm.g[t] += pst->sm.wuw[t][i] * pst->par[t + i][m];
|
||||
if (t + 1 > i)
|
||||
pst->sm.g[t] += pst->sm.wuw[t - i][i] * pst->par[t - i][m];
|
||||
}
|
||||
}
|
||||
|
||||
for (t = 0, hmmobj = 0.0; t < pst->length; t++) {
|
||||
hmmobj += W1 * w * pst->par[t][m] * (pst->sm.wum[t] - 0.5 * pst->sm.g[t]);
|
||||
h = -W1 * w * pst->sm.wuw[t][1 - 1] - W2 * 2.0 / (pst->length * pst->length) * ((pst->length - 1) * pst->gv_vari[m] * (vari - pst->gv_mean[m]) + 2.0 * pst->gv_vari[m] * (pst->par[t][m] - mean) * (pst->par[t][m] - mean));
|
||||
if (pst->gv_switch[t])
|
||||
pst->sm.g[t] = 1.0 / h * (W1 * w * (-pst->sm.g[t] + pst->sm.wum[t]) + W2 * dv * (pst->par[t][m] - mean));
|
||||
else
|
||||
pst->sm.g[t] = 1.0 / h * (W1 * w * (-pst->sm.g[t] + pst->sm.wum[t]));
|
||||
}
|
||||
|
||||
return (-(hmmobj + gvobj));
|
||||
}
|
||||
|
||||
/* HTS_PStream_gv_parmgen: function for mlpg using GV */
|
||||
static void HTS_PStream_gv_parmgen(HTS_PStream * pst, size_t m)
|
||||
{
|
||||
size_t t, i;
|
||||
double step = STEPINIT;
|
||||
double prev = 0.0;
|
||||
double obj;
|
||||
|
||||
if (pst->gv_length == 0)
|
||||
return;
|
||||
|
||||
HTS_PStream_conv_gv(pst, m);
|
||||
if (GV_MAX_ITERATION > 0) {
|
||||
HTS_PStream_calc_wuw_and_wum(pst, m);
|
||||
for (i = 1; i <= GV_MAX_ITERATION; i++) {
|
||||
obj = HTS_PStream_calc_derivative(pst, m);
|
||||
if (i > 1) {
|
||||
if (obj > prev)
|
||||
step *= STEPDEC;
|
||||
if (obj < prev)
|
||||
step *= STEPINC;
|
||||
}
|
||||
for (t = 0; t < pst->length; t++) {
|
||||
if (pst->gv_switch[t])
|
||||
pst->par[t][m] += step * pst->sm.g[t];
|
||||
}
|
||||
prev = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_PStream_mlpg: generate sequence of speech parameter vector maximizing its output probability for given pdf sequence */
|
||||
static void HTS_PStream_mlpg(HTS_PStream * pst)
|
||||
{
|
||||
size_t m;
|
||||
|
||||
if (pst->length == 0)
|
||||
return;
|
||||
|
||||
for (m = 0; m < pst->vector_length; m++) {
|
||||
HTS_PStream_calc_wuw_and_wum(pst, m);
|
||||
HTS_PStream_ldl_factorization(pst); /* LDL factorization */
|
||||
HTS_PStream_forward_substitution(pst); /* forward substitution */
|
||||
HTS_PStream_backward_substitution(pst, m); /* backward substitution */
|
||||
if (pst->gv_length > 0)
|
||||
HTS_PStream_gv_parmgen(pst, m);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_initialize: initialize parameter stream set */
|
||||
void HTS_PStreamSet_initialize(HTS_PStreamSet * pss)
|
||||
{
|
||||
pss->pstream = NULL;
|
||||
pss->nstream = 0;
|
||||
pss->total_frame = 0;
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_create: parameter generation using GV weight */
|
||||
HTS_Boolean HTS_PStreamSet_create(HTS_PStreamSet * pss, HTS_SStreamSet * sss, double *msd_threshold, double *gv_weight)
|
||||
{
|
||||
size_t i, j, k, l, m;
|
||||
int shift;
|
||||
size_t frame, msd_frame, state;
|
||||
|
||||
HTS_PStream *pst;
|
||||
HTS_Boolean not_bound;
|
||||
|
||||
if (pss->nstream != 0) {
|
||||
HTS_error(1, "HTS_PstreamSet_create: HTS_PStreamSet should be clear.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* initialize */
|
||||
pss->nstream = HTS_SStreamSet_get_nstream(sss);
|
||||
pss->pstream = (HTS_PStream *) HTS_calloc(pss->nstream, sizeof(HTS_PStream));
|
||||
pss->total_frame = HTS_SStreamSet_get_total_frame(sss);
|
||||
|
||||
/* create */
|
||||
for (i = 0; i < pss->nstream; i++) {
|
||||
pst = &pss->pstream[i];
|
||||
if (HTS_SStreamSet_is_msd(sss, i) == TRUE) { /* for MSD */
|
||||
pst->length = 0;
|
||||
for (state = 0; state < HTS_SStreamSet_get_total_state(sss); state++)
|
||||
if (HTS_SStreamSet_get_msd(sss, i, state) > msd_threshold[i])
|
||||
pst->length += HTS_SStreamSet_get_duration(sss, state);
|
||||
pst->msd_flag = (HTS_Boolean *) HTS_calloc(pss->total_frame, sizeof(HTS_Boolean));
|
||||
for (state = 0, frame = 0; state < HTS_SStreamSet_get_total_state(sss); state++) {
|
||||
if (HTS_SStreamSet_get_msd(sss, i, state) > msd_threshold[i]) {
|
||||
for (j = 0; j < HTS_SStreamSet_get_duration(sss, state); j++) {
|
||||
pst->msd_flag[frame] = TRUE;
|
||||
frame++;
|
||||
}
|
||||
} else {
|
||||
for (j = 0; j < HTS_SStreamSet_get_duration(sss, state); j++) {
|
||||
pst->msd_flag[frame] = FALSE;
|
||||
frame++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { /* for non MSD */
|
||||
pst->length = pss->total_frame;
|
||||
pst->msd_flag = NULL;
|
||||
}
|
||||
pst->vector_length = HTS_SStreamSet_get_vector_length(sss, i);
|
||||
pst->width = HTS_SStreamSet_get_window_max_width(sss, i) * 2 + 1; /* band width of R */
|
||||
pst->win_size = HTS_SStreamSet_get_window_size(sss, i);
|
||||
if (pst->length > 0) {
|
||||
pst->sm.mean = HTS_alloc_matrix(pst->length, pst->vector_length * pst->win_size);
|
||||
pst->sm.ivar = HTS_alloc_matrix(pst->length, pst->vector_length * pst->win_size);
|
||||
pst->sm.wum = (double *) HTS_calloc(pst->length, sizeof(double));
|
||||
pst->sm.wuw = HTS_alloc_matrix(pst->length, pst->width);
|
||||
pst->sm.g = (double *) HTS_calloc(pst->length, sizeof(double));
|
||||
pst->par = HTS_alloc_matrix(pst->length, pst->vector_length);
|
||||
}
|
||||
/* copy dynamic window */
|
||||
pst->win_l_width = (int *) HTS_calloc(pst->win_size, sizeof(int));
|
||||
pst->win_r_width = (int *) HTS_calloc(pst->win_size, sizeof(int));
|
||||
pst->win_coefficient = (double **) HTS_calloc(pst->win_size, sizeof(double));
|
||||
for (j = 0; j < pst->win_size; j++) {
|
||||
pst->win_l_width[j] = HTS_SStreamSet_get_window_left_width(sss, i, j);
|
||||
pst->win_r_width[j] = HTS_SStreamSet_get_window_right_width(sss, i, j);
|
||||
if (pst->win_l_width[j] + pst->win_r_width[j] == 0)
|
||||
pst->win_coefficient[j] = (double *)
|
||||
HTS_calloc(-2 * pst->win_l_width[j] + 1, sizeof(double));
|
||||
else
|
||||
pst->win_coefficient[j] = (double *)
|
||||
HTS_calloc(-2 * pst->win_l_width[j], sizeof(double));
|
||||
pst->win_coefficient[j] -= pst->win_l_width[j];
|
||||
for (shift = pst->win_l_width[j]; shift <= pst->win_r_width[j]; shift++)
|
||||
pst->win_coefficient[j][shift] = HTS_SStreamSet_get_window_coefficient(sss, i, j, shift);
|
||||
}
|
||||
/* copy GV */
|
||||
if (HTS_SStreamSet_use_gv(sss, i)) {
|
||||
pst->gv_mean = (double *) HTS_calloc(pst->vector_length, sizeof(double));
|
||||
pst->gv_vari = (double *) HTS_calloc(pst->vector_length, sizeof(double));
|
||||
for (j = 0; j < pst->vector_length; j++) {
|
||||
pst->gv_mean[j] = HTS_SStreamSet_get_gv_mean(sss, i, j) * gv_weight[i];
|
||||
pst->gv_vari[j] = HTS_SStreamSet_get_gv_vari(sss, i, j);
|
||||
}
|
||||
pst->gv_switch = (HTS_Boolean *) HTS_calloc(pst->length, sizeof(HTS_Boolean));
|
||||
if (HTS_SStreamSet_is_msd(sss, i) == TRUE) { /* for MSD */
|
||||
for (state = 0, frame = 0, msd_frame = 0; state < HTS_SStreamSet_get_total_state(sss); state++)
|
||||
for (j = 0; j < HTS_SStreamSet_get_duration(sss, state); j++, frame++)
|
||||
if (pst->msd_flag[frame] == TRUE)
|
||||
pst->gv_switch[msd_frame++] = HTS_SStreamSet_get_gv_switch(sss, i, state);
|
||||
} else { /* for non MSD */
|
||||
for (state = 0, frame = 0; state < HTS_SStreamSet_get_total_state(sss); state++)
|
||||
for (j = 0; j < HTS_SStreamSet_get_duration(sss, state); j++)
|
||||
pst->gv_switch[frame++] = HTS_SStreamSet_get_gv_switch(sss, i, state);
|
||||
}
|
||||
for (j = 0, pst->gv_length = 0; j < pst->length; j++)
|
||||
if (pst->gv_switch[j])
|
||||
pst->gv_length++;
|
||||
} else {
|
||||
pst->gv_switch = NULL;
|
||||
pst->gv_length = 0;
|
||||
pst->gv_mean = NULL;
|
||||
pst->gv_vari = NULL;
|
||||
}
|
||||
/* copy pdfs */
|
||||
if (HTS_SStreamSet_is_msd(sss, i) == TRUE) { /* for MSD */
|
||||
for (state = 0, frame = 0, msd_frame = 0; state < HTS_SStreamSet_get_total_state(sss); state++) {
|
||||
for (j = 0; j < HTS_SStreamSet_get_duration(sss, state); j++) {
|
||||
if (pst->msd_flag[frame] == TRUE) {
|
||||
/* check current frame is MSD boundary or not */
|
||||
for (k = 0; k < pst->win_size; k++) {
|
||||
not_bound = TRUE;
|
||||
for (shift = pst->win_l_width[k]; shift <= pst->win_r_width[k]; shift++)
|
||||
if ((int) frame + shift < 0 || (int) pss->total_frame <= (int) frame + shift || pst->msd_flag[frame + shift] != TRUE) {
|
||||
not_bound = FALSE;
|
||||
break;
|
||||
}
|
||||
for (l = 0; l < pst->vector_length; l++) {
|
||||
m = pst->vector_length * k + l;
|
||||
pst->sm.mean[msd_frame][m] = HTS_SStreamSet_get_mean(sss, i, state, m);
|
||||
if (not_bound || k == 0)
|
||||
pst->sm.ivar[msd_frame][m] = HTS_finv(HTS_SStreamSet_get_vari(sss, i, state, m));
|
||||
else
|
||||
pst->sm.ivar[msd_frame][m] = 0.0;
|
||||
}
|
||||
}
|
||||
msd_frame++;
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
}
|
||||
} else { /* for non MSD */
|
||||
for (state = 0, frame = 0; state < HTS_SStreamSet_get_total_state(sss); state++) {
|
||||
for (j = 0; j < HTS_SStreamSet_get_duration(sss, state); j++) {
|
||||
for (k = 0; k < pst->win_size; k++) {
|
||||
not_bound = TRUE;
|
||||
for (shift = pst->win_l_width[k]; shift <= pst->win_r_width[k]; shift++)
|
||||
if ((int) frame + shift < 0 || (int) pss->total_frame <= (int) frame + shift) {
|
||||
not_bound = FALSE;
|
||||
break;
|
||||
}
|
||||
for (l = 0; l < pst->vector_length; l++) {
|
||||
m = pst->vector_length * k + l;
|
||||
pst->sm.mean[frame][m] = HTS_SStreamSet_get_mean(sss, i, state, m);
|
||||
if (not_bound || k == 0)
|
||||
pst->sm.ivar[frame][m] = HTS_finv(HTS_SStreamSet_get_vari(sss, i, state, m));
|
||||
else
|
||||
pst->sm.ivar[frame][m] = 0.0;
|
||||
}
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* parameter generation */
|
||||
HTS_PStream_mlpg(pst);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_get_nstream: get number of stream */
|
||||
size_t HTS_PStreamSet_get_nstream(HTS_PStreamSet * pss)
|
||||
{
|
||||
return pss->nstream;
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_get_vector_length: get feature length */
|
||||
size_t HTS_PStreamSet_get_vector_length(HTS_PStreamSet * pss, size_t stream_index)
|
||||
{
|
||||
return pss->pstream[stream_index].vector_length;
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_get_total_frame: get total number of frame */
|
||||
size_t HTS_PStreamSet_get_total_frame(HTS_PStreamSet * pss)
|
||||
{
|
||||
return pss->total_frame;
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_get_parameter: get parameter */
|
||||
double HTS_PStreamSet_get_parameter(HTS_PStreamSet * pss, size_t stream_index, size_t frame_index, size_t vector_index)
|
||||
{
|
||||
return pss->pstream[stream_index].par[frame_index][vector_index];
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_get_parameter_vector: get parameter vector*/
|
||||
double *HTS_PStreamSet_get_parameter_vector(HTS_PStreamSet * pss, size_t stream_index, size_t frame_index)
|
||||
{
|
||||
return pss->pstream[stream_index].par[frame_index];
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_get_msd_flag: get generated MSD flag per frame */
|
||||
HTS_Boolean HTS_PStreamSet_get_msd_flag(HTS_PStreamSet * pss, size_t stream_index, size_t frame_index)
|
||||
{
|
||||
return pss->pstream[stream_index].msd_flag[frame_index];
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_is_msd: get MSD flag */
|
||||
HTS_Boolean HTS_PStreamSet_is_msd(HTS_PStreamSet * pss, size_t stream_index)
|
||||
{
|
||||
return pss->pstream[stream_index].msd_flag ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/* HTS_PStreamSet_clear: free parameter stream set */
|
||||
void HTS_PStreamSet_clear(HTS_PStreamSet * pss)
|
||||
{
|
||||
size_t i, j;
|
||||
HTS_PStream *pstream;
|
||||
|
||||
if (pss->pstream) {
|
||||
for (i = 0; i < pss->nstream; i++) {
|
||||
pstream = &pss->pstream[i];
|
||||
if (pstream->sm.wum)
|
||||
HTS_free(pstream->sm.wum);
|
||||
if (pstream->sm.g)
|
||||
HTS_free(pstream->sm.g);
|
||||
if (pstream->sm.wuw)
|
||||
HTS_free_matrix(pstream->sm.wuw, pstream->length);
|
||||
if (pstream->sm.ivar)
|
||||
HTS_free_matrix(pstream->sm.ivar, pstream->length);
|
||||
if (pstream->sm.mean)
|
||||
HTS_free_matrix(pstream->sm.mean, pstream->length);
|
||||
if (pstream->par)
|
||||
HTS_free_matrix(pstream->par, pstream->length);
|
||||
if (pstream->msd_flag)
|
||||
HTS_free(pstream->msd_flag);
|
||||
if (pstream->win_coefficient) {
|
||||
for (j = 0; j < pstream->win_size; j++) {
|
||||
pstream->win_coefficient[j] += pstream->win_l_width[j];
|
||||
HTS_free(pstream->win_coefficient[j]);
|
||||
}
|
||||
}
|
||||
if (pstream->gv_mean)
|
||||
HTS_free(pstream->gv_mean);
|
||||
if (pstream->gv_vari)
|
||||
HTS_free(pstream->gv_vari);
|
||||
if (pstream->win_coefficient)
|
||||
HTS_free(pstream->win_coefficient);
|
||||
if (pstream->win_l_width)
|
||||
HTS_free(pstream->win_l_width);
|
||||
if (pstream->win_r_width)
|
||||
HTS_free(pstream->win_r_width);
|
||||
if (pstream->gv_switch)
|
||||
HTS_free(pstream->gv_switch);
|
||||
}
|
||||
HTS_free(pss->pstream);
|
||||
}
|
||||
HTS_PStreamSet_initialize(pss);
|
||||
}
|
||||
|
||||
HTS_PSTREAM_C_END;
|
||||
|
||||
#endif /* !HTS_PSTREAM_C */
|
||||
512
3rdparty/hts_engine_API/lib/HTS_sstream.c
vendored
Normal file
512
3rdparty/hts_engine_API/lib/HTS_sstream.c
vendored
Normal file
@@ -0,0 +1,512 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_SSTREAM_C
|
||||
#define HTS_SSTREAM_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_SSTREAM_C_START extern "C" {
|
||||
#define HTS_SSTREAM_C_END }
|
||||
#else
|
||||
#define HTS_SSTREAM_C_START
|
||||
#define HTS_SSTREAM_C_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_SSTREAM_C_START;
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
/* hts_engine libraries */
|
||||
#include "HTS_hidden.h"
|
||||
|
||||
/* HTS_set_default_duration: set default duration from state duration probability distribution */
|
||||
static double HTS_set_default_duration(size_t * duration, double *mean, double *vari, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
double temp;
|
||||
size_t sum = 0;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
temp = mean[i] + 0.5;
|
||||
if (temp < 1.0)
|
||||
duration[i] = 1;
|
||||
else
|
||||
duration[i] = (size_t) temp;
|
||||
sum += duration[i];
|
||||
}
|
||||
|
||||
return (double) sum;
|
||||
}
|
||||
|
||||
/* HTS_set_specified_duration: set duration from state duration probability distribution and specified frame length */
|
||||
static double HTS_set_specified_duration(size_t * duration, double *mean, double *vari, size_t size, double frame_length)
|
||||
{
|
||||
size_t i;
|
||||
int j;
|
||||
double temp1, temp2;
|
||||
double rho = 0.0;
|
||||
size_t sum = 0;
|
||||
size_t target_length;
|
||||
|
||||
/* get the target frame length */
|
||||
if (frame_length + 0.5 < 1.0)
|
||||
target_length = 1;
|
||||
else
|
||||
target_length = (size_t) (frame_length + 0.5);
|
||||
|
||||
/* check the specified duration */
|
||||
if (target_length <= size) {
|
||||
if (target_length < size)
|
||||
HTS_error(-1, "HTS_set_specified_duration: Specified frame length is too short.\n");
|
||||
for (i = 0; i < size; i++)
|
||||
duration[i] = 1;
|
||||
return (double) size;
|
||||
}
|
||||
|
||||
/* RHO calculation */
|
||||
temp1 = 0.0;
|
||||
temp2 = 0.0;
|
||||
for (i = 0; i < size; i++) {
|
||||
temp1 += mean[i];
|
||||
temp2 += vari[i];
|
||||
}
|
||||
rho = ((double) target_length - temp1) / temp2;
|
||||
|
||||
/* first estimation */
|
||||
for (i = 0; i < size; i++) {
|
||||
temp1 = mean[i] + rho * vari[i] + 0.5;
|
||||
if (temp1 < 1.0)
|
||||
duration[i] = 1;
|
||||
else
|
||||
duration[i] = (size_t) temp1;
|
||||
sum += duration[i];
|
||||
}
|
||||
|
||||
/* loop estimation */
|
||||
while (target_length != sum) {
|
||||
/* sarch flexible state and modify its duration */
|
||||
if (target_length > sum) {
|
||||
j = -1;
|
||||
for (i = 0; i < size; i++) {
|
||||
temp2 = fabs(rho - ((double) duration[i] + 1 - mean[i]) / vari[i]);
|
||||
if (j < 0 || temp1 > temp2) {
|
||||
j = i;
|
||||
temp1 = temp2;
|
||||
}
|
||||
}
|
||||
sum++;
|
||||
duration[j]++;
|
||||
} else {
|
||||
j = -1;
|
||||
for (i = 0; i < size; i++) {
|
||||
if (duration[i] > 1) {
|
||||
temp2 = fabs(rho - ((double) duration[i] - 1 - mean[i]) / vari[i]);
|
||||
if (j < 0 || temp1 > temp2) {
|
||||
j = i;
|
||||
temp1 = temp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
sum--;
|
||||
duration[j]--;
|
||||
}
|
||||
}
|
||||
|
||||
return (double) target_length;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_initialize: initialize state stream set */
|
||||
void HTS_SStreamSet_initialize(HTS_SStreamSet * sss)
|
||||
{
|
||||
sss->nstream = 0;
|
||||
sss->nstate = 0;
|
||||
sss->sstream = NULL;
|
||||
sss->duration = NULL;
|
||||
sss->total_state = 0;
|
||||
sss->total_frame = 0;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_create: parse label and determine state duration */
|
||||
HTS_Boolean HTS_SStreamSet_create(HTS_SStreamSet * sss, HTS_ModelSet * ms, HTS_Label * label, HTS_Boolean phoneme_alignment_flag, double speed, double *duration_iw, double **parameter_iw, double **gv_iw)
|
||||
{
|
||||
size_t i, j, k;
|
||||
double temp;
|
||||
int shift;
|
||||
size_t state;
|
||||
HTS_SStream *sst;
|
||||
double *duration_mean, *duration_vari;
|
||||
double frame_length;
|
||||
size_t next_time;
|
||||
size_t next_state;
|
||||
|
||||
if (HTS_Label_get_size(label) == 0)
|
||||
return FALSE;
|
||||
|
||||
/* check interpolation weights */
|
||||
for (i = 0, temp = 0.0; i < HTS_ModelSet_get_nvoices(ms); i++)
|
||||
temp += duration_iw[i];
|
||||
if (temp == 0.0) {
|
||||
return FALSE;
|
||||
} else if (temp != 1.0) {
|
||||
for (i = 0; i < HTS_ModelSet_get_nvoices(ms); i++)
|
||||
if (duration_iw[i] != 0.0)
|
||||
duration_iw[i] /= temp;
|
||||
}
|
||||
|
||||
for (i = 0; i < HTS_ModelSet_get_nstream(ms); i++) {
|
||||
for (j = 0, temp = 0.0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
temp += parameter_iw[j][i];
|
||||
if (temp == 0.0) {
|
||||
return FALSE;
|
||||
} else if (temp != 1.0) {
|
||||
for (j = 0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
if (parameter_iw[j][i] != 0.0)
|
||||
parameter_iw[j][i] /= temp;
|
||||
}
|
||||
if (HTS_ModelSet_use_gv(ms, i)) {
|
||||
for (j = 0, temp = 0.0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
temp += gv_iw[j][i];
|
||||
if (temp == 0.0)
|
||||
return FALSE;
|
||||
else if (temp != 1.0)
|
||||
for (j = 0; j < HTS_ModelSet_get_nvoices(ms); j++)
|
||||
if (gv_iw[j][i] != 0.0)
|
||||
gv_iw[j][i] /= temp;
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize state sequence */
|
||||
sss->nstate = HTS_ModelSet_get_nstate(ms);
|
||||
sss->nstream = HTS_ModelSet_get_nstream(ms);
|
||||
sss->total_frame = 0;
|
||||
sss->total_state = HTS_Label_get_size(label) * sss->nstate;
|
||||
sss->duration = (size_t *) HTS_calloc(sss->total_state, sizeof(size_t));
|
||||
sss->sstream = (HTS_SStream *) HTS_calloc(sss->nstream, sizeof(HTS_SStream));
|
||||
for (i = 0; i < sss->nstream; i++) {
|
||||
sst = &sss->sstream[i];
|
||||
sst->vector_length = HTS_ModelSet_get_vector_length(ms, i);
|
||||
sst->mean = (double **) HTS_calloc(sss->total_state, sizeof(double *));
|
||||
sst->vari = (double **) HTS_calloc(sss->total_state, sizeof(double *));
|
||||
if (HTS_ModelSet_is_msd(ms, i))
|
||||
sst->msd = (double *) HTS_calloc(sss->total_state, sizeof(double));
|
||||
else
|
||||
sst->msd = NULL;
|
||||
for (j = 0; j < sss->total_state; j++) {
|
||||
sst->mean[j] = (double *) HTS_calloc(sst->vector_length * HTS_ModelSet_get_window_size(ms, i), sizeof(double));
|
||||
sst->vari[j] = (double *) HTS_calloc(sst->vector_length * HTS_ModelSet_get_window_size(ms, i), sizeof(double));
|
||||
}
|
||||
if (HTS_ModelSet_use_gv(ms, i)) {
|
||||
sst->gv_switch = (HTS_Boolean *) HTS_calloc(sss->total_state, sizeof(HTS_Boolean));
|
||||
for (j = 0; j < sss->total_state; j++)
|
||||
sst->gv_switch[j] = TRUE;
|
||||
} else {
|
||||
sst->gv_switch = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* determine state duration */
|
||||
duration_mean = (double *) HTS_calloc(sss->total_state, sizeof(double));
|
||||
duration_vari = (double *) HTS_calloc(sss->total_state, sizeof(double));
|
||||
for (i = 0; i < HTS_Label_get_size(label); i++)
|
||||
HTS_ModelSet_get_duration(ms, HTS_Label_get_string(label, i), duration_iw, &duration_mean[i * sss->nstate], &duration_vari[i * sss->nstate]);
|
||||
if (phoneme_alignment_flag == TRUE) {
|
||||
/* use duration set by user */
|
||||
next_time = 0;
|
||||
next_state = 0;
|
||||
state = 0;
|
||||
for (i = 0; i < HTS_Label_get_size(label); i++) {
|
||||
temp = HTS_Label_get_end_frame(label, i);
|
||||
if (temp >= 0) {
|
||||
next_time += (size_t) HTS_set_specified_duration(&sss->duration[next_state], &duration_mean[next_state], &duration_vari[next_state], state + sss->nstate - next_state, temp - next_time);
|
||||
next_state = state + sss->nstate;
|
||||
} else if (i + 1 == HTS_Label_get_size(label)) {
|
||||
HTS_error(-1, "HTS_SStreamSet_create: The time of final label is not specified.\n");
|
||||
HTS_set_default_duration(&sss->duration[next_state], &duration_mean[next_state], &duration_vari[next_state], state + sss->nstate - next_state);
|
||||
}
|
||||
state += sss->nstate;
|
||||
}
|
||||
} else {
|
||||
/* determine frame length */
|
||||
if (speed != 1.0) {
|
||||
temp = 0.0;
|
||||
for (i = 0; i < sss->total_state; i++) {
|
||||
temp += duration_mean[i];
|
||||
}
|
||||
frame_length = temp / speed;
|
||||
HTS_set_specified_duration(sss->duration, duration_mean, duration_vari, sss->total_state, frame_length);
|
||||
} else {
|
||||
HTS_set_default_duration(sss->duration, duration_mean, duration_vari, sss->total_state);
|
||||
}
|
||||
}
|
||||
HTS_free(duration_mean);
|
||||
HTS_free(duration_vari);
|
||||
|
||||
/* get parameter */
|
||||
for (i = 0, state = 0; i < HTS_Label_get_size(label); i++) {
|
||||
for (j = 2; j <= sss->nstate + 1; j++) {
|
||||
sss->total_frame += sss->duration[state];
|
||||
for (k = 0; k < sss->nstream; k++) {
|
||||
sst = &sss->sstream[k];
|
||||
if (sst->msd)
|
||||
HTS_ModelSet_get_parameter(ms, k, j, HTS_Label_get_string(label, i), (const double *const *) parameter_iw, sst->mean[state], sst->vari[state], &sst->msd[state]);
|
||||
else
|
||||
HTS_ModelSet_get_parameter(ms, k, j, HTS_Label_get_string(label, i), (const double *const *) parameter_iw, sst->mean[state], sst->vari[state], NULL);
|
||||
}
|
||||
state++;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy dynamic window */
|
||||
for (i = 0; i < sss->nstream; i++) {
|
||||
sst = &sss->sstream[i];
|
||||
sst->win_size = HTS_ModelSet_get_window_size(ms, i);
|
||||
sst->win_max_width = HTS_ModelSet_get_window_max_width(ms, i);
|
||||
sst->win_l_width = (int *) HTS_calloc(sst->win_size, sizeof(int));
|
||||
sst->win_r_width = (int *) HTS_calloc(sst->win_size, sizeof(int));
|
||||
sst->win_coefficient = (double **) HTS_calloc(sst->win_size, sizeof(double));
|
||||
for (j = 0; j < sst->win_size; j++) {
|
||||
sst->win_l_width[j] = HTS_ModelSet_get_window_left_width(ms, i, j);
|
||||
sst->win_r_width[j] = HTS_ModelSet_get_window_right_width(ms, i, j);
|
||||
if (sst->win_l_width[j] + sst->win_r_width[j] == 0)
|
||||
sst->win_coefficient[j] = (double *) HTS_calloc(-2 * sst->win_l_width[j] + 1, sizeof(double));
|
||||
else
|
||||
sst->win_coefficient[j] = (double *) HTS_calloc(-2 * sst->win_l_width[j], sizeof(double));
|
||||
sst->win_coefficient[j] -= sst->win_l_width[j];
|
||||
for (shift = sst->win_l_width[j]; shift <= sst->win_r_width[j]; shift++)
|
||||
sst->win_coefficient[j][shift] = HTS_ModelSet_get_window_coefficient(ms, i, j, shift);
|
||||
}
|
||||
}
|
||||
|
||||
/* determine GV */
|
||||
for (i = 0; i < sss->nstream; i++) {
|
||||
sst = &sss->sstream[i];
|
||||
if (HTS_ModelSet_use_gv(ms, i)) {
|
||||
sst->gv_mean = (double *) HTS_calloc(sst->vector_length, sizeof(double));
|
||||
sst->gv_vari = (double *) HTS_calloc(sst->vector_length, sizeof(double));
|
||||
HTS_ModelSet_get_gv(ms, i, HTS_Label_get_string(label, 0), (const double *const *) gv_iw, sst->gv_mean, sst->gv_vari);
|
||||
} else {
|
||||
sst->gv_mean = NULL;
|
||||
sst->gv_vari = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < HTS_Label_get_size(label); i++)
|
||||
if (HTS_ModelSet_get_gv_flag(ms, HTS_Label_get_string(label, i)) == FALSE)
|
||||
for (j = 0; j < sss->nstream; j++)
|
||||
if (HTS_ModelSet_use_gv(ms, j) == TRUE)
|
||||
for (k = 0; k < sss->nstate; k++)
|
||||
sss->sstream[j].gv_switch[i * sss->nstate + k] = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_nstream: get number of stream */
|
||||
size_t HTS_SStreamSet_get_nstream(HTS_SStreamSet * sss)
|
||||
{
|
||||
return sss->nstream;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_vector_length: get vector length */
|
||||
size_t HTS_SStreamSet_get_vector_length(HTS_SStreamSet * sss, size_t stream_index)
|
||||
{
|
||||
return sss->sstream[stream_index].vector_length;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_is_msd: get MSD flag */
|
||||
HTS_Boolean HTS_SStreamSet_is_msd(HTS_SStreamSet * sss, size_t stream_index)
|
||||
{
|
||||
return sss->sstream[stream_index].msd ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_total_state: get total number of state */
|
||||
size_t HTS_SStreamSet_get_total_state(HTS_SStreamSet * sss)
|
||||
{
|
||||
return sss->total_state;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_total_frame: get total number of frame */
|
||||
size_t HTS_SStreamSet_get_total_frame(HTS_SStreamSet * sss)
|
||||
{
|
||||
return sss->total_frame;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_msd: get MSD parameter */
|
||||
double HTS_SStreamSet_get_msd(HTS_SStreamSet * sss, size_t stream_index, size_t state_index)
|
||||
{
|
||||
return sss->sstream[stream_index].msd[state_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_window_size: get dynamic window size */
|
||||
size_t HTS_SStreamSet_get_window_size(HTS_SStreamSet * sss, size_t stream_index)
|
||||
{
|
||||
return sss->sstream[stream_index].win_size;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_window_left_width: get left width of dynamic window */
|
||||
int HTS_SStreamSet_get_window_left_width(HTS_SStreamSet * sss, size_t stream_index, size_t window_index)
|
||||
{
|
||||
return sss->sstream[stream_index].win_l_width[window_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_winodow_right_width: get right width of dynamic window */
|
||||
int HTS_SStreamSet_get_window_right_width(HTS_SStreamSet * sss, size_t stream_index, size_t window_index)
|
||||
{
|
||||
return sss->sstream[stream_index].win_r_width[window_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_window_coefficient: get coefficient of dynamic window */
|
||||
double HTS_SStreamSet_get_window_coefficient(HTS_SStreamSet * sss, size_t stream_index, size_t window_index, int coefficient_index)
|
||||
{
|
||||
return sss->sstream[stream_index].win_coefficient[window_index][coefficient_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_window_max_width: get max width of dynamic window */
|
||||
size_t HTS_SStreamSet_get_window_max_width(HTS_SStreamSet * sss, size_t stream_index)
|
||||
{
|
||||
return sss->sstream[stream_index].win_max_width;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_use_gv: get GV flag */
|
||||
HTS_Boolean HTS_SStreamSet_use_gv(HTS_SStreamSet * sss, size_t stream_index)
|
||||
{
|
||||
return sss->sstream[stream_index].gv_mean ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_duration: get state duration */
|
||||
size_t HTS_SStreamSet_get_duration(HTS_SStreamSet * sss, size_t state_index)
|
||||
{
|
||||
return sss->duration[state_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_mean: get mean parameter */
|
||||
double HTS_SStreamSet_get_mean(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, size_t vector_index)
|
||||
{
|
||||
return sss->sstream[stream_index].mean[state_index][vector_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_set_mean: set mean parameter */
|
||||
void HTS_SStreamSet_set_mean(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, size_t vector_index, double f)
|
||||
{
|
||||
sss->sstream[stream_index].mean[state_index][vector_index] = f;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_vari: get variance parameter */
|
||||
double HTS_SStreamSet_get_vari(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, size_t vector_index)
|
||||
{
|
||||
return sss->sstream[stream_index].vari[state_index][vector_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_set_vari: set variance parameter */
|
||||
void HTS_SStreamSet_set_vari(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, size_t vector_index, double f)
|
||||
{
|
||||
sss->sstream[stream_index].vari[state_index][vector_index] = f;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_gv_mean: get GV mean parameter */
|
||||
double HTS_SStreamSet_get_gv_mean(HTS_SStreamSet * sss, size_t stream_index, size_t vector_index)
|
||||
{
|
||||
return sss->sstream[stream_index].gv_mean[vector_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_gv_mean: get GV variance parameter */
|
||||
double HTS_SStreamSet_get_gv_vari(HTS_SStreamSet * sss, size_t stream_index, size_t vector_index)
|
||||
{
|
||||
return sss->sstream[stream_index].gv_vari[vector_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_set_gv_switch: set GV switch */
|
||||
void HTS_SStreamSet_set_gv_switch(HTS_SStreamSet * sss, size_t stream_index, size_t state_index, HTS_Boolean i)
|
||||
{
|
||||
sss->sstream[stream_index].gv_switch[state_index] = i;
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_get_gv_switch: get GV switch */
|
||||
HTS_Boolean HTS_SStreamSet_get_gv_switch(HTS_SStreamSet * sss, size_t stream_index, size_t state_index)
|
||||
{
|
||||
return sss->sstream[stream_index].gv_switch[state_index];
|
||||
}
|
||||
|
||||
/* HTS_SStreamSet_clear: free state stream set */
|
||||
void HTS_SStreamSet_clear(HTS_SStreamSet * sss)
|
||||
{
|
||||
size_t i, j;
|
||||
HTS_SStream *sst;
|
||||
|
||||
if (sss->sstream) {
|
||||
for (i = 0; i < sss->nstream; i++) {
|
||||
sst = &sss->sstream[i];
|
||||
for (j = 0; j < sss->total_state; j++) {
|
||||
HTS_free(sst->mean[j]);
|
||||
HTS_free(sst->vari[j]);
|
||||
}
|
||||
if (sst->msd)
|
||||
HTS_free(sst->msd);
|
||||
HTS_free(sst->mean);
|
||||
HTS_free(sst->vari);
|
||||
for (j = 0; j < sst->win_size; j++) {
|
||||
sst->win_coefficient[j] += sst->win_l_width[j];
|
||||
HTS_free(sst->win_coefficient[j]);
|
||||
}
|
||||
HTS_free(sst->win_coefficient);
|
||||
HTS_free(sst->win_l_width);
|
||||
HTS_free(sst->win_r_width);
|
||||
if (sst->gv_mean)
|
||||
HTS_free(sst->gv_mean);
|
||||
if (sst->gv_vari)
|
||||
HTS_free(sst->gv_vari);
|
||||
if (sst->gv_switch)
|
||||
HTS_free(sst->gv_switch);
|
||||
}
|
||||
HTS_free(sss->sstream);
|
||||
}
|
||||
if (sss->duration)
|
||||
HTS_free(sss->duration);
|
||||
|
||||
HTS_SStreamSet_initialize(sss);
|
||||
}
|
||||
|
||||
HTS_SSTREAM_C_END;
|
||||
|
||||
#endif /* !HTS_SSTREAM_C */
|
||||
997
3rdparty/hts_engine_API/lib/HTS_vocoder.c
vendored
Normal file
997
3rdparty/hts_engine_API/lib/HTS_vocoder.c
vendored
Normal file
@@ -0,0 +1,997 @@
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* The HMM-Based Speech Synthesis Engine "hts_engine API" */
|
||||
/* developed by HTS Working Group */
|
||||
/* http://hts-engine.sourceforge.net/ */
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* */
|
||||
/* Copyright (c) 2001-2015 Nagoya Institute of Technology */
|
||||
/* Department of Computer Science */
|
||||
/* */
|
||||
/* 2001-2008 Tokyo Institute of Technology */
|
||||
/* Interdisciplinary Graduate School of */
|
||||
/* Science and Engineering */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or */
|
||||
/* without modification, are permitted provided that the following */
|
||||
/* conditions are met: */
|
||||
/* */
|
||||
/* - Redistributions of source code must retain the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer. */
|
||||
/* - Redistributions in binary form must reproduce the above */
|
||||
/* copyright notice, this list of conditions and the following */
|
||||
/* disclaimer in the documentation and/or other materials provided */
|
||||
/* with the distribution. */
|
||||
/* - Neither the name of the HTS working group nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived */
|
||||
/* from this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
||||
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
||||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
||||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
||||
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
|
||||
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
|
||||
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
|
||||
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
|
||||
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
|
||||
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
|
||||
/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
||||
/* POSSIBILITY OF SUCH DAMAGE. */
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
#ifndef HTS_VOCODER_C
|
||||
#define HTS_VOCODER_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HTS_VOCODER_C_START extern "C" {
|
||||
#define HTS_VOCODER_C_END }
|
||||
#else
|
||||
#define HTS_VOCODER_C_START
|
||||
#define HTS_VOCODER_C_END
|
||||
#endif /* __CPLUSPLUS */
|
||||
|
||||
HTS_VOCODER_C_START;
|
||||
|
||||
#include <math.h> /* for sqrt(),log(),exp(),pow(),cos() */
|
||||
|
||||
/* hts_engine libraries */
|
||||
#include "HTS_hidden.h"
|
||||
|
||||
static const double HTS_pade[21] = {
|
||||
1.00000000000,
|
||||
1.00000000000,
|
||||
0.00000000000,
|
||||
1.00000000000,
|
||||
0.00000000000,
|
||||
0.00000000000,
|
||||
1.00000000000,
|
||||
0.00000000000,
|
||||
0.00000000000,
|
||||
0.00000000000,
|
||||
1.00000000000,
|
||||
0.49992730000,
|
||||
0.10670050000,
|
||||
0.01170221000,
|
||||
0.00056562790,
|
||||
1.00000000000,
|
||||
0.49993910000,
|
||||
0.11070980000,
|
||||
0.01369984000,
|
||||
0.00095648530,
|
||||
0.00003041721
|
||||
};
|
||||
|
||||
/* HTS_movem: move memory */
|
||||
static void HTS_movem(double *a, double *b, const int nitem)
|
||||
{
|
||||
long i = (long) nitem;
|
||||
|
||||
if (a > b)
|
||||
while (i--)
|
||||
*b++ = *a++;
|
||||
else {
|
||||
a += i;
|
||||
b += i;
|
||||
while (i--)
|
||||
*--b = *--a;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_mlsafir: sub functions for MLSA filter */
|
||||
static double HTS_mlsafir(const double x, const double *b, const int m, const double a, const double aa, double *d)
|
||||
{
|
||||
double y = 0.0;
|
||||
int i;
|
||||
|
||||
d[0] = x;
|
||||
d[1] = aa * d[0] + a * d[1];
|
||||
|
||||
for (i = 2; i <= m; i++)
|
||||
d[i] += a * (d[i + 1] - d[i - 1]);
|
||||
|
||||
for (i = 2; i <= m; i++)
|
||||
y += d[i] * b[i];
|
||||
|
||||
for (i = m + 1; i > 1; i--)
|
||||
d[i] = d[i - 1];
|
||||
|
||||
return (y);
|
||||
}
|
||||
|
||||
/* HTS_mlsadf1: sub functions for MLSA filter */
|
||||
static double HTS_mlsadf1(double x, const double *b, const int m, const double a, const double aa, const int pd, double *d, const double *ppade)
|
||||
{
|
||||
double v, out = 0.0, *pt;
|
||||
int i;
|
||||
|
||||
pt = &d[pd + 1];
|
||||
|
||||
for (i = pd; i >= 1; i--) {
|
||||
d[i] = aa * pt[i - 1] + a * d[i];
|
||||
pt[i] = d[i] * b[1];
|
||||
v = pt[i] * ppade[i];
|
||||
x += (1 & i) ? v : -v;
|
||||
out += v;
|
||||
}
|
||||
|
||||
pt[0] = x;
|
||||
out += x;
|
||||
|
||||
return (out);
|
||||
}
|
||||
|
||||
/* HTS_mlsadf2: sub functions for MLSA filter */
|
||||
static double HTS_mlsadf2(double x, const double *b, const int m, const double a, const double aa, const int pd, double *d, const double *ppade)
|
||||
{
|
||||
double v, out = 0.0, *pt;
|
||||
int i;
|
||||
|
||||
pt = &d[pd * (m + 2)];
|
||||
|
||||
for (i = pd; i >= 1; i--) {
|
||||
pt[i] = HTS_mlsafir(pt[i - 1], b, m, a, aa, &d[(i - 1) * (m + 2)]);
|
||||
v = pt[i] * ppade[i];
|
||||
|
||||
x += (1 & i) ? v : -v;
|
||||
out += v;
|
||||
}
|
||||
|
||||
pt[0] = x;
|
||||
out += x;
|
||||
|
||||
return (out);
|
||||
}
|
||||
|
||||
/* HTS_mlsadf: functions for MLSA filter */
|
||||
static double HTS_mlsadf(double x, const double *b, const int m, const double a, const int pd, double *d)
|
||||
{
|
||||
const double aa = 1 - a * a;
|
||||
const double *ppade = &(HTS_pade[pd * (pd + 1) / 2]);
|
||||
|
||||
x = HTS_mlsadf1(x, b, m, a, aa, pd, d, ppade);
|
||||
x = HTS_mlsadf2(x, b, m, a, aa, pd, &d[2 * (pd + 1)], ppade);
|
||||
|
||||
return (x);
|
||||
}
|
||||
|
||||
/* HTS_rnd: functions for random noise generation */
|
||||
static double HTS_rnd(unsigned long *next)
|
||||
{
|
||||
double r;
|
||||
|
||||
*next = *next * 1103515245L + 12345;
|
||||
r = (*next / 65536L) % 32768L;
|
||||
|
||||
return (r / RANDMAX);
|
||||
}
|
||||
|
||||
/* HTS_nrandom: functions for gaussian random noise generation */
|
||||
static double HTS_nrandom(HTS_Vocoder * v)
|
||||
{
|
||||
if (v->sw == 0) {
|
||||
v->sw = 1;
|
||||
do {
|
||||
v->r1 = 2 * HTS_rnd(&v->next) - 1;
|
||||
v->r2 = 2 * HTS_rnd(&v->next) - 1;
|
||||
v->s = v->r1 * v->r1 + v->r2 * v->r2;
|
||||
} while (v->s > 1 || v->s == 0);
|
||||
v->s = sqrt(-2 * log(v->s) / v->s);
|
||||
return (v->r1 * v->s);
|
||||
} else {
|
||||
v->sw = 0;
|
||||
return (v->r2 * v->s);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_mceq: function for M-sequence random noise generation */
|
||||
static int HTS_mseq(HTS_Vocoder * v)
|
||||
{
|
||||
int x0, x28;
|
||||
|
||||
v->x >>= 1;
|
||||
if (v->x & B0)
|
||||
x0 = 1;
|
||||
else
|
||||
x0 = -1;
|
||||
if (v->x & B28)
|
||||
x28 = 1;
|
||||
else
|
||||
x28 = -1;
|
||||
if (x0 + x28)
|
||||
v->x &= B31_;
|
||||
else
|
||||
v->x |= B31;
|
||||
|
||||
return (x0);
|
||||
}
|
||||
|
||||
/* HTS_mc2b: transform mel-cepstrum to MLSA digital fillter coefficients */
|
||||
static void HTS_mc2b(double *mc, double *b, int m, const double a)
|
||||
{
|
||||
if (mc != b) {
|
||||
if (a != 0.0) {
|
||||
b[m] = mc[m];
|
||||
for (m--; m >= 0; m--)
|
||||
b[m] = mc[m] - a * b[m + 1];
|
||||
} else
|
||||
HTS_movem(mc, b, m + 1);
|
||||
} else if (a != 0.0)
|
||||
for (m--; m >= 0; m--)
|
||||
b[m] -= a * b[m + 1];
|
||||
}
|
||||
|
||||
/* HTS_b2bc: transform MLSA digital filter coefficients to mel-cepstrum */
|
||||
static void HTS_b2mc(const double *b, double *mc, int m, const double a)
|
||||
{
|
||||
double d, o;
|
||||
|
||||
d = mc[m] = b[m];
|
||||
for (m--; m >= 0; m--) {
|
||||
o = b[m] + a * d;
|
||||
d = b[m];
|
||||
mc[m] = o;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_freqt: frequency transformation */
|
||||
static void HTS_freqt(HTS_Vocoder * v, const double *c1, const int m1, double *c2, const int m2, const double a)
|
||||
{
|
||||
int i, j;
|
||||
const double b = 1 - a * a;
|
||||
double *g;
|
||||
|
||||
if (m2 > v->freqt_size) {
|
||||
if (v->freqt_buff != NULL)
|
||||
HTS_free(v->freqt_buff);
|
||||
v->freqt_buff = (double *) HTS_calloc(m2 + m2 + 2, sizeof(double));
|
||||
v->freqt_size = m2;
|
||||
}
|
||||
g = v->freqt_buff + v->freqt_size + 1;
|
||||
|
||||
for (i = 0; i < m2 + 1; i++)
|
||||
g[i] = 0.0;
|
||||
|
||||
for (i = -m1; i <= 0; i++) {
|
||||
if (0 <= m2)
|
||||
g[0] = c1[-i] + a * (v->freqt_buff[0] = g[0]);
|
||||
if (1 <= m2)
|
||||
g[1] = b * v->freqt_buff[0] + a * (v->freqt_buff[1] = g[1]);
|
||||
for (j = 2; j <= m2; j++)
|
||||
g[j] = v->freqt_buff[j - 1] + a * ((v->freqt_buff[j] = g[j]) - g[j - 1]);
|
||||
}
|
||||
|
||||
HTS_movem(g, c2, m2 + 1);
|
||||
}
|
||||
|
||||
/* HTS_c2ir: The minimum phase impulse response is evaluated from the minimum phase cepstrum */
|
||||
static void HTS_c2ir(const double *c, const int nc, double *h, const int leng)
|
||||
{
|
||||
int n, k, upl;
|
||||
double d;
|
||||
|
||||
h[0] = exp(c[0]);
|
||||
for (n = 1; n < leng; n++) {
|
||||
d = 0;
|
||||
upl = (n >= nc) ? nc - 1 : n;
|
||||
for (k = 1; k <= upl; k++)
|
||||
d += k * c[k] * h[n - k];
|
||||
h[n] = d / n;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_b2en: calculate frame energy */
|
||||
static double HTS_b2en(HTS_Vocoder * v, const double *b, const int m, const double a)
|
||||
{
|
||||
int i;
|
||||
double en = 0.0;
|
||||
double *cep;
|
||||
double *ir;
|
||||
|
||||
if (v->spectrum2en_size < m) {
|
||||
if (v->spectrum2en_buff != NULL)
|
||||
HTS_free(v->spectrum2en_buff);
|
||||
v->spectrum2en_buff = (double *) HTS_calloc((m + 1) + 2 * IRLENG, sizeof(double));
|
||||
v->spectrum2en_size = m;
|
||||
}
|
||||
cep = v->spectrum2en_buff + m + 1;
|
||||
ir = cep + IRLENG;
|
||||
|
||||
HTS_b2mc(b, v->spectrum2en_buff, m, a);
|
||||
HTS_freqt(v, v->spectrum2en_buff, m, cep, IRLENG - 1, -a);
|
||||
HTS_c2ir(cep, IRLENG, ir, IRLENG);
|
||||
|
||||
for (i = 0; i < IRLENG; i++)
|
||||
en += ir[i] * ir[i];
|
||||
|
||||
return (en);
|
||||
}
|
||||
|
||||
/* HTS_ignorm: inverse gain normalization */
|
||||
static void HTS_ignorm(double *c1, double *c2, int m, const double g)
|
||||
{
|
||||
double k;
|
||||
if (g != 0.0) {
|
||||
k = pow(c1[0], g);
|
||||
for (; m >= 1; m--)
|
||||
c2[m] = k * c1[m];
|
||||
c2[0] = (k - 1.0) / g;
|
||||
} else {
|
||||
HTS_movem(&c1[1], &c2[1], m);
|
||||
c2[0] = log(c1[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_gnorm: gain normalization */
|
||||
static void HTS_gnorm(double *c1, double *c2, int m, const double g)
|
||||
{
|
||||
double k;
|
||||
if (g != 0.0) {
|
||||
k = 1.0 + g * c1[0];
|
||||
for (; m >= 1; m--)
|
||||
c2[m] = c1[m] / k;
|
||||
c2[0] = pow(k, 1.0 / g);
|
||||
} else {
|
||||
HTS_movem(&c1[1], &c2[1], m);
|
||||
c2[0] = exp(c1[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_lsp2lpc: transform LSP to LPC */
|
||||
static void HTS_lsp2lpc(HTS_Vocoder * v, double *lsp, double *a, const int m)
|
||||
{
|
||||
int i, k, mh1, mh2, flag_odd;
|
||||
double xx, xf, xff;
|
||||
double *p, *q;
|
||||
double *a0, *a1, *a2, *b0, *b1, *b2;
|
||||
|
||||
flag_odd = 0;
|
||||
if (m % 2 == 0)
|
||||
mh1 = mh2 = m / 2;
|
||||
else {
|
||||
mh1 = (m + 1) / 2;
|
||||
mh2 = (m - 1) / 2;
|
||||
flag_odd = 1;
|
||||
}
|
||||
|
||||
if (m > v->lsp2lpc_size) {
|
||||
if (v->lsp2lpc_buff != NULL)
|
||||
HTS_free(v->lsp2lpc_buff);
|
||||
v->lsp2lpc_buff = (double *) HTS_calloc(5 * m + 6, sizeof(double));
|
||||
v->lsp2lpc_size = m;
|
||||
}
|
||||
p = v->lsp2lpc_buff + m;
|
||||
q = p + mh1;
|
||||
a0 = q + mh2;
|
||||
a1 = a0 + (mh1 + 1);
|
||||
a2 = a1 + (mh1 + 1);
|
||||
b0 = a2 + (mh1 + 1);
|
||||
b1 = b0 + (mh2 + 1);
|
||||
b2 = b1 + (mh2 + 1);
|
||||
|
||||
HTS_movem(lsp, v->lsp2lpc_buff, m);
|
||||
|
||||
for (i = 0; i < mh1 + 1; i++)
|
||||
a0[i] = 0.0;
|
||||
for (i = 0; i < mh1 + 1; i++)
|
||||
a1[i] = 0.0;
|
||||
for (i = 0; i < mh1 + 1; i++)
|
||||
a2[i] = 0.0;
|
||||
for (i = 0; i < mh2 + 1; i++)
|
||||
b0[i] = 0.0;
|
||||
for (i = 0; i < mh2 + 1; i++)
|
||||
b1[i] = 0.0;
|
||||
for (i = 0; i < mh2 + 1; i++)
|
||||
b2[i] = 0.0;
|
||||
|
||||
/* lsp filter parameters */
|
||||
for (i = k = 0; i < mh1; i++, k += 2)
|
||||
p[i] = -2.0 * cos(v->lsp2lpc_buff[k]);
|
||||
for (i = k = 0; i < mh2; i++, k += 2)
|
||||
q[i] = -2.0 * cos(v->lsp2lpc_buff[k + 1]);
|
||||
|
||||
/* impulse response of analysis filter */
|
||||
xx = 1.0;
|
||||
xf = xff = 0.0;
|
||||
|
||||
for (k = 0; k <= m; k++) {
|
||||
if (flag_odd) {
|
||||
a0[0] = xx;
|
||||
b0[0] = xx - xff;
|
||||
xff = xf;
|
||||
xf = xx;
|
||||
} else {
|
||||
a0[0] = xx + xf;
|
||||
b0[0] = xx - xf;
|
||||
xf = xx;
|
||||
}
|
||||
|
||||
for (i = 0; i < mh1; i++) {
|
||||
a0[i + 1] = a0[i] + p[i] * a1[i] + a2[i];
|
||||
a2[i] = a1[i];
|
||||
a1[i] = a0[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < mh2; i++) {
|
||||
b0[i + 1] = b0[i] + q[i] * b1[i] + b2[i];
|
||||
b2[i] = b1[i];
|
||||
b1[i] = b0[i];
|
||||
}
|
||||
|
||||
if (k != 0)
|
||||
a[k - 1] = -0.5 * (a0[mh1] + b0[mh2]);
|
||||
xx = 0.0;
|
||||
}
|
||||
|
||||
for (i = m - 1; i >= 0; i--)
|
||||
a[i + 1] = -a[i];
|
||||
a[0] = 1.0;
|
||||
}
|
||||
|
||||
/* HTS_gc2gc: generalized cepstral transformation */
|
||||
static void HTS_gc2gc(HTS_Vocoder * v, double *c1, const int m1, const double g1, double *c2, const int m2, const double g2)
|
||||
{
|
||||
int i, min, k, mk;
|
||||
double ss1, ss2, cc;
|
||||
|
||||
if (m1 > v->gc2gc_size) {
|
||||
if (v->gc2gc_buff != NULL)
|
||||
HTS_free(v->gc2gc_buff);
|
||||
v->gc2gc_buff = (double *) HTS_calloc(m1 + 1, sizeof(double));
|
||||
v->gc2gc_size = m1;
|
||||
}
|
||||
|
||||
HTS_movem(c1, v->gc2gc_buff, m1 + 1);
|
||||
|
||||
c2[0] = v->gc2gc_buff[0];
|
||||
for (i = 1; i <= m2; i++) {
|
||||
ss1 = ss2 = 0.0;
|
||||
min = m1 < i ? m1 : i - 1;
|
||||
for (k = 1; k <= min; k++) {
|
||||
mk = i - k;
|
||||
cc = v->gc2gc_buff[k] * c2[mk];
|
||||
ss2 += k * cc;
|
||||
ss1 += mk * cc;
|
||||
}
|
||||
|
||||
if (i <= m1)
|
||||
c2[i] = v->gc2gc_buff[i] + (g2 * ss2 - g1 * ss1) / i;
|
||||
else
|
||||
c2[i] = (g2 * ss2 - g1 * ss1) / i;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_mgc2mgc: frequency and generalized cepstral transformation */
|
||||
static void HTS_mgc2mgc(HTS_Vocoder * v, double *c1, const int m1, const double a1, const double g1, double *c2, const int m2, const double a2, const double g2)
|
||||
{
|
||||
double a;
|
||||
|
||||
if (a1 == a2) {
|
||||
HTS_gnorm(c1, c1, m1, g1);
|
||||
HTS_gc2gc(v, c1, m1, g1, c2, m2, g2);
|
||||
HTS_ignorm(c2, c2, m2, g2);
|
||||
} else {
|
||||
a = (a2 - a1) / (1 - a1 * a2);
|
||||
HTS_freqt(v, c1, m1, c2, m2, a);
|
||||
HTS_gnorm(c2, c2, m2, g1);
|
||||
HTS_gc2gc(v, c2, m2, g1, c2, m2, g2);
|
||||
HTS_ignorm(c2, c2, m2, g2);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_lsp2mgc: transform LSP to MGC */
|
||||
static void HTS_lsp2mgc(HTS_Vocoder * v, double *lsp, double *mgc, const int m, const double alpha)
|
||||
{
|
||||
int i;
|
||||
/* lsp2lpc */
|
||||
HTS_lsp2lpc(v, lsp + 1, mgc, m);
|
||||
if (v->use_log_gain)
|
||||
mgc[0] = exp(lsp[0]);
|
||||
else
|
||||
mgc[0] = lsp[0];
|
||||
|
||||
/* mgc2mgc */
|
||||
if (NORMFLG1)
|
||||
HTS_ignorm(mgc, mgc, m, v->gamma);
|
||||
else if (MULGFLG1)
|
||||
mgc[0] = (1.0 - mgc[0]) * ((double) v->stage);
|
||||
if (MULGFLG1)
|
||||
for (i = m; i >= 1; i--)
|
||||
mgc[i] *= -((double) v->stage);
|
||||
HTS_mgc2mgc(v, mgc, m, alpha, v->gamma, mgc, m, alpha, v->gamma);
|
||||
if (NORMFLG2)
|
||||
HTS_gnorm(mgc, mgc, m, v->gamma);
|
||||
else if (MULGFLG2)
|
||||
mgc[0] = mgc[0] * v->gamma + 1.0;
|
||||
if (MULGFLG2)
|
||||
for (i = m; i >= 1; i--)
|
||||
mgc[i] *= v->gamma;
|
||||
}
|
||||
|
||||
/* HTS_mglsadff: sub functions for MGLSA filter */
|
||||
static double HTS_mglsadff(double x, const double *b, const int m, const double a, double *d)
|
||||
{
|
||||
int i;
|
||||
|
||||
double y;
|
||||
y = d[0] * b[1];
|
||||
for (i = 1; i < m; i++) {
|
||||
d[i] += a * (d[i + 1] - d[i - 1]);
|
||||
y += d[i] * b[i + 1];
|
||||
}
|
||||
x -= y;
|
||||
|
||||
for (i = m; i > 0; i--)
|
||||
d[i] = d[i - 1];
|
||||
d[0] = a * d[0] + (1 - a * a) * x;
|
||||
return x;
|
||||
}
|
||||
|
||||
/* HTS_mglsadf: sub functions for MGLSA filter */
|
||||
static double HTS_mglsadf(double x, const double *b, const int m, const double a, const int n, double *d)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
x = HTS_mglsadff(x, b, m, a, &d[i * (m + 1)]);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/* THS_check_lsp_stability: check LSP stability */
|
||||
static void HTS_check_lsp_stability(double *lsp, size_t m)
|
||||
{
|
||||
size_t i, j;
|
||||
double tmp;
|
||||
double min = (CHECK_LSP_STABILITY_MIN * PI) / (m + 1);
|
||||
HTS_Boolean find;
|
||||
|
||||
for (i = 0; i < CHECK_LSP_STABILITY_NUM; i++) {
|
||||
find = FALSE;
|
||||
|
||||
for (j = 1; j < m; j++) {
|
||||
tmp = lsp[j + 1] - lsp[j];
|
||||
if (tmp < min) {
|
||||
lsp[j] -= 0.5 * (min - tmp);
|
||||
lsp[j + 1] += 0.5 * (min - tmp);
|
||||
find = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (lsp[1] < min) {
|
||||
lsp[1] = min;
|
||||
find = TRUE;
|
||||
}
|
||||
if (lsp[m] > PI - min) {
|
||||
lsp[m] = PI - min;
|
||||
find = TRUE;
|
||||
}
|
||||
|
||||
if (find == FALSE)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_lsp2en: calculate frame energy */
|
||||
static double HTS_lsp2en(HTS_Vocoder * v, double *lsp, size_t m, double alpha)
|
||||
{
|
||||
size_t i;
|
||||
double en = 0.0;
|
||||
double *buff;
|
||||
|
||||
if (v->spectrum2en_size < m) {
|
||||
if (v->spectrum2en_buff != NULL)
|
||||
HTS_free(v->spectrum2en_buff);
|
||||
v->spectrum2en_buff = (double *) HTS_calloc(m + 1 + IRLENG, sizeof(double));
|
||||
v->spectrum2en_size = m;
|
||||
}
|
||||
buff = v->spectrum2en_buff + m + 1;
|
||||
|
||||
/* lsp2lpc */
|
||||
HTS_lsp2lpc(v, lsp + 1, v->spectrum2en_buff, m);
|
||||
if (v->use_log_gain)
|
||||
v->spectrum2en_buff[0] = exp(lsp[0]);
|
||||
else
|
||||
v->spectrum2en_buff[0] = lsp[0];
|
||||
|
||||
/* mgc2mgc */
|
||||
if (NORMFLG1)
|
||||
HTS_ignorm(v->spectrum2en_buff, v->spectrum2en_buff, m, v->gamma);
|
||||
else if (MULGFLG1)
|
||||
v->spectrum2en_buff[0] = (1.0 - v->spectrum2en_buff[0]) * ((double) v->stage);
|
||||
if (MULGFLG1)
|
||||
for (i = 1; i <= m; i++)
|
||||
v->spectrum2en_buff[i] *= -((double) v->stage);
|
||||
HTS_mgc2mgc(v, v->spectrum2en_buff, m, alpha, v->gamma, buff, IRLENG - 1, 0.0, 1);
|
||||
|
||||
for (i = 0; i < IRLENG; i++)
|
||||
en += buff[i] * buff[i];
|
||||
return en;
|
||||
}
|
||||
|
||||
/* HTS_white_noise: return white noise */
|
||||
static double HTS_white_noise(HTS_Vocoder * v)
|
||||
{
|
||||
if (v->gauss)
|
||||
return (double) HTS_nrandom(v);
|
||||
else
|
||||
return (double) HTS_mseq(v);
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_initialize_excitation: initialize excitation */
|
||||
static void HTS_Vocoder_initialize_excitation(HTS_Vocoder * v, double pitch, size_t nlpf)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
v->pitch_of_curr_point = pitch;
|
||||
v->pitch_counter = pitch;
|
||||
v->pitch_inc_per_point = 0.0;
|
||||
if (nlpf > 0) {
|
||||
v->excite_buff_size = nlpf;
|
||||
v->excite_ring_buff = (double *) HTS_calloc(v->excite_buff_size, sizeof(double));
|
||||
for (i = 0; i < v->excite_buff_size; i++)
|
||||
v->excite_ring_buff[i] = 0.0;
|
||||
v->excite_buff_index = 0;
|
||||
} else {
|
||||
v->excite_buff_size = 0;
|
||||
v->excite_ring_buff = NULL;
|
||||
v->excite_buff_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_start_excitation: start excitation of each frame */
|
||||
static void HTS_Vocoder_start_excitation(HTS_Vocoder * v, double pitch)
|
||||
{
|
||||
if (v->pitch_of_curr_point != 0.0 && pitch != 0.0) {
|
||||
v->pitch_inc_per_point = (pitch - v->pitch_of_curr_point) / v->fprd;
|
||||
} else {
|
||||
v->pitch_inc_per_point = 0.0;
|
||||
v->pitch_of_curr_point = pitch;
|
||||
v->pitch_counter = pitch;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_excite_unvoiced_frame: ping noise to ring buffer */
|
||||
static void HTS_Vocoder_excite_unvoiced_frame(HTS_Vocoder * v, double noise)
|
||||
{
|
||||
size_t center = (v->excite_buff_size - 1) / 2;
|
||||
v->excite_ring_buff[(v->excite_buff_index + center) % v->excite_buff_size] += noise;
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_excite_vooiced_frame: ping noise and pulse to ring buffer */
|
||||
static void HTS_Vocoder_excite_voiced_frame(HTS_Vocoder * v, double noise, double pulse, const double *lpf)
|
||||
{
|
||||
size_t i;
|
||||
size_t center = (v->excite_buff_size - 1) / 2;
|
||||
|
||||
if (noise != 0.0) {
|
||||
for (i = 0; i < v->excite_buff_size; i++) {
|
||||
if (i == center)
|
||||
v->excite_ring_buff[(v->excite_buff_index + i) % v->excite_buff_size] += noise * (1.0 - lpf[i]);
|
||||
else
|
||||
v->excite_ring_buff[(v->excite_buff_index + i) % v->excite_buff_size] += noise * (0.0 - lpf[i]);
|
||||
}
|
||||
}
|
||||
if (pulse != 0.0) {
|
||||
for (i = 0; i < v->excite_buff_size; i++)
|
||||
v->excite_ring_buff[(v->excite_buff_index + i) % v->excite_buff_size] += pulse * lpf[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_get_excitation: get excitation of each sample */
|
||||
static double HTS_Vocoder_get_excitation(HTS_Vocoder * v, const double *lpf)
|
||||
{
|
||||
double x;
|
||||
double noise, pulse = 0.0;
|
||||
|
||||
if (v->excite_buff_size > 0) {
|
||||
noise = HTS_white_noise(v);
|
||||
pulse = 0.0;
|
||||
if (v->pitch_of_curr_point == 0.0) {
|
||||
HTS_Vocoder_excite_unvoiced_frame(v, noise);
|
||||
} else {
|
||||
v->pitch_counter += 1.0;
|
||||
if (v->pitch_counter >= v->pitch_of_curr_point) {
|
||||
pulse = sqrt(v->pitch_of_curr_point);
|
||||
v->pitch_counter -= v->pitch_of_curr_point;
|
||||
}
|
||||
HTS_Vocoder_excite_voiced_frame(v, noise, pulse, lpf);
|
||||
v->pitch_of_curr_point += v->pitch_inc_per_point;
|
||||
}
|
||||
x = v->excite_ring_buff[v->excite_buff_index];
|
||||
v->excite_ring_buff[v->excite_buff_index] = 0.0;
|
||||
v->excite_buff_index++;
|
||||
if (v->excite_buff_index >= v->excite_buff_size)
|
||||
v->excite_buff_index = 0;
|
||||
} else {
|
||||
if (v->pitch_of_curr_point == 0.0) {
|
||||
x = HTS_white_noise(v);
|
||||
} else {
|
||||
v->pitch_counter += 1.0;
|
||||
if (v->pitch_counter >= v->pitch_of_curr_point) {
|
||||
x = sqrt(v->pitch_of_curr_point);
|
||||
v->pitch_counter -= v->pitch_of_curr_point;
|
||||
} else {
|
||||
x = 0.0;
|
||||
}
|
||||
v->pitch_of_curr_point += v->pitch_inc_per_point;
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_end_excitation: end excitation of each frame */
|
||||
static void HTS_Vocoder_end_excitation(HTS_Vocoder * v, double pitch)
|
||||
{
|
||||
v->pitch_of_curr_point = pitch;
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_postfilter_mcp: postfilter for MCP */
|
||||
static void HTS_Vocoder_postfilter_mcp(HTS_Vocoder * v, double *mcp, const int m, double alpha, double beta)
|
||||
{
|
||||
double e1, e2;
|
||||
int k;
|
||||
|
||||
if (beta > 0.0 && m > 1) {
|
||||
if (v->postfilter_size < m) {
|
||||
if (v->postfilter_buff != NULL)
|
||||
HTS_free(v->postfilter_buff);
|
||||
v->postfilter_buff = (double *) HTS_calloc(m + 1, sizeof(double));
|
||||
v->postfilter_size = m;
|
||||
}
|
||||
HTS_mc2b(mcp, v->postfilter_buff, m, alpha);
|
||||
e1 = HTS_b2en(v, v->postfilter_buff, m, alpha);
|
||||
|
||||
v->postfilter_buff[1] -= beta * alpha * v->postfilter_buff[2];
|
||||
for (k = 2; k <= m; k++)
|
||||
v->postfilter_buff[k] *= (1.0 + beta);
|
||||
|
||||
e2 = HTS_b2en(v, v->postfilter_buff, m, alpha);
|
||||
v->postfilter_buff[0] += log(e1 / e2) / 2;
|
||||
HTS_b2mc(v->postfilter_buff, mcp, m, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_postfilter_lsp: postfilter for LSP */
|
||||
static void HTS_Vocoder_postfilter_lsp(HTS_Vocoder * v, double *lsp, size_t m, double alpha, double beta)
|
||||
{
|
||||
double e1, e2;
|
||||
size_t i;
|
||||
double d1, d2;
|
||||
|
||||
if (beta > 0.0 && m > 1) {
|
||||
if (v->postfilter_size < m) {
|
||||
if (v->postfilter_buff != NULL)
|
||||
HTS_free(v->postfilter_buff);
|
||||
v->postfilter_buff = (double *) HTS_calloc(m + 1, sizeof(double));
|
||||
v->postfilter_size = m;
|
||||
}
|
||||
|
||||
e1 = HTS_lsp2en(v, lsp, m, alpha);
|
||||
|
||||
/* postfiltering */
|
||||
for (i = 0; i <= m; i++) {
|
||||
if (i > 1 && i < m) {
|
||||
d1 = beta * (lsp[i + 1] - lsp[i]);
|
||||
d2 = beta * (lsp[i] - lsp[i - 1]);
|
||||
v->postfilter_buff[i] = lsp[i - 1] + d2 + (d2 * d2 * ((lsp[i + 1] - lsp[i - 1]) - (d1 + d2))) / ((d2 * d2) + (d1 * d1));
|
||||
} else {
|
||||
v->postfilter_buff[i] = lsp[i];
|
||||
}
|
||||
}
|
||||
HTS_movem(v->postfilter_buff, lsp, m + 1);
|
||||
|
||||
e2 = HTS_lsp2en(v, lsp, m, alpha);
|
||||
|
||||
if (e1 != e2) {
|
||||
if (v->use_log_gain)
|
||||
lsp[0] += 0.5 * log(e1 / e2);
|
||||
else
|
||||
lsp[0] *= sqrt(e1 / e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_initialize: initialize vocoder */
|
||||
void HTS_Vocoder_initialize(HTS_Vocoder * v, size_t m, size_t stage, HTS_Boolean use_log_gain, size_t rate, size_t fperiod)
|
||||
{
|
||||
/* set parameter */
|
||||
v->is_first = TRUE;
|
||||
v->stage = stage;
|
||||
if (stage != 0)
|
||||
v->gamma = -1.0 / v->stage;
|
||||
else
|
||||
v->gamma = 0.0;
|
||||
v->use_log_gain = use_log_gain;
|
||||
v->fprd = fperiod;
|
||||
v->next = SEED;
|
||||
v->gauss = GAUSS;
|
||||
v->rate = rate;
|
||||
v->pitch_of_curr_point = 0.0;
|
||||
v->pitch_counter = 0.0;
|
||||
v->pitch_inc_per_point = 0.0;
|
||||
v->excite_ring_buff = NULL;
|
||||
v->excite_buff_size = 0;
|
||||
v->excite_buff_index = 0;
|
||||
v->sw = 0;
|
||||
v->x = 0x55555555;
|
||||
/* init buffer */
|
||||
v->freqt_buff = NULL;
|
||||
v->freqt_size = 0;
|
||||
v->gc2gc_buff = NULL;
|
||||
v->gc2gc_size = 0;
|
||||
v->lsp2lpc_buff = NULL;
|
||||
v->lsp2lpc_size = 0;
|
||||
v->postfilter_buff = NULL;
|
||||
v->postfilter_size = 0;
|
||||
v->spectrum2en_buff = NULL;
|
||||
v->spectrum2en_size = 0;
|
||||
if (v->stage == 0) { /* for MCP */
|
||||
v->c = (double *) HTS_calloc(m * (3 + PADEORDER) + 5 * PADEORDER + 6, sizeof(double));
|
||||
v->cc = v->c + m + 1;
|
||||
v->cinc = v->cc + m + 1;
|
||||
v->d1 = v->cinc + m + 1;
|
||||
} else { /* for LSP */
|
||||
v->c = (double *) HTS_calloc((m + 1) * (v->stage + 3), sizeof(double));
|
||||
v->cc = v->c + m + 1;
|
||||
v->cinc = v->cc + m + 1;
|
||||
v->d1 = v->cinc + m + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_synthesize: pulse/noise excitation and MLSA/MGLSA filster based waveform synthesis */
|
||||
void HTS_Vocoder_synthesize(HTS_Vocoder * v, size_t m, double lf0, double *spectrum, size_t nlpf, double *lpf, double alpha, double beta, double volume, double *rawdata, HTS_Audio * audio)
|
||||
{
|
||||
double x;
|
||||
int i, j;
|
||||
short xs;
|
||||
int rawidx = 0;
|
||||
double p;
|
||||
|
||||
/* lf0 -> pitch */
|
||||
if (lf0 == LZERO)
|
||||
p = 0.0;
|
||||
else if (lf0 <= MIN_LF0)
|
||||
p = v->rate / MIN_F0;
|
||||
else if (lf0 >= MAX_LF0)
|
||||
p = v->rate / MAX_F0;
|
||||
else
|
||||
p = v->rate / exp(lf0);
|
||||
|
||||
/* first time */
|
||||
if (v->is_first == TRUE) {
|
||||
HTS_Vocoder_initialize_excitation(v, p, nlpf);
|
||||
if (v->stage == 0) { /* for MCP */
|
||||
HTS_mc2b(spectrum, v->c, m, alpha);
|
||||
} else { /* for LSP */
|
||||
HTS_movem(spectrum, v->c, m + 1);
|
||||
HTS_lsp2mgc(v, v->c, v->c, m, alpha);
|
||||
HTS_mc2b(v->c, v->c, m, alpha);
|
||||
HTS_gnorm(v->c, v->c, m, v->gamma);
|
||||
for (i = 1; i <= m; i++)
|
||||
v->c[i] *= v->gamma;
|
||||
}
|
||||
v->is_first = FALSE;
|
||||
}
|
||||
|
||||
HTS_Vocoder_start_excitation(v, p);
|
||||
if (v->stage == 0) { /* for MCP */
|
||||
HTS_Vocoder_postfilter_mcp(v, spectrum, m, alpha, beta);
|
||||
HTS_mc2b(spectrum, v->cc, m, alpha);
|
||||
for (i = 0; i <= m; i++)
|
||||
v->cinc[i] = (v->cc[i] - v->c[i]) / v->fprd;
|
||||
} else { /* for LSP */
|
||||
HTS_Vocoder_postfilter_lsp(v, spectrum, m, alpha, beta);
|
||||
HTS_check_lsp_stability(spectrum, m);
|
||||
HTS_lsp2mgc(v, spectrum, v->cc, m, alpha);
|
||||
HTS_mc2b(v->cc, v->cc, m, alpha);
|
||||
HTS_gnorm(v->cc, v->cc, m, v->gamma);
|
||||
for (i = 1; i <= m; i++)
|
||||
v->cc[i] *= v->gamma;
|
||||
for (i = 0; i <= m; i++)
|
||||
v->cinc[i] = (v->cc[i] - v->c[i]) / v->fprd;
|
||||
}
|
||||
|
||||
for (j = 0; j < v->fprd; j++) {
|
||||
x = HTS_Vocoder_get_excitation(v, lpf);
|
||||
if (v->stage == 0) { /* for MCP */
|
||||
if (x != 0.0)
|
||||
x *= exp(v->c[0]);
|
||||
x = HTS_mlsadf(x, v->c, m, alpha, PADEORDER, v->d1);
|
||||
} else { /* for LSP */
|
||||
if (!NGAIN)
|
||||
x *= v->c[0];
|
||||
x = HTS_mglsadf(x, v->c, m, alpha, v->stage, v->d1);
|
||||
}
|
||||
x *= volume;
|
||||
|
||||
/* output */
|
||||
if (rawdata)
|
||||
rawdata[rawidx++] = x;
|
||||
if (audio) {
|
||||
if (x > 32767.0)
|
||||
xs = 32767;
|
||||
else if (x < -32768.0)
|
||||
xs = -32768;
|
||||
else
|
||||
xs = (short) x;
|
||||
HTS_Audio_write(audio, xs);
|
||||
}
|
||||
|
||||
for (i = 0; i <= m; i++)
|
||||
v->c[i] += v->cinc[i];
|
||||
}
|
||||
|
||||
HTS_Vocoder_end_excitation(v, p);
|
||||
HTS_movem(v->cc, v->c, m + 1);
|
||||
}
|
||||
|
||||
/* HTS_Vocoder_clear: clear vocoder */
|
||||
void HTS_Vocoder_clear(HTS_Vocoder * v)
|
||||
{
|
||||
if (v != NULL) {
|
||||
/* free buffer */
|
||||
if (v->freqt_buff != NULL) {
|
||||
HTS_free(v->freqt_buff);
|
||||
v->freqt_buff = NULL;
|
||||
}
|
||||
v->freqt_size = 0;
|
||||
if (v->gc2gc_buff != NULL) {
|
||||
HTS_free(v->gc2gc_buff);
|
||||
v->gc2gc_buff = NULL;
|
||||
}
|
||||
v->gc2gc_size = 0;
|
||||
if (v->lsp2lpc_buff != NULL) {
|
||||
HTS_free(v->lsp2lpc_buff);
|
||||
v->lsp2lpc_buff = NULL;
|
||||
}
|
||||
v->lsp2lpc_size = 0;
|
||||
if (v->postfilter_buff != NULL) {
|
||||
HTS_free(v->postfilter_buff);
|
||||
v->postfilter_buff = NULL;
|
||||
}
|
||||
v->postfilter_size = 0;
|
||||
if (v->spectrum2en_buff != NULL) {
|
||||
HTS_free(v->spectrum2en_buff);
|
||||
v->spectrum2en_buff = NULL;
|
||||
}
|
||||
v->spectrum2en_size = 0;
|
||||
if (v->c != NULL) {
|
||||
HTS_free(v->c);
|
||||
v->c = NULL;
|
||||
}
|
||||
v->excite_buff_size = 0;
|
||||
v->excite_buff_index = 0;
|
||||
if (v->excite_ring_buff != NULL) {
|
||||
HTS_free(v->excite_ring_buff);
|
||||
v->excite_ring_buff = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HTS_VOCODER_C_END;
|
||||
|
||||
#endif /* !HTS_VOCODER_C */
|
||||
14
3rdparty/hts_engine_API/lib/Makefile.am
vendored
Normal file
14
3rdparty/hts_engine_API/lib/Makefile.am
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
EXTRA_DIST = Makefile.mak
|
||||
|
||||
AM_CPPFLAGS = -I @top_srcdir@/include
|
||||
|
||||
lib_LIBRARIES = libHTSEngine.a
|
||||
|
||||
libHTSEngine_a_SOURCES = HTS_audio.c HTS_engine.c HTS_hidden.h HTS_misc.c \
|
||||
HTS_pstream.c HTS_sstream.c HTS_model.c HTS_vocoder.c \
|
||||
HTS_gstream.c HTS_label.c
|
||||
|
||||
DISTCLEANFILES = *.log *.out *~
|
||||
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
613
3rdparty/hts_engine_API/lib/Makefile.in
vendored
Normal file
613
3rdparty/hts_engine_API/lib/Makefile.in
vendored
Normal file
@@ -0,0 +1,613 @@
|
||||
# Makefile.in generated by automake 1.15 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994-2014 Free Software Foundation, Inc.
|
||||
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
VPATH = @srcdir@
|
||||
am__is_gnu_make = { \
|
||||
if test -z '$(MAKELEVEL)'; then \
|
||||
false; \
|
||||
elif test -n '$(MAKE_HOST)'; then \
|
||||
true; \
|
||||
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
|
||||
true; \
|
||||
else \
|
||||
false; \
|
||||
fi; \
|
||||
}
|
||||
am__make_running_with_option = \
|
||||
case $${target_option-} in \
|
||||
?) ;; \
|
||||
*) echo "am__make_running_with_option: internal error: invalid" \
|
||||
"target option '$${target_option-}' specified" >&2; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
has_opt=no; \
|
||||
sane_makeflags=$$MAKEFLAGS; \
|
||||
if $(am__is_gnu_make); then \
|
||||
sane_makeflags=$$MFLAGS; \
|
||||
else \
|
||||
case $$MAKEFLAGS in \
|
||||
*\\[\ \ ]*) \
|
||||
bs=\\; \
|
||||
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
|
||||
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
|
||||
esac; \
|
||||
fi; \
|
||||
skip_next=no; \
|
||||
strip_trailopt () \
|
||||
{ \
|
||||
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
|
||||
}; \
|
||||
for flg in $$sane_makeflags; do \
|
||||
test $$skip_next = yes && { skip_next=no; continue; }; \
|
||||
case $$flg in \
|
||||
*=*|--*) continue;; \
|
||||
-*I) strip_trailopt 'I'; skip_next=yes;; \
|
||||
-*I?*) strip_trailopt 'I';; \
|
||||
-*O) strip_trailopt 'O'; skip_next=yes;; \
|
||||
-*O?*) strip_trailopt 'O';; \
|
||||
-*l) strip_trailopt 'l'; skip_next=yes;; \
|
||||
-*l?*) strip_trailopt 'l';; \
|
||||
-[dEDm]) skip_next=yes;; \
|
||||
-[JT]) skip_next=yes;; \
|
||||
esac; \
|
||||
case $$flg in \
|
||||
*$$target_option*) has_opt=yes; break;; \
|
||||
esac; \
|
||||
done; \
|
||||
test $$has_opt = yes
|
||||
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
|
||||
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkglibexecdir = $(libexecdir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
subdir = lib
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
|
||||
am__install_max = 40
|
||||
am__nobase_strip_setup = \
|
||||
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
|
||||
am__nobase_strip = \
|
||||
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
|
||||
am__nobase_list = $(am__nobase_strip_setup); \
|
||||
for p in $$list; do echo "$$p $$p"; done | \
|
||||
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
|
||||
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
|
||||
if (++n[$$2] == $(am__install_max)) \
|
||||
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
|
||||
END { for (dir in files) print dir, files[dir] }'
|
||||
am__base_list = \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
|
||||
am__uninstall_files_from_dir = { \
|
||||
test -z "$$files" \
|
||||
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|
||||
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
|
||||
$(am__cd) "$$dir" && rm -f $$files; }; \
|
||||
}
|
||||
am__installdirs = "$(DESTDIR)$(libdir)"
|
||||
LIBRARIES = $(lib_LIBRARIES)
|
||||
ARFLAGS = cru
|
||||
AM_V_AR = $(am__v_AR_@AM_V@)
|
||||
am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@)
|
||||
am__v_AR_0 = @echo " AR " $@;
|
||||
am__v_AR_1 =
|
||||
libHTSEngine_a_AR = $(AR) $(ARFLAGS)
|
||||
libHTSEngine_a_LIBADD =
|
||||
am_libHTSEngine_a_OBJECTS = HTS_audio.$(OBJEXT) HTS_engine.$(OBJEXT) \
|
||||
HTS_misc.$(OBJEXT) HTS_pstream.$(OBJEXT) HTS_sstream.$(OBJEXT) \
|
||||
HTS_model.$(OBJEXT) HTS_vocoder.$(OBJEXT) \
|
||||
HTS_gstream.$(OBJEXT) HTS_label.$(OBJEXT)
|
||||
libHTSEngine_a_OBJECTS = $(am_libHTSEngine_a_OBJECTS)
|
||||
AM_V_P = $(am__v_P_@AM_V@)
|
||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||
am__v_P_0 = false
|
||||
am__v_P_1 = :
|
||||
AM_V_GEN = $(am__v_GEN_@AM_V@)
|
||||
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
|
||||
am__v_GEN_0 = @echo " GEN " $@;
|
||||
am__v_GEN_1 =
|
||||
AM_V_at = $(am__v_at_@AM_V@)
|
||||
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
|
||||
am__v_at_0 = @
|
||||
am__v_at_1 =
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@
|
||||
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
am__mv = mv -f
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
AM_V_CC = $(am__v_CC_@AM_V@)
|
||||
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
|
||||
am__v_CC_0 = @echo " CC " $@;
|
||||
am__v_CC_1 =
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
|
||||
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
||||
am__v_CCLD_0 = @echo " CCLD " $@;
|
||||
am__v_CCLD_1 =
|
||||
SOURCES = $(libHTSEngine_a_SOURCES)
|
||||
DIST_SOURCES = $(libHTSEngine_a_SOURCES)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
*) (install-info --version) >/dev/null 2>&1;; \
|
||||
esac
|
||||
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
|
||||
# Read a list of newline-separated strings from the standard input,
|
||||
# and print each of them once, without duplicates. Input order is
|
||||
# *not* preserved.
|
||||
am__uniquify_input = $(AWK) '\
|
||||
BEGIN { nonempty = 0; } \
|
||||
{ items[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in items) print i; }; } \
|
||||
'
|
||||
# Make sure the list of sources is unique. This is necessary because,
|
||||
# e.g., the same source file might be shared among _SOURCES variables
|
||||
# for different programs/libraries.
|
||||
am__define_uniq_tagged_files = \
|
||||
list='$(am__tagged_files)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | $(am__uniquify_input)`
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/config/depcomp
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
GREP = @GREP@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
RANLIB = @RANLIB@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
EXTRA_DIST = Makefile.mak
|
||||
AM_CPPFLAGS = -I @top_srcdir@/include
|
||||
lib_LIBRARIES = libHTSEngine.a
|
||||
libHTSEngine_a_SOURCES = HTS_audio.c HTS_engine.c HTS_hidden.h HTS_misc.c \
|
||||
HTS_pstream.c HTS_sstream.c HTS_model.c HTS_vocoder.c \
|
||||
HTS_gstream.c HTS_label.c
|
||||
|
||||
DISTCLEANFILES = *.log *.out *~
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
|
||||
&& { if test -f $@; then exit 0; else break; fi; }; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu lib/Makefile'; \
|
||||
$(am__cd) $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu lib/Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(am__aclocal_m4_deps):
|
||||
install-libLIBRARIES: $(lib_LIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
@list='$(lib_LIBRARIES)'; test -n "$(libdir)" || list=; \
|
||||
list2=; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
list2="$$list2 $$p"; \
|
||||
else :; fi; \
|
||||
done; \
|
||||
test -z "$$list2" || { \
|
||||
echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
|
||||
$(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
|
||||
echo " $(INSTALL_DATA) $$list2 '$(DESTDIR)$(libdir)'"; \
|
||||
$(INSTALL_DATA) $$list2 "$(DESTDIR)$(libdir)" || exit $$?; }
|
||||
@$(POST_INSTALL)
|
||||
@list='$(lib_LIBRARIES)'; test -n "$(libdir)" || list=; \
|
||||
for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
$(am__strip_dir) \
|
||||
echo " ( cd '$(DESTDIR)$(libdir)' && $(RANLIB) $$f )"; \
|
||||
( cd "$(DESTDIR)$(libdir)" && $(RANLIB) $$f ) || exit $$?; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-libLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(lib_LIBRARIES)'; test -n "$(libdir)" || list=; \
|
||||
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
|
||||
dir='$(DESTDIR)$(libdir)'; $(am__uninstall_files_from_dir)
|
||||
|
||||
clean-libLIBRARIES:
|
||||
-test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
|
||||
|
||||
libHTSEngine.a: $(libHTSEngine_a_OBJECTS) $(libHTSEngine_a_DEPENDENCIES) $(EXTRA_libHTSEngine_a_DEPENDENCIES)
|
||||
$(AM_V_at)-rm -f libHTSEngine.a
|
||||
$(AM_V_AR)$(libHTSEngine_a_AR) libHTSEngine.a $(libHTSEngine_a_OBJECTS) $(libHTSEngine_a_LIBADD)
|
||||
$(AM_V_at)$(RANLIB) libHTSEngine.a
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_audio.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_engine.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_gstream.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_label.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_misc.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_model.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_pstream.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_sstream.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HTS_vocoder.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
ID: $(am__tagged_files)
|
||||
$(am__define_uniq_tagged_files); mkid -fID $$unique
|
||||
tags: tags-am
|
||||
TAGS: tags
|
||||
|
||||
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
|
||||
set x; \
|
||||
here=`pwd`; \
|
||||
$(am__define_uniq_tagged_files); \
|
||||
shift; \
|
||||
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
if test $$# -gt 0; then \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
"$$@" $$unique; \
|
||||
else \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$unique; \
|
||||
fi; \
|
||||
fi
|
||||
ctags: ctags-am
|
||||
|
||||
CTAGS: ctags
|
||||
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
|
||||
$(am__define_uniq_tagged_files); \
|
||||
test -z "$(CTAGS_ARGS)$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& $(am__cd) $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) "$$here"
|
||||
cscopelist: cscopelist-am
|
||||
|
||||
cscopelist-am: $(am__tagged_files)
|
||||
list='$(am__tagged_files)'; \
|
||||
case "$(srcdir)" in \
|
||||
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
|
||||
*) sdir=$(subdir)/$(srcdir) ;; \
|
||||
esac; \
|
||||
for i in $$list; do \
|
||||
if test -f "$$i"; then \
|
||||
echo "$(subdir)/$$i"; \
|
||||
else \
|
||||
echo "$$sdir/$$i"; \
|
||||
fi; \
|
||||
done >> $(top_builddir)/cscope.files
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d "$(distdir)/$$file"; then \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
|
||||
else \
|
||||
test -f "$(distdir)/$$file" \
|
||||
|| cp -p $$d/$$file "$(distdir)/$$file" \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(LIBRARIES)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(libdir)"; do \
|
||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
if test -z '$(STRIP)'; then \
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
install; \
|
||||
else \
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
|
||||
fi
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
|
||||
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libLIBRARIES mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
html-am:
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-dvi-am:
|
||||
|
||||
install-exec-am: install-libLIBRARIES
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-html-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-info-am:
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-pdf-am:
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
install-ps-am:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-libLIBRARIES
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
|
||||
clean-libLIBRARIES cscopelist-am ctags ctags-am distclean \
|
||||
distclean-compile distclean-generic distclean-tags distdir dvi \
|
||||
dvi-am html html-am info info-am install install-am \
|
||||
install-data install-data-am install-dvi install-dvi-am \
|
||||
install-exec install-exec-am install-html install-html-am \
|
||||
install-info install-info-am install-libLIBRARIES install-man \
|
||||
install-pdf install-pdf-am install-ps install-ps-am \
|
||||
install-strip installcheck installcheck-am installdirs \
|
||||
maintainer-clean maintainer-clean-generic mostlyclean \
|
||||
mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
|
||||
tags tags-am uninstall uninstall-am uninstall-libLIBRARIES
|
||||
|
||||
.PRECIOUS: Makefile
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
19
3rdparty/hts_engine_API/lib/Makefile.mak
vendored
Normal file
19
3rdparty/hts_engine_API/lib/Makefile.mak
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
CC = cl
|
||||
|
||||
CFLAGS = /O2 /Ob2 /Oi /Ot /Oy /GT /GL /TC /I ..\include
|
||||
LFLAGS = /LTCG
|
||||
|
||||
CORES = HTS_audio.obj HTS_engine.obj HTS_gstream.obj HTS_label.obj HTS_misc.obj HTS_model.obj HTS_pstream.obj HTS_sstream.obj HTS_vocoder.obj
|
||||
|
||||
all: hts_engine_API.lib
|
||||
|
||||
hts_engine_API.lib: $(CORES)
|
||||
lib $(LFLAGS) /OUT:$@ $(CORES)
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) /c $<
|
||||
|
||||
clean:
|
||||
del *.lib
|
||||
del *.obj
|
||||
Reference in New Issue
Block a user