- /
-
Mini Hack (Audio to Image)
on 13 Oct 2024
- 17
- 273
- 0
- 3
- 508
Cite your audio source here (if applicable): Westminster Quarters
Image: みんちりえ( https://min-chi.material.jp/ )
Write your drawframe function below
function drawframe(f)
if f == 1 % Create image
set(gca, 'position', [0 0 1 1]);
y = audioread("audio.wav");
y = reshape(y, 150, 150, 3);
image(imresize(y, 4));
axis off
end
if f == 96 % Create audio
Fs = 44100;
t = 0 : 1/Fs : 1;
frequencies = [
261.626 % C4 ド
293.665 % D4 レ
329.628 % E4 ミ
349.228 % F4 ファ
391.995 % G4 ソ
440.000 % A4 ラ
493.883 % B4 シ
523.251 % C4 ド
];
d = Fs * 0.1;
fade = linspace(1, 0, d);
sounds = [];
for i = [4 6 5 1 4 5 6 4 6 4 5 1]
sound = 0.2 * sin(2 * pi * frequencies(i) * t);
sound(1:d) = sound(1:d) .* flip(fade);
sound(end-d+1:end) = sound(end-d+1:end) .* fade;
sounds = [sounds, sound];
end
audiowrite('audio.wav', sounds, Fs);
end
end