Skip to content

MaxAlyokhin/binary-synth

Repository files navigation

Binary Synth

Audio synthesis from binary code of any file

Uptime Robot status Uptime Robot status

Demo: https://bs.stranno.su

Эта страница есть также на русском

All data on any computer or smartphone is in the form of files (which are, in essence, texts). The contents of these files are ultimately just zeros and ones. And these zeros and ones are basically all the same, so we need an interpreter to extract meaning from these texts. Basically, the file format (.mp3, .docx, etc.) is just a pointer to which interpreter we need to pass the text in order to extract meaning from it.

But what if the file format and the interpreter don't match?

In the case of musical experimentation, there have been earlier attempts, for example, to "play" a file through an audio editor.

We could go further and write our own interpreter that would look at the files without regard to format, use its own "manner of reading" the original zeros and ones, and on that basis provide a complete system for controlled synthesis of sounds.

Application principle

  1. We can interpret files as an array of numbers. That is, we divide continuous machine code (ArrayBuffer) into words of some information capacity (bitness):
  • 8 bits (numbers from 0 to 255)
  • 16 bits (numbers from 0 to 65 535)
  1. Then, each word is a command that defines the frequency of the sound

  2. At the level of the whole system, we set global parameters:

  • speed of interpretation
  • musical scale (or lack thereof), range of notes/frequencies
  • looping
  • MIDI mode
  • smooth or abrupt transition between commands
  • settings of virtual devices required for synthesis (oscillator, filter, LFO) or MIDI settings
  1. To reduce the load on the device, we divide the file into chunks of 500 commands each

  2. Recursively schedule the synthesis control by reading 500 instructions per iteration and using global parameters

  3. If we have reached the end of the file, stop execution or start again

MIDI

When the MIDI mode is enabled, the first available port and its first channel are automatically selected. Next, a noteOn signal is sent sequentially when reading, and a noteOff signal is sent after the Reading speed time. In Continuous mode, a Pitch signal is sent after each noteOn to hit the desired frequency.

MIDI messages can be sent:

  • to neighboring tabs and browser windows if they are listening to MIDI (e.g., in the web analog DX7)
  • in DAW and other applications with virtual synthesizers (i.e. BS can control, for example, synthesizer in Ableton).
  • to MIDI-compatible external devices connected to a computer

To send MIDI messages to a DAW on Windows devices, you can use loopMIDI.

Note: After any manipulations with MIDI ports (connection/disconnection/re-connection) it is necessary to completely restart the browser, closing all browser windows if there are several of them

Note: MIDI messages are generated on the desktop only

Interface features

  • Reading speed - interpretation speed; at high speeds over 0.001 the application may become unstable

  • Bitness - we can divide the binary code into words of 8 or 16 bits, which changes the number of available frequencies (256 or 65536).

  • Frequency generation mode

    • continuous - continuous frequency distribution
    • tempered - distribution by 12-step equal-tempered scale. There are notes from C-2 to B8
  • Transition type - transition between frequencies

    • immediate - instantaneous, rough transition
    • linear - linearly to the next frequency
    • exponential - exponentially to the next frequency
  • Random time gap - adds a random amount of time to the next tone within the Reading speed parameter. Makes the sound less "robotic", as the distance to each tone is slightly different and it adds more "liveliness" to the playing

  • Commands range - allows to play not the whole file, but a certain part of it

  • Solid mode - the "solid press" mode, does not send noteOff commands; if the commands are the same in a row (and as a consequence notes), even noteOn is not sent. allSoundOff is sent at the end. On some synthesizers it allows smooth transitions between notes

  • Some input fields have a keyboard shortcut: pressing the corresponding key automatically moves the focus to the item. By pressing a key and moving the mouse at the same time, the values can be changed smoothly. The Y axis of the mouse movement determines the "power" of the value change

Run locally and build the project

Just copy the app

Everything you need for the system is contained in a single .html file, which you can download in the dist folder, or simply go to https://bs.ѕtranno.su and right-click and select Save As in the menu.

Build locally to work with the code

Tech stack: Vue3 + Pinia + Vite.

  1. Download and install the LTS version of Node.js
  2. Download the code directly from Github, or via git clone.
  3. In the project folder in the terminal execute:
npm i
npm run dev # development-build
npm run build # production-build, generate index.html with everything we need

For MIDI tests, you can use this resource https://studiocode.dev/midi-monitor/