Skip to content

Commit

Permalink
Rename some struct members for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Dec 24, 2024
1 parent eaa6881 commit 14fde4c
Show file tree
Hide file tree
Showing 36 changed files with 342 additions and 338 deletions.
68 changes: 34 additions & 34 deletions alc/alc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,9 +1032,9 @@ auto CreateDeviceLimiter(const al::Device *device, const float threshold)
const auto flags = Compressor::FlagBits{}.set(Compressor::AutoKnee).set(Compressor::AutoAttack)
.set(Compressor::AutoRelease).set(Compressor::AutoPostGain).set(Compressor::AutoDeclip);

return Compressor::Create(device->RealOut.Buffer.size(), static_cast<float>(device->Frequency),
flags, LookAheadTime, HoldTime, PreGainDb, PostGainDb, threshold, Ratio, KneeDb,
AttackTime, ReleaseTime);
return Compressor::Create(device->RealOut.Buffer.size(),
static_cast<float>(device->mSampleRate), flags, LookAheadTime, HoldTime, PreGainDb,
PostGainDb, threshold, Ratio, KneeDb, AttackTime, ReleaseTime);
}

/**
Expand All @@ -1052,7 +1052,7 @@ inline void UpdateClockBase(al::Device *device)
auto clockBaseSec = device->mClockBaseSec.load(std::memory_order_relaxed);
auto clockBaseNSec = nanoseconds{device->mClockBaseNSec.load(std::memory_order_relaxed)};
clockBaseNSec += nanoseconds{seconds{device->mSamplesDone.load(std::memory_order_relaxed)}}
/ device->Frequency;
/ device->mSampleRate;

clockBaseSec += duration_cast<DeviceBase::seconds32>(clockBaseNSec);
clockBaseNSec %= seconds{1};
Expand Down Expand Up @@ -1465,7 +1465,7 @@ auto UpdateDeviceParams(al::Device *device, const al::span<const int> attrList)

if(device->Type == DeviceType::Loopback)
{
device->Frequency = *optsrate;
device->mSampleRate = *optsrate;
device->FmtChans = *optchans;
device->FmtType = *opttype;
if(device->FmtChans == DevFmtAmbi3D)
Expand All @@ -1481,9 +1481,9 @@ auto UpdateDeviceParams(al::Device *device, const al::span<const int> attrList)
device->FmtType = opttype.value_or(DevFmtTypeDefault);
device->FmtChans = optchans.value_or(DevFmtChannelsDefault);
device->mAmbiOrder = 0;
device->BufferSize = buffer_size;
device->UpdateSize = period_size;
device->Frequency = optsrate.value_or(DefaultOutputRate);
device->mBufferSize = buffer_size;
device->mUpdateSize = period_size;
device->mSampleRate = optsrate.value_or(DefaultOutputRate);
device->Flags.set(FrequencyRequest, optsrate.has_value())
.set(ChannelsRequest, optchans.has_value())
.set(SampleTypeRequest, opttype.has_value());
Expand All @@ -1507,10 +1507,10 @@ auto UpdateDeviceParams(al::Device *device, const al::span<const int> attrList)
TRACE("Pre-reset: {}{}, {}{}, {}{}hz, {} / {} buffer",
device->Flags.test(ChannelsRequest)?"*":"", DevFmtChannelsString(device->FmtChans),
device->Flags.test(SampleTypeRequest)?"*":"", DevFmtTypeString(device->FmtType),
device->Flags.test(FrequencyRequest)?"*":"", device->Frequency,
device->UpdateSize, device->BufferSize);
device->Flags.test(FrequencyRequest)?"*":"", device->mSampleRate,
device->mUpdateSize, device->mBufferSize);

const uint oldFreq{device->Frequency};
const uint oldFreq{device->mSampleRate};
const DevFmtChannels oldChans{device->FmtChans};
const DevFmtType oldType{device->FmtType};
try {
Expand All @@ -1536,15 +1536,15 @@ auto UpdateDeviceParams(al::Device *device, const al::span<const int> attrList)
DevFmtTypeString(device->FmtType));
device->Flags.reset(SampleTypeRequest);
}
if(device->Frequency != oldFreq && device->Flags.test(FrequencyRequest))
if(device->mSampleRate != oldFreq && device->Flags.test(FrequencyRequest))
{
WARN("Failed to set {}hz, got {}hz instead", oldFreq, device->Frequency);
WARN("Failed to set {}hz, got {}hz instead", oldFreq, device->mSampleRate);
device->Flags.reset(FrequencyRequest);
}

TRACE("Post-reset: {}, {}, {}hz, {} / {} buffer",
DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
device->Frequency, device->UpdateSize, device->BufferSize);
device->mSampleRate, device->mUpdateSize, device->mBufferSize);

if(device->Type != DeviceType::Loopback)
{
Expand Down Expand Up @@ -1699,7 +1699,7 @@ auto UpdateDeviceParams(al::Device *device, const al::span<const int> attrList)

/* Convert the sample delay from samples to nanosamples to nanoseconds. */
sample_delay = std::min<size_t>(sample_delay, std::numeric_limits<int>::max());
device->FixedLatency += nanoseconds{seconds{sample_delay}} / device->Frequency;
device->FixedLatency += nanoseconds{seconds{sample_delay}} / device->mSampleRate;
TRACE("Fixed device latency: {}ns", device->FixedLatency.count());

FPUCtl mixer_mode{};
Expand Down Expand Up @@ -1871,7 +1871,7 @@ auto UpdateDeviceParams(al::Device *device, const al::span<const int> attrList)
}
TRACE("Post-start: {}, {}, {}hz, {} / {} buffer",
DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
device->Frequency, device->UpdateSize, device->BufferSize);
device->mSampleRate, device->mUpdateSize, device->mBufferSize);
}

return ALC_NO_ERROR;
Expand Down Expand Up @@ -2284,11 +2284,11 @@ auto GetIntegerv(al::Device *device, ALCenum param, const al::span<int> values)
values[i++] = alcEFXMinorVersion;

values[i++] = ALC_FREQUENCY;
values[i++] = static_cast<int>(device->Frequency);
values[i++] = static_cast<int>(device->mSampleRate);
if(device->Type != DeviceType::Loopback)
{
values[i++] = ALC_REFRESH;
values[i++] = static_cast<int>(device->Frequency / device->UpdateSize);
values[i++] = static_cast<int>(device->mSampleRate / device->mUpdateSize);

values[i++] = ALC_SYNC;
values[i++] = ALC_FALSE;
Expand Down Expand Up @@ -2362,7 +2362,7 @@ auto GetIntegerv(al::Device *device, ALCenum param, const al::span<int> values)
return 1;

case ALC_FREQUENCY:
values[0] = static_cast<int>(device->Frequency);
values[0] = static_cast<int>(device->mSampleRate);
return 1;

case ALC_REFRESH:
Expand All @@ -2371,7 +2371,7 @@ auto GetIntegerv(al::Device *device, ALCenum param, const al::span<int> values)
alcSetError(device, ALC_INVALID_DEVICE);
return 0;
}
values[0] = static_cast<int>(device->Frequency / device->UpdateSize);
values[0] = static_cast<int>(device->mSampleRate / device->mUpdateSize);
return 1;

case ALC_SYNC:
Expand Down Expand Up @@ -2523,12 +2523,12 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname,
{
size_t i{0};
valuespan[i++] = ALC_FREQUENCY;
valuespan[i++] = dev->Frequency;
valuespan[i++] = dev->mSampleRate;

if(dev->Type != DeviceType::Loopback)
{
valuespan[i++] = ALC_REFRESH;
valuespan[i++] = dev->Frequency / dev->UpdateSize;
valuespan[i++] = dev->mSampleRate / dev->mUpdateSize;

valuespan[i++] = ALC_SYNC;
valuespan[i++] = ALC_FALSE;
Expand Down Expand Up @@ -2600,7 +2600,7 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname,
} while(refcount != dev->mMixCount.load(std::memory_order_relaxed));

valuespan[0] = nanoseconds{clocksec + nanoseconds{clocknsec}
+ nanoseconds{seconds{samplecount}}/dev->Frequency}.count();
+ nanoseconds{seconds{samplecount}}/dev->mSampleRate}.count();
}
break;

Expand Down Expand Up @@ -2983,9 +2983,9 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) noexcep
/* Set output format */
device->FmtChans = DevFmtChannelsDefault;
device->FmtType = DevFmtTypeDefault;
device->Frequency = DefaultOutputRate;
device->UpdateSize = DefaultUpdateSize;
device->BufferSize = DefaultUpdateSize * DefaultNumUpdates;
device->mSampleRate = DefaultOutputRate;
device->mUpdateSize = DefaultUpdateSize;
device->mBufferSize = DefaultUpdateSize * DefaultNumUpdates;

device->SourcesMax = 256;
device->NumStereoSources = 1;
Expand Down Expand Up @@ -3144,19 +3144,19 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
return nullptr;
}

device->Frequency = frequency;
device->mSampleRate = frequency;
device->FmtChans = decompfmt->chans;
device->FmtType = decompfmt->type;
device->Flags.set(FrequencyRequest);
device->Flags.set(ChannelsRequest);
device->Flags.set(SampleTypeRequest);

device->UpdateSize = static_cast<uint>(samples);
device->BufferSize = static_cast<uint>(samples);
device->mUpdateSize = static_cast<uint>(samples);
device->mBufferSize = static_cast<uint>(samples);

TRACE("Capture format: {}, {}, {}hz, {} / {} buffer",
DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
device->Frequency, device->UpdateSize, device->BufferSize);
device->mSampleRate, device->mUpdateSize, device->mBufferSize);

try {
auto backend = CaptureFactory->createBackend(device.get(), BackendType::Capture);
Expand Down Expand Up @@ -3326,10 +3326,10 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
device->NumAuxSends = DefaultSends;

//Set output format
device->BufferSize = 0;
device->UpdateSize = 0;
device->mBufferSize = 0;
device->mUpdateSize = 0;

device->Frequency = DefaultOutputRate;
device->mSampleRate = DefaultOutputRate;
device->FmtChans = DevFmtChannelsDefault;
device->FmtType = DevFmtTypeDefault;

Expand Down Expand Up @@ -3466,7 +3466,7 @@ ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device) noexcept
}
TRACE("Post-resume: {}, {}, {}hz, {} / {} buffer",
DevFmtChannelsString(dev->FmtChans), DevFmtTypeString(dev->FmtType),
dev->Frequency, dev->UpdateSize, dev->BufferSize);
dev->mSampleRate, dev->mUpdateSize, dev->mBufferSize);
}


Expand Down
10 changes: 5 additions & 5 deletions alc/alu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
ChanPosMap{FrontRight, std::array{ sin30, 0.0f, -cos30}},
};

const auto Frequency = static_cast<float>(Device->Frequency);
const auto Frequency = static_cast<float>(Device->mSampleRate);
const uint NumSends{Device->NumAuxSends};

const size_t num_channels{voice->mChans.size()};
Expand Down Expand Up @@ -1481,7 +1481,7 @@ void CalcNonAttnSourceParams(Voice *voice, const VoiceProps *props, const Contex

/* Calculate the stepping value */
const auto Pitch = static_cast<float>(voice->mFrequency) /
static_cast<float>(Device->Frequency) * props->Pitch;
static_cast<float>(Device->mSampleRate) * props->Pitch;
if(Pitch > float{MaxPitch})
voice->mStep = MaxPitch<<MixerFracBits;
else
Expand Down Expand Up @@ -1767,7 +1767,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ContextBa
/* Adjust pitch based on the buffer and output frequencies, and calculate
* fixed-point stepping value.
*/
Pitch *= static_cast<float>(voice->mFrequency) / static_cast<float>(Device->Frequency);
Pitch *= static_cast<float>(voice->mFrequency) / static_cast<float>(Device->mSampleRate);
if(Pitch > float{MaxPitch})
voice->mStep = MaxPitch<<MixerFracBits;
else
Expand Down Expand Up @@ -2206,8 +2206,8 @@ uint DeviceBase::renderSamples(const uint numSamples)
*/
auto samplesDone = mSamplesDone.load(std::memory_order_relaxed) + samplesToDo;
auto clockBaseSec = mClockBaseSec.load(std::memory_order_relaxed) +
seconds32{samplesDone/Frequency};
mSamplesDone.store(samplesDone%Frequency, std::memory_order_relaxed);
seconds32{samplesDone/mSampleRate};
mSamplesDone.store(samplesDone%mSampleRate, std::memory_order_relaxed);
mClockBaseSec.store(clockBaseSec, std::memory_order_relaxed);
}

Expand Down
38 changes: 19 additions & 19 deletions alc/backends/alsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ int AlsaPlayback::mixerProc()
SetRTPriority();
althrd_setname(GetMixerThreadName());

const snd_pcm_uframes_t update_size{mDevice->UpdateSize};
const snd_pcm_uframes_t buffer_size{mDevice->BufferSize};
const snd_pcm_uframes_t update_size{mDevice->mUpdateSize};
const snd_pcm_uframes_t buffer_size{mDevice->mBufferSize};
while(!mKillNow.load(std::memory_order_acquire))
{
int state{verify_state(mPcmHandle)};
Expand Down Expand Up @@ -575,8 +575,8 @@ int AlsaPlayback::mixerNoMMapProc()
SetRTPriority();
althrd_setname(GetMixerThreadName());

const snd_pcm_uframes_t update_size{mDevice->UpdateSize};
const snd_pcm_uframes_t buffer_size{mDevice->BufferSize};
const snd_pcm_uframes_t update_size{mDevice->mUpdateSize};
const snd_pcm_uframes_t buffer_size{mDevice->mBufferSize};
while(!mKillNow.load(std::memory_order_acquire))
{
int state{verify_state(mPcmHandle)};
Expand Down Expand Up @@ -725,9 +725,9 @@ bool AlsaPlayback::reset()
}

bool allowmmap{GetConfigValueBool(mDevice->mDeviceName, "alsa"sv, "mmap"sv, true)};
uint periodLen{static_cast<uint>(mDevice->UpdateSize * 1000000_u64 / mDevice->Frequency)};
uint bufferLen{static_cast<uint>(mDevice->BufferSize * 1000000_u64 / mDevice->Frequency)};
uint rate{mDevice->Frequency};
uint periodLen{static_cast<uint>(mDevice->mUpdateSize * 1000000_u64 / mDevice->mSampleRate)};
uint bufferLen{static_cast<uint>(mDevice->mBufferSize * 1000000_u64 / mDevice->mSampleRate)};
uint rate{mDevice->mSampleRate};

HwParamsPtr hp{CreateHwParams()};
#define CHECK(x) do { \
Expand Down Expand Up @@ -819,9 +819,9 @@ bool AlsaPlayback::reset()
#undef CHECK
sp = nullptr;

mDevice->BufferSize = static_cast<uint>(bufferSizeInFrames);
mDevice->UpdateSize = static_cast<uint>(periodSizeInFrames);
mDevice->Frequency = rate;
mDevice->mBufferSize = static_cast<uint>(bufferSizeInFrames);
mDevice->mUpdateSize = static_cast<uint>(periodSizeInFrames);
mDevice->mSampleRate = rate;

setDefaultChannelOrder();

Expand All @@ -845,7 +845,7 @@ void AlsaPlayback::start()
int (AlsaPlayback::*thread_func)(){};
if(access == SND_PCM_ACCESS_RW_INTERLEAVED)
{
auto datalen = snd_pcm_frames_to_bytes(mPcmHandle, mDevice->UpdateSize);
auto datalen = snd_pcm_frames_to_bytes(mPcmHandle, mDevice->mUpdateSize);
mBuffer.resize(static_cast<size_t>(datalen));
thread_func = &AlsaPlayback::mixerNoMMapProc;
}
Expand Down Expand Up @@ -891,7 +891,7 @@ ClockLatency AlsaPlayback::getClockLatency()
delay = 0;
}
ret.Latency = std::chrono::seconds{std::max<snd_pcm_sframes_t>(0, delay)};
ret.Latency /= mDevice->Frequency;
ret.Latency /= mDevice->mSampleRate;

return ret;
}
Expand Down Expand Up @@ -982,10 +982,10 @@ void AlsaCapture::open(std::string_view name)
break;
}

snd_pcm_uframes_t bufferSizeInFrames{std::max(mDevice->BufferSize,
100u*mDevice->Frequency/1000u)};
snd_pcm_uframes_t periodSizeInFrames{std::min(mDevice->BufferSize,
25u*mDevice->Frequency/1000u)};
snd_pcm_uframes_t bufferSizeInFrames{std::max(mDevice->mBufferSize,
100u*mDevice->mSampleRate/1000u)};
snd_pcm_uframes_t periodSizeInFrames{std::min(mDevice->mBufferSize,
25u*mDevice->mSampleRate/1000u)};

bool needring{false};
HwParamsPtr hp{CreateHwParams()};
Expand All @@ -1002,7 +1002,7 @@ void AlsaCapture::open(std::string_view name)
/* set channels (implicitly sets frame bits) */
CHECK(snd_pcm_hw_params_set_channels(mPcmHandle, hp.get(), mDevice->channelsFromFmt()));
/* set rate (implicitly constrains period/buffer parameters) */
CHECK(snd_pcm_hw_params_set_rate(mPcmHandle, hp.get(), mDevice->Frequency, 0));
CHECK(snd_pcm_hw_params_set_rate(mPcmHandle, hp.get(), mDevice->mSampleRate, 0));
/* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
if(snd_pcm_hw_params_set_buffer_size_min(mPcmHandle, hp.get(), &bufferSizeInFrames) < 0)
{
Expand All @@ -1020,7 +1020,7 @@ void AlsaCapture::open(std::string_view name)
hp = nullptr;

if(needring)
mRing = RingBuffer::Create(mDevice->BufferSize, mDevice->frameSizeFromFmt(), false);
mRing = RingBuffer::Create(mDevice->mBufferSize, mDevice->frameSizeFromFmt(), false);

mDeviceName = name;
}
Expand Down Expand Up @@ -1210,7 +1210,7 @@ ClockLatency AlsaCapture::getClockLatency()
delay = 0;
}
ret.Latency = std::chrono::seconds{std::max<snd_pcm_sframes_t>(0, delay)};
ret.Latency /= mDevice->Frequency;
ret.Latency /= mDevice->mSampleRate;

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions alc/backends/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ ClockLatency BackendBase::getClockLatency()
* any given time during playback. Without a more accurate measurement from
* the output, this is an okay approximation.
*/
ret.Latency = std::chrono::seconds{mDevice->BufferSize - mDevice->UpdateSize};
ret.Latency /= mDevice->Frequency;
ret.Latency = std::chrono::seconds{mDevice->mBufferSize - mDevice->mUpdateSize};
ret.Latency /= mDevice->mSampleRate;

return ret;
}
Expand Down
Loading

0 comments on commit 14fde4c

Please sign in to comment.