summaryrefslogtreecommitdiff
path: root/src/audio/audio_fsm.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-09-04 16:17:55 +1000
committerjacqueline <me@jacqueline.id.au>2023-09-04 16:17:55 +1000
commitd5d6e3993cd67238ff245446e69e2f200c3fd0e5 (patch)
tree6245939ab341694363eac8bc24ab1b91b5140c6e /src/audio/audio_fsm.cpp
parent6d831fa7a8c50e15424814fd2be1dd3951e06a4f (diff)
downloadtangara-fw-d5d6e3993cd67238ff245446e69e2f200c3fd0e5.tar.gz
Support changing max volume, persisted to nvs
Diffstat (limited to 'src/audio/audio_fsm.cpp')
-rw-r--r--src/audio/audio_fsm.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp
index 9121cb5a..f5ce2957 100644
--- a/src/audio/audio_fsm.cpp
+++ b/src/audio/audio_fsm.cpp
@@ -5,6 +5,7 @@
*/
#include "audio_fsm.hpp"
+#include <stdint.h>
#include <future>
#include <memory>
@@ -29,6 +30,7 @@
#include "system_events.hpp"
#include "track.hpp"
#include "track_queue.hpp"
+#include "wm8523.hpp"
namespace audio {
@@ -39,6 +41,7 @@ std::shared_ptr<system_fsm::ServiceLocator> AudioState::sServices;
std::shared_ptr<FatfsAudioInput> AudioState::sFileSource;
std::unique_ptr<Decoder> AudioState::sDecoder;
std::shared_ptr<SampleConverter> AudioState::sSampleConverter;
+std::shared_ptr<I2SAudioOutput> AudioState::sI2SOutput;
std::shared_ptr<IAudioOutput> AudioState::sOutput;
std::optional<database::TrackId> AudioState::sCurrentTrack;
@@ -65,6 +68,13 @@ void AudioState::react(const system_fsm::HasPhonesChanged& ev) {
}
}
+void AudioState::react(const ChangeMaxVolume& ev) {
+ ESP_LOGI(kTag, "new max volume %u db",
+ (ev.new_max - drivers::wm8523::kLineLevelReferenceVolume) / 4);
+ sI2SOutput->SetMaxVolume(ev.new_max);
+ sServices->nvs().AmpMaxVolume(ev.new_max);
+}
+
namespace states {
void Uninitialised::react(const system_fsm::BootComplete& ev) {
@@ -78,8 +88,14 @@ void Uninitialised::react(const system_fsm::BootComplete& ev) {
}
sFileSource.reset(new FatfsAudioInput(sServices->tag_parser()));
- sOutput.reset(new I2SAudioOutput(sServices->gpios(),
- std::unique_ptr<drivers::I2SDac>{*dac}));
+ sI2SOutput.reset(new I2SAudioOutput(sServices->gpios(),
+ std::unique_ptr<drivers::I2SDac>{*dac}));
+
+ auto& nvs = sServices->nvs();
+ sI2SOutput->SetMaxVolume(nvs.AmpMaxVolume().get());
+ sI2SOutput->SetVolumeDb(nvs.AmpCurrentVolume().get());
+
+ sOutput = sI2SOutput;
// sOutput.reset(new BluetoothAudioOutput(bluetooth));
sSampleConverter.reset(new SampleConverter());