Exemple #1
0
	SoundStream* InitSoundStream()
	{
		CMixer *mixer = new CMixer(48000);

		// TODO: possible memleak with mixer

		std::string backend = SConfig::GetInstance().sBackend;
		if (backend == BACKEND_OPENAL           && OpenALStream::isValid())
			soundStream = new OpenALStream(mixer);
		else if (backend == BACKEND_NULLSOUND   && NullSound::isValid())
			soundStream = new NullSound(mixer);
		else if (backend == BACKEND_XAUDIO2)
		{
			if (XAudio2::isValid())
				soundStream = new XAudio2(mixer);
			else if (XAudio2_7::isValid())
				soundStream = new XAudio2_7(mixer);
		}
		else if (backend == BACKEND_AOSOUND     && AOSound::isValid())
			soundStream = new AOSound(mixer);
		else if (backend == BACKEND_ALSA        && AlsaSound::isValid())
			soundStream = new AlsaSound(mixer);
		else if (backend == BACKEND_COREAUDIO   && CoreAudioSound::isValid())
			soundStream = new CoreAudioSound(mixer);
		else if (backend == BACKEND_PULSEAUDIO  && PulseAudio::isValid())
			soundStream = new PulseAudio(mixer);
		else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid())
			soundStream = new OpenSLESStream(mixer);

		if (!soundStream && NullSound::isValid())
		{
			WARN_LOG(DSPHLE, "Could not initialize backend %s, using %s instead.",
				backend.c_str(), BACKEND_NULLSOUND);
			soundStream = new NullSound(mixer);
		}

		if (soundStream)
		{
			UpdateSoundStream();
			if (soundStream->Start())
			{
				if (SConfig::GetInstance().m_DumpAudio)
				{
					std::string audio_file_name = File::GetUserPath(D_DUMPAUDIO_IDX) + "audiodump.wav";
					File::CreateFullPath(audio_file_name);
					mixer->StartLogAudio(audio_file_name);
				}

				return soundStream;
			}
			PanicAlertT("Could not initialize backend %s.", backend.c_str());
		}

		PanicAlertT("Sound backend %s is not valid.", backend.c_str());

		delete soundStream;
		soundStream = nullptr;
		return nullptr;
	}
Exemple #2
0
	void DecreaseVolume(unsigned short offset)
	{
		SConfig::GetInstance().m_IsMuted = false;
		int& currentVolume = SConfig::GetInstance().m_Volume;
		currentVolume -= offset;
		if (currentVolume < AUDIO_VOLUME_MIN)
			currentVolume = AUDIO_VOLUME_MIN;
		UpdateSoundStream();
	}
Exemple #3
0
	SoundStream* InitSoundStream()
	{
		std::string backend = SConfig::GetInstance().sBackend;
		if (backend == BACKEND_OPENAL && OpenALStream::isValid())
			g_sound_stream = new OpenALStream();
		else if (backend == BACKEND_NULLSOUND && NullSound::isValid())
			g_sound_stream = new NullSound();
		else if (backend == BACKEND_XAUDIO2)
		{
			if (XAudio2::isValid())
				g_sound_stream = new XAudio2();
			else if (XAudio2_7::isValid())
				g_sound_stream = new XAudio2_7();
		}
		else if (backend == BACKEND_AOSOUND && AOSound::isValid())
			g_sound_stream = new AOSound();
		else if (backend == BACKEND_ALSA && AlsaSound::isValid())
			g_sound_stream = new AlsaSound();
		else if (backend == BACKEND_COREAUDIO && CoreAudioSound::isValid())
			g_sound_stream = new CoreAudioSound();
		else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid())
			g_sound_stream = new PulseAudio();
		else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid())
			g_sound_stream = new OpenSLESStream();

		if (!g_sound_stream && NullSound::isValid())
		{
			WARN_LOG(AUDIO, "Could not initialize backend %s, using %s instead.",
				backend.c_str(), BACKEND_NULLSOUND);
			g_sound_stream = new NullSound();
		}

		if (g_sound_stream)
		{
			UpdateSoundStream();
			if (!g_sound_stream->Start())
			{
				ERROR_LOG(AUDIO, "Could not start backend %s, using %s instead",
					  backend.c_str(), BACKEND_NULLSOUND);
				delete g_sound_stream;
				g_sound_stream = new NullSound();
				g_sound_stream->Start();
			}

			if (SConfig::GetInstance().m_DumpAudio && !s_audio_dump_start)
				StartAudioDump();

			return g_sound_stream;
		}

		PanicAlertT("Sound backend %s is not valid.", backend.c_str());

		delete g_sound_stream;
		g_sound_stream = nullptr;
		return nullptr;
	}
void InitSoundStream()
{
  std::string backend = SConfig::GetInstance().sBackend;
  if (backend == BACKEND_CUBEB)
    g_sound_stream = std::make_unique<CubebStream>();
  else if (backend == BACKEND_OPENAL && OpenALStream::isValid())
    g_sound_stream = std::make_unique<OpenALStream>();
  else if (backend == BACKEND_NULLSOUND)
    g_sound_stream = std::make_unique<NullSound>();
  else if (backend == BACKEND_XAUDIO2)
  {
    if (XAudio2::isValid())
      g_sound_stream = std::make_unique<XAudio2>();
    else if (XAudio2_7::isValid())
      g_sound_stream = std::make_unique<XAudio2_7>();
  }
  else if (backend == BACKEND_ALSA && AlsaSound::isValid())
    g_sound_stream = std::make_unique<AlsaSound>();
  else if (backend == BACKEND_COREAUDIO && CoreAudioSound::isValid())
    g_sound_stream = std::make_unique<CoreAudioSound>();
  else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid())
    g_sound_stream = std::make_unique<PulseAudio>();
  else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid())
    g_sound_stream = std::make_unique<OpenSLESStream>();

  if (!g_sound_stream)
  {
    WARN_LOG(AUDIO, "Could not initialize backend %s, using %s instead.", backend.c_str(),
             BACKEND_NULLSOUND);
    g_sound_stream = std::make_unique<NullSound>();
  }

  if (!g_sound_stream->Start())
  {
    ERROR_LOG(AUDIO, "Could not start backend %s, using %s instead", backend.c_str(),
              BACKEND_NULLSOUND);

    g_sound_stream = std::make_unique<NullSound>();
    g_sound_stream->Start();
  }

  UpdateSoundStream();

  if (SConfig::GetInstance().m_DumpAudio && !s_audio_dump_start)
    StartAudioDump();
}
Exemple #5
0
	void ToggleMuteVolume()
	{
		bool& isMuted = SConfig::GetInstance().m_IsMuted;
		isMuted = !isMuted;
		UpdateSoundStream();
	}