Mozzi  alpha 0.01.1t
sound synthesis library for Arduino
 All Classes Functions Typedefs
MozziGuts.h
00001 /*
00002  * MozziGuts.h
00003  *
00004  * Copyright 2012 Tim Barrass.
00005  *
00006  * This file is part of Mozzi.
00007  *
00008  * Mozzi is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Mozzi is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Mozzi.  If not, see <http://www.gnu.org/licenses/>.
00020  *
00021  */
00022 
00023 #ifndef MOZZIGUTS_H_
00024 #define MOZZIGUTS_H_
00025 
00026 #if F_CPU != 16000000
00027 #error Mozzi expects a cpu clock speed of 16MHz!
00028 #endif
00029 
00030 #include "Arduino.h"
00031 #include "TimerOne.h"
00032 #include "TimerZero.h"
00033 
00034 
00084 #define AUDIO_CHANNEL_1_PIN TIMER1_A_PIN // defined in TimerOne/config/known_16bit_timers.h
00085 
00086 // #define MOZZI_AC_OUTPUT 1
00087 // see notes in MozziGuts.cpp
00088 #ifdef MOZZI_AC_OUTPUT
00089 #define AUDIO_CHANNEL_1_AC_PIN TIMER1_B_PIN // defined in TimerOne/config/known_16bit_timers.h
00090 #endif
00091 
00092 // Used internally.  If there was a channel 2, it would be OCR1B.
00093 #define AUDIO_CHANNEL_1_OUTPUT_REGISTER OCR1A
00094 
00095 // see notes in MozziGuts.cpp
00096 #ifdef MOZZI_AC_OUTPUT
00097 #define AUDIO_CHANNEL_1_AC_OUTPUT_REGISTER OCR1B
00098 #endif
00099 
00100 
00116 // maybe 20,24 or 28k-ish later with combos of pow2
00117 #define AUDIO_RATE 16384
00118 
00119 #if AUDIO_RATE == 16384
00120 /* Used internally for audio-rate optimisation.*/
00121 #define AUDIO_RATE_AS_LSHIFT 14
00122 
00123 
00141 #define AUDIO_PWM_RESOLUTION 488
00142 /* Used internally to put the 0-biased generated audio into the right range for PWM output.*/
00143 #define AUDIO_BIAS 244
00144 #endif
00145 
00146 // #define FIXMATH_OPTIMIZE_8BIT /* libfixmath option - it's an external library not used at the moment */
00147 
00148 // these are documented in .cpp file
00149 void startMozzi(unsigned int control_rate_hz);
00150 void audioHook();
00151 static void outputAudio();
00152 
00159 void updateControl();
00160 
00161 
00168 int updateAudio();
00169 
00170 // common abbreviations
00171 typedef unsigned char uchar;
00172 typedef unsigned int uint;
00173 typedef unsigned long ulong;
00174 
00175 
00176 #endif /* MOZZIGUTS_H_ */