1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-12 02:22:26 +01:00

Rename _format to _outputFormat

This commit is contained in:
Gymnasiast
2025-11-15 18:48:55 +01:00
parent 766cfd2f18
commit 22e50556a9
2 changed files with 22 additions and 21 deletions

View File

@@ -40,9 +40,9 @@ void AudioMixer::Init(const char* device)
SDL_AudioSpec have; SDL_AudioSpec have;
_deviceId = SDL_OpenAudioDevice(device, 0, &want, &have, 0); _deviceId = SDL_OpenAudioDevice(device, 0, &want, &have, 0);
_format.format = have.format; _outputFormat.format = have.format;
_format.channels = have.channels; _outputFormat.channels = have.channels;
_format.freq = have.freq; _outputFormat.freq = have.freq;
SDL_PauseAudioDevice(_deviceId, 0); SDL_PauseAudioDevice(_deviceId, 0);
} }
@@ -121,7 +121,7 @@ void AudioMixer::RemoveReleasedSources()
const AudioFormat& AudioMixer::GetFormat() const const AudioFormat& AudioMixer::GetFormat() const
{ {
return _format; return _outputFormat;
} }
void AudioMixer::GetNextAudioChunk(uint8_t* dst, size_t length) void AudioMixer::GetNextAudioChunk(uint8_t* dst, size_t length)
@@ -173,10 +173,10 @@ void AudioMixer::UpdateAdjustedSound()
void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t length) void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t length)
{ {
int32_t byteRate = _format.GetByteRate(); int32_t byteRate = _outputFormat.GetByteRate();
auto numSamples = static_cast<int32_t>(length / byteRate); auto numSamples = static_cast<int32_t>(length / byteRate);
double rate = 1; double rate = 1;
if (_format.format == AUDIO_S16SYS) if (_outputFormat.format == AUDIO_S16SYS)
{ {
rate = channel->GetRate(); rate = channel->GetRate();
} }
@@ -185,11 +185,11 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len
SDL_AudioCVT cvt; SDL_AudioCVT cvt;
cvt.len_ratio = 1; cvt.len_ratio = 1;
AudioFormat streamformat = channel->GetFormat(); AudioFormat streamformat = channel->GetFormat();
if (streamformat != _format) if (streamformat != _outputFormat)
{ {
if (SDL_BuildAudioCVT( if (SDL_BuildAudioCVT(
&cvt, streamformat.format, streamformat.channels, streamformat.freq, _format.format, _format.channels, &cvt, streamformat.format, streamformat.channels, streamformat.freq, _outputFormat.format,
_format.freq) _outputFormat.channels, _outputFormat.freq)
== -1) == -1)
{ {
// Unable to convert channel data // Unable to convert channel data
@@ -232,8 +232,8 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len
int32_t outRate = numSamples; int32_t outRate = numSamples;
if (bytesRead != readLength) if (bytesRead != readLength)
{ {
inRate = _format.freq; inRate = _outputFormat.freq;
outRate = _format.freq * (1 / rate); outRate = _outputFormat.freq * (1 / rate);
} }
_effectBuffer.resize(length); _effectBuffer.resize(length);
bufferLen = ApplyResample(channel, buffer, static_cast<int32_t>(bufferLen / byteRate), numSamples, inRate, outRate); bufferLen = ApplyResample(channel, buffer, static_cast<int32_t>(bufferLen / byteRate), numSamples, inRate, outRate);
@@ -246,25 +246,26 @@ void AudioMixer::MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t len
// Finally mix on to destination buffer // Finally mix on to destination buffer
size_t dstLength = std::min(length, bufferLen); size_t dstLength = std::min(length, bufferLen);
SDL_MixAudioFormat(data, static_cast<const uint8_t*>(buffer), _format.format, static_cast<uint32_t>(dstLength), mixVolume); SDL_MixAudioFormat(
data, static_cast<const uint8_t*>(buffer), _outputFormat.format, static_cast<uint32_t>(dstLength), mixVolume);
channel->UpdateOldVolume(); channel->UpdateOldVolume();
} }
/** /**
* Resample the given buffer into _effectBuffer. * Resample the given buffer into _effectBuffer.
* Assumes that srcBuffer is the same format as _format. * Assumes that srcBuffer is the same format as _outputFormat.
*/ */
size_t AudioMixer::ApplyResample( size_t AudioMixer::ApplyResample(
ISDLAudioChannel* channel, const void* srcBuffer, int32_t srcSamples, int32_t dstSamples, int32_t inRate, int32_t outRate) ISDLAudioChannel* channel, const void* srcBuffer, int32_t srcSamples, int32_t dstSamples, int32_t inRate, int32_t outRate)
{ {
int32_t byteRate = _format.GetByteRate(); int32_t byteRate = _outputFormat.GetByteRate();
// Create resampler // Create resampler
SpeexResamplerState* resampler = channel->GetResampler(); SpeexResamplerState* resampler = channel->GetResampler();
if (resampler == nullptr) if (resampler == nullptr)
{ {
resampler = speex_resampler_init(_format.channels, _format.freq, _format.freq, 0, nullptr); resampler = speex_resampler_init(_outputFormat.channels, _outputFormat.freq, _outputFormat.freq, 0, nullptr);
channel->SetResampler(resampler); channel->SetResampler(resampler);
} }
speex_resampler_set_rate(resampler, inRate, outRate); speex_resampler_set_rate(resampler, inRate, outRate);
@@ -280,9 +281,9 @@ size_t AudioMixer::ApplyResample(
void AudioMixer::ApplyPan(const IAudioChannel* channel, void* buffer, size_t len, size_t sampleSize) void AudioMixer::ApplyPan(const IAudioChannel* channel, void* buffer, size_t len, size_t sampleSize)
{ {
if (channel->GetPan() != 0.5f && _format.channels == 2) if (channel->GetPan() != 0.5f && _outputFormat.channels == 2)
{ {
switch (_format.format) switch (_outputFormat.format)
{ {
case AUDIO_S16SYS: case AUDIO_S16SYS:
EffectPanS16(channel, static_cast<int16_t*>(buffer), static_cast<int32_t>(len / sampleSize)); EffectPanS16(channel, static_cast<int16_t*>(buffer), static_cast<int32_t>(len / sampleSize));
@@ -331,8 +332,8 @@ int32_t AudioMixer::ApplyVolume(const IAudioChannel* channel, void* buffer, size
mixVolume = kMixerVolumeMax; mixVolume = kMixerVolumeMax;
// Fade between volume levels to smooth out sound and minimize clicks from sudden volume changes // Fade between volume levels to smooth out sound and minimize clicks from sudden volume changes
int32_t fadeLength = static_cast<int32_t>(len) / _format.BytesPerSample(); int32_t fadeLength = static_cast<int32_t>(len) / _outputFormat.BytesPerSample();
switch (_format.format) switch (_outputFormat.format)
{ {
case AUDIO_S16SYS: case AUDIO_S16SYS:
EffectFadeS16(static_cast<int16_t*>(buffer), fadeLength, startVolume, endVolume); EffectFadeS16(static_cast<int16_t*>(buffer), fadeLength, startVolume, endVolume);

View File

@@ -33,7 +33,7 @@ namespace OpenRCT2::Audio
std::vector<std::unique_ptr<SDLAudioSource>> _sources; std::vector<std::unique_ptr<SDLAudioSource>> _sources;
SDL_AudioDeviceID _deviceId = 0; SDL_AudioDeviceID _deviceId = 0;
AudioFormat _format = {}; AudioFormat _outputFormat = {};
std::list<std::shared_ptr<ISDLAudioChannel>> _channels; std::list<std::shared_ptr<ISDLAudioChannel>> _channels;
float _volume = 1.0f; float _volume = 1.0f;
float _adjustSoundVolume = 0.0f; float _adjustSoundVolume = 0.0f;
@@ -67,7 +67,7 @@ namespace OpenRCT2::Audio
/** /**
* Resample the given buffer into _effectBuffer. * Resample the given buffer into _effectBuffer.
* Assumes that srcBuffer is the same format as _format. * Assumes that srcBuffer is the same format as _outputFormat.
*/ */
size_t ApplyResample( size_t ApplyResample(
ISDLAudioChannel* channel, const void* srcBuffer, int32_t srcSamples, int32_t dstSamples, int32_t inRate, ISDLAudioChannel* channel, const void* srcBuffer, int32_t srcSamples, int32_t dstSamples, int32_t inRate,