Skip to content

Instantly share code, notes, and snippets.

@lennyerik
Created November 2, 2022 21:14
Show Gist options
  • Save lennyerik/7fc52da9e6959c7e72d62e5516130c94 to your computer and use it in GitHub Desktop.
Save lennyerik/7fc52da9e6959c7e72d62e5516130c94 to your computer and use it in GitHub Desktop.
Plays the Tetris theme in the TScript programming language
var frequency = [
659.25511, 493.8833, 523.25113, 587.32954, 523.25113, 493.8833, 440.0, 440.0,
523.25113, 659.25511, 587.32954, 523.25113, 493.8833, 523.25113, 587.32954,
659.25511, 523.25113, 440.0, 440.0, 440.0, 493.8833, 523.25113, 587.32954,
698.45646, 880.0, 783.99087, 698.45646, 659.25511, 523.25113, 659.25511,
587.32954, 523.25113, 493.8833, 493.8833, 523.25113, 587.32954, 659.25511,
523.25113, 440.0, 440.0
];
var duration = [
406.250, 203.125, 203.125, 406.250, 203.125, 203.125, 406.250, 203.125,
203.125, 406.250, 203.125, 203.125, 609.375, 203.125, 406.250, 406.250,
406.250, 406.250, 203.125, 203.125, 203.125, 203.125, 609.375, 203.125,
406.250, 203.125, 203.125, 609.375, 203.125, 406.250, 203.125, 203.125,
406.250, 203.125, 203.125, 406.250, 406.250, 406.250, 406.250, 406.250
];
var sample_rate = 8000;
function arr_sum(arr) {
var sum = 0;
for var elem in arr do {
sum += elem;
}
return sum;
}
var samples = [];
for var i in 0:frequency.size() do {
var freq = frequency[i];
for var j in 0:sample_rate*(duration[i]/1000) do {
samples.push(math.sin((freq / sample_rate) * j * 2 * math.pi()));
}
}
var sound = audio.Sound([samples, samples], sample_rate);
sound.play();
wait(arr_sum(duration));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment