Re: Combining sound files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, February 25, 2007 9:22 am, tedd wrote:
> Hi gang:
>
> I can combine two mp3 sound files together by simply:
>
> // load  first
>
> $file = "a.mp3";
> $handle = fopen($file, "rb");
> $size = filesize($file);
> $load = fread($handle, $size);
> fclose($handle);
>
> // load second
>
> $file = "b.mp3";
> $handle = fopen($file, "rb");
> $size = filesize($file);
> $load .= fread($handle, $size);
> fclose($handle);
>
> // save both as one audio file
>
> $filename = "tmp/a.mp3";
> $file = fopen( $filename, "wb" );
> fwrite( $file, $load);
> fclose( $file );

I am not certain that that creates a truly valid MP3 file, but it does
seem to work in all the players I've ever tried.

I do it all the time with ID3 tags on the fly from the DB and the
actual MP3 data from a static file.

Anybody know a good MP3 validator in command line Linux, off the top
of their heads?  My last attempt to Google didn't yeild anything, but
that was a couple years ago...

> However, I can't do the same with .WAV files. Does anyone know a way
> to combine .WAV files similar to the way shown above?

The first 256 bytes of a .WAV file contains magic numbers indicating
the bit-size (16-bit, 8-bit, whatever) and sampling rate (44.1 kHz,
22.05 kHz, 96kHz, etc) and imaging (stereo, mono, and I think maybe
others) as well as the total number of samples (I.e., file length).

There are also some slots for things like copyright, comments etc, as
I recall.

You're going to have to find specs on that header info, read the first
256 bytes of each file, compute new numbers to put into the .wav
header, and write out the new 256 bytes and then the remainders of the
two files.

If the two files are NOT both the same bit/sample rate, then you'd
have some REAL fun trying to scale/re-sample the actual audio... :-)

You may find it easier/faster to just locate a .wav splicer command
line tool and run exec with it.  Though perhaps not nearly as fun,
depending on your definition of fun.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux