Online Sequencer Make music online
  • Sequences
  • Members
  • Chat
  • Forum
  • Wiki

Existing user? Sign In Create account
Login at Online Sequencer Forums

Online Sequencer Forums › Online Sequencer › Online Sequencer Discussion
« Previous 1 … 44 45 46 47 48 … 79 Next »

Useful Console Code Thread

Pages (3): « Previous 1 2 3
Thread tools
Useful Console Code Thread
Cringe_Gaming_64yt Offline
i have no idea of music theory and yet make decent music
357 Posts:
 
#21
08-02-2020, 11:41 AM
function playSynthNote(context, id, note, length, delay) {
  delay = delay ? delay : 0;
  var oscillator = oscillators[id][note];
  if (oscillator) {
    var gain = oscillator.gain.gain;
    var volume = 0.1 * audioSystem.masterVolume;
    var onTime = context.currentTime + delay + 0.01;
    var offTime = context.currentTime + delay + 0.01 + length;
    if (noteOffTime[id][note] > onTime) {
      gain.setTargetAtTime(volume / 2, context.currentTime, 0.01);
      gain.setTargetAtTime(volume, noteOffTime[id][note], 0.01);
    }
    noteOffTime[id][note] = offTime;
    gain.setTargetAtTime(volume, onTime, 1);
    gain.setTargetAtTime(0, offTime, 0);
  }
}






gain.setTargetAtTime(volume, onTime: this is for attack

gain.setTargetAtTime(0, offTime: this is for decay (the 2nd interger)



if you plug this in the console then you can edit the 8 bit instruments more but it wont save to a sequence


Reply
Jacob_ Offline
Administrator
343 Posts:
 
#22
12-11-2020, 04:48 PM
Now with note volume:
Code:
var resolution = 4; // how many times to subdivide each 1/4 note, 4 means 1/16 notes
var fftSize = 8192; // must be power of 2
var maxNotes = 1000; // maximum number of notes to add for each interval
var minIntensity = 128; // minimum volume for note to be added (0-255)

loadInstrument(13);
var el = $('<input type="file" accept="audio/*">');
$(document.body).append(el);

el.on('change', function(e){
  var reader = new FileReader();
  reader.onload = function (e) {
      var context = new AudioContext();
      context.decodeAudioData(e.target.result, function(buffer){
          var node = context.createAnalyser();
          node.fftSize = fftSize;
          node.smoothingTimeConstant = 0;
          node.maxDecibels = 0;
          var bufferLength = node.frequencyBinCount;
          var dataArray = new Uint8Array(bufferLength);
          var audioSource = context.createBufferSource();
          audioSource.buffer = buffer;
          audioSource.loop = false;
          audioSource.connect(node);
          var time = 0;
          audioSource.start(0);  
          setInterval(function(){
              node.getByteFrequencyData(dataArray);
              var f = []; // [index, amplitude]
              for (var i = 1; i < dataArray.length - 1; i++) {
                var isPeak = dataArray[i] >= dataArray[i-1] && dataArray[i] >= dataArray[i+1];
                if (isPeak) {
                  f.push([i, dataArray[i]]);
                }
              }
              f.sort(function(a, b){return b[1] - a[1]});
              var i = 0;
              var added = 0;
              var s = "";
              while (added < maxNotes) {
                var frequency = f[i][0] * context.sampleRate / node.fftSize;
                var note = piano[Math.round((piano.length*Math.log(2)+12*Math.log(55/frequency)+Math.log(4))/(Math.log(2)))];
                if (note != undefined && f[i][1] > minIntensity) {
                  song.addNote(new Note(song, note, time/resolution, 1/resolution, 13, (f[i][1]-minIntensity)/(255-minIntensity)));
                  added++;
                  s += "[" + note + " " + f[i][1] + "] ";
                }
                i++;
                if (i >= f.length) {
                   break;
                }
              }
              time++;
          }, song.sleepTime/resolution);
          setInterval(SequencerView.repaint, 1000);
      });
  }

  reader.readAsArrayBuffer(e.target.files[0]);
});

el.click();


Reply
Pages (3): « Previous 1 2 3



Users browsing this thread:   1 Guest(s)


  •  Return to Top
  •  Contact Us
  •   Home
  •  Lite mode
© Rush Crafted with ❤ by iAndrew
Powered By MyBB, © 2002-2025 MyBB Group.
Linear Mode
Threaded Mode
View a Printable Version
Subscribe to this thread
Add Poll to this thread
Send thread to a friend