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

Volume support #17

Open
RubenSandwich opened this issue Mar 2, 2016 · 7 comments
Open

Volume support #17

RubenSandwich opened this issue Mar 2, 2016 · 7 comments

Comments

@RubenSandwich
Copy link

It would be helpful to be able to change the volume of the music being played.

@deskjet
Copy link
Owner

deskjet commented Mar 2, 2016

Actually one should be able to wire the internal ScriptProcessorNode to any WebAudio sink. So you could use a GainNode to control volume. I'll think about ways of doing so.

Currently the internal ScriptProcessor Node is directly wired to the AudioDestination (speakers) with no nice way to intercept between. However you can try the hackish approach:

// create a GainNode
var gain = player.context.createGain()

// wire gain to speaker output
gain.connect(player.context.destination)

// disconnect internal ScriptProcessorNode from speakers
player.currentPlayingNode.disconnect()

// wire script processor to gain
player.currentPlayingNode.connect(gain)

// make it quieter
gain.gain.value = 0.5

You will have to do the rewiring after each call to play(), because it creates a new currentPlayingNode. I'll think of a nicer way of doing that.

@RubenSandwich
Copy link
Author

Cool that works great. Thanks. Maybe make it part of the API though so it would be more easily accessible and hide the implementation details.

@sagamusix
Copy link
Contributor

Note that you can also set the gain directly in libopenmpt via openmpt::module::set_render_param.

@ClassicOldSong
Copy link

@deskjet I once merged several input source to one output just by copying and adding the buffer to the output processor. Maybe you can use this method to maintain one currentPlayingNode.
Another solution to this is using MediaSourceExtension, which also solves the requirement for seek bar.

@KingPossum
Copy link

Note that you can also set the gain directly in libopenmpt via openmpt::module::set_render_param.

How exactly? I'm struggling to change the volume currently using any means

@deskjet
Copy link
Owner

deskjet commented Jul 28, 2021

@KingPossum
Here is how set_render_param is called to configure libopenmpt.

chiptune2.js/chiptune2.js

Lines 146 to 147 in 05349a0

libopenmpt._openmpt_module_set_render_param(processNode.modulePtr, OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT, this.config.stereoSeparation);
libopenmpt._openmpt_module_set_render_param(processNode.modulePtr, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, this.config.interpolationFilter);

Try RENDER_MASTERGAIN_MILLIBEL as the first parameter. If that is not defined use the value 1 as that's what it should be according to the original source code. The second paramter would be your desired gain in milliBels (e.g. -600 to lower the volume)

https://github.com/OpenMPT/openmpt/blob/324e20cb74eacd0c758a251ac1ffdc264aeb24b3/libopenmpt/libopenmpt.h#L809-L815

@KingPossum
Copy link

@KingPossum
Here is how set_render_param is called to configure libopenmpt.

chiptune2.js/chiptune2.js

Lines 146 to 147 in 05349a0

libopenmpt._openmpt_module_set_render_param(processNode.modulePtr, OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT, this.config.stereoSeparation);
libopenmpt._openmpt_module_set_render_param(processNode.modulePtr, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, this.config.interpolationFilter);

Try RENDER_MASTERGAIN_MILLIBEL as the first parameter. If that is not defined use the value 1 as that's what it should be according to the original source code. The second paramter would be your desired gain in milliBels (e.g. -600 to lower the volume)

https://github.com/OpenMPT/openmpt/blob/324e20cb74eacd0c758a251ac1ffdc264aeb24b3/libopenmpt/libopenmpt.h#L809-L815

Thank you so much for the quick and concise reply! I hope you can forgive my ignorance on the topic, I'm new to JS and website creation in general. Here's the current syntax I'm attempting to use, and it's still having no effect. I'm sure I'm just not using it correctly.

libopenmpt._openmpt_module_set_render_param(1, -600);

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

No branches or pull requests

5 participants