diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 645036ce..7607cc44 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2021,10 +2021,11 @@ void pwm_interrupt_handler() { // based on code https://github.com/rgrosset/pico-pwm-audio // pwm_clear_irq(pwm_gpio_to_slice_num(AUDIO_OUT_PIN)); - if (wav_position < (WAV_DATA_LENGTH<<3) - 1) { +// if (wav_position < (WAV_DATA_LENGTH<<3) - 1) { + if (wav_position > (buffer_size - 1)) { // set pwm level // allow the pwm value to repeat for 8 cycles this is >>3 - pwm_set_gpio_level(AUDIO_OUT_PIN, buffer[wav_position>>3]); + pwm_set_gpio_level(AUDIO_OUT_PIN, buffer[wav_position]); wav_position++; } else { // reset to start