以编程方式对音轨进行混音(无播放) [英] Programmatically Mixdown of audio tracks (no playback)

查看:21
本文介绍了以编程方式对音轨进行混音(无播放)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些关于如何将声音对象混合在一起以进行实时播放的出色演示.请参阅下面的工作示例...

I've found some excellent demos of how to mix together sound objects together for live playback. See the working example bellow...

但是可以在没有任何播放的情况下以编程方式完成,以便我可以输出混合文件吗?此外,我将在此过程中添加一些音量更改信息,因此需要将其添加为小块,例如播放缓冲区的工作方式.

But can it be done programmatically without any playback so I can just output the mixed file? Also I'll be adding some volume change info along the way so it'll need to be added in small chunks like how the play buffer works.

[Embed(source = "audio/track01.mp3")] 
private var Track1:Class;       
[Embed(source = "audio/track02.mp3")] 
private var Track2:Class;       
[Embed(source = "audio/track03.mp3")] 
private var Track3:Class;
[Embed(source = "audio/track04.mp3")] 
private var Track4:Class;[Embed(source = "AudioMixerFilter2.pbj",mimeType = "application/octet-stream")]
private var EmbedShader:Class;

private var shader:Shader = new Shader(new EmbedShader());

private var sound:Vector.<Sound> = new Vector.<Sound>();    
private var bytes:Vector.<ByteArray> = new Vector.<ByteArray>();
private var sliders:Vector.<Number> = new Vector.<Number>();

private var sliderVol:int = 1;

private var BUFFER_SIZE:int = 0x800;

public var playback:Sound = new Sound();

public function startAudioMixer(event:FlexEvent):void{


    sound.push(new Track1(), new Track2(), new Track3(), new Track4());
    sliders.push(sliderVol,sliderVol,sliderVol,sliderVol);

    playback.addEventListener(SampleDataEvent.SAMPLE_DATA, onSoundData);
    playback.play();
}

private function onSoundData(event:SampleDataEvent):void {

    for(var i:int = 0; i < sound.length; i++){
        bytes[i] = new ByteArray();
        bytes[i].length = BUFFER_SIZE * 4 * 2;
        sound[i].extract(bytes[i], BUFFER_SIZE);                

        var volume:Number = 0;
        bytes[i].position = 0;  

        for(var j:int = 0; j < BUFFER_SIZE; j++){
            volume += Math.abs(bytes[i].readFloat());
            volume += Math.abs(bytes[i].readFloat());                   
        }



        volume = (volume / (BUFFER_SIZE * .5)) * sliderVol; // SLIDER VOL WILL CHANGE       

        shader.data['track' + (i + 1)].width    = BUFFER_SIZE / 1024;
        shader.data['track' + (i + 1)].height   = 512;
        shader.data['track' + (i + 1)].input    = bytes[i];
        shader.data['vol'   + (i + 1)].value    = [sliders[i]];

    }

    var shaderJob:ShaderJob = new ShaderJob(shader,event.data,BUFFER_SIZE / 1024,512);
    shaderJob.start(true);
}       

推荐答案

最简单的方法就是忘记 Pixel Bender 的东西.

Easiest way would be to just forget about the Pixel Bender stuff.

加载声音后,使用使用 Sound.extract 的 ENTER_FRAME 从每个声音中获取一个较小的 ByteArray,然后读取所有四个提取的 ByteArray,做一些基本的数学运算,以得出左侧 & 的混合"值.正确的信号.将这些值写入最终/混合/输出"ByteArray.每一帧重复这个过程,直到声音结束.如果声音的长度不完全相同,您还需要弄清楚如何处理.

Once the Sounds are loaded, use an ENTER_FRAME that uses Sound.extract to get a smallish ByteArray from each Sound, then read through all four extracted ByteArrays doing some basic math to arrive at the 'mixed' values for the left & right signals. Write those values to the "final/mixed/output" ByteArray. Repeat the process each frame until you're at the end of the sounds. If the Sounds aren't all the identical length, you'll need to figure out how to handle that as well.

如果您需要在每个轨道的振幅随时间变化的情况下进行混音,这将是一个很好的挑战,但需要时间进行设置.

If you need to perform a mix where the amplitude of each track changes over time, it'd be a good challenge, but would take time to set up.

在此期间,请查看 Andre Michelle 的 Tonfall 项目...这是一个复杂但很好的起点,可以开始了解 AS3 中音频的输入/输出.

While you're at it, check out Andre Michelle's Tonfall project... It's a complex but great place to start with understanding the ins/outs of audio in AS3.

这篇关于以编程方式对音轨进行混音(无播放)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆