tremolo effect with beads
in
Contributed Library Questions
•
1 year ago
Hello,
I am trying to make a virtual theremin with beads, to make it sound like a real deal I applied tremolo effect like in code below, but if I try to change sound pitch quickly it begin generating an awful sound, you clearly can hear that in example below, just try to move mouse cursor fast as possible up an down. So my question is, what to do, to be able to change sound pitch quickly and smoothly and still get decent tremolo effect
thank in advance :)
- // Frequency_Modulation_02.pde
- import beads.*; //sound library
- AudioContext ac; // create our AudioContext
- // declare our unit generators
- WavePlayer modulator;
- Glide modulatorFrequency;
- WavePlayer carrier;
- Gain g;
- void setup()
- {
- size(400, 300);
- // initialize our AudioContext
- ac = new AudioContext();
- // create the modulator, this WavePlayer will control the frequency of the carrier
- modulatorFrequency = new Glide(ac, 20, 30);
- modulator = new WavePlayer(ac, 1, Buffer.SINE);
- // this is a custom function
- // custom functions are a bit like custom Unit Generators (custom Beads)
- // but they only override the calculate function
- Function frequencyModulation = new Function(modulator)
- {
- public float calculate() {
- // return x[0], which is the original value of the modulator signal (a sine wave)
- // multiplied by 200.0 to make the sine vary between -200 and 200
- // the number 200 here is called the "Modulation Index"
- // the higher the Modulation Index, the louder the sidebands
- // then add mouseY, so that it varies from mouseY - 200 to mouseY + 200
- return (x[0] * 50.0) + mouseY;
- }
- };
- // create a second WavePlayer, control the frequency with the function created above
- carrier = new WavePlayer(ac, frequencyModulation, Buffer.SINE);
- g = new Gain(ac, 1, 0.5); // create a Gain object to make sure we don't peak
- g.addInput(carrier); // connect the carrier to the Gain input
- ac.out.addInput(g); // connect the Gain output to the AudioContext
- ac.start(); // start audio processing
- }
- void draw()
- {
- modulatorFrequency.setValue(mouseX);
- }
1