Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Modify AudioBuffer volume in JavaScript

How can modify AudioBuffer volume in javascript ? I just wanna modify AudioBuffer volume without play any sound and without use any gain. Finally , I wanna to have a new AudioBuffer with modified volume.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Let's say you want to multiply all values within an existing AudioBuffer by 2. You could do that by looping over all values to apply the computation.

for (let channel = 0; channel < audioBuffer.numberOfChannels; channel += 1) {
    const channelData = audioBuffer.getChannelData(channel);

    for (let sample = 0; sample < channelData.length; sample += 1) {
        channelData[sample] *= 2;
    }
}

This will edit all values in place. If you want to copy all values to a new AudioBuffer instead you can do it as follows.

const copiedAudioBuffer = new AudioBuffer({
    length: audioBuffer.length,
    numberOfChannels: audioBuffer.numberOfChannels,
    sampleRate: audioBuffer.sampleRate
});

for (let channel = 0; channel < audioBuffer.numberOfChannels; channel += 1) {
    const channelData = audioBuffer.getChannelData(channel);
    const copiedChannelData = copiedAudioBuffer.getChannelData(channel);

    for (let sample = 0; sample < channelData.length; sample += 1) {
        copiedChannelData[sample] = channelData[sample] * 2;
    }
}

The example above creates an AudioBuffer with the exact same properties as the existing one. It will leave the existing AudioBuffer untouched.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!