Mozzi  version v2.0
sound synthesis library for Arduino
MozziGuts.h
1 /*
2  * MozziGuts.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2012-2024 Tim Barrass and the Mozzi Team
7  *
8  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
9  *
10  */
11 
12 #ifndef MOZZIGUTS_H_
13 #define MOZZIGUTS_H_
14 
15 #include "Arduino.h"
16 
17 #include "MozziConfigValues.h"
18 
19 #if !(defined(MOZZI_H_) || defined(MOZZI_HEADERS_ONLY_H_))
20 #warning Direct inclusion of MozziGuts.h is deprecated. Use Mozzi.h, instead, and read about porting to Mozzi 2.0
21 #define MOZZI_COMPATIBILITY_LEVEL MOZZI_COMPATIBILITY_1_1
22 #endif
23 
24 #include "hardware_defines.h"
25 
26 #if IS_TEENSY3() || IS_TEENSY4()
27 // required from http://github.com/pedvide/ADC for Teensy 3.*
28 #include <ADC.h>
29 #endif
30 
31 #include "internal/config_checks_generic.h"
32 
33 #include "mozzi_analog.h"
34 #include "AudioOutput.h"
35 
36 // TODO Mozzi 2.0: These typedef probably obsolete?
37 // common numeric types
38 typedef unsigned char uchar;
39 typedef unsigned int uint;
40 typedef unsigned long ulong;
41 
42 #if defined(__AVR__)
43 typedef unsigned char byte; // for arduino ide
44 typedef unsigned char uint8_t;
45 typedef signed char int8_t;
46 typedef unsigned int uint16_t;
47 typedef signed int int16_t;
48 typedef unsigned long uint32_t;
49 typedef signed long int32_t;
50 #else
51 // Other supported arches add typedefs, here, unless already defined for that platform needed
52 #endif
53 
77 void startMozzi(int control_rate_hz = MOZZI_CONTROL_RATE);
78 
79 
80 
98 void stopMozzi();
99 
100 
101 #if (MOZZI_COMPATIBILITY_LEVEL <= MOZZI_COMPATIBILITY_1_1) && MOZZI_IS(MOZZI_AUDIO_CHANNELS, MOZZI_MONO)
102 AudioOutput_t updateAudio();
103 #else
115 #endif
116 
124 
125 
139 void audioHook();
140 
144 template<byte RES> uint16_t getAudioInput();
145 
149 template<byte RES> inline uint16_t getAudioInput16() { return getAudioInput<16>(); }
150 
170 #if defined(FOR_DOXYGEN_ONLY) || (!MOZZI_IS(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE))
171 #if defined(FOR_DOXYGEN_ONLY) || defined(MOZZI_ANALOG_READ_RESOLUTION)
172 inline uint16_t getAudioInput() { return getAudioInput<MOZZI_ANALOG_READ_RESOLUTION>(); };
173 #else
174 MOZZI_DEPRECATED("2.0", "This use of getAudioInput() is not portable. Refer to the API documentation for suggested alternatives") inline uint16_t getAudioInput() { return getAudioInput<MOZZI__INTERNAL_ANALOG_READ_RESOLUTION>(); };
175 #endif
176 #endif
177 
178 
188 unsigned long audioTicks();
189 
190 
191 
202 unsigned long mozziMicros();
203 
204 #ifndef _MOZZI_HEADER_ONLY
205 #include "internal/MozziGuts.hpp"
206 #endif
207 
208 #endif /* MOZZIGUTS_H_ */
This file keeps a list of named configuration values.
uint16_t getAudioInput16()
See getAudioInput().
Definition: MozziGuts.h:149
uint16_t getAudioInput()
See getAudioInput().
Definition: MozziGuts.h:172
#define MOZZI_CONTROL_RATE
Control rate setting.
void audioHook()
This is required in Arduino's loop().
Definition: MozziGuts.hpp:313
unsigned long audioTicks()
An alternative for Arduino time functions like micros() and millis().
Definition: MozziGuts.hpp:301
void updateControl()
This is where you put your control code.
void stopMozzi()
Stops audio and control interrupts and restores the timers to the values they had before Mozzi was st...
Definition: MozziGuts.hpp:303
AudioOutput updateAudio()
This is where you put your audio code.
unsigned long mozziMicros()
An alternative for Arduino time functions like micros() and millis().
Definition: MozziGuts.hpp:300
This struct encapsulates one frame of mono audio output.
Definition: AudioOutput.h:111