Browse Source

Add OptionEntries for Audio

pull/3757/head
obligaron 4 years ago committed by Anders Jenbo
parent
commit
8a4d4b6375
  1. 34
      Source/options.cpp
  2. 8
      Source/options.h
  3. 4
      Source/sound.cpp
  4. 2
      Source/storm/storm_svid.cpp
  5. 4
      Source/utils/soundsample.cpp

34
Source/options.cpp

@ -252,6 +252,19 @@ void OptionSharewareChanged()
gbIsSpawn = *sgOptions.StartUp.shareware;
}
void OptionAudioChanged()
{
effects_cleanup_sfx();
music_stop();
snd_deinit();
snd_init();
music_start(TMUSIC_INTRO);
if (gbRunGame)
sound_init();
else
ui_sound_init();
}
} // namespace
void SetIniValue(const char *sectionName, const char *keyName, const char *value, int len)
@ -294,11 +307,6 @@ void LoadOptions()
sgOptions.Audio.nSoundVolume = GetIniInt("Audio", "Sound Volume", VOLUME_MAX);
sgOptions.Audio.nMusicVolume = GetIniInt("Audio", "Music Volume", VOLUME_MAX);
sgOptions.Audio.nSampleRate = GetIniInt("Audio", "Sample Rate", DEFAULT_AUDIO_SAMPLE_RATE);
sgOptions.Audio.nChannels = GetIniInt("Audio", "Channels", DEFAULT_AUDIO_CHANNELS);
sgOptions.Audio.nBufferSize = GetIniInt("Audio", "Buffer Size", DEFAULT_AUDIO_BUFFER_SIZE);
sgOptions.Audio.nResamplingQuality = GetIniInt("Audio", "Resampling Quality", DEFAULT_AUDIO_RESAMPLING_QUALITY);
sgOptions.Graphics.nGammaCorrection = GetIniInt("Graphics", "Gamma Correction", 100);
#if SDL_VERSION_ATLEAST(2, 0, 0)
sgOptions.Graphics.bHardwareCursor = GetIniBool("Graphics", "Hardware Cursor", HardwareCursorDefault());
@ -348,10 +356,6 @@ void SaveOptions()
SetIniValue("Audio", "Sound Volume", sgOptions.Audio.nSoundVolume);
SetIniValue("Audio", "Music Volume", sgOptions.Audio.nMusicVolume);
SetIniValue("Audio", "Sample Rate", sgOptions.Audio.nSampleRate);
SetIniValue("Audio", "Channels", sgOptions.Audio.nChannels);
SetIniValue("Audio", "Buffer Size", sgOptions.Audio.nBufferSize);
SetIniValue("Audio", "Resampling Quality", sgOptions.Audio.nResamplingQuality);
SetIniValue("Graphics", "Gamma Correction", sgOptions.Graphics.nGammaCorrection);
#if SDL_VERSION_ATLEAST(2, 0, 0)
SetIniValue("Graphics", "Hardware Cursor", sgOptions.Graphics.bHardwareCursor);
@ -605,7 +609,15 @@ AudioOptions::AudioOptions()
, walkingSound("Walking Sound", OptionEntryFlags::None, N_("Walking Sound"), N_("Player emits sound when walking."), true)
, autoEquipSound("Auto Equip Sound", OptionEntryFlags::None, N_("Auto Equip Sound"), N_("Automatically equipping items on pickup emits the equipment sound."), false)
, itemPickupSound("Item Pickup Sound", OptionEntryFlags::None, N_("Item Pickup Sound"), N_("Picking up items emits the items pickup sound."), false)
, sampleRate("Sample Rate", OptionEntryFlags::CantChangeInGame, N_("Sample Rate"), N_("Output sample rate (Hz)."), DEFAULT_AUDIO_SAMPLE_RATE, { 22050, 44100, 48000 })
, channels("Channels", OptionEntryFlags::CantChangeInGame, N_("Channels"), N_("Number of output channels."), DEFAULT_AUDIO_CHANNELS, { 1, 2 })
, bufferSize("Buffer Size", OptionEntryFlags::CantChangeInGame, N_("Buffer Size"), N_("Buffer size (number of frames per channel)."), DEFAULT_AUDIO_BUFFER_SIZE, { 1024, 2048, 5120 })
, resamplingQuality("Resampling Quality", OptionEntryFlags::CantChangeInGame, N_("Resampling Quality"), N_("Quality of the resampler, from 0 (lowest) to 10 (highest)."), DEFAULT_AUDIO_RESAMPLING_QUALITY, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
{
sampleRate.SetValueChangedCallback(OptionAudioChanged);
channels.SetValueChangedCallback(OptionAudioChanged);
bufferSize.SetValueChangedCallback(OptionAudioChanged);
resamplingQuality.SetValueChangedCallback(OptionAudioChanged);
}
std::vector<OptionEntryBase *> AudioOptions::GetEntries()
{
@ -613,6 +625,10 @@ std::vector<OptionEntryBase *> AudioOptions::GetEntries()
&walkingSound,
&autoEquipSound,
&itemPickupSound,
&sampleRate,
&channels,
&bufferSize,
&resamplingQuality,
};
}

8
Source/options.h

@ -360,13 +360,13 @@ struct AudioOptions : OptionCategoryBase {
OptionEntryBoolean itemPickupSound;
/** @brief Output sample rate (Hz) */
std::uint32_t nSampleRate;
OptionEntryInt<std::uint32_t> sampleRate;
/** @brief The number of output channels (1 or 2) */
std::uint8_t nChannels;
OptionEntryInt<std::uint8_t> channels;
/** @brief Buffer size (number of frames per channel) */
std::uint32_t nBufferSize;
OptionEntryInt<std::uint32_t> bufferSize;
/** @brief Quality of the resampler, from 0 (lowest) to 10 (highest) */
std::uint8_t nResamplingQuality;
OptionEntryInt<std::uint8_t> resamplingQuality;
};
struct GraphicsOptions : OptionCategoryBase {

4
Source/sound.cpp

@ -56,7 +56,7 @@ void LoadMusic(SDL_RWops *handle)
handle = SDL_RWFromConstMem(musicBuffer.get(), bytestoread);
#endif
music.emplace(handle, std::make_unique<Aulib::DecoderDrwav>(),
std::make_unique<Aulib::ResamplerSpeex>(sgOptions.Audio.nResamplingQuality), /*closeRw=*/true);
std::make_unique<Aulib::ResamplerSpeex>(*sgOptions.Audio.resamplingQuality), /*closeRw=*/true);
}
void CleanupMusic()
@ -201,7 +201,7 @@ void snd_init()
// Initialize the SDL_audiolib library. Set the output sample rate to
// 22kHz, the audio format to 16-bit signed, use 2 output channels
// (stereo), and a 2KiB output buffer.
if (!Aulib::init(sgOptions.Audio.nSampleRate, AUDIO_S16, sgOptions.Audio.nChannels, sgOptions.Audio.nBufferSize)) {
if (!Aulib::init(*sgOptions.Audio.sampleRate, AUDIO_S16, *sgOptions.Audio.channels, *sgOptions.Audio.bufferSize)) {
LogError(LogCategory::Audio, "Failed to initialize audio (Aulib::init): {}", SDL_GetError());
return;
}

2
Source/storm/storm_svid.cpp

@ -263,7 +263,7 @@ bool SVidPlayBegin(const char *filename, int flags)
auto decoder = std::make_unique<PushAulibDecoder>(audioInfo.nChannels, audioInfo.sampleRate);
SVidAudioDecoder = decoder.get();
SVidAudioStream.emplace(/*rwops=*/nullptr, std::move(decoder),
std::make_unique<Aulib::ResamplerSpeex>(sgOptions.Audio.nResamplingQuality), /*closeRw=*/false);
std::make_unique<Aulib::ResamplerSpeex>(*sgOptions.Audio.resamplingQuality), /*closeRw=*/false);
const float volume = static_cast<float>(sgOptions.Audio.nSoundVolume - VOLUME_MIN) / -VOLUME_MIN;
SVidAudioStream->setVolume(volume);
if (!SVidAudioStream->open()) {

4
Source/utils/soundsample.cpp

@ -123,7 +123,7 @@ int SoundSample::SetChunkStream(std::string filePath)
}
stream_ = std::make_unique<Aulib::Stream>(handle, std::make_unique<Aulib::DecoderDrwav>(),
std::make_unique<Aulib::ResamplerSpeex>(sgOptions.Audio.nResamplingQuality), /*closeRw=*/true);
std::make_unique<Aulib::ResamplerSpeex>(*sgOptions.Audio.resamplingQuality), /*closeRw=*/true);
if (!stream_->open()) {
stream_ = nullptr;
LogError(LogCategory::Audio, "Aulib::Stream::open (from SoundSample::SetChunkStream): {}", SDL_GetError());
@ -143,7 +143,7 @@ int SoundSample::SetChunk(ArraySharedPtr<std::uint8_t> fileData, std::size_t dwB
}
stream_ = std::make_unique<Aulib::Stream>(buf, std::make_unique<Aulib::DecoderDrwav>(),
std::make_unique<Aulib::ResamplerSpeex>(sgOptions.Audio.nResamplingQuality), /*closeRw=*/true);
std::make_unique<Aulib::ResamplerSpeex>(*sgOptions.Audio.resamplingQuality), /*closeRw=*/true);
if (!stream_->open()) {
stream_ = nullptr;
file_data_ = nullptr;

Loading…
Cancel
Save