Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Volume #24

Closed
roeilulavy opened this issue Jun 6, 2022 · 5 comments
Closed

Implement Volume #24

roeilulavy opened this issue Jun 6, 2022 · 5 comments

Comments

@roeilulavy
Copy link

Hello!
Love this repo!
How can I set a Volume slider () on the audioStreamer?

@StefansArya
Copy link
Member

Hi!
Have you tried to connect the audioStreamer to GainNode?

The implementation is similar like adding effect that created from ScarletsMediaEffect:

var ppDelay = ScarletsMediaEffect.pingPongDelay();
// source (stream) -> Ping pong delay -> destination (speaker)
presenterStream.connect(ppDelay.input);
ppDelay.output.connect(ScarletsMedia.audioContext.destination);

You can get the AudioContext with ScarletsMedia.audioContext.

If the AudioNode is created from audioContext you don't need to add .input or .output properties when connecting each node, and it's should be looks like below:

let gainNode = ScarletsMedia.audioContext.createGain();

// source (stream) -> GainNode -> destination (speaker) 
audioStreamer.connect(gainNode);
gainNode.connect(ScarletsMedia.audioContext.destination);

gainNode.gain.value = 0.2; // range 0~1, where 0.2 == 10%

@roeilulavy
Copy link
Author

Thank you!
Works perfect!

@roeilulavy
Copy link
Author

Now lets say I want to control the Equalizer parameters...
How do I do that?

@StefansArya
Copy link
Member

To control the equalizer parameters, you can just adjust the frequency's dB value

frequency:function(frequency, dB){ // value: -20 ~ 20
if(dB === undefined) return equalizer[frequency].gain.value;
equalizer[frequency].gain.value = dB;
},

And don't forget to connect each node, different connection order may give different result

let equalizer = ScarletsMediaEffect.equalizer(/* [32, 64, 125, 250, 500, 1000, 2000, 4000, 8000, 16000] */);
// 32Hz ~16KHz will be set as default frequency which you can control

// source (stream) -> Equalizer -> GainNode -> destination (speaker) 
audioStreamer.connect(equalizer.input);
equalizer.output.connect(gainNode);
gainNode.connect(ScarletsMedia.audioContext.destination);

equalizer.frequency(32, 15); // 32Hz, 15dB

@roeilulavy
Copy link
Author

Thank you very much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants