Jump to content

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


Recommended Posts

I have this function call I want tied directly into a var:

startTone( tone );

How would I tie it into a var similar to how I have this var created:

    audio = new Audio();
    audio.src = "sound.mp3";
    audio.loop = false;
Link to comment
Share on other sites

You want to store the result of calling startTone() in a variable?


var foo = startTone(tone);
The question however is, what does this function actually return?


Obviously, there is no way for us to know the answer to that.

Link to comment
Share on other sites

Would it be easier to grab the sounds from the whole page to manipulate them as I want to?

Your ability to describe your issue is non existent. This post makes zero sense, and your cryptic posts are nothing but frustrating.


I'm out.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();
    oscillator.frequency.value = frequency;

    var amp = context.createGainNode();

    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);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.