Я пытаюсь создать .mp3, который можно использовать в качестве метронома (с нотами с акцентом/без акцента). Я новичок в потоках PHP, а также в LAME. Используя эту документацию, я попробовал ее, но не думаю, что я правильно использую потоки:
<?php
// mp3=/Bottle_120_4_4_16.mp3 (Bottle 4/4 time, 120bpm - 4 measures (16 beats))
$mp3 = strtolower(str_replace('/', '', $_GET['mp3']));
$m = explode('_', $mp3);
$sound = $m[0];//bottle
$BPM = $m[1];//120
$time_a = $m[2];//4
$time_b = $m[3];//4
$nBeats = $m[4];//16
header('Content-Type: audio/mpeg');
header('Content-Disposition:attachment;filename='.$mp3);
header('Pragma: no-cache');
$stream = fopen('php://output', 'a');
// GENERATE PCM
$sampleRate = 48000;
$channels = 1;//Mono
$bytePerSample = 2;
$bytesInSecond = ($sampleRate * $bytePerSample * $channels);
$beatLenInSec = (60 / $BPM);
if ($time_b == 8){
$beatLenInSec = ($beatLenInSec / 2);
}
$bytesInBeat = intval($beatLenInSec * $bytesInSecond);
$bytesInBeat = (intval($bytesInBeat / $bytePerSample) * $bytePerSample);
$accentFileName = 'sound/'.$sound.'/wav/'.$sound.'-accent_ws.wav';
$noteFileName = 'sound/'.$sound.'/wav/'.$sound.'-note_ws.wav';
$PCMDataPosition = 58;
$fileA = fopen($accentFileName, 'r');
$fileB = fopen($noteFileName, 'r');
$data = '';
for ($i = 0; $i < $nBeats; $i++) {
if (($i % $time_a) == 1){
fseek($fileA, $PCMDataPosition);
$data = fread($fileA, $bytesInBeat);
} else {
fseek($fileB, $PCMDataPosition);
$data = fread($fileB, $bytesInBeat);
}
fwrite($stream, $data);
}
$lame = fopen('php://output', 'a');
// LAME ENCODE
$path = '/home/html/';
system($path.'bin/lame -r -s 48.00 -m m -b 16 - - '.$stream.' '.$lame);
fclose($stream);
fclose($lame);
?>
Два потока необходимы для того, что я делаю?