mudcube / MIDI.js

:musical_keyboard: Making life easy to create a MIDI-app on the web. Includes a library to program synesthesia into your app for memory recognition or for creating trippy effects. Convert soundfonts for Guitar, Bass, Drums, ect. into code that can be read by the browser. Supports multiple simultaneous instruments and perfect timing.
http://mudcu.be/midi-js/
MIT License
3.79k stars 640 forks source link

Notes only play a maximum of 2 seconds or so #73

Open kusog opened 10 years ago

kusog commented 10 years ago

The way audio and audiocontext are setup, they only play through the given mp3/ogg note once. If the music has a note that lasts longer than that it wont play. I have fixed this in my branch by adding loop=true to both the audio tag and web audio api plugins.

I use this for violin drone practices: http://kusogmusic.com/violin/drones

I have fixed a bunch of similar types of issues that have kept tools like that from working.

mudcube commented 10 years ago

You're right it's definitely an issue w/ Violin, Organ and similar instruments.

If we want to handle this properly, the repeat should be setup to be able to take a portion of the audio and repeat from there (not necessarily the entire thing). Here's an example, this one has the attack (at the beginning) then the later half repeats over and over until the noteOff happens:

screen shot 2014-03-24 at 7 56 05 pm

kusog commented 10 years ago

I’ve come to the same conclusion. In fact that could be the solution to getting attack/decay with normal note playback. I know it can be done with web audio api, and with audio we can jump the current position as needed.

From: Michael Deal [mailto:notifications@github.com] Sent: Monday, March 24, 2014 10:58 PM To: mudcube/MIDI.js Cc: kusog Subject: Re: [MIDI.js] Notes only play a maximum of 2 seconds or so (#73)

You're right it's definitely an issue w/ Violin, Organ and similar instruments.

If we want to handle this properly, the repeat should be setup to be able to take a portion of the audio and repeat from there (not necessarily the entire thing). Here's an example, this one has the attack (at the beginning) then the later half repeats over and over until the noteOff happens:

https://f.cloud.github.com/assets/101564/2507920/06503990-b3c9-11e3-8428-b6e83e42b035.png screen shot 2014-03-24 at 7 56 05 pm

— Reply to this email directly or view it on GitHub https://github.com/mudcube/MIDI.js/issues/73#issuecomment-38526120 . https://github.com/notifications/beacon/1085858__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxMTMzNTQ5MCwiZGF0YSI6eyJpZCI6Mjg0MjczNzl9fQ==--29f46c98b3194e082e3cfc27e23885a3befbeed5.gif

mudcube commented 10 years ago

Wow, in WebAudioAPI it actually looks really easy:

// here are our starting and stopping points // for this file's internal loop var wpn_machinegun_fire_loop_start = 0; var wpn_machinegun_fire_loop_end = 0.5782708333;

// let's play a sound myContext = soundWpnMachineGunFire01.play(); // gotta set the loop points myContext.loopStart = wpn_machinegun_fire_loop_start; myContext.loopEnd = wpn_machinegun_fire_loop_end;

via http://www.html5audio.org/2013/03/new-looping-functionality-in-web-audio-api.html

kusog commented 10 years ago

I have experimented with the loop start/end on the source node and it works, but there is still a very obvious sound when it loops around which I do not think is simply a part of the audio file. It is something like a click. Perhaps it is due to the instrument file having a variance in the sound due to vibrato, but it sounds to be more than that, similar to the sound you can hear on http://kusogmusic.com/violin/drones

From: Michael Deal [mailto:notifications@github.com] Sent: Tuesday, March 25, 2014 5:17 AM To: mudcube/MIDI.js Cc: kusog Subject: Re: [MIDI.js] Notes only play a maximum of 2 seconds or so (#73)

Wow, in WebAudioAPI it actually looks really easy:

// here are our starting and stopping points // for this file's internal loop var wpn_machinegun_fire_loop_start = 0; var wpn_machinegun_fire_loop_end = 0.5782708333;

// let's play a sound myContext = soundWpnMachineGunFire01.play(); // gotta set the loop points myContext.loopStart = wpn_machinegun_fire_loop_start; myContext.loopEnd = wpn_machinegun_fire_loop_end;

via http://www.html5audio.org/2013/03/new-looping-functionality-in-web-audio-api.html

— Reply to this email directly or view it on GitHub https://github.com/mudcube/MIDI.js/issues/73#issuecomment-38543748 . https://github.com/notifications/beacon/1085858__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxMTM1ODI0NiwiZGF0YSI6eyJpZCI6Mjg0MjczNzl9fQ==--d8170a720a88eac69010ef5d8b27d69afacd93d2.gif

kusog commented 10 years ago

I noticed the machine gun demo site, and it is very convenient that they use a sound that naturally has a burst rather than continuous sound like the instrument sounds. So I am curious to know if a pure tone sound file would work to where the user cannot tell there is a loop and it just sounds like one continuous long sound, like a violin note that never ends.

From: Michael Deal [mailto:notifications@github.com] Sent: Tuesday, March 25, 2014 5:17 AM To: mudcube/MIDI.js Cc: kusog Subject: Re: [MIDI.js] Notes only play a maximum of 2 seconds or so (#73)

Wow, in WebAudioAPI it actually looks really easy:

// here are our starting and stopping points // for this file's internal loop var wpn_machinegun_fire_loop_start = 0; var wpn_machinegun_fire_loop_end = 0.5782708333;

// let's play a sound myContext = soundWpnMachineGunFire01.play(); // gotta set the loop points myContext.loopStart = wpn_machinegun_fire_loop_start; myContext.loopEnd = wpn_machinegun_fire_loop_end;

via http://www.html5audio.org/2013/03/new-looping-functionality-in-web-audio-api.html

— Reply to this email directly or view it on GitHub https://github.com/mudcube/MIDI.js/issues/73#issuecomment-38543748 . https://github.com/notifications/beacon/1085858__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxMTM1ODI0NiwiZGF0YSI6eyJpZCI6Mjg0MjczNzl9fQ==--d8170a720a88eac69010ef5d8b27d69afacd93d2.gif

mudcube commented 10 years ago

With soundfont files, the repeat is programmed at a specific time so the loop feels continuous even with violins. There's an app called Polyphone on OSX where you can analyze the soundfont and see these repeat patterns (which makes soundfonts make a lot more sense).

http://sourceforge.net/projects/polyphone/

mudcube commented 10 years ago

@kusog Hey, I lost your email, could you send me a message? I have another job that might be worthwhile looking into.

kusog commented 10 years ago

Did you really mean to talk to me? I sent a message through http://mudcu.be/contact/

From: Michael Deal [mailto:notifications@github.com] Sent: Monday, March 31, 2014 5:05 PM To: mudcube/MIDI.js Cc: kusog Subject: Re: [MIDI.js] Notes only play a maximum of 2 seconds or so (#73)

@kusog https://github.com/kusog Hey, I lost your email, could you send me a message? I have another job that might be worthwhile looking into.

— Reply to this email directly or view it on GitHub https://github.com/mudcube/MIDI.js/issues/73#issuecomment-39141804 . https://github.com/notifications/beacon/1085858__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxMTkxOTEyOCwiZGF0YSI6eyJpZCI6Mjg0MjczNzl9fQ==--91feadd6a28271b1282027259fff6156d83a4a66.gif

mudcube commented 10 years ago

@kusog Yup, sorry, just stepped out for a few hours. I'm going to forward you a job that might be fun in a bit here.

charlieroberts commented 9 years ago

Hello,

Just curious if anymore work had been done along these lines. Thanks! - Charlie

kusog commented 9 years ago

I have code in place in my version that does the looping, but it still doesn’t sound right because you have to know exactly what points to loop with to sound like a continuous sound. I don’t have that info and thus the solution doesn’t help.

From: charlie roberts [mailto:notifications@github.com] Sent: Friday, September 12, 2014 3:40 PM To: mudcube/MIDI.js Cc: kusog Subject: Re: [MIDI.js] Notes only play a maximum of 2 seconds or so (#73)

Hello,

Just curious if anymore work had been done along these lines. Thanks! - Charlie

— Reply to this email directly or view it on GitHub https://github.com/mudcube/MIDI.js/issues/73#issuecomment-55451097 . https://github.com/notifications/beacon/1085858__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNjE2OTk4MywiZGF0YSI6eyJpZCI6Mjg0MjczNzl9fQ==--8461149ea545aed4118d5a979d2d731c483e71ca.gif

charlieroberts commented 9 years ago

Well, we need more information from the soundfont converter. The spec says that loop points can be provided (section 6.3):

http://www.synthfont.com/sfspec24.pdf

So I guess the next step will be working on that. I might take that on if I find the time, as I like the idea of being able to use soundfonts, but require the looping.