Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:22:57+00:00 2026-06-17T16:22:57+00:00

I would like to play a chord using OscillatorNodes: var ac = new (window.AudioContext

  • 0

I would like to play a chord using OscillatorNodes:

var ac = new (window.AudioContext || window.webkitAudioContext);
// C4, E4, G4
var freqs = [261.63, 329.63, 392.00];
for(var i=0;i<freqs.length;i++) {
  var o = ac.createOscillator();
  o.frequency.value = freqs[i];
  o.connect(ac.destination);
  o.noteOn(0);
  setTimeout(function() {o.noteOff(0)}, 1000);
}

But this approach sounds like a mess (here’s what it sounds like). If I try creating new AudioContexts for each note in the chord, then it sounds fine (like this):

// C4, E4, G4
var freqs = [261.63, 329.63, 392.00];
for(var i=0;i<freqs.length;i++) {
  var ac = new (window.AudioContext || window.webkitAudioContext);
  var o = ac.createOscillator();
  o.frequency.value = freqs[i];
  o.connect(ac.destination);
  o.noteOn(0);
  setTimeout(function() {o.noteOff(0)}, 1000);
}

But I read that you’re only supposed to have one AudioContext. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:22:59+00:00Added an answer on June 17, 2026 at 4:22 pm

    Not sure this can be a solution, but I found out inserting a GainNode and setting it’s value so that the gain will sum to 1 eliminates the issue:

    var ac = new (window.AudioContext || window.webkitAudioContext);
    // C4, E4, G4
    var freqs = [261.63, 329.63, 392.00];
    for(var i=0;i<freqs.length;i++) {
      var o = ac.createOscillator();
      var g = ac.createGainNode();
      o.frequency.value = freqs[i];
      o.connect(g);
      g.gain.value = 1/freqs.length;
      g.connect(ac.destination);
      o.start(0);
      setTimeout(function(s) {s.stop(0)}, 1000, o);
    }
    

    I tried this on Chrome 23.0.1271.101

    Updated to use the new start and stop methods: createOscillator noteOn not working

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to play/pause video using jquery. Here is my code: (function ($)
I would like to play a .mp4 file. I was using the following code
I would like to play 2 videos together using python. Apart from that, I
I am using UIReferenceLibraryViewController and would like to play sound when it is dismissed.
I'am new to C and would like to play with threads a bit. I
I'm using popcorn.js with Vimeo. I would like to play my Vimeo video programmatically,
During install, I would like to play a .wav or .mp3 (using Media Player
I would like to play the song x times like 1,2,3 ..etc using android
I would like to play short sounds in my new JavaScript game. It is
I would like to play a sound in Objective-C with a millisecond start time.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.