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

chrome: "audio resources unavailable for AudioContext construction" #40

Closed
dannycochran opened this issue Jul 14, 2013 · 7 comments
Closed

Comments

@dannycochran
Copy link

using the basic demo and playing a note over and over again, Chrome throws this error:
"Uncaught SyntaxError: audio resources unavailable for AudioContext construction"

as seen on here:
http://stanford.edu/~c0chran/cgi-bin/midi-default/

if I put a try block around the new audio context that is generated in plugin.js, it doesn't throw the error:
try {
MIDI.Player.ctx = ctx = new AudioContext();
} catch(err) {}

however, the rendering of the audio is much slower on chrome than on Firefox, such that you could only play a note about once every 2 seconds.when the try block is removed, the audio can play more rapidly but then the error is thrown after 5-6 plays.

is there no having one without the other?

@mudcube
Copy link
Owner

mudcube commented Jul 16, 2013

Hi Danny,
You're reloading the plugin each time "click" is called, you should only need to run noteOn/noteOff. It should look something like this:

MIDI.loadPlugin({
    soundfontUrl: "./soundfont/",
    instrument: "acoustic_grand_piano",
    callback: function () {
        var delay = 0; // play one note every quarter second
        var note = 50; // the MIDI note
        var velocity = 127; // how hard the note hits
        // play the note
        MIDI.setVolume(0, 127);
        $("#play").click(function () {
            MIDI.noteOn(0, note, velocity, delay);
            MIDI.noteOff(0, note, delay + 0.75);
        });
    }
});

@mudcube mudcube closed this as completed Jul 16, 2013
@JoshTheDerf
Copy link

@mudcube, is there a way to load an additional instrument without reloading the plugin itself? That is how I'm doing it at http://tribex.derfers.us/index.php?page=MIDI_Piano but after loading 10 or 12 instruments, it fails with the same error as the OP.

function loadInstrument(id) {
    MIDI.loadPlugin({
        soundfontUrl: "./soundfonts/",
        instrument: id,
        callback: function () {
            //Set the instrument to the channel 0 so we can actually hear it.
            MIDI.programChange(0, id);
                },
       })
};
...
...
...
<p class="selection" onclick="loadInstrument(0)">Acoustic Grand Piano</p>

(I hope you don't mind a reply to a closed thread)

@artfoundry
Copy link

Load all the instruments in one go when you load the plugin. Then have your onclick call a program change instead of an instrument load.

@JoshTheDerf
Copy link

Unfortunately, that requires sending about 347.3MB to the client, and it would all be loaded in order, so the client would have to wait until the instrument he wanted to actually use was loaded.

The way I have it now, only the instruments that the client actually wants are loaded when he selects an item from a list.

(The code example above is very shortened. I actually have a list of all the instruments that is automagically generated).

@artfoundry
Copy link

Ah ok, yeah that's a lot of data to send. Mine is only a tenth of that amount. Well, I still think the way you have it now is fine.

@Silverwolf90
Copy link

@tribex Sorry about trying to contact you via this issue. I couldn't seem to find an email to reach you on your website (am I blind?).

Did you create all those base64 encoded soundfonts? Are they available to the public? It's quite an impressive list!

Edit: Did some more sleuthing and I found the https://github.com/gleitz/midi-js-soundfonts :) So you can disregard.

@JoshTheDerf
Copy link

@Silverwolf90 No you're not blind, The website is still VERY fresh and I haven't finished adding all the content.

And no, I got them from the link you posted.

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

No branches or pull requests

5 participants