Mozziメモ-01
01.Basics Permalink
Control_Gainのメモです。
/* Example changing the gain of a sinewave,
using Mozzi sonification library.
Demonstrates the use of a control variable to influence an
audio signal.
Circuit: Audio output on digital pin 9 on a Uno or similar, or
DAC/A14 on Teensy 3.1, or
check the README or http://sensorium.github.com/Mozzi/
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, 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);
// control variable, use the smallest data size you can for anything used in audio
byte gain = 255; // byte型のgainという変数が255に設定されている。
void setup(){
startMozzi(); // start with default control rate of 64 一秒間に何回繰り返すか 初期値は一秒間に64回繰り返す。
aSin.setFreq(3320); // set the frequency 周波数を設定する 3320Hz
}
void updateControl(){
// as byte, this will automatically roll around to 255 when it passes 0
// 一回で3減る 255から0になるまで85回かかる。0になったらまた255から繰り返し
gain = gain - 3 ;
}
int updateAudio(){
return (aSin.next()* gain)>>8; // shift back to STANDARD audio range, like /256 but faster 256で割るより早く標準のオーディオ範囲に戻します。
}
void loop(){
audioHook(); // required here
}