Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
74
Task/Musical-scale/Ada/musical-scale.adb
Normal file
74
Task/Musical-scale/Ada/musical-scale.adb
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
pragma Ada_2022;
|
||||
with Ada.Numerics; use Ada.Numerics;
|
||||
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
|
||||
with Ada.Sequential_IO;
|
||||
with Interfaces; use Interfaces;
|
||||
|
||||
procedure Musical_Scale is
|
||||
package Byte_IO is new Ada.Sequential_IO (Unsigned_8); use Byte_IO;
|
||||
|
||||
SAMPLE_RATE : constant Unsigned_32 := 44100;
|
||||
DURATION : constant Unsigned_32 := 8;
|
||||
DATA_LENGTH : constant Unsigned_32 := SAMPLE_RATE * DURATION;
|
||||
WAV_HDR_LEN : constant Integer := 44;
|
||||
FILE_SIZE_8 : constant Unsigned_32 := Unsigned_32 (WAV_HDR_LEN) + DATA_LENGTH + 4;
|
||||
|
||||
type Byte_Arr is array (Positive range <>) of Unsigned_8;
|
||||
Wav_Header : constant Byte_Arr (1 .. WAV_HDR_LEN) := [
|
||||
Character'Pos ('R'), Character'Pos ('I'), Character'Pos ('F'), Character'Pos ('F'),
|
||||
Unsigned_8 (FILE_SIZE_8 and 16#ff#),
|
||||
Unsigned_8 (Shift_Right (FILE_SIZE_8, 8) and 16#ff#),
|
||||
Unsigned_8 (Shift_Right (FILE_SIZE_8, 16) and 16#ff#),
|
||||
Unsigned_8 (Shift_Right (FILE_SIZE_8, 24) and 16#ff#),
|
||||
Character'Pos ('W'), Character'Pos ('A'), Character'Pos ('V'), Character'Pos ('E'),
|
||||
Character'Pos ('f'), Character'Pos ('m'), Character'Pos ('t'), Character'Pos (' '),
|
||||
16#10#, 0, 0, 0, 1, 0, 1, 0, 16#44#, 16#ac#, 0, 0, 16#44#, 16#ac#, 0, 0, 1, 0, 8, 0,
|
||||
Character'Pos ('d'), Character'Pos ('a'), Character'Pos ('t'), Character'Pos ('a'),
|
||||
Unsigned_8 (DATA_LENGTH and 16#ff#),
|
||||
Unsigned_8 (Shift_Right (DATA_LENGTH, 8) and 16#ff#),
|
||||
Unsigned_8 (Shift_Right (DATA_LENGTH, 16) and 16#ff#),
|
||||
Unsigned_8 (Shift_Right (DATA_LENGTH, 24) and 16#ff#)
|
||||
];
|
||||
MIDI_Header : constant Byte_Arr (1 .. 22) := [
|
||||
Character'Pos ('M'), Character'Pos ('T'), Character'Pos ('h'), Character'Pos ('d'),
|
||||
0, 0, 0, 6, 0, 0, 0, 1, 0, 96, -- File header
|
||||
Character'Pos ('M'), Character'Pos ('T'), Character'Pos ('r'), Character'Pos ('k'),
|
||||
0, 0, 0, 8 * 8 + 4 -- Track header
|
||||
];
|
||||
MIDI_Trailer : constant Byte_Arr := [0, 16#ff#, 16#2f#, 0];
|
||||
type Freq_Arr is array (Positive range <>) of Float;
|
||||
Freqs : constant Freq_Arr := [261.63, 293.67, 329.63, 349.23, 392.0, 440.0, 493.88, 523.25];
|
||||
Notes : constant Byte_Arr := [60, 62, 64, 65, 67, 69, 71, 72];
|
||||
Note_On_Off : Byte_Arr := [0, 16#90#, 0, 16#40#, 16#60#, 16#80#, 0, 0];
|
||||
|
||||
Wav_File, MIDI_File : File_Type;
|
||||
Omega : Float;
|
||||
|
||||
procedure Write_Arr (File : File_Type; Arr : Byte_Arr) is
|
||||
begin
|
||||
for B of Arr loop
|
||||
Write (File, B);
|
||||
end loop;
|
||||
end Write_Arr;
|
||||
|
||||
begin
|
||||
Create (Wav_File, Out_File, "scale.wav");
|
||||
Write_Arr (Wav_File, Wav_Header);
|
||||
for Freq of Freqs loop
|
||||
Omega := 2.0 * Pi * Freq;
|
||||
for Tick in 0 .. Integer (DATA_LENGTH) / 8 loop
|
||||
Write (Wav_File, Unsigned_8 (32.0 * (Sin (Omega * Float (Tick) / Float (SAMPLE_RATE)) + 1.0)));
|
||||
end loop;
|
||||
end loop;
|
||||
Close (Wav_File);
|
||||
|
||||
Create (MIDI_File, Out_File, "scale.mid");
|
||||
Write_Arr (MIDI_File, MIDI_Header);
|
||||
for Note of Notes loop
|
||||
Note_On_Off (3) := Note;
|
||||
Note_On_Off (7) := Note;
|
||||
Write_Arr (MIDI_File, Note_On_Off);
|
||||
end loop;
|
||||
Write_Arr (MIDI_File, MIDI_Trailer);
|
||||
Close (MIDI_File);
|
||||
end Musical_Scale;
|
||||
22
Task/Musical-scale/Emacs-Lisp/musical-scale.el
Normal file
22
Task/Musical-scale/Emacs-Lisp/musical-scale.el
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(defun play-scale (freq-list dur)
|
||||
"Play a list of frequencies."
|
||||
(setq header (unibyte-string ; AU header:
|
||||
46 115 110 100 ; ".snd" magic number
|
||||
0 0 0 24 ; start of data bytes
|
||||
255 255 255 255 ; file size is unknown
|
||||
0 0 0 3 ; 16 bit PCM samples
|
||||
0 0 172 68 ; 44,100 samples/s
|
||||
0 0 0 1)) ; mono
|
||||
(setq s nil)
|
||||
(dolist (freq freq-list)
|
||||
(setq v (mapcar (lambda (x)
|
||||
(mod (round (* 32000 (sin (* 2 pi freq x (/ 44100.0))))) 65536))
|
||||
(number-sequence 0 (* dur 44100))))
|
||||
(setq s (apply #'concat s (flatten-list (mapcar (lambda (x)
|
||||
(list (unibyte-string (ash x -8))
|
||||
(unibyte-string (mod x 256))))
|
||||
v)))))
|
||||
(setq s (concat header s))
|
||||
(play-sound `(sound :data ,s)))
|
||||
|
||||
(play-scale '(261.63 293.66 329.63 349.23 392.00 440.00 493.88 523.25) .5)
|
||||
65
Task/Musical-scale/Odin/musical-scale.odin
Normal file
65
Task/Musical-scale/Odin/musical-scale.odin
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package main
|
||||
|
||||
import "core:time"
|
||||
import "core:fmt"
|
||||
import ma "vendor:miniaudio"
|
||||
|
||||
data_callback :: proc "c" (device: ^ma.device, output: rawptr, input: rawptr, frameCount: u32) {
|
||||
assert_contextless(device.playback.channels == 2)
|
||||
|
||||
sine := (^ma.waveform)(device.pUserData)
|
||||
assert_contextless(sine != nil)
|
||||
|
||||
ma.waveform_read_pcm_frames(sine, output, u64(frameCount), nil)
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
NOTE :: [8]f64 {261.63, 293.67, 329.63, 349.23, 392.00, 440.01, 493.89, 523.26}
|
||||
NOTE_NAME := [8]string {"C", "D", "E", "F", "G", "A", "B", "C'" }
|
||||
|
||||
wave_config : ma.waveform_config = ---
|
||||
device_config : ma.device_config = ---
|
||||
wave : ma.waveform = ---
|
||||
device : ma.device = ---
|
||||
|
||||
device_config = ma.device_config_init(.playback)
|
||||
device_config.dataCallback = data_callback
|
||||
device_config.pUserData = &wave
|
||||
|
||||
if ma.device_init(nil, &device_config, &device) != .SUCCESS {
|
||||
panic("Failed to open playback device")
|
||||
}
|
||||
fmt.printfln("Device Name: %s", device.playback.name)
|
||||
|
||||
for freq, i in NOTE {
|
||||
wave_config = ma.waveform_config_init(
|
||||
device.playback.playback_format,
|
||||
device.playback.channels,
|
||||
device.sampleRate,
|
||||
.triangle,
|
||||
0.2,
|
||||
freq,
|
||||
)
|
||||
|
||||
if ma.waveform_init(&wave_config, &wave) != .SUCCESS {
|
||||
fmt.eprintln("Failed to init waveform")
|
||||
break
|
||||
}
|
||||
|
||||
if ma.device_start(&device) != .SUCCESS {
|
||||
fmt.eprintln("Failed to start playback device")
|
||||
break
|
||||
} else {
|
||||
fmt.printfln("Playing %s", NOTE_NAME[i])
|
||||
}
|
||||
|
||||
time.sleep(time.Second)
|
||||
|
||||
if ma.device_stop(&device) != .SUCCESS {
|
||||
fmt.eprintln("Failed to stop playback device")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
ma.device_uninit(&device)
|
||||
}
|
||||
18
Task/Musical-scale/Pluto/musical-scale.pluto
Normal file
18
Task/Musical-scale/Pluto/musical-scale.pluto
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
local audio = require "audio"
|
||||
require "table2"
|
||||
|
||||
local sample_rate = 44100
|
||||
local duration = 8
|
||||
local data = table.rep(sample_rate * duration, 0)
|
||||
local freqs = {261.6, 293.6, 329.6, 349.2, 392.0, 440.0, 493.9, 523.3}
|
||||
for j = 0, duration - 1 do
|
||||
local freq = freqs[j + 1]
|
||||
local omega = 2 * math.pi * freq
|
||||
for i = 0, sample_rate - 1 do
|
||||
local y = math.round(32 * math.sin(omega * i / sample_rate)) & 255
|
||||
data[i + j * sample_rate + 1] = y
|
||||
end
|
||||
end
|
||||
local filepath = "musical_scale.wav"
|
||||
audio.create(filepath, data, sample_rate)
|
||||
audio.play(filepath)
|
||||
4
Task/Musical-scale/PowerShell/musical-scale.ps1
Normal file
4
Task/Musical-scale/PowerShell/musical-scale.ps1
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
$frequencies = 261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25
|
||||
foreach($tone in $frequencies){
|
||||
[Console]::beep($tone, 500)
|
||||
}
|
||||
3
Task/Musical-scale/Uiua/musical-scale.uiua
Normal file
3
Task/Musical-scale/Uiua/musical-scale.uiua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
f ← ×261˜ⁿ2÷12 [0 2 4 5 7 9 11 12]
|
||||
s ← ∿×τ⊞×f ÷⟜⇡&asr
|
||||
÷⧻f/⊂s
|
||||
Loading…
Add table
Add a link
Reference in a new issue