13 # error "Wrong implementation included for this platform"
22 #if MOZZI_IS(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_STANDARD)
23 #define MOZZI__LEGACY_AUDIO_INPUT_IMPL 0
26 #include <Arduino_AdvancedAnalog.h>
33 bool audioInputAvailable() {
34 if (inbufpos >= CHUNKSIZE) {
35 if (!adc.available())
return false;
36 SampleBuffer buf = adc.read();
37 memcpy(inbuf,buf.data(), CHUNKSIZE*
sizeof(
Sample));
44 AudioOutputStorage_t readAudioInput(){
45 return inbuf[inbufpos++];
49 static void startAudioInput() {
50 if (!adc.begin(AN_RESOLUTION_12,
MOZZI_AUDIO_RATE, CHUNKSIZE, 256/CHUNKSIZE)) {
51 Serial.println(
"Failed to start analog acquisition!");
56 static void startAudioInput() {};
59 #if MOZZI_IS(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_STANDARD)
60 #error not yet implemented
67 #define getADCReading() 0
82 uint8_t adcPinToChannelNum(uint8_t pin) {
87 void adcStartConversion(uint8_t channel) {
92 void startSecondADCReadOnCurrentChannel() {
97 void setupFastAnalogRead(int8_t speed) {
102 void setupMozziADC(int8_t speed) {
110 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED)
112 #define US_PER_AUDIO_TICK (1000000L / MOZZI_AUDIO_RATE)
116 mbed::Ticker audio_output_timer;
118 volatile bool audio_output_requested =
false;
119 inline void defaultAudioOutputCallback() {
120 audio_output_requested =
true;
123 #define AUDIO_HOOK_HOOK { if (audio_output_requested) { audio_output_requested = false; defaultAudioOutput(); } }
125 static void startAudio() {
126 audio_output_timer.attach_us(&defaultAudioOutputCallback, US_PER_AUDIO_TICK);
131 audio_output_timer.detach();
134 #elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC)
137 #include <Arduino_AdvancedAnalog.h>
142 #if (MOZZI_AUDIO_CHANNELS > 1)
143 AdvancedDAC dac2(MOZZI_AUDIO_PIN_2);
148 inline void commitBuffer(
Sample buffer[], AdvancedDAC &dac) {
149 SampleBuffer dmabuf = dac.dequeue();
151 for (
unsigned int i=0;i<CHUNKSIZE;i++) memcpy(dmabuf.data(), buffer, CHUNKSIZE*
sizeof(
Sample));
156 if (bufpos >= CHUNKSIZE) {
157 commitBuffer(buf1, dac1);
158 #if (MOZZI_AUDIO_CHANNELS > 1)
159 commitBuffer(buf2, dac2);
163 buf1[bufpos] = f.l()+MOZZI_AUDIO_BIAS;
164 #if (MOZZI_AUDIO_CHANNELS > 1)
165 buf2[bufpos] = f.r()+MOZZI_AUDIO_BIAS;
170 bool canBufferAudioOutput() {
171 return (bufpos < CHUNKSIZE || (dac1.available()
178 static void startAudio() {
180 if (!dac1.begin(AN_RESOLUTION_12,
MOZZI_AUDIO_RATE, CHUNKSIZE, 256/CHUNKSIZE)) {
181 Serial.println(
"Failed to start DAC1 !");
184 #if (MOZZI_AUDIO_CHANNELS > 1)
185 if (!dac2.begin(AN_RESOLUTION_12,
MOZZI_AUDIO_RATE, CHUNKSIZE, 256/CHUNKSIZE)) {
186 Serial.println(
"Failed to start DAC2 !");
195 #if (MOZZI_AUDIO_CHANNELS > 1)
200 #elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_SERIAL)
206 mbed::BufferedSerial serial_out1(digitalPinToPinName(MOZZI_SERIAL_PIN_TX), digitalPinToPinName(MOZZI_SERIAL_PIN_RX));
207 uint8_t buf[MOZZI_PDM_RESOLUTION*4];
209 bool canBufferAudioOutput() {
210 return serial_out1.writable();
214 for (uint8_t i = 0; i < MOZZI_PDM_RESOLUTION*4; ++i) {
215 buf[i] = pdmCode8(f.l()+MOZZI_AUDIO_BIAS);
217 serial_out1.write(&buf, MOZZI_PDM_RESOLUTION*4);
220 static void startAudio() {
222 serial_out1.set_format(8, mbed::BufferedSerial::None, 1);
226 #warning implement me
234 void MozziRandPrivate::autoSeed() {
235 #warning Automatic random seeding is not implemented on this platform
242 #undef US_PER_AUDIO_TICK
Sample is like Oscil, it plays a wavetable.
#define MOZZI_AUDIO_CHANNELS
This sets allows to change from a single/mono audio output channel to stereo output.
#define MOZZI_AUDIO_PIN_1
Only for MOZZI_AUDIO_MODE s MOZZI_OUTPUT_PWM and MOZZI_OUTPUT_2PIN_PWM: The IO pin to use as (first) ...
#define MOZZI_AUDIO_RATE
Defines the audio rate, i.e.
#define MOZZI_AUDIO_INPUT_PIN
This sets which analog input channel to use for audio input, if you have enabled MOZZI_AUDIO_INPUT,...
void stopMozzi()
Stops audio and control interrupts and restores the timers to the values they had before Mozzi was st...
This struct encapsulates one frame of mono audio output.