Skip to content

Commit e0fbf98

Browse files
committed
Preliminary RingModulator sketch
1 parent 1214d70 commit e0fbf98

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Example playing a sinewave at a set frequency,
2+
using Mozzi sonification library.
3+
4+
Demonstrates the use of Oscil to play a wavetable.
5+
6+
Circuit: Audio output on digital pin 9 on a Uno or similar, or
7+
DAC/A14 on Teensy 3.1, or
8+
check the README or http://sensorium.github.io/Mozzi/
9+
10+
Mozzi documentation/API
11+
https://sensorium.github.io/Mozzi/doc/html/index.html
12+
13+
Mozzi help/discussion/announcements:
14+
https://groups.google.com/forum/#!forum/mozzi-users
15+
16+
Copyright 2012-2024 Tim Barrass and the Mozzi Team
17+
18+
Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
19+
*/
20+
21+
#define MOZZI_CONTROL_RATE 64 // Hz, powers of 2 are most reliable; 64 Hz is actually the default, but shown here, for clarity
22+
#include <Mozzi.h>
23+
#include <Oscil.h> // oscillator template
24+
#include <tables/sin2048_int8.h> // sine table for oscillator
25+
#include <EventDelay.h>
26+
#include <Smooth.h>
27+
#include <mozzi_rand.h>
28+
29+
EventDelay kModulationChangeDelay;
30+
Smooth<uint8_t> kSmoothModulation(0.9f);
31+
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
32+
Oscil<SIN2048_NUM_CELLS, MOZZI_AUDIO_RATE> aSin(SIN2048_DATA);
33+
//Oscil <SIN2048_NUM_CELLS, MOZZI_CONTROL_RATE> aSin2(SIN2048_DATA); // controls the amount of Ring Modulation
34+
35+
int8_t prev_sample = 0;
36+
uint8_t ring_mod, smoothed_ring_mod;
37+
38+
void setup() {
39+
Serial.begin(115200);
40+
kModulationChangeDelay.set(2000);
41+
startMozzi(); // :)
42+
aSin.setFreq(64); // set the frequency
43+
}
44+
45+
46+
void updateControl() {
47+
//ring_mod_amount = int(aSin2.next() + 128);
48+
//Serial.println(ring_mod_amount);
49+
//ring_mod_amount = 255;
50+
if (kModulationChangeDelay.ready()) {
51+
ring_mod = rand(150);
52+
kModulationChangeDelay.start();
53+
}
54+
smoothed_ring_mod = kSmoothModulation(ring_mod);
55+
}
56+
57+
58+
AudioOutput updateAudio() {
59+
prev_sample = aSin.phMod(int32_t(prev_sample) * smoothed_ring_mod);
60+
return MonoOutput::from8Bit(prev_sample); // return an int signal centred around 0
61+
}
62+
63+
64+
void loop() {
65+
audioHook(); // required here
66+
}

0 commit comments

Comments
 (0)