From f9ee8a462e2911c8b33f5eb7028c0894d635a58b Mon Sep 17 00:00:00 2001 From: Jonathan Williamson Date: Tue, 2 Nov 2021 06:14:39 +0000 Subject: [PATCH] tidy of audio api --- examples/audio/audio.cpp | 4 ++-- libraries/audio.cpp | 9 ++------- libraries/picosystem.hpp | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/examples/audio/audio.cpp b/examples/audio/audio.cpp index 5eb46d7..3645deb 100644 --- a/examples/audio/audio.cpp +++ b/examples/audio/audio.cpp @@ -103,7 +103,7 @@ void update(uint32_t tick) { // if the current sound has finished playing, or we changed a dial value // then restart the sound uint32_t full_duration = get_dial_value("duration") + get_dial_value("release") + get_dial_value("reverb"); - if(change || audio_position() > full_duration) { + if(change || position() > full_duration) { set_voice(); } } @@ -188,6 +188,6 @@ void draw(uint32_t tick) { // draw current playback marker pen(0, 15, 15); - uint32_t pos = (audio_position() * 230) / full_duration; + uint32_t pos = (position() * 230) / full_duration; frect(pos + 5, 5, 2, 50); } \ No newline at end of file diff --git a/libraries/audio.cpp b/libraries/audio.cpp index c0d4b1b..40f87f9 100644 --- a/libraries/audio.cpp +++ b/libraries/audio.cpp @@ -19,13 +19,8 @@ namespace picosystem { _ms = 0; } - uint32_t audio_position() { - return _ms; - } - - // Convenience function to tell if the note is still playing - bool audio_playing() { - return !(_ms > _duration + _voice.release + _voice.reverb); + int32_t position() { + return (_ms > _duration + _voice.release + _voice.reverb) ? -1 : _ms; } uint8_t audio_sample(uint32_t ms) { diff --git a/libraries/picosystem.hpp b/libraries/picosystem.hpp index d26aaa1..8478437 100644 --- a/libraries/picosystem.hpp +++ b/libraries/picosystem.hpp @@ -174,8 +174,8 @@ namespace picosystem { voice_t voice, uint32_t frequency, uint32_t duration = 500, uint32_t volume = 100); uint8_t audio_sample(uint32_t ms); - uint32_t audio_position(); - bool audio_playing(); + int32_t position(); + bool playing(); // utility std::string str(float v, uint8_t precision = 2);