Skip to content

Commit

Permalink
unintended binary recursion is bad (#751)
Browse files Browse the repository at this point in the history
* mute speaker while volume is 0

* run mute detection when volume is still 0-64

* better logs, use existing bool

* fixup last commit

* unintended binary recursion is bad

* ready fire aim

* wait for audio playback before reconnecting

* pass it in
  • Loading branch information
plasticchris authored Apr 5, 2017
1 parent 9ef4265 commit 6a28afa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
17 changes: 15 additions & 2 deletions kitsune/hlo_audio_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ uint32_t _next_keepalive_interval(uint32_t base, uint32_t range){
}
return base + (rand() % KEEPALIVE_INTERVAL_RANGE);
}

void _give_playback_sem(void * context) {

DISP("\r\giving\r\n");
xSemaphoreGive(*(xSemaphoreHandle*)context);
}
int hlo_filter_voice_command(hlo_stream_t * input, hlo_stream_t * output, void * ctx, hlo_stream_signal signal){
#define NSAMPLES 512
int ret = 0;
Expand Down Expand Up @@ -522,11 +528,13 @@ int hlo_filter_voice_command(hlo_stream_t * input, hlo_stream_t * output, void *
output = hlo_stream_bw_limited( output, 1, 5000);
output = hlo_light_stream( output, false );

xSemaphoreHandle playback_sem = xSemaphoreCreateBinary();

AudioPlaybackDesc_t desc;
desc.context = NULL;
desc.context = &playback_sem;
desc.durationInSeconds = INT32_MAX;
desc.to_fade_out_ms = desc.fade_in_ms = desc.fade_out_ms = 0;
desc.onFinished = NULL;
desc.onFinished = _give_playback_sem;
desc.rate = AUDIO_SAMPLE_RATE;
desc.stream = output;
desc.volume = sys_volume;
Expand All @@ -535,6 +543,11 @@ int hlo_filter_voice_command(hlo_stream_t * input, hlo_stream_t * output, void *
AudioTask_StartPlayback(&desc);

LOGI("\r\n===========\r\n");
xSemaphoreTake(playback_sem, 60*1000);

DISP("\r\ndeleting\r\n");
vSemaphoreDelete(playback_sem);
LOGI("\r\n===========\r\n");
}
}

Expand Down
34 changes: 19 additions & 15 deletions kitsune/i2c_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,23 +691,10 @@ int32_t set_system_volume(int new_volume) {
volatile int last_set_volume = 0;
static bool codec_muted = true;

int32_t set_volume(int v, unsigned int dly) {
LOGI("v %d\n", v);
last_set_volume = v;

static _set_volume_raw(int v, unsigned int dly) {
char send_stop = 1;
unsigned char cmd[2];

if(v < 0) v = 0;
if(v >64) v = 64;

if( v == 0 && !codec_muted ) {
codec_mute_spkr();
}
if( v != 0 && codec_muted ) {
codec_unmute_spkr();
}

v = 64-v;
v <<= 10;
v /= 560;
Expand All @@ -727,6 +714,23 @@ int32_t set_volume(int v, unsigned int dly) {
} else {
return -1;
}
}

int32_t set_volume(int v, unsigned int dly) {
LOGI("v %d\n", v);
last_set_volume = v;

if(v < 0) v = 0;
if(v >64) v = 64;

if( v == 0 && !codec_muted ) {
codec_mute_spkr();
}
if( v != 0 && codec_muted ) {
codec_unmute_spkr();
}

_set_volume_raw(v,dly);

}

Expand Down Expand Up @@ -957,7 +961,7 @@ void codec_unmute_spkr(void)

LOGI("codec: unmuting\n");

set_volume(0, portMAX_DELAY);
_set_volume_raw(0, portMAX_DELAY);

codec_set_book(0);

Expand Down

0 comments on commit 6a28afa

Please sign in to comment.