Jump to content

How do I plug a tone generated by a function into a var?


Q695

Recommended Posts

In JavaScript I'm trying to:

take a tone generated by a tone generator

manipulate the tone (the only thing that will be on the whole page for sound) in several ways at the same time

produce the tone in its manipulated form

 

What I understand:

the tone is generated by startTone( tone )

computer speaker manipulation

 

What I need to do:

make the product of startTone() manipulatable

From what I can tell briefly looking at the script if you want to store the tone into a variable you need to create another generateTone function which will create a new oscillator object at the proper frequency. Eg:

function generateTone(context, frequency){
    var oscillator = context.createOscillator();
    fixOscillator(oscillator);
    oscillator.frequency.value = frequency;

    var amp = context.createGainNode();
    oscillator.connect(amp);
    amp.connect(context.destination);

    return { oscillator: oscillator, amp: amp };
}
That would create the oscillator and an associated amp object and return them. You'd then use the oscillator to alter the tone's frequency or the amp object to alter it's volume level. You could wrap that all up into a Tone object so that you'd just have to do something like

var tone = new Tone(context, 100);
tone.setVolume(0.6);
tone.start();
tone.changeFrequency(60);
tone.stop();
//etc

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.