forked from PaulStoffregen/Audio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
user
authored and
user
committed
Feb 26, 2021
1 parent
21edb98
commit a094ae3
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <Audio.h> | ||
//#include <effect_wavefolder.h> // added to Audio.h in the branch now | ||
|
||
AudioOutputI2S i2sout ; | ||
|
||
AudioSynthWaveform sig ; // signal to be modulated | ||
AudioSynthWaveformDc mod ; // modulate the amplitude into folder | ||
AudioSynthWaveformDc mod2 ; // modulate the amplitude afterwards | ||
AudioEffectWaveFolder folder ; | ||
AudioEffectMultiply mult ; | ||
|
||
AudioConnection c0 (mod, 0, folder, 0) ; | ||
AudioConnection c1 (sig, 0, folder, 1) ; | ||
AudioConnection c2 (folder, 0, mult, 0) ; | ||
AudioConnection c3 (mod2, 0, mult, 1) ; | ||
AudioConnection c4 (mult, 0, i2sout, 0) ; | ||
AudioConnection c5 (mult, 0, i2sout, 1) ; | ||
|
||
// The Audio Shield chip | ||
AudioControlSGTL5000 codec; | ||
|
||
#define MIN_GAIN 0.2 | ||
#define MAX_GAIN 5.0 | ||
#define GAIN_STEP 1.002 | ||
|
||
float gain = MIN_GAIN ; | ||
bool increasing = true ; | ||
|
||
void set_gains () // the output gain (mod2) compensates to keep vol roughly level | ||
{ | ||
AudioNoInterrupts () ; | ||
mod.amplitude (0.2 * gain) ; | ||
mod2.amplitude (gain > 1 ? 1 : 1 / gain) ; | ||
AudioInterrupts () ; | ||
} | ||
|
||
void audio_setup() | ||
{ | ||
AudioMemory(4); | ||
|
||
sig.begin (1, 70, WAVEFORM_SINE) ; // test tone | ||
set_gains () ; | ||
|
||
codec.enable(); | ||
codec.volume(0.3); // headphone volume low for harsh waveform! | ||
codec.lineOutLevel (13) ; // turn up line out to max | ||
} | ||
|
||
void loop () // constantly changing the gains | ||
{ | ||
if (increasing) | ||
{ | ||
gain *= GAIN_STEP ; | ||
if (gain > MAX_GAIN) | ||
{ | ||
gain = MAX_GAIN ; | ||
increasing = false ; | ||
} | ||
} | ||
else | ||
{ | ||
gain /= GAIN_STEP ; | ||
if (gain < MIN_GAIN) | ||
{ | ||
gain = MIN_GAIN ; | ||
increasing = true; | ||
} | ||
} | ||
|
||
set_gains () ; | ||
delay (3) ; // wait for another audio block | ||
} | ||
|
||
void setup () | ||
{ | ||
Serial.begin (115200) ; | ||
audio_setup () ; | ||
} |