diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2024-04-02 04:19:50 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-04-02 04:19:50 +0000 |
| commit | b229f452a6a0c8e047e1e9c0c709953ed822c610 (patch) | |
| tree | 5814aa946a5e260a688831a028031e6613eecc2f /src/audio/i2s_audio_output.cpp | |
| parent | 0d0c4b2307cac8436fea7276956f293262b265ed (diff) | |
| parent | 25dca40e5dab82c5a814233813c24180fcf975eb (diff) | |
| download | tangara-fw-b229f452a6a0c8e047e1e9c0c709953ed822c610.tar.gz | |
Merge pull request 'lua-volume' (#60) from lua-volume into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/60
Reviewed-by: cooljqln <cooljqln@noreply.codeberg.org>
Diffstat (limited to 'src/audio/i2s_audio_output.cpp')
| -rw-r--r-- | src/audio/i2s_audio_output.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/audio/i2s_audio_output.cpp b/src/audio/i2s_audio_output.cpp index 3fb99159..2a251685 100644 --- a/src/audio/i2s_audio_output.cpp +++ b/src/audio/i2s_audio_output.cpp @@ -111,6 +111,15 @@ auto I2SAudioOutput::GetVolumePct() -> uint_fast8_t { return (current_volume_ - kMinVolume) * 100 / (max_volume_ - kMinVolume); } +auto I2SAudioOutput::SetVolumePct(uint_fast8_t val) -> bool { + if (val > 100) { + return false; + } + uint16_t vol = (val * (max_volume_ - kMinVolume))/100 + kMinVolume; + SetVolume(vol); + return true; +} + auto I2SAudioOutput::GetVolumeDb() -> int_fast16_t { // Add two before dividing in order to round correctly. return (static_cast<int>(current_volume_) - @@ -118,6 +127,11 @@ auto I2SAudioOutput::GetVolumeDb() -> int_fast16_t { 4; } +auto I2SAudioOutput::SetVolumeDb(int_fast16_t val) -> bool { + SetVolume(val * 4 + static_cast<int>(drivers::wm8523::kLineLevelReferenceVolume) - 2); + return true; +} + auto I2SAudioOutput::AdjustVolumeUp() -> bool { if (GetVolume() >= max_volume_) { return false; |
