mirror of
https://github.com/firewalkwithm3/qmk_firmware.git
synced 2024-11-22 11:30:30 +08:00
Reduce popping during audio initialization using the additive DAC (#21642)
This commit is contained in:
parent
1d94de5358
commit
2f4e1a78ad
|
@ -84,7 +84,7 @@ static const dacsample_t dac_buffer_trapezoid[AUDIO_DAC_BUFFER_SIZE] = {0x0, 0
|
||||||
0xfff, 0xfdf, 0xf7f, 0xf1f, 0xebf, 0xe5f, 0xdff, 0xd9f, 0xd3f, 0xcdf, 0xc7f, 0xc1f, 0xbbf, 0xb5f, 0xaff, 0xa9f, 0xa3f, 0x9df, 0x97f, 0x91f, 0x8bf, 0x85f, 0x7ff, 0x79f, 0x73f, 0x6df, 0x67f, 0x61f, 0x5bf, 0x55f, 0x4ff, 0x49f, 0x43f, 0x3df, 0x37f, 0x31f, 0x2bf, 0x25f, 0x1ff, 0x19f, 0x13f, 0xdf, 0x7f, 0x1f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
0xfff, 0xfdf, 0xf7f, 0xf1f, 0xebf, 0xe5f, 0xdff, 0xd9f, 0xd3f, 0xcdf, 0xc7f, 0xc1f, 0xbbf, 0xb5f, 0xaff, 0xa9f, 0xa3f, 0x9df, 0x97f, 0x91f, 0x8bf, 0x85f, 0x7ff, 0x79f, 0x73f, 0x6df, 0x67f, 0x61f, 0x5bf, 0x55f, 0x4ff, 0x49f, 0x43f, 0x3df, 0x37f, 0x31f, 0x2bf, 0x25f, 0x1ff, 0x19f, 0x13f, 0xdf, 0x7f, 0x1f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||||
#endif // AUDIO_DAC_SAMPLE_WAVEFORM_TRAPEZOID
|
#endif // AUDIO_DAC_SAMPLE_WAVEFORM_TRAPEZOID
|
||||||
|
|
||||||
static dacsample_t dac_buffer_empty[AUDIO_DAC_BUFFER_SIZE] = {AUDIO_DAC_OFF_VALUE};
|
static dacsample_t dac_buffer[AUDIO_DAC_BUFFER_SIZE];
|
||||||
|
|
||||||
/* keep track of the sample position for for each frequency */
|
/* keep track of the sample position for for each frequency */
|
||||||
static float dac_if[AUDIO_MAX_SIMULTANEOUS_TONES] = {0.0};
|
static float dac_if[AUDIO_MAX_SIMULTANEOUS_TONES] = {0.0};
|
||||||
|
@ -311,10 +311,17 @@ void audio_driver_initialize(void) {
|
||||||
DACD1.params->dac->CR &= ~DAC_CR_BOFF1;
|
DACD1.params->dac->CR &= ~DAC_CR_BOFF1;
|
||||||
DACD2.params->dac->CR &= ~DAC_CR_BOFF2;
|
DACD2.params->dac->CR &= ~DAC_CR_BOFF2;
|
||||||
|
|
||||||
|
/* Start the DAC output with all off values. This buffer will then get fed
|
||||||
|
* with samples from dac_end, which will play notes.
|
||||||
|
*/
|
||||||
|
for (size_t i = 0; i < AUDIO_DAC_BUFFER_SIZE; i++) {
|
||||||
|
dac_buffer[i] = AUDIO_DAC_OFF_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (AUDIO_PIN == A4) {
|
if (AUDIO_PIN == A4) {
|
||||||
dacStartConversion(&DACD1, &dac_conv_cfg, dac_buffer_empty, AUDIO_DAC_BUFFER_SIZE);
|
dacStartConversion(&DACD1, &dac_conv_cfg, dac_buffer, AUDIO_DAC_BUFFER_SIZE);
|
||||||
} else if (AUDIO_PIN == A5) {
|
} else if (AUDIO_PIN == A5) {
|
||||||
dacStartConversion(&DACD2, &dac_conv_cfg, dac_buffer_empty, AUDIO_DAC_BUFFER_SIZE);
|
dacStartConversion(&DACD2, &dac_conv_cfg, dac_buffer, AUDIO_DAC_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// no inverted/out-of-phase waveform (yet?), only pulling AUDIO_PIN_ALT to AUDIO_DAC_OFF_VALUE
|
// no inverted/out-of-phase waveform (yet?), only pulling AUDIO_PIN_ALT to AUDIO_DAC_OFF_VALUE
|
||||||
|
|
Loading…
Reference in a new issue