我正在构建一个Flash应用程序,它允许用户混合两个mp3文件并将混合结果发送到我们的服务器。
使用Pixel Bender我已经能够创建混音:
public class Mixer
{
[Embed(source="mix.pbj", mimeType="application/octet-stream")]
protected var NewFilter:Class;
private var shader:Shader;
private var shaderJob:ShaderJob;
protected var _output:ByteArray;
shader = new Shader(new NewFilter() as ByteArray);
private function onSampleDataHandler(event:SampleDataEvent):void
{
var width:int = 1;
var height:Vector.<int> = new Vector.<int>(numOfTracks);
for (var i:int = 0; i < numOfTracks; i++)
{
buffer[i] = new ByteArray();
sound[i].extract(buffer[i],BUFFER_SIZE * 4);
height[i] = buffer[i].length >> 4;
buffer[i].position = 0;
shader.data["src"+i]["input"] = buffer[i];
shader.data["src"+i]["width"] = width;
shader.data["src"+i]["height"] = height[i];
}
shaderJob = new ShaderJob(shader, event.data,width, height[0]);
shaderJob.addEventListener(Event.COMPLETE, onShaderJobComplete, false, 0, true);
shaderJob.start(false);
}
protected function onShaderJobComplete(event:ShaderEvent):void
{
// event.byteArray is the result
}
不确定event.byteArray是否可以转换为mp3文件?理想情况下,我们会将mp3发送到我们的服务器进行上传。
答案 0 :(得分:0)
Shine MP3是一个用Alchemy移植的Flash的开源mp3编码器:http://code.google.com/p/flash-kikko/
另外在sazameki音频操作库中有一个WAV编码器: http://www.libspark.org/svn/as3/sazameki/trunk/src/org/sazameki/audio/format/Wav.as