WIP booyah mp3

This commit is contained in:
Brooke Vibber 2023-03-07 14:41:16 -08:00
parent cbae496cf8
commit 6f9d18670d

View file

@ -568,7 +568,7 @@ class MP3Reader {
return ftell( $this->file );
}
public function readFrame() {
public function readSegment() {
while ( true ) {
$start = $this->pos();
$lookahead = 10;
@ -582,16 +582,15 @@ class MP3Reader {
$data = unpack( "Nval", $bytes );
$header = new MP3FrameHeader( $data['val'] );
if ( $header->sync ) {
$segments[] = [
// Note we don't need the data at this time.
fseek( $this->file, $start + $header->size, SEEK_SET );
$this->timestamp += $header->duration;
return [
'start' => $start,
'size' => $header->size,
'timestamp' => $this->timestamp,
'duration' => $header->duration,
];
$this->timestamp += $header->duration;
// Note we don't need the data at this time.
fseek( $this->file, $start + $header->size, SEEK_SET );
continue;
}
// ID3v2.3
@ -608,14 +607,13 @@ class MP3Reader {
( $id3['size2'] << 14) |
( $id3['size1'] << 21) );
// For byte range purposes; count as zero duration
$segments[] = [
fseek( $this->file, $start + $size, SEEK_SET );
return [
'start' => $start,
'size' => $size,
'timestamp' => $this->timestamp,
'duration' => 0.0,
];
fseek( $this->file, $start + $size, SEEK_SET );
continue;
}
$hex = hexdump( $bytes );
@ -640,12 +638,14 @@ function extractMP3( $filename ) {
$timestamp = 0.0;
while ( true ) {
$start = $reader->pos();
$segment = $reader->readFrame();
$segment = $reader->readSegment();
var_dump($segment);
if ( !$segment ) {
return $segments;
break;
}
$segments[] = $segment;
}
var_dump($segments);
return $segments;
} finally {
fclose( $file );