Beispiel #1
0
static int
awaitSpeechSegment (void) {
  while (synthesisThreadStarted) {
    int error;

    if (pcm) {
      struct timeval now;
      struct timespec timeout;
      gettimeofday(&now, NULL);
      timeout.tv_sec = now.tv_sec + 3;
      timeout.tv_nsec = now.tv_usec * 1000;
      error = pthread_cond_timedwait(&speechConditional, &speechMutex, &timeout);
    } else {
      error = pthread_cond_wait(&speechConditional, &speechMutex);
    }

    switch (error) {
      case 0:
        return 1;

      case ETIMEDOUT:
        closeSoundDevice();
        continue;

      default:
        logSystemError("pthread_cond_timedwait");
        return 0;
    }
  }
  return 0;
}
Beispiel #2
0
static void
spk_destruct (volatile SpeechSynthesizer *spk) {
  stopSynthesisThread();
  closeSoundDevice();

  if (speechQueue) {
    deallocateQueue(speechQueue);
    speechQueue = NULL;
  }

  if (speechChannel) {
    if (mpChannelExit) mpChannelExit(speechChannel, NULL, 0);
    speechChannel = NULL;
  }

#ifdef ENABLE_SHARED_OBJECTS
  if (speechLibrary) {
    const SymbolEntry *symbol = symbolTable;
    while (symbol->name) {
      void **address = (symbol++)->address;
      *address = NULL;
    }

    unloadSharedObject(speechLibrary);
    speechLibrary = NULL;
  }
#endif /* ENABLE_SHARED_OBJECTS */
}
bool ckLowLevelAPI::openSoundDevice(u8 channel_num, u16 sample_rate, u16 snd_mix_buf_msec, SoundMixFunction snd_mix_func)
{
    if (isSoundDeviceOpen())
    {
        closeSoundDevice();
    }

    s_channel_num = channel_num;
    s_sample_rate = sample_rate;
    s_snd_mix_buf_msec = snd_mix_buf_msec;
    s_snd_mix_buf_size = channel_num * sample_rate * 2 * snd_mix_buf_msec / 1000;
    s_snd_mix_buf_sample_num = sample_rate * snd_mix_buf_msec / 1000;

    // TODO
    // s_is_snd_dev_open = true;

    return false; // TODO
}
bool fsLowLevelAPI::openSoundDevice(u8 channel_num, u16 sample_rate, u16 snd_mix_buf_msec, SoundMixFunction snd_mix_func)
{
	fprintf(stderr,"channel_num %d sample_rate %d snd_mix_buf_mse %d \n",channel_num, sample_rate, snd_mix_buf_msec);
    if (isSoundDeviceOpen())
    {
        closeSoundDevice();
    }

    pthread_mutex_init(&s_snd_mix_mutex, NULL);

    s_snd_mix_func =  snd_mix_func;

	m_pAudioDevice = alcOpenDevice(NULL);

	if (m_pAudioDevice)
	{
		m_pAlcContext = alcCreateContext(m_pAudioDevice, NULL);
		alcMakeContextCurrent(m_pAlcContext);
	}

	ALenum err = alGetError();
	if (err != AL_NO_ERROR)
	{
		return false;
	}

	alGenSources(1, &m_AudioSource);
	alGenBuffers(BUFFER_COUNT, m_AudioBuffers);
    s_channel_num = channel_num;
    s_sample_rate = sample_rate;
    s_snd_mix_buf_msec = snd_mix_buf_msec;

	s_snd_mix_buf_sample_num = sample_rate * snd_mix_buf_msec / 1000;
	s_bits_per_sample = 16;

    if (s_channel_num != 1 && s_channel_num != 2)
    {
        return false;
    }
	
	switch (s_bits_per_sample){
	case 8:
		m_AudioFormat = (channel_num == 1) ? AL_FORMAT_MONO8 : AL_FORMAT_STEREO8;
		break;
	case 16:
		m_AudioFormat = (channel_num == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
		break;
	default:
		return 0;
	}
	//	m_AudioFormat = AL_FORMAT_STEREO16;
	s_snd_mix_buf_size = 2 * s_channel_num * s_snd_mix_buf_sample_num;
	/*for (s32 i = 0; i < 2; i++)
	  {
	  s_snd_mix_buf[i] = ckMalloc(s_snd_mix_buf_size);
	  ckMemMgr::memset(s_snd_mix_buf[i], 0, s_snd_mix_buf_size);
	  }*/
	buf = fsMalloc(s_snd_mix_buf_size);
	s_snd_mix_buf = fsMalloc(s_snd_mix_buf_size*2);
	//alGenBuffers(BUFFER_COUNT, m_AudioBuffers);
	//alGenSources(1, &m_AudioSource);
	//alSourcePlay(m_AudioSource);

	s_is_playing = true;
	if (pthread_create(&s_snd_play_thread, NULL, soundPlayThread, NULL) != 0)
	{
		s_is_playing = false;
		closeSoundDevice();
		return false;
	}

//    if (pthread_create(&s_snd_play_thread, NULL, soundPlayThread, NULL) != 0)
//    {
//        s_is_playing = false;
//        closeSoundDevice();
//        return false;
//    }
//
    s_is_snd_dev_open = true;

	return true;
}