Page 1 of 1
manipulate audio
Posted: Thu Feb 03, 2005 10:19 am
by bimo
I haven't been able to find anything, but is it possible to manipulate an mp3 with ph3? I'm looking for some way to manipulate what a streamable/downloadable audio file sounds like (pitch, volume, sound quality, every or any way) in PHP (I'm trying to avaoid Flash... not that it's bad, I'm just focussing my energy on PHP).
Any ideas?
Posted: Thu Feb 03, 2005 10:23 am
by feyd
just so you know, those operations are very cpu intensive.
Posted: Thu Feb 03, 2005 11:59 am
by bimo
even volume?
Posted: Thu Feb 03, 2005 12:11 pm
by feyd
depending on how you want to do it, yes it can be. Remember that there are 22K to 96K samples per second, and probably 2 channels to perform that on.
96K * 2 = 192K floating point ops required to run per second. I haven't benchmarked PHP's floating point op speed, but I'd bet it isn't extremely fast.
Posted: Thu Feb 03, 2005 1:31 pm
by bimo
True, digital audio is a hog... I was hoping to be able to dynamically truncate the mp3 before all of it were downloaded for processing, although, while I feel like ftruncate() could do it, I haven't tried yet.
It also seems like there's some info stored in the mp3's ID3 frame (correct term?) that can be used to manipulate teh frequency, sample rate, stereo/mono, etc (maybe). I was thinking that if I truncated the audio file first thing then shorter clips could be downloaded and sampled automatically.
It looks like the Ming functions can turn an mp3 into a swf (or at least stream it like one) but that would involve talking to my server admin and having the Ming package installed (which could take a while and he might not want to do it anyway.)
Sorry if I'm babbling. I'm doing too many things at the same time while ideasurfing. I'll just send this and see what you think.
thanks
Posted: Thu Feb 03, 2005 4:36 pm
by feyd
what about a shoutcast server? They can provide multiple streams of various bitrates automatically..
Posted: Thu Feb 03, 2005 10:20 pm
by bimo
I'm looking into that. It sounds like it has potential. I just need to see if I can wrap my head around it.
Thanks again, feyd
Posted: Thu Feb 03, 2005 10:24 pm
by feyd
the problem I see with just fiddling with the ID3 information is that it doesn't process the file, so changing the bitrate or frequency or whatever to a different value will just make the reading program process the file differently, but not resample the data, as it would expect the data stream to already be in that format, instead of having to do the conversion on the fly itself.
Posted: Thu Feb 03, 2005 11:27 pm
by bimo
Well, my experience with using wrong bitrates is that if you tell it that an audio file recorded with a 16bit bit-depth bitrate of 22,000Hz is 16bit/8000Hz, the song plays extra-slow (I think that would be lowering it's frequency).
The ID3 doesn't actually reprocess the audio but maybe I can get the plugin to. I know that digital music doesn't work exactly like an lp but it seems like it's worth a shot.
h
Posted: Thu Feb 03, 2005 11:37 pm
by feyd
Pitch shifting, without time expansion is difficult, as it requires a lot of conversion and math, very intense math. Your example would extend the time to play the file proportionally to the difference of the frequencies.
Volume is the easiest to manipulate, as it doesn't change how the data is read, just the values of them. However, because of alias stepping, and the algorithm you use to change volume, you may be changing the volume with errors.
Changing the sampling rate is simple, provided the stepping is a denominator of the original. If not, then interpolation is required, which can add lots of math, when accuracy is needed.
There are some ~quick math versions of the traditional math functions used for this that will speed up processing times, but will slowly introduce errors in calculations.
Posted: Thu Feb 03, 2005 11:56 pm
by bimo
Sounds very cool. I'm no math whiz but I do enjoy it.
So are you still talking about using php to accomplish the audio manip or do you need to use some other means?
I'm very intrigued...
Posted: Fri Feb 04, 2005 12:24 am
by feyd
if the server is free of other processes and it is a fairly powerful machine, php should be able to do some of it.. However, because of the interpretive nature of php, it's best to use a fully compiled executable to do it, or hardware when possible.
Posted: Fri Feb 04, 2005 1:00 am
by bimo
Well, if I'm only working on tiny mp3's or bits of them and the server is rarely very busy, would it put the server under that much stress? I'll have to check on how much power in has b/c I think it is the oldest server my department uses.
Also, I am not looking to make an online audio production tool or anything, although that would be cool. The manipulation idea is just an offshoot of another idea that I had. I guess the kid in me can't help but poke at things that I don't understand.
Is is possible to dig down into an mp3 and change individual bit order?
Also, I don't think creating minor errors wiould matter too much for what I would need it for. The pitch and bitrate changing problems would be more in relation to "creative" pursuits so jumbled sound would add to the element of surprise. For my original project I had originally only conceived of cropping sound length and possibly volume.
Are you talking about "digging down" into the various layers of the mp3 and changing them bitwise?
Posted: Fri Feb 04, 2005 1:11 am
by feyd
this would be effectively after the mp3 was converted back into PCM information. As it is, manipulating mp3 frame information directly requires a lot of fore and post information, which is probably more pain that it's worth in that department. However, if you operated on the PCM, you can potentially create inefficiently stored, but good quality mp3's somewhat in realtime, dynamically.
Posted: Fri Feb 04, 2005 11:06 pm
by bimo
Okay, I talked to some people and have been forced to change my plans (rats). I'm not looking to do what I was thinking about last night anymore. I think I do still want to truncate the audio files, though. I will experiment and see how ftruncate() works with audio.
thanks