Sound Bytes

A coding competition


Project maintained by coding-competitions Hosted on GitHub Pages — Theme by mattgraham

Constant spectrum melody

by pswg

Listen

A constant spectrum melody generator.

This is an example submission written in JavaScript / Node.js.

index.js


n = 10, harmon = 10, rate = 44100, df = 0.1;
for (t = 1; t <= 30 * rate; t++) {
  for (i = 0, y = 0; i <= n; i++)
    for (j = 1; j <= harmon; j++) 
      y += Math.sin(2 * Math.PI * (55 + i * df) * j * t / rate) / (n * harmon);
  process.stdout.write(Buffer.from(Float32Array.of(y).buffer));
}

Language

JavaScript

Golf Score

294

Parameters

Sample Rate: 44100 Hz
Sample Size: 32 bits
Channels: 1 (mono)
Encoding: floating-point

Commands

Run

node .

Spectrogram

Spectrogram