diff --git a/content/Bytebeat.md b/content/Bytebeat.md new file mode 100644 index 00000000..768bec5e --- /dev/null +++ b/content/Bytebeat.md @@ -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年間を超えなければ連続再生しても大丈夫ということになるっぽい。 \ No newline at end of file diff --git a/content/メディアアート・プログラミング2 リーディングリスト.md b/content/メディアアート・プログラミング2 リーディングリスト.md index 6c3991db..1536c5c4 100644 --- a/content/メディアアート・プログラミング2 リーディングリスト.md +++ b/content/メディアアート・プログラミング2 リーディングリスト.md @@ -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 2023-02-07 -https://rhizome.org/editorial/2023/feb/07/sfpc_malware_anthologyzip/ \ No newline at end of file +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 + - diff --git a/content/授業に関わるメモ.md b/content/授業に関わるメモ.md index 1e53e962..d8dfb583 100644 --- a/content/授業に関わるメモ.md +++ b/content/授業に関わるメモ.md @@ -1 +1,3 @@ -[[メディアアート・プログラミング2 リーディングリスト]] \ No newline at end of file +[[メディアアート・プログラミング2 リーディングリスト]] + +[[Bytebeat]] \ No newline at end of file diff --git a/content/音楽プログラミング言語.md b/content/音楽プログラミング言語.md index d3fbb006..62e21001 100644 --- a/content/音楽プログラミング言語.md +++ b/content/音楽プログラミング言語.md @@ -17,4 +17,6 @@ [[Cranelift]] -[[竹内関数で音楽]] \ No newline at end of file +[[竹内関数で音楽]] + +[[Bytebeat]] \ No newline at end of file