Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to achieve smoother fades like setTargetAtTime() instead of linear fades? #1763

Open
Labels
@taariqelliott

Description

Issue

The current fade() function creates linear volume transitions that can cause audible clicks and pops, especially when fading in/out quickly. I'm looking for a way to achieve smooth exponential fades similar to Web Audio API's setTargetAtTime().

Current Behavior

// Current implementation
sound.fade(sound.volume(), 1, 200);

Desired Behavior

// I've done this in the past to create smooth audio fades
volumeGainNode.gain.setTargetAtTime(0, audioCtx.currentTime, 0.04);

Code Example

const playSound = () => {
 if (!sound?.playing()) {
 sound?.fade(sound.volume(), 1, 200);
 setTimeout(() => {
 sound?.play();
 }, 100);
 }
};
const pauseSound = () => {
 if (sound?.playing()) {
 sound?.fade(sound.volume(), 0, 200);
 setTimeout(() => {
 sound?.pause();
 }, 100);
 }
};

Question

  1. Is there a way to configure Howler to use exponential fading curves instead of linear?
  2. Would it be possible to expose the underlying Web Audio gain node so we can use setTargetAtTime() directly?
  3. Are there any recommended workarounds for achieving smoother fades?

Reproducible Example

https://github.com/taariqelliott/ugubhu-v1/blob/main/src/routes/About.tsx

Reproduction Steps

Setup play/pause or mute/unmute functions as so:

 const playSound = () => {
 if (!sound?.playing()) {
 sound?.fade(sound.volume(), 1, 200);
 setTimeout(() => {
 sound?.play();
 }, 100);
 }
 };
 const pauseSound = () => {
 if (sound?.playing()) {
 sound?.fade(sound.volume(), 0, 200);
 setTimeout(() => {
 sound?.pause();
 }, 100);
 }
 };

Possible Solution

No response

Context

No response

Howler.js Version

2.2.4

Affected Browser(s)/Versiuon(s)

Electron[chromium]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /