Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
The microphone uses the Analog to Digital Converter (ADC) Continuous Mode Driver.
The microphone code is based on the ADC DMA Example.
The microphone is continuously sampled at 8KHz.
You don't need to call initMic() or deinitMic(). The system does at the appropriate times.
The system will also automatically call startMic(), though the Swadge mode can later call stopMic() or startMic() when the microphone needs to be used. Stopping the microphone when not in use can save some processing cycles.
loopMic() is called automatically by the system while the microphone is started and samples are delivered to the Swadge mode through a callback, swadgeMode_t.fnAudioCallback. The Swadge mode can do what it wants with the samples from there.
If swadgeMode_t.fnAudioCallback is left NULL, then the microphone will not be initialized or sampled.
Go to the source code of this file.
Macros | |
#define | ADC_READ_LEN 512 |
The maximum number of bytes read by the ADC in one go. | |
#define | MAX_MIC_GAIN 7 |
#define | ADC_SAMPLE_RATE_HZ 8000 |
Functions | |
void | initMic (gpio_num_t gpio) |
Initialize the ADC which continuously samples the microphone. | |
void | startMic (void) |
Start sampling the microphone's ADC. | |
uint32_t | loopMic (uint16_t *outSamples, uint32_t outSamplesMax) |
Attempt to read a block of 12-bit samples from the ADC in continuous mode. This may return fewer than expected samples (or zero samples) if the task rate is faster than the sampling rate. | |
void | stopMic (void) |
Stop sampling the microphone's ADC. | |
void | deinitMic (void) |
Deinitialize the ADC which continuously samples the microphone. | |
#define ADC_READ_LEN 512 |
The maximum number of bytes read by the ADC in one go.
#define MAX_MIC_GAIN 7 |
#define ADC_SAMPLE_RATE_HZ 8000 |
void initMic | ( | gpio_num_t | gpio | ) |
Initialize the ADC which continuously samples the microphone.
This does not start sampling, so startMic() must be called afterwards.
gpio | The GPIO the microphone is attached to |
void startMic | ( | void | ) |
Start sampling the microphone's ADC.
uint32_t loopMic | ( | uint16_t * | outSamples, |
uint32_t | outSamplesMax ) |
Attempt to read a block of 12-bit samples from the ADC in continuous mode. This may return fewer than expected samples (or zero samples) if the task rate is faster than the sampling rate.
[out] | outSamples | A pointer to write 12-bit samples from the ADC |
[in] | outSamplesMax | The maximum number of samples that can be written to outSamples |
void stopMic | ( | void | ) |
Stop sampling the microphone's ADC.
void deinitMic | ( | void | ) |
Deinitialize the ADC which continuously samples the microphone.