This commit is contained in:
2024-11-04 17:04:35 +09:00
parent 56e5f290e2
commit 43ee7b8e5b
25 changed files with 414 additions and 21 deletions

View File

@@ -4,7 +4,6 @@ date: "2023-10-29T18:14:14+0900"
#programming #music #sound
[Algorithmic symphonies from one line of code -- how and why?(2011)](http://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html)
@@ -18,7 +17,7 @@ Bytebeatは2011年に[[viznut]]がYoutube上の動画で公開し、自身のブ
[HTML5 Bytebeat](https://greggman.com/downloads/examples/html5bytebeat/html5bytebeat.html)
[Bytebeat Composer](https://sarpnt.github.io/bytebeat-composer)
[Bytebeat Composer](https://bytebeat.ficial.net/)
---
@@ -32,13 +31,12 @@ Bytebeatは元々次のようなC言語のプログラムで作られてた。
main(t){for(;;t++)putchar(((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7);}
```
このC言語のコードは極限まで圧縮されているのでもうちょっと丁寧に書くとこうなります。
このC言語のコードは極限まで圧縮されているのでもうちょっと丁寧に書くとこうなります(大昔のCコンパイラでない限りエラーで落とされる)
```c
int main(int t){
for(;;t++){
putchar(((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7);
}
#include <stdio.h>
int main(){
for(int t=0;;t++) putchar(((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7);
}
```
@@ -47,7 +45,7 @@ int main(int t){
macOSでやろうとするなら、`ffmpeg`に付属する`ffplay`で次のようなコードで書ける
```sh
program | ffplay -f u8 -i pipe:0 -ar 44k -ac 1
program | ffplay -f u8 -i pipe:0 -ar 8k -ch_layout mono
```
どうせならC言語使わずにデータを生成したいが、シェルスクリプトで直接バイナリを扱うのは死ぬほどだるい`printf`コマンドや`bc`であれこれすれば不可能でもないが、結局ファイルを一度経由しないと厳しい)
@@ -65,11 +63,7 @@ let t = 0;
const mainProcess = () =>{
const data = Uint8Array.from({ length: length },
(v, _t) => {
const res = bytebeat(t);
t += 1;
return res
}
(v, _t) => bytebeat(t++)
);
process.stdout.write(data);
};