예제 #1
0
파일: HTS_audio.c 프로젝트: A-L-E-X/RHVoice
/* HTS_Audio_open: open audio device */
static void HTS_Audio_open(HTS_Audio * audio, int sampling_rate, int max_buff_size)
{
   if (audio->sampling_rate == sampling_rate && audio->max_buff_size == max_buff_size)
      return;

   HTS_Audio_close(audio);

   audio->sampling_rate = sampling_rate;
   audio->max_buff_size = max_buff_size;

   if (audio->max_buff_size <= 0)
      return;

   audio->err = Pa_Initialize();
   if (audio->err != paNoError)
      HTS_error(0, "hts_engine: Failed to initialize your output audio device to play waveform.\n");

   audio->parameters.device = Pa_GetDefaultOutputDevice();
   audio->parameters.channelCount = 1;
   audio->parameters.sampleFormat = paInt16;
   audio->parameters.suggestedLatency = Pa_GetDeviceInfo(audio->parameters.device)->defaultLowOutputLatency;
   audio->parameters.hostApiSpecificStreamInfo = NULL;

   audio->err = Pa_OpenStream(&audio->stream, NULL, &audio->parameters, sampling_rate, max_buff_size, paClipOff, NULL, NULL);
   if (audio->err != paNoError)
      HTS_error(0, "hts_engine: Failed to open your output audio device to play waveform.\n");

   audio->err = Pa_StartStream(audio->stream);
   if (audio->err != paNoError)
      HTS_error(0, "hts_engine: Failed to start your output audio device to play waveform.\n");

   audio->buff = (short *) HTS_calloc(max_buff_size, sizeof(short));
   audio->buff_size = 0;
}
예제 #2
0
파일: HTS_audio.c 프로젝트: A-L-E-X/RHVoice
/* HTS_Audio_open: open audio device */
static void HTS_Audio_open(HTS_Audio * audio, int sampling_rate, int max_buff_size)
{
   MMRESULT error;

   if (audio->sampling_rate == sampling_rate && audio->max_buff_size == max_buff_size)
      return;

   HTS_Audio_close(audio);

   audio->sampling_rate = sampling_rate;
   audio->max_buff_size = max_buff_size;

   if (audio->max_buff_size <= 0)
      return;

   /* queue */
   audio->which_buff = 1;
   audio->now_buff_1 = FALSE;
   audio->now_buff_2 = FALSE;
   audio->buff = (short *) HTS_calloc(max_buff_size, sizeof(short));

   /* format */
   audio->waveformatex.wFormatTag = WAVE_FORMAT_PCM;
   audio->waveformatex.nChannels = AUDIO_CHANNEL;
   audio->waveformatex.nSamplesPerSec = sampling_rate;
   audio->waveformatex.wBitsPerSample = sizeof(short) * 8;
   audio->waveformatex.nBlockAlign = AUDIO_CHANNEL * audio->waveformatex.wBitsPerSample / 8;
   audio->waveformatex.nAvgBytesPerSec = sampling_rate * audio->waveformatex.nBlockAlign;
   /* open */
   error = waveOutOpen(&audio->hwaveout, WAVE_MAPPER, &audio->waveformatex, (DWORD) HTS_Audio_callback_function, (DWORD) audio, CALLBACK_FUNCTION);
   if (error != MMSYSERR_NOERROR)
      HTS_error(0, "hts_engine: Failed to open your output audio device to play waveform.\n");

   /* prepare */
   audio->buff_1.lpData = (LPSTR) HTS_calloc(max_buff_size, sizeof(short));
   audio->buff_1.dwBufferLength = max_buff_size * sizeof(short);
   audio->buff_1.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP;
   audio->buff_1.dwLoops = 1;
   audio->buff_1.lpNext = 0;
   audio->buff_1.reserved = 0;
   error = waveOutPrepareHeader(audio->hwaveout, &(audio->buff_1), sizeof(WAVEHDR));
   if (error != MMSYSERR_NOERROR)
      HTS_error(0, "hts_engine: Cannot initialize audio datablocks to play waveform.\n");
   audio->buff_2.lpData = (LPSTR) HTS_calloc(max_buff_size, sizeof(short));
   audio->buff_2.dwBufferLength = max_buff_size * sizeof(short);
   audio->buff_2.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP;
   audio->buff_2.dwLoops = 1;
   audio->buff_2.lpNext = 0;
   audio->buff_2.reserved = 0;
   error = waveOutPrepareHeader(audio->hwaveout, &(audio->buff_2), sizeof(WAVEHDR));
   if (error != MMSYSERR_NOERROR)
      HTS_error(0, "hts_engine: Cannot initialize audio datablocks to play waveform.\n");
}
예제 #3
0
/* 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->pade != NULL) {
         HTS_free(v->pade);
         v->pade = NULL;
      }
      if (v->c != NULL) {
         HTS_free(v->c);
         v->c = NULL;
      }
      /* close audio device */
      if (v->audio != NULL) {
         HTS_Audio_close(v->audio);
         HTS_free(v->audio);
         v->audio = NULL;
      }
   }
}
예제 #4
0
파일: HTS_audio.c 프로젝트: A-L-E-X/RHVoice
/* HTS_Audio_clear: free audio */
void HTS_Audio_clear(HTS_Audio * audio)
{
   HTS_Audio_flush(audio);
   HTS_Audio_close(audio);
}