rp2040/PWMAudioOut: Fix the click at start / stop of playback.
Signed-off-by: Andrew Leech <andrew@alelec.net>
This commit is contained in:
parent
9c066825a7
commit
dfcc56b14a
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "extmod/vfs_fat.h"
|
#include "extmod/vfs_fat.h"
|
||||||
#include "py/gc.h"
|
#include "py/gc.h"
|
||||||
|
#include "py/mphal.h"
|
||||||
#include "py/mperrno.h"
|
#include "py/mperrno.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "shared-bindings/pwmio/PWMOut.h"
|
#include "shared-bindings/pwmio/PWMOut.h"
|
||||||
@ -153,14 +154,24 @@ void common_hal_audiopwmio_pwmaudioout_construct(audiopwmio_pwmaudioout_obj_t *s
|
|||||||
mp_raise_RuntimeError(translate("All timers in use"));
|
mp_raise_RuntimeError(translate("All timers in use"));
|
||||||
}
|
}
|
||||||
|
|
||||||
self->quiescent_value = quiescent_value >> SAMPLE_BITS_TO_DISCARD;
|
self->quiescent_value = quiescent_value;
|
||||||
common_hal_pwmio_pwmout_set_duty_cycle(&self->left_pwm, self->quiescent_value);
|
|
||||||
pwmio_pwmout_set_top(&self->left_pwm, PWM_TOP);
|
pwmio_pwmout_set_top(&self->left_pwm, PWM_TOP);
|
||||||
if (self->stereo) {
|
if (self->stereo) {
|
||||||
common_hal_pwmio_pwmout_set_duty_cycle(&self->right_pwm, self->quiescent_value);
|
|
||||||
pwmio_pwmout_set_top(&self->right_pwm, PWM_TOP);
|
pwmio_pwmout_set_top(&self->right_pwm, PWM_TOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ramp the PWM from zero to the quiescent value
|
||||||
|
uint16_t incr = 0;
|
||||||
|
for (int i = 0; i < 256; i++) {
|
||||||
|
incr += self->quiescent_value / 256;
|
||||||
|
|
||||||
|
mp_hal_delay_ms(2);
|
||||||
|
common_hal_pwmio_pwmout_set_duty_cycle(&self->left_pwm, incr);
|
||||||
|
if (self->stereo) {
|
||||||
|
common_hal_pwmio_pwmout_set_duty_cycle(&self->right_pwm, incr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
audio_dma_init(&self->dma);
|
audio_dma_init(&self->dma);
|
||||||
self->pacing_timer = NUM_DMA_TIMERS;
|
self->pacing_timer = NUM_DMA_TIMERS;
|
||||||
}
|
}
|
||||||
@ -254,14 +265,6 @@ void common_hal_audiopwmio_pwmaudioout_stop(audiopwmio_pwmaudioout_obj_t *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
audio_dma_stop(&self->dma);
|
audio_dma_stop(&self->dma);
|
||||||
|
|
||||||
// Set to quiescent level.
|
|
||||||
common_hal_pwmio_pwmout_set_duty_cycle(&self->left_pwm, self->quiescent_value);
|
|
||||||
pwmio_pwmout_set_top(&self->left_pwm, PWM_TOP);
|
|
||||||
if (self->stereo) {
|
|
||||||
common_hal_pwmio_pwmout_set_duty_cycle(&self->right_pwm, self->quiescent_value);
|
|
||||||
pwmio_pwmout_set_top(&self->right_pwm, PWM_TOP);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_audiopwmio_pwmaudioout_get_playing(audiopwmio_pwmaudioout_obj_t *self) {
|
bool common_hal_audiopwmio_pwmaudioout_get_playing(audiopwmio_pwmaudioout_obj_t *self) {
|
||||||
|
Loading…
Reference in New Issue
Block a user