diff options
Diffstat (limited to '')
-rw-r--r-- | src/audio_core/algorithm/filter.cpp | 12 | ||||
-rw-r--r-- | src/audio_core/algorithm/filter.h | 4 | ||||
-rw-r--r-- | src/audio_core/algorithm/interpolate.cpp | 12 | ||||
-rw-r--r-- | src/audio_core/algorithm/interpolate.h | 4 | ||||
-rw-r--r-- | src/audio_core/audio_out.cpp | 3 | ||||
-rw-r--r-- | src/audio_core/audio_out.h | 2 | ||||
-rw-r--r-- | src/audio_core/audio_renderer.cpp | 24 | ||||
-rw-r--r-- | src/audio_core/audio_renderer.h | 8 | ||||
-rw-r--r-- | src/audio_core/codec.cpp | 20 | ||||
-rw-r--r-- | src/audio_core/codec.h | 2 | ||||
-rw-r--r-- | src/audio_core/cubeb_sink.cpp | 21 | ||||
-rw-r--r-- | src/audio_core/null_sink.h | 2 | ||||
-rw-r--r-- | src/audio_core/stream.cpp | 8 | ||||
-rw-r--r-- | src/audio_core/stream.h | 4 | ||||
-rw-r--r-- | src/audio_core/time_stretch.cpp | 3 | ||||
-rw-r--r-- | src/audio_core/time_stretch.h | 2 |
16 files changed, 67 insertions, 64 deletions
diff --git a/src/audio_core/algorithm/filter.cpp b/src/audio_core/algorithm/filter.cpp index 9fcd0614d..f65bf64f7 100644 --- a/src/audio_core/algorithm/filter.cpp +++ b/src/audio_core/algorithm/filter.cpp @@ -35,12 +35,12 @@ Filter::Filter(double a0, double a1, double a2, double b0, double b1, double b2) : a1(a1 / a0), a2(a2 / a0), b0(b0 / a0), b1(b1 / a0), b2(b2 / a0) {} void Filter::Process(std::vector<s16>& signal) { - const size_t num_frames = signal.size() / 2; - for (size_t i = 0; i < num_frames; i++) { + const std::size_t num_frames = signal.size() / 2; + for (std::size_t i = 0; i < num_frames; i++) { std::rotate(in.begin(), in.end() - 1, in.end()); std::rotate(out.begin(), out.end() - 1, out.end()); - for (size_t ch = 0; ch < channel_count; ch++) { + for (std::size_t ch = 0; ch < channel_count; ch++) { in[0][ch] = signal[i * channel_count + ch]; out[0][ch] = b0 * in[0][ch] + b1 * in[1][ch] + b2 * in[2][ch] - a1 * out[1][ch] - @@ -54,14 +54,14 @@ void Filter::Process(std::vector<s16>& signal) { /// Calculates the appropriate Q for each biquad in a cascading filter. /// @param total_count The total number of biquads to be cascaded. /// @param index 0-index of the biquad to calculate the Q value for. -static double CascadingBiquadQ(size_t total_count, size_t index) { +static double CascadingBiquadQ(std::size_t total_count, std::size_t index) { const double pole = M_PI * (2 * index + 1) / (4.0 * total_count); return 1.0 / (2.0 * std::cos(pole)); } -CascadingFilter CascadingFilter::LowPass(double cutoff, size_t cascade_size) { +CascadingFilter CascadingFilter::LowPass(double cutoff, std::size_t cascade_size) { std::vector<Filter> cascade(cascade_size); - for (size_t i = 0; i < cascade_size; i++) { + for (std::size_t i = 0; i < cascade_size; i++) { cascade[i] = Filter::LowPass(cutoff, CascadingBiquadQ(cascade_size, i)); } return CascadingFilter{std::move(cascade)}; diff --git a/src/audio_core/algorithm/filter.h b/src/audio_core/algorithm/filter.h index a41beef98..3546d149b 100644 --- a/src/audio_core/algorithm/filter.h +++ b/src/audio_core/algorithm/filter.h @@ -30,7 +30,7 @@ public: void Process(std::vector<s16>& signal); private: - static constexpr size_t channel_count = 2; + static constexpr std::size_t channel_count = 2; /// Coefficients are in normalized form (a0 = 1.0). double a1, a2, b0, b1, b2; @@ -46,7 +46,7 @@ public: /// Creates a cascading low-pass filter. /// @param cutoff Determines the cutoff frequency. A value from 0.0 to 1.0. /// @param cascade_size Number of biquads in cascade. - static CascadingFilter LowPass(double cutoff, size_t cascade_size); + static CascadingFilter LowPass(double cutoff, std::size_t cascade_size); /// Passthrough. CascadingFilter(); diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp index 11459821f..3aea9b0f2 100644 --- a/src/audio_core/algorithm/interpolate.cpp +++ b/src/audio_core/algorithm/interpolate.cpp @@ -14,7 +14,7 @@ namespace AudioCore { /// The Lanczos kernel -static double Lanczos(size_t a, double x) { +static double Lanczos(std::size_t a, double x) { if (x == 0.0) return 1.0; const double px = M_PI * x; @@ -37,15 +37,15 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input, } state.nyquist.Process(input); - constexpr size_t taps = InterpolationState::lanczos_taps; - const size_t num_frames = input.size() / 2; + constexpr std::size_t taps = InterpolationState::lanczos_taps; + const std::size_t num_frames = input.size() / 2; std::vector<s16> output; - output.reserve(static_cast<size_t>(input.size() / ratio + 4)); + output.reserve(static_cast<std::size_t>(input.size() / ratio + 4)); double& pos = state.position; auto& h = state.history; - for (size_t i = 0; i < num_frames; ++i) { + for (std::size_t i = 0; i < num_frames; ++i) { std::rotate(h.begin(), h.end() - 1, h.end()); h[0][0] = input[i * 2 + 0]; h[0][1] = input[i * 2 + 1]; @@ -53,7 +53,7 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input, while (pos <= 1.0) { double l = 0.0; double r = 0.0; - for (size_t j = 0; j < h.size(); j++) { + for (std::size_t j = 0; j < h.size(); j++) { l += Lanczos(taps, pos + j - taps + 1) * h[j][0]; r += Lanczos(taps, pos + j - taps + 1) * h[j][1]; } diff --git a/src/audio_core/algorithm/interpolate.h b/src/audio_core/algorithm/interpolate.h index c79c2eef4..edbd6460f 100644 --- a/src/audio_core/algorithm/interpolate.h +++ b/src/audio_core/algorithm/interpolate.h @@ -12,8 +12,8 @@ namespace AudioCore { struct InterpolationState { - static constexpr size_t lanczos_taps = 4; - static constexpr size_t history_size = lanczos_taps * 2 - 1; + static constexpr std::size_t lanczos_taps = 4; + static constexpr std::size_t history_size = lanczos_taps * 2 - 1; double current_ratio = 0.0; CascadingFilter nyquist; diff --git a/src/audio_core/audio_out.cpp b/src/audio_core/audio_out.cpp index 12632a95c..0c8f5b18e 100644 --- a/src/audio_core/audio_out.cpp +++ b/src/audio_core/audio_out.cpp @@ -39,7 +39,8 @@ StreamPtr AudioOut::OpenStream(u32 sample_rate, u32 num_channels, std::string&& sink->AcquireSinkStream(sample_rate, num_channels, name), std::move(name)); } -std::vector<Buffer::Tag> AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream, size_t max_count) { +std::vector<Buffer::Tag> AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream, + std::size_t max_count) { return stream->GetTagsAndReleaseBuffers(max_count); } diff --git a/src/audio_core/audio_out.h b/src/audio_core/audio_out.h index 39b7e656b..df9607ac7 100644 --- a/src/audio_core/audio_out.h +++ b/src/audio_core/audio_out.h @@ -25,7 +25,7 @@ public: Stream::ReleaseCallback&& release_callback); /// Returns a vector of recently released buffers specified by tag for the specified stream - std::vector<Buffer::Tag> GetTagsAndReleaseBuffers(StreamPtr stream, size_t max_count); + std::vector<Buffer::Tag> GetTagsAndReleaseBuffers(StreamPtr stream, std::size_t max_count); /// Starts an audio stream for playback void StartStream(StreamPtr stream); diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index a75cd3be5..ed3b7defc 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -52,8 +52,8 @@ std::vector<u8> AudioRenderer::UpdateAudioRenderer(const std::vector<u8>& input_ memory_pool_count * sizeof(MemoryPoolInfo)); // Copy VoiceInfo structs - size_t offset{sizeof(UpdateDataHeader) + config.behavior_size + config.memory_pools_size + - config.voice_resource_size}; + std::size_t offset{sizeof(UpdateDataHeader) + config.behavior_size + config.memory_pools_size + + config.voice_resource_size}; for (auto& voice : voices) { std::memcpy(&voice.Info(), input_params.data() + offset, sizeof(VoiceInfo)); offset += sizeof(VoiceInfo); @@ -72,7 +72,7 @@ std::vector<u8> AudioRenderer::UpdateAudioRenderer(const std::vector<u8>& input_ // Update memory pool state std::vector<MemoryPoolEntry> memory_pool(memory_pool_count); - for (size_t index = 0; index < memory_pool.size(); ++index) { + for (std::size_t index = 0; index < memory_pool.size(); ++index) { if (mem_pool_info[index].pool_state == MemoryPoolStates::RequestAttach) { memory_pool[index].state = MemoryPoolStates::Attached; } else if (mem_pool_info[index].pool_state == MemoryPoolStates::RequestDetach) { @@ -93,7 +93,7 @@ std::vector<u8> AudioRenderer::UpdateAudioRenderer(const std::vector<u8>& input_ response_data.memory_pools_size); // Copy output voice status - size_t voice_out_status_offset{sizeof(UpdateDataHeader) + response_data.memory_pools_size}; + std::size_t voice_out_status_offset{sizeof(UpdateDataHeader) + response_data.memory_pools_size}; for (const auto& voice : voices) { std::memcpy(output_params.data() + voice_out_status_offset, &voice.GetOutStatus(), sizeof(VoiceOutStatus)); @@ -103,12 +103,12 @@ std::vector<u8> AudioRenderer::UpdateAudioRenderer(const std::vector<u8>& input_ return output_params; } -void AudioRenderer::VoiceState::SetWaveIndex(size_t index) { +void AudioRenderer::VoiceState::SetWaveIndex(std::size_t index) { wave_index = index & 3; is_refresh_pending = true; } -std::vector<s16> AudioRenderer::VoiceState::DequeueSamples(size_t sample_count) { +std::vector<s16> AudioRenderer::VoiceState::DequeueSamples(std::size_t sample_count) { if (!IsPlaying()) { return {}; } @@ -117,9 +117,9 @@ std::vector<s16> AudioRenderer::VoiceState::DequeueSamples(size_t sample_count) RefreshBuffer(); } - const size_t max_size{samples.size() - offset}; - const size_t dequeue_offset{offset}; - size_t size{sample_count * STREAM_NUM_CHANNELS}; + const std::size_t max_size{samples.size() - offset}; + const std::size_t dequeue_offset{offset}; + std::size_t size{sample_count * STREAM_NUM_CHANNELS}; if (size > max_size) { size = max_size; } @@ -184,7 +184,7 @@ void AudioRenderer::VoiceState::RefreshBuffer() { case 1: // 1 channel is upsampled to 2 channel samples.resize(new_samples.size() * 2); - for (size_t index = 0; index < new_samples.size(); ++index) { + for (std::size_t index = 0; index < new_samples.size(); ++index) { samples[index * 2] = new_samples[index]; samples[index * 2 + 1] = new_samples[index]; } @@ -210,7 +210,7 @@ static constexpr s16 ClampToS16(s32 value) { } void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { - constexpr size_t BUFFER_SIZE{512}; + constexpr std::size_t BUFFER_SIZE{512}; std::vector<s16> buffer(BUFFER_SIZE * stream->GetNumChannels()); for (auto& voice : voices) { @@ -218,7 +218,7 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) { continue; } - size_t offset{}; + std::size_t offset{}; s64 samples_remaining{BUFFER_SIZE}; while (samples_remaining > 0) { const std::vector<s16> samples{voice.DequeueSamples(samples_remaining)}; diff --git a/src/audio_core/audio_renderer.h b/src/audio_core/audio_renderer.h index 6d069d693..c8d2cd188 100644 --- a/src/audio_core/audio_renderer.h +++ b/src/audio_core/audio_renderer.h @@ -184,16 +184,16 @@ private: return info; } - void SetWaveIndex(size_t index); - std::vector<s16> DequeueSamples(size_t sample_count); + void SetWaveIndex(std::size_t index); + std::vector<s16> DequeueSamples(std::size_t sample_count); void UpdateState(); void RefreshBuffer(); private: bool is_in_use{}; bool is_refresh_pending{}; - size_t wave_index{}; - size_t offset{}; + std::size_t wave_index{}; + std::size_t offset{}; Codec::ADPCMState adpcm_state{}; InterpolationState interp_state{}; std::vector<s16> samples; diff --git a/src/audio_core/codec.cpp b/src/audio_core/codec.cpp index c3021403f..454de798b 100644 --- a/src/audio_core/codec.cpp +++ b/src/audio_core/codec.cpp @@ -8,27 +8,27 @@ namespace AudioCore::Codec { -std::vector<s16> DecodeADPCM(const u8* const data, size_t size, const ADPCM_Coeff& coeff, +std::vector<s16> DecodeADPCM(const u8* const data, std::size_t size, const ADPCM_Coeff& coeff, ADPCMState& state) { // GC-ADPCM with scale factor and variable coefficients. // Frames are 8 bytes long containing 14 samples each. // Samples are 4 bits (one nibble) long. - constexpr size_t FRAME_LEN = 8; - constexpr size_t SAMPLES_PER_FRAME = 14; + constexpr std::size_t FRAME_LEN = 8; + constexpr std::size_t SAMPLES_PER_FRAME = 14; constexpr std::array<int, 16> SIGNED_NIBBLES = { {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}}; - const size_t sample_count = (size / FRAME_LEN) * SAMPLES_PER_FRAME; - const size_t ret_size = + const std::size_t sample_count = (size / FRAME_LEN) * SAMPLES_PER_FRAME; + const std::size_t ret_size = sample_count % 2 == 0 ? sample_count : sample_count + 1; // Ensure multiple of two. std::vector<s16> ret(ret_size); int yn1 = state.yn1, yn2 = state.yn2; - const size_t NUM_FRAMES = + const std::size_t NUM_FRAMES = (sample_count + (SAMPLES_PER_FRAME - 1)) / SAMPLES_PER_FRAME; // Round up. - for (size_t framei = 0; framei < NUM_FRAMES; framei++) { + for (std::size_t framei = 0; framei < NUM_FRAMES; framei++) { const int frame_header = data[framei * FRAME_LEN]; const int scale = 1 << (frame_header & 0xF); const int idx = (frame_header >> 4) & 0x7; @@ -53,9 +53,9 @@ std::vector<s16> DecodeADPCM(const u8* const data, size_t size, const ADPCM_Coef return static_cast<s16>(val); }; - size_t outputi = framei * SAMPLES_PER_FRAME; - size_t datai = framei * FRAME_LEN + 1; - for (size_t i = 0; i < SAMPLES_PER_FRAME && outputi < sample_count; i += 2) { + std::size_t outputi = framei * SAMPLES_PER_FRAME; + std::size_t datai = framei * FRAME_LEN + 1; + for (std::size_t i = 0; i < SAMPLES_PER_FRAME && outputi < sample_count; i += 2) { const s16 sample1 = decode_sample(SIGNED_NIBBLES[data[datai] >> 4]); ret[outputi] = sample1; outputi++; diff --git a/src/audio_core/codec.h b/src/audio_core/codec.h index 3f845c42c..ef2ce01a8 100644 --- a/src/audio_core/codec.h +++ b/src/audio_core/codec.h @@ -38,7 +38,7 @@ using ADPCM_Coeff = std::array<s16, 16>; * @param state ADPCM state, this is updated with new state * @return Decoded stereo signed PCM16 data, sample_count in length */ -std::vector<s16> DecodeADPCM(const u8* const data, size_t size, const ADPCM_Coeff& coeff, +std::vector<s16> DecodeADPCM(const u8* const data, std::size_t size, const ADPCM_Coeff& coeff, ADPCMState& state); }; // namespace AudioCore::Codec diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 79155a7a0..855d64d05 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -63,8 +63,8 @@ public: // Downsample 6 channels to 2 std::vector<s16> buf; buf.reserve(samples.size() * num_channels / source_num_channels); - for (size_t i = 0; i < samples.size(); i += source_num_channels) { - for (size_t ch = 0; ch < num_channels; ch++) { + for (std::size_t i = 0; i < samples.size(); i += source_num_channels) { + for (std::size_t ch = 0; ch < num_channels; ch++) { buf.push_back(samples[i + ch]); } } @@ -75,7 +75,7 @@ public: queue.Push(samples); } - size_t SamplesInQueue(u32 num_channels) const override { + std::size_t SamplesInQueue(u32 num_channels) const override { if (!ctx) return 0; @@ -159,15 +159,16 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const return {}; } - const size_t num_channels = impl->GetNumChannels(); - const size_t samples_to_write = num_channels * num_frames; - size_t samples_written; + const std::size_t num_channels = impl->GetNumChannels(); + const std::size_t samples_to_write = num_channels * num_frames; + std::size_t samples_written; if (Settings::values.enable_audio_stretching) { const std::vector<s16> in{impl->queue.Pop()}; - const size_t num_in{in.size() / num_channels}; + const std::size_t num_in{in.size() / num_channels}; s16* const out{reinterpret_cast<s16*>(buffer)}; - const size_t out_frames = impl->time_stretch.Process(in.data(), num_in, out, num_frames); + const std::size_t out_frames = + impl->time_stretch.Process(in.data(), num_in, out, num_frames); samples_written = out_frames * num_channels; if (impl->should_flush) { @@ -184,7 +185,7 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const } // Fill the rest of the frames with last_frame - for (size_t i = samples_written; i < samples_to_write; i += num_channels) { + for (std::size_t i = samples_written; i < samples_to_write; i += num_channels) { std::memcpy(buffer + i * sizeof(s16), &impl->last_frame[0], num_channels * sizeof(s16)); } @@ -206,7 +207,7 @@ std::vector<std::string> ListCubebSinkDevices() { if (cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_OUTPUT, &collection) != CUBEB_OK) { LOG_WARNING(Audio_Sink, "Audio output device enumeration not supported"); } else { - for (size_t i = 0; i < collection.count; i++) { + for (std::size_t i = 0; i < collection.count; i++) { const cubeb_device_info& device = collection.device[i]; if (device.friendly_name) { device_list.emplace_back(device.friendly_name); diff --git a/src/audio_core/null_sink.h b/src/audio_core/null_sink.h index 2ed0c83b6..a78d78893 100644 --- a/src/audio_core/null_sink.h +++ b/src/audio_core/null_sink.h @@ -22,7 +22,7 @@ private: struct NullSinkStreamImpl final : SinkStream { void EnqueueSamples(u32 /*num_channels*/, const std::vector<s16>& /*samples*/) override {} - size_t SamplesInQueue(u32 /*num_channels*/) const override { + std::size_t SamplesInQueue(u32 /*num_channels*/) const override { return 0; } diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 84dcdd98d..386f2ec66 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -17,7 +17,7 @@ namespace AudioCore { -constexpr size_t MaxAudioBufferCount{32}; +constexpr std::size_t MaxAudioBufferCount{32}; u32 Stream::GetNumChannels() const { switch (format) { @@ -52,7 +52,7 @@ void Stream::Stop() { } s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const { - const size_t num_samples{buffer.GetSamples().size() / GetNumChannels()}; + const std::size_t num_samples{buffer.GetSamples().size() / GetNumChannels()}; return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate); } @@ -122,9 +122,9 @@ bool Stream::ContainsBuffer(Buffer::Tag tag) const { return {}; } -std::vector<Buffer::Tag> Stream::GetTagsAndReleaseBuffers(size_t max_count) { +std::vector<Buffer::Tag> Stream::GetTagsAndReleaseBuffers(std::size_t max_count) { std::vector<Buffer::Tag> tags; - for (size_t count = 0; count < max_count && !released_buffers.empty(); ++count) { + for (std::size_t count = 0; count < max_count && !released_buffers.empty(); ++count) { tags.push_back(released_buffers.front()->GetTag()); released_buffers.pop(); } diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h index 049b92ca9..3a435982d 100644 --- a/src/audio_core/stream.h +++ b/src/audio_core/stream.h @@ -49,7 +49,7 @@ public: bool ContainsBuffer(Buffer::Tag tag) const; /// Returns a vector of recently released buffers specified by tag - std::vector<Buffer::Tag> GetTagsAndReleaseBuffers(size_t max_count); + std::vector<Buffer::Tag> GetTagsAndReleaseBuffers(std::size_t max_count); /// Returns true if the stream is currently playing bool IsPlaying() const { @@ -57,7 +57,7 @@ public: } /// Returns the number of queued buffers - size_t GetQueueSize() const { + std::size_t GetQueueSize() const { return queued_buffers.size(); } diff --git a/src/audio_core/time_stretch.cpp b/src/audio_core/time_stretch.cpp index da094c46b..5da35e74e 100644 --- a/src/audio_core/time_stretch.cpp +++ b/src/audio_core/time_stretch.cpp @@ -26,7 +26,8 @@ void TimeStretcher::Flush() { m_sound_touch.flush(); } -size_t TimeStretcher::Process(const s16* in, size_t num_in, s16* out, size_t num_out) { +std::size_t TimeStretcher::Process(const s16* in, std::size_t num_in, s16* out, + std::size_t num_out) { const double time_delta = static_cast<double>(num_out) / m_sample_rate; // seconds // We were given actual_samples number of samples, and num_samples were requested from us. diff --git a/src/audio_core/time_stretch.h b/src/audio_core/time_stretch.h index 7e39e695e..c2286fba1 100644 --- a/src/audio_core/time_stretch.h +++ b/src/audio_core/time_stretch.h @@ -20,7 +20,7 @@ public: /// @param out Output sample buffer /// @param num_out Desired number of output frames in `out` /// @returns Actual number of frames written to `out` - size_t Process(const s16* in, size_t num_in, s16* out, size_t num_out); + std::size_t Process(const s16* in, std::size_t num_in, s16* out, std::size_t num_out); void Clear(); |