Bytebeat


Return
1. Don`t create new thread for each song every time, or you will be banned!
2. Create your own thread and post all your songs in it, or post in the Common Thread.
3. Post your requests and reports here.

[ Common thread / Requests / Changelog / Rules ]
absolute197 / aniruF / ANoUserXD / aturned777 / BaenHoHoHo / Blueygray / botbeat / BrokenCircle / Chasyxx / ChrisRM380 / Decent-Manager-6169 / emelchenko / eSlashMachine / Glebguything / Greaserpirate / hcdphobe / Holiday-Charge-1313 / HypernovaHeathen / IgorZevel / kOLbOSa_exe / Kouzerumatsu / LarkeyFactorial / lhphr / MarioFan171 / MT2023 / n3409 / nickdoesthings / OnixIsThePewterGod / p8192 / PortablePorcelain / PrincessPriscillaPT / psubscirbe / rubi / SArpnt / SentleXR / Slinx92 / SthephanShi / Syranero / Thinguy / TKBMC1845 / trashimpossible3699 / Two2Fall / Underline / Unname4798 / Zackx

CAPTCHA
 Deletion password
  • Supported file types are JPG, PNG, GIF, AVIF, WEBP, WEBM, MP4 and MOV.
  • Limit: 4 files, 30 MB per file (60 MB for Passcode users).
  • Images greater than 250x250 will be thumbnailed.
  • 2479 unique users on the board.

photo_2025-09-18_00-42-48.jpg
565.32KB, 1014x919
so i was just interested can i turn midi into a bytecode, and the answer is yes but the final code is too big and idk how to optimize it
const fs = require('fs');
const { Midi } = require('@tonejs/midi');

const midiData = fs.readFileSync('song.mid');
const midi = new Midi(midiData);

const sampleRate = 44100;
let notesByteCode = [];

function midiToFrequency(n) {
    return 440 * Math.pow(2, (n - 69) / 12);
}

function getADSRCode(startT, endT) {
    const attack = 50;  
    const release = 50; 
    return `(t<${startT}+${attack}?((t-${startT})/${attack}):t>${endT}-${release}?(${endT}-t)/${release}:1)`;
}

function getByteCode(note) {
    const startT = Math.round(note.time * sampleRate);
    const endT = Math.round((note.time + note.duration) * sampleRate);
    const freq = midiToFrequency(note.midi);
    const velocity = note.velocity || 1; 

    const adsr = getADSRCode(startT, endT);

    return `(t>=${startT}&&t<${endT}?(${velocity}*${adsr}*Math.sin(2*Math.PI*${freq}*t/${sampleRate})*127 + 128):0)`;
}

midi.tracks.forEach(track => {
    track.notes.forEach(note => {
        notesByteCode.push(getByteCode(note));
    });
});

const result = `Math.max(${notesByteCode.join(',')})`;

fs.writeFileSync('result.txt', result);
im curios if someone can fix it for the result being more compact but it can run mario! Here's the link:
[Click]

Message edited: 28.09.25 Sun 01:35:11

Delete Post  

1. Don`t create new thread for each song every time, or you will be banned!
2. Create your own thread and post all your songs in it, or post in the Common Thread.
3. Post your requests and reports here.

[ Common thread / Requests / Changelog / Rules ]
absolute197 / aniruF / ANoUserXD / aturned777 / BaenHoHoHo / Blueygray / botbeat / BrokenCircle / Chasyxx / ChrisRM380 / Decent-Manager-6169 / emelchenko / eSlashMachine / Glebguything / Greaserpirate / hcdphobe / Holiday-Charge-1313 / HypernovaHeathen / IgorZevel / kOLbOSa_exe / Kouzerumatsu / LarkeyFactorial / lhphr / MarioFan171 / MT2023 / n3409 / nickdoesthings / OnixIsThePewterGod / p8192 / PortablePorcelain / PrincessPriscillaPT / psubscirbe / rubi / SArpnt / SentleXR / Slinx92 / SthephanShi / Syranero / Thinguy / TKBMC1845 / trashimpossible3699 / Two2Fall / Underline / Unname4798 / Zackx
Return