-
Notifications
You must be signed in to change notification settings - Fork 183
/
Sinewave_HIFI.ino
70 lines (52 loc) · 2.23 KB
/
Sinewave_HIFI.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Example playing a sinewave at a set frequency,
using Mozzi sonification library.
Demonstrates the use of Oscil to play a wavetable.
This sketch using HIFI mode on AVR (i.e. the classic Arduino borads, not Teensy 3.x and friends).
IMPORTANT: this sketch requires Mozzi/mozzi_config.h to be
be changed from STANDARD mode to HIFI.
In Mozz/mozzi_config.h, change
#define AUDIO_MODE STANDARD
//#define AUDIO_MODE HIFI
to
//#define AUDIO_MODE STANDARD
#define AUDIO_MODE HIFI
Circuit: Audio output on digital pin 9 and 10 (on a Uno or similar),
Check the Mozzi core module documentation for others and more detail
3.9k
pin 9 ---WWWW-----|-----output
499k |
pin 10 ---WWWW---- |
|
4.7n ==
|
ground
Resistors are ±0.5% Measure and choose the most precise
from a batch of whatever you can get. Use two 1M resistors
in parallel if you can't find 499k.
Alternatively using 39 ohm, 4.99k and 470nF components will
work directly with headphones.
Mozzi documentation/API
https://sensorium.github.io/Mozzi/doc/html/index.html
Mozzi help/discussion/announcements:
https://groups.google.com/forum/#!forum/mozzi-users
Tim Barrass 2012-13, CC by-nc-sa.
*/
#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
void setup(){
startMozzi(); // uses the default control rate of 64, defined in mozzi_config.h
aSin.setFreq(440); // set the frequency
}
void updateControl(){}
AudioOutput_t updateAudio(){
// this would make more sense with a higher resolution signal
// MonoOutput::from8Bit() (and it friends from16Bit() and fromNBit()) take care of scaling the output signal
// as appropiate for the platform (to 14 bits on AVR with AUDIO_MODE HIFI).
return MonoOutput::from8Bit(aSin.next());
}
void loop(){
audioHook(); // required here
}