471,873 Members | 992 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

Merge Two Wave Files using php

Hi Guys

I need a php script which will merge two wave files as i have already done a script which will will join the two wave files and play one after the other, can anyone advice me how to merge the two wave file and the two files has to play simultaneously. i have placed my script here


<?php

$content = joinwavs(array('1.wav','2.wav'));
header('Content-Type: audio/x-wav');
//echo $content;



function joinwavs($wavs){
$fields = join('/',array( 'H8ChunkID', 'VChunkSize', 'H8Format',
'H8Subchunk1ID', 'VSubchunk1Size',
'vAudioFormat', 'vNumChannels', 'VSampleRate',
'VByteRate', 'vBlockAlign', 'vBitsPerSample' ));
$data = '';

foreach($wavs as $wav){
$fp = fopen($wav,'rb');
$header = fread($fp,36);
$info = unpack($fields,$header);
// Destination file to be writed
$destfile = "destination.wav";
// read optional extra stuff
if($info['Subchunk1Size'] > 16){
$header .= fread($fp,($info['Subchunk1Size']-16));
}
// read SubChunk2ID
$header .= fread($fp,4);
// read Subchunk2Size
$size = unpack('vsize',fread($fp,4));
$size = $size['size'];
// read data
$data .= fread($fp,$size);
$filecontent = $header.pack('V',strlen($data)).$data;
// Write the output data in a seperate file
$fp1 = fopen($destfile,"wb");
fwrite($fp1,$filecontent);
fclose($fp1);


}
}

?>





Regards

Karthik
Apr 25 '07 #1
3 5069
Motoma
3,237 Expert 2GB
This is getting more into the area of programming that PHP is not designed for. You will need to examine the WAV standard and see exactly how two overlapped WAV files are represented as data. My assumption is that you will first need to read in each segment of data from each WAV file and perform a sort of "data merge" on the waveform, and then produce a new file using your new data set.

You will probably have better luck finding a tool that will do this for you.
Apr 25 '07 #2
tolkienarda
316 100+
just as a brief suggestion of a language that would work is python. it is so versitle i an still a total beginer but the more i learn the more i love the language and its odd rules.

eric
Apr 25 '07 #3
This is getting more into the area of programming that PHP is not designed for. You will need to examine the WAV standard and see exactly how two overlapped WAV files are represented as data. My assumption is that you will first need to read in each segment of data from each WAV file and perform a sort of "data merge" on the waveform, and then produce a new file using your new data set.

You will probably have better luck finding a tool that will do this for you.

Is there any third party tool to do this , if so can u mention some of the tools that should work in linux server.
May 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by vikram | last post: by
8 posts views Thread by Squirrel | last post: by
5 posts views Thread by m.topczewski | last post: by
1 post views Thread by blitzme | last post: by
4 posts views Thread by Tom Jones | last post: by
7 posts views Thread by giladp1 | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.