保存 Pixel Bender 生成的 ByteArray
我正在构建一个 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 发送到我们的服务器进行上传。
I am building a Flash Application which will allow a user to mix two mp3 files and send the mixed result to our server.
Using Pixel Bender I am already able to create a mix:
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
}
Not sure if the event.byteArray can be transformed to an mp3 file? Ideally we'd send the mp3 to our server for uploading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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
Shine MP3 is an open source mp3 encoder for Flash ported with Alchemy: http://code.google.com/p/flash-kikko/
Alternatively there is a WAV encoder in the sazameki audio manipulating library:
http://www.libspark.org/svn/as3/sazameki/trunk/src/org/sazameki/audio/format/Wav.as