Mozzi  version 2015-05-11-20:23
sound synthesis library for Arduino
 All Classes Functions Typedefs Groups
MozziGuts.h
1 /*
2  * MozziGuts.h
3  *
4  * Copyright 2012 Tim Barrass.
5  *
6  * This file is part of Mozzi.
7  *
8  * Mozzi by Tim Barrass is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
9  *
10  */
11 
12 #ifndef MOZZIGUTS_H_
13 #define MOZZIGUTS_H_
14 
15 //#define F_CPU 8000000 // testing
16 
17 #if ARDUINO >= 100
18  #include "Arduino.h"
19 #else
20  #include "WProgram.h"
21 #endif
22 
23 #include "mozzi_analog.h"
24 
36 #define CONTROL_RATE 64
37 
38 
39 
138 //enum audio_modes {STANDARD,STANDARD_PLUS,HIFI};
139 #define STANDARD 0
140 #define STANDARD_PLUS 1
141 #define HIFI 2
142 
143 
144 #include "mozzi_config.h" // User can change the config file to set audio mode
145 
146 
147 // Print warning/reminder about the AUDIO_MODE setting to the arduino console while compiling
148 #if AUDIO_MODE == STANDARD
149 #warning "AUDIO_MODE is set to STANDARD in mozzi_config.h. If things sound wrong, check if STANDARD is the correct AUDIO_MODE for your sketch."
150 #elif AUDIO_MODE == STANDARD_PLUS
151 #warning "AUDIO_MODE is set to STANDARD_PLUS in mozzi_config.h. If things sound wrong, check if STANDARD_PLUS is the correct AUDIO_MODE for your sketch."
152 #elif AUDIO_MODE == HIFI
153 #warning "AUDIO_MODE is set to HIFI in mozzi_config.h. If things sound wrong, check if HIFI is the correct AUDIO_MODE for your sketch."
154 #endif
155 
156 #if (AUDIO_MODE == STANDARD) && (AUDIO_RATE == 32768)
157 #error AUDIO_RATE 32768 does not work when AUDIO_MODE is STANDARD, try setting the AUDIO_MODE to STANDARD_PLUS in Mozzi/mozzi_config.h
158 #endif
159 
160 
161 #define CLOCK_TICKS_PER_AUDIO_TICK (F_CPU / AUDIO_RATE)
162 
163 
164 #if AUDIO_RATE == 16384
165 #define AUDIO_RATE_AS_LSHIFT 14
166 #define MICROS_PER_AUDIO_TICK 61 // 1000000 / 16384 = 61.035, ...* 256 = 15625
167 #elif AUDIO_RATE == 32768
168 #define AUDIO_RATE_AS_LSHIFT 15
169 #define MICROS_PER_AUDIO_TICK 31 // = 1000000 / 32768 = 30.518, ...* 256 = 7812.6
170 #endif
171 
172 
173 #if defined(__MK20DX128__) || defined(__MK20DX256__) // Teensy 3
174 #include "AudioConfigTeensy3_12bit.h"
175 #else
176 #if (AUDIO_MODE == STANDARD)
177 #include "AudioConfigStandard9bitPwm.h"
178 #elif (AUDIO_MODE == STANDARD_PLUS)
179 #include "AudioConfigStandardPlus.h"
180 #elif (AUDIO_MODE == HIFI)
181 #include "AudioConfigHiSpeed14bitPwm.h"
182 #endif
183 
184 #endif
185 
186 // common numeric types
187 typedef unsigned char uchar;
188 typedef unsigned int uint;
189 typedef unsigned long ulong;
190 
191 #if defined(__MK20DX128__) || defined(__MK20DX256__) // teensy 3, 3.1
192 //typedef uint8_t byte;//unsigned char;
193 //typedef int8_t char;
194 //typedef (uint16_t) (short unsigned int);
195 //typedef int16_t int;
196 //typedef (uint32_t) (unsigned long);
197 //typedef int32_t long;
198 #else
199 typedef unsigned char uint8_t;
200 typedef signed char int8_t;
201 typedef unsigned int uint16_t;
202 typedef signed int int16_t;
203 typedef unsigned long uint32_t;
204 typedef signed long int32_t;
205 #endif
206 
207 
233 void startMozzi(int control_rate_hz = CONTROL_RATE);
234 
235 
236 
253 void pauseMozzi();
254 
255 
256 
263 void unPauseMozzi();
264 
272 int updateAudio();
273 
274 
281 void updateControl();
282 
283 
297 void audioHook();
298 
299 
300 
316 #if (USE_AUDIO_INPUT == true)
317 int getAudioInput();
318 #endif
319 
320 
328 unsigned long audioTicks();
329 
330 
331 
340 unsigned long mozziMicros();
341 
342 
343 
344 
345 // internal use
346 #if (AUDIO_MODE == HIFI)
347 static void setupTimer2();
348 #endif
349 
350 
351 #endif /* MOZZIGUTS_H_ */
#define CONTROL_RATE
Control rate setting.
Definition: MozziGuts.h:36
unsigned long mozziMicros()
A replacement for Arduino micros() which is disabled by Mozzi which takes over Timer 0 for control in...
Definition: MozziGuts.cpp:617
void updateControl()
This is where you put your control code.
void audioHook()
This is required in Arduino's loop().
Definition: MozziGuts.cpp:223
void unPauseMozzi()
Restores Mozzi audio and control interrupts, if they have been temporarily disabled with pauseMozzi()...
Definition: MozziGuts.cpp:571
unsigned long audioTicks()
An alternative for Arduino time funcitions like micros() which are disabled by Mozzi when it takes ov...
Definition: MozziGuts.cpp:611
void pauseMozzi()
Stops audio and control interrupts and restores the timers to the values they had before Mozzi was st...
Definition: MozziGuts.cpp:532
int getAudioInput()
This returns audio input from the input buffer, if #define USE_AUDIO_INPUT true is in the Mozzi/mozzi...
Definition: MozziGuts.cpp:142
int updateAudio()
This is where you put your audio code.
void startMozzi(int control_rate_hz=CONTROL_RATE)
Sets up the timers for audio and control rate processes, storing the timer registers so they can be r...
Definition: MozziGuts.cpp:519