1
0
Fork 0

dac_additive: Decouple the buffer length from the waveform length (#22276)

* dac_additive: Decouple the buffer length from the waveform length

* Formatting changes for the previous commit

* Reformat waveform tables with rows of 16 entries, ending at column 116

* Revert "Reformat waveform tables with rows of 16 entries, ending at column 116"

This reverts commit 6f2d37908d6e73e1505ce61e63190f32f051586f.
This commit is contained in:
Nebuleon 2023-12-12 14:06:56 -05:00 committed by GitHub
parent 02c5afc7d5
commit 229a1690a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 31 deletions

View file

@ -23,11 +23,6 @@
# define A5 PAL_LINE(GPIOA, 5)
#endif
/**
* Size of the dac_buffer arrays. All must be the same size.
*/
#define AUDIO_DAC_BUFFER_SIZE 256U
/**
* Highest value allowed sample value.
@ -96,6 +91,35 @@
# define AUDIO_DAC_SAMPLE_RATE 44100U
#endif
/**
* Size of the dac_buffer array. This controls the length of the runtime buffer
* which accumulates the data to be sent to the DAC every few milliseconds, and
* it does not need to correspond to the length of the wavetable for the chosen
* waveform defined by AUDIO_DAC_SAMPLE_WAVEFORM_* in the additive DAC driver.
* By default, this is set to be as close to 3.3 ms as possible, giving 300 DAC
* interrupts per second. Any smaller and the interrupt load gets too heavy and
* this results in crackling due to buffer underrun in the additive DAC driver;
* too large and the RAM (additive driver) or flash (basic driver) usage may be
* too high, causing build failures, and matrix scanning is liable to have long
* periodic pauses that delay key presses or releases or fully lose short taps.
* Large buffers also cause notes to take longer to stop after they should from
* music mode or MIDI input.
* This should be a power of 2 for maximum compatibility.
*/
#ifndef AUDIO_DAC_BUFFER_SIZE
# if AUDIO_DAC_SAMPLE_RATE < 5100U
# define AUDIO_DAC_BUFFER_SIZE 16U
# elif AUDIO_DAC_SAMPLE_RATE < 9900U
# define AUDIO_DAC_BUFFER_SIZE 32U
# elif AUDIO_DAC_SAMPLE_RATE < 19500U
# define AUDIO_DAC_BUFFER_SIZE 64U
# elif AUDIO_DAC_SAMPLE_RATE < 38700U
# define AUDIO_DAC_BUFFER_SIZE 128U
# else
# define AUDIO_DAC_BUFFER_SIZE 256U
# endif
#endif
/**
* The number of tones that can be played simultaneously. If too high a value
* is used here, the keyboard will freeze and glitch-out when that many tones