Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy of audio api #63

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
}
9 changes: 2 additions & 7 deletions libraries/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/picosystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down