[obsidian] vault backup: 2023-10-29 18:14:14[

This commit is contained in:
松浦 知也 Matsuura Tomoya 2023-10-29 18:14:14 +09:00
parent b36689f9a1
commit ce4613814f
4 changed files with 108 additions and 3 deletions

73
content/Bytebeat.md Normal file
View File

@ -0,0 +1,73 @@
#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)
https://youtu.be/tCRPUv8V22o
Bytebeatは2011年に[[viznut]]がYoutube上の動画で公開し、自身のブログの解説などで広がっていった、短いプログラムでオーディオを生成する技法。
[Algorithmic symphonies from one line of code -- how and why?(2011)](http://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html)
その後、Webブラウザ上でも同様のコードを実行できる環境がいくつか誕生
[HTML5 Bytebeat](https://greggman.com/downloads/examples/html5bytebeat/html5bytebeat.html)
[Bytebeat Composer](https://sarpnt.github.io/bytebeat-composer)
---
Bytebeatは元々次のようなC言語のプログラムで作られてた。
```c
main(t){for(;;t++)putchar(((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7);}
```
この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);
}
}
```
これをLinuxの、昔なら`/dev/dsp`、今なら`aplay`のようなパイプで直接音声波形を流し込めるものを使って音を鳴らしていた。
macOSでやろうとするなら、`ffmpeg`に付属する`ffplay`で次のようなコードで書ける
```sh
program | ffplay -f u8 -i pipe:0 -ar 44k -ac 1
```
どうせならC言語使わずにデータを生成したいが、シェルスクリプトで直接バイナリを扱うのは死ぬほどだるい`printf`コマンドや`bc`であれこれすれば不可能でもないが、結局ファイルを一度経由しないと厳しい)
ので、Node.jsでやるとこういう感じでできる
```js
const sample_rate = 8000;
const seconds = 1;
const length = sample_rate * seconds;
//メインの曲の生成部
const bytebeat = t =>
(((t >> 10 ^ t >> 11) % 5) * t >> 16) * ((t >> 14 & 3 ^ t >> 15 & 1) + 1) * t % 99 + ((3 + (t >> 14 & 3) - (t >> 16 & 1)) / 3 * t % 99 & 64);
let t = 0;
const mainProcess = () =>{
const data = Uint8Array.from({ length: length },
(v, _t) => {
const res = bytebeat(t);
t += 1;
return res
}
);
process.stdout.write(data);
};
//場合によってはインターバルを少し短くしないとデータ不足で落ちることあり
setInterval(mainProcess,seconds / 1000.0);
```
これがうまくいくのはJavascriptの整数変換処理が32bitになったりするためなのだが、詳しいことは[授業資料](https://teach.matsuuratomoya.com/docs/2023/mediaart-programming2/4/)に書いた。割愛すると3238年間を超えなければ連続再生しても大丈夫ということになるっぽい。

View File

@ -33,4 +33,32 @@ https://nickm.com/poems/concrete_perl/index.html
SFPC_Malware_Anthology.zip A collection of boundary-pushing software art. by Todd Anderson SFPC_Malware_Anthology.zip A collection of boundary-pushing software art. by Todd Anderson
2023-02-07 2023-02-07
https://rhizome.org/editorial/2023/feb/07/sfpc_malware_anthologyzip/ https://rhizome.org/editorial/2023/feb/07/sfpc_malware_anthologyzip/
Scrapism
https://scrapism.lav.io/
[[谷口暁彦]]さんのStudy
- http://okikata.org/study/test79/ 吾輩は猫であるの圧縮
- http://okikata.org/study/test77/ マラルメ
## キーワード
[[具体詩]] [[コンクリート・ポエトリー]]
## 雑なアイデア
Code poetry
- 青空文庫からランダムに何かを落として使う
- ランダムネスだけでできる何か
- 置き換えだけでできる何か
- ブラウザ拡張でできる何か(読点を全部!!に置き換えるみたいなやつ)
- NLP系(npmの使い方解説ついでに)
- kuromoji使う
- word2vec
-

View File

@ -1 +1,3 @@
[[メディアアート・プログラミング2 リーディングリスト]] [[メディアアート・プログラミング2 リーディングリスト]]
[[Bytebeat]]

View File

@ -17,4 +17,6 @@
[[Cranelift]] [[Cranelift]]
[[竹内関数で音楽]] [[竹内関数で音楽]]
[[Bytebeat]]