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

Add a volume adjust to the player please [eob] #2

Closed
negge opened this issue Sep 28, 2020 · 7 comments
Closed

Add a volume adjust to the player please [eob] #2

negge opened this issue Sep 28, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@negge
Copy link

negge commented Sep 28, 2020

No description provided.

@orhun orhun assigned bufgix and orhun Oct 1, 2020
@orhun orhun added the enhancement New feature or request label Oct 1, 2020
@mash-97
Copy link

mash-97 commented Apr 9, 2021

YO! I like these kind of projects. Though I'm not really proficient in JS and don't know Next.js. But I think I'll go passionate about this. So in order to contribute, can you give me a basic guideline about how can I struggle with this issue?

@orhun
Copy link
Owner

orhun commented Apr 9, 2021

YO!

Hey!

I like these kind of projects. Though I'm not really proficient in JS and don't know Next.js. But I think I'll go passionate about this.

I'm glad to hear someone's interested in this project!

So in order to contribute, can you give me a basic guideline about how can I struggle with this issue?

Of course.

Basically what we need is adjusting the volume via calling the libopenmpt functions. We're using a web assembly file for importing these. (See /bin) Last time I checked, I couldn't find any function related to adjusting volume but I cannot say I made a in-depth search. Maybe we should update the version of the library, I don't know. So you can start by diving into libopenmpt and see what can we do in order to adjust the volume since all the "playing" related operations are handled by this library. Also you can check what else we can use to achieve that.

Then we can basically update the front-end. e.g. Adding another slider to the Player component(s). (See Player.js & Player.module.scss)

@mash-97
Copy link

mash-97 commented Apr 10, 2021

Thank you for your precious response. I did some researches how you guided. Most of the tools above are new to me. libopenmpt is to some extent low-level library to me that I tried to look for the other way. I found web audio api 's AudioContext promising, as it provides a way to control the volume via it's GainNode.

@orhun
Copy link
Owner

orhun commented Apr 11, 2021

I found web audio api 's AudioContext promising, as it provides a way to control the volume via it's GainNode.

Sounds nice. Any ideas how can we implement that into our current player?

@Cthulhu2
Copy link
Contributor

openmpt_module_set_render_param and OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL can be used. Something like that:

// chiptune2.js

const OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL = 1
...
function ChiptuneJsConfig(repeatCount, volume) {
   ...
  this.volume = volume;
}

/**
 * Set player volume
 * @param volume Integer, empiric -6000 (silence) .. 2000 (too loud)
 */
ChiptuneJsPlayer.prototype.setVolume = function (volume) {
  this.config.volume = volume
  if (this.currentPlayingNode != null) {
    libopenmpt._openmpt_module_set_render_param(
      this.currentPlayingNode.modulePtr,
      OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL,
      volume,
    );
  }
};

ChiptuneJsPlayer.prototype.createLibopenmptNode = function(buffer, config) {
  ...
  libopenmpt._openmpt_module_set_render_param(
    processNode.modulePtr,
    OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL,
    config.volume,
  );
  ...
}

@Cthulhu2
Copy link
Contributor

Also, @deskjet in Volume support #17 offer the hackish approach with GainNode:

// 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

Cthulhu2 pushed a commit to Cthulhu2/CoolModFiles that referenced this issue Dec 1, 2021
Cthulhu2 pushed a commit to Cthulhu2/CoolModFiles that referenced this issue Dec 2, 2021
Cthulhu2 pushed a commit to Cthulhu2/CoolModFiles that referenced this issue Dec 9, 2021
orhun added a commit that referenced this issue Dec 13, 2021
* feat: Add volume adjust to PlayerBig (#2)

* feat: Move volume adjust to the left side (#2)

* fix: PlayerBig random thickness w style width: 93% (#2)

* style: Add animation to volume slider

Co-authored-by: cthulhu <>
Co-authored-by: Orhun Parmaksız <[email protected]>
@orhun
Copy link
Owner

orhun commented Dec 13, 2021

rec

@orhun orhun closed this as completed Dec 13, 2021
Cthulhu2 pushed a commit to Cthulhu2/CoolModFiles that referenced this issue Jul 13, 2023
orhun pushed a commit that referenced this issue Aug 19, 2023
* feat: Add volume icon n percent label (#2)

* feat: Increase distance for volume items, 5px -> 10px

Move percent label on the top of slider

* feat: Mute on volume icon click

* feat: Volume keyboard shortcuts (a up, z down, x mute)

---------

Co-authored-by: cthulhu <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants