Skip to content

Commit

Permalink
audition toggles playback
Browse files Browse the repository at this point in the history
  • Loading branch information
marchingband committed Feb 2, 2022
1 parent a92f700 commit 089663b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ char* on_rpc_in(cJSON *json)
uint8_t voice = cJSON_GetObjectItemCaseSensitive(json, "voice")->valueint;
uint8_t note = cJSON_GetObjectItemCaseSensitive(json, "note")->valueint;
uint8_t velocity = cJSON_GetObjectItemCaseSensitive(json, "velocity")->valueint;
play_wav(voice, note, velocity);
toggle_wav(voice, note, velocity);
char * res = "started wav";
return(res);
break;
Expand Down
24 changes: 24 additions & 0 deletions src/wav_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ int16_t IRAM_ATTR scale_sample_clamped_16(int in, uint8_t volume)
return (int16_t)(out * lin_float_lut[volume].val);
}

bool is_playing(uint8_t voice, uint8_t note)
{
for(int i=0;i<NUM_BUFFERS;i++)
{
if((bufs[i].free == false) && (bufs[i].wav_player_event.voice == voice) && (bufs[i].wav_player_event.note == note))
{
return true;
}
}
return false;
}

void stop_wav(uint8_t voice, uint8_t note)
{
struct wav_player_event_t wav_player_event;
Expand All @@ -256,6 +268,18 @@ void play_wav(uint8_t voice, uint8_t note, uint8_t velocity)
xQueueSendToBack(wav_player_queue, &wav_player_event, portMAX_DELAY);
}

void toggle_wav(uint8_t voice, uint8_t note, uint8_t velocity)
{
if(is_playing(voice, note))
{
stop_wav(voice, note);
}
else
{
play_wav(voice, note, velocity);
}
}

int prune(uint8_t priority)
{
int candidate = -1;
Expand Down

0 comments on commit 089663b

Please sign in to comment.