diff options
| author | 2018-07-30 23:57:53 -0400 | |
|---|---|---|
| committer | 2018-07-31 22:38:42 -0400 | |
| commit | ca84b530a376e826c1a90d7c7e402d4a3bce00b7 (patch) | |
| tree | 3febdf01f6402c88f0372d2c2644601108734031 /src/audio_core/stream.cpp | |
| parent | Merge pull request #876 from lioncash/include (diff) | |
| download | yuzu-ca84b530a376e826c1a90d7c7e402d4a3bce00b7.tar.gz yuzu-ca84b530a376e826c1a90d7c7e402d4a3bce00b7.tar.xz yuzu-ca84b530a376e826c1a90d7c7e402d4a3bce00b7.zip | |
audio_core: Add configuration settings.
Diffstat (limited to 'src/audio_core/stream.cpp')
| -rw-r--r-- | src/audio_core/stream.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 689f51a1d..a0045b7a1 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp | |||
| @@ -2,14 +2,17 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/assert.h" | 5 | #include <algorithm> |
| 6 | #include "common/logging/log.h" | 6 | #include <cmath> |
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/core_timing_util.h" | ||
| 9 | 7 | ||
| 10 | #include "audio_core/sink.h" | 8 | #include "audio_core/sink.h" |
| 11 | #include "audio_core/sink_details.h" | 9 | #include "audio_core/sink_details.h" |
| 12 | #include "audio_core/stream.h" | 10 | #include "audio_core/stream.h" |
| 11 | #include "common/assert.h" | ||
| 12 | #include "common/logging/log.h" | ||
| 13 | #include "core/core_timing.h" | ||
| 14 | #include "core/core_timing_util.h" | ||
| 15 | #include "core/settings.h" | ||
| 13 | 16 | ||
| 14 | namespace AudioCore { | 17 | namespace AudioCore { |
| 15 | 18 | ||
| @@ -56,6 +59,24 @@ s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const { | |||
| 56 | return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate); | 59 | return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate); |
| 57 | } | 60 | } |
| 58 | 61 | ||
| 62 | static std::vector<s16> GetVolumeAdjustedSamples(const std::vector<u8>& data) { | ||
| 63 | std::vector<s16> samples(data.size() / sizeof(s16)); | ||
| 64 | std::memcpy(samples.data(), data.data(), data.size()); | ||
| 65 | const float volume{std::clamp(Settings::values.volume, 0.0f, 1.0f)}; | ||
| 66 | |||
| 67 | if (volume == 1.0f) { | ||
| 68 | return samples; | ||
| 69 | } | ||
| 70 | |||
| 71 | // Implementation of a volume slider with a dynamic range of 60 dB | ||
| 72 | const float volume_scale_factor{std::exp(6.90775f * volume) * 0.001f}; | ||
| 73 | for (auto& sample : samples) { | ||
| 74 | sample = static_cast<s16>(sample * volume_scale_factor); | ||
| 75 | } | ||
| 76 | |||
| 77 | return samples; | ||
| 78 | } | ||
| 79 | |||
| 59 | void Stream::PlayNextBuffer() { | 80 | void Stream::PlayNextBuffer() { |
| 60 | if (!IsPlaying()) { | 81 | if (!IsPlaying()) { |
| 61 | // Ensure we are in playing state before playing the next buffer | 82 | // Ensure we are in playing state before playing the next buffer |
| @@ -75,9 +96,9 @@ void Stream::PlayNextBuffer() { | |||
| 75 | active_buffer = queued_buffers.front(); | 96 | active_buffer = queued_buffers.front(); |
| 76 | queued_buffers.pop(); | 97 | queued_buffers.pop(); |
| 77 | 98 | ||
| 78 | sink_stream.EnqueueSamples(GetNumChannels(), | 99 | const size_t sample_count{active_buffer->GetData().size() / GetSampleSize()}; |
| 79 | reinterpret_cast<const s16*>(active_buffer->GetData().data()), | 100 | sink_stream.EnqueueSamples( |
| 80 | active_buffer->GetData().size() / GetSampleSize()); | 101 | GetNumChannels(), GetVolumeAdjustedSamples(active_buffer->GetData()).data(), sample_count); |
| 81 | 102 | ||
| 82 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); | 103 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); |
| 83 | } | 104 | } |