Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Composerだって音楽を奏でたい

 Composerだって音楽を奏でたい

PHPMatsuri Reboot in Hackone での成果発表LTです

Avatar for hideki kinjyo

hideki kinjyo PRO

November 07, 2026

More Decks by hideki kinjyo

Other Decks in Programming

Transcript

  1. 音の送信 $osc = new UdpOscClient( '127.0.0.1', 9000, ); $osc->send( '/drum/snare',

    [0.8, 0.22], ); • Open Sound Control • という規格(に乗っかった) • 「メッセージ」と 「引数」で構成される
  2. 音の送信 for ($n = 0; $n < $count; $n++, $i++)

    { $t = $i / $sampleRate; $phase += 2 * M_PI * (46 + 170 * exp(-$t / 0.028)) / $sampleRate; $body = sin($phase) * exp(-$t / $decayConstant); $click = self::noise() * exp(-$t / 0.0015) * 0.35; $fade = min(1.0, ($length - 1 - $i) / self::FADE_SAMPLES); $sample = tanh(self::DRIVE * $body + $click) * $fade * $gain; $left[$n] += $sample; $right[$n] += $sample; } 受け 取っ た音 を波 形 デー タに する
  3. 音の再生 • FFIで良い感じにやる foreach ($buffer->samples as $i => $sample) {

    $this->samples[$i] = $sample; } $result = $this ->portAudio->Pa_WriteStream( $this->stream[0], $this->samples, intdiv( count($buffer->samples), $this->format->channels), ); • • PortAudio