English 中文(简体)
混合2台来自拜特阿雷
原标题:mixing 2 sounds from ByteArray

我已经建立了组合,挽救了阵列中的所有顺序,然后又再次发挥这种作用,因为我现在要把混为一号的MP3,我已经寻找任何办法来挽救混凝土,而答案是装上作为星号(声)的声。 我有一点不舒服,但我没有真正知道如何把所有声音储存在单只一个拜特阿雷里,以便作为MP3加以拯救,我只想用这部法律,例如,装上2个音频文件,将其存放在单独的拜特阿雷,并发挥每条声音,任何机构都知道如何仅仅储存2个旁听器?

var mySound:Sound = new Sound(); 
var sourceSnd:Sound = new Sound(); 
var urlReq:URLRequest = new URLRequest("Track1.mp3"); 
sourceSnd.load(urlReq); 
sourceSnd.addEventListener(Event.COMPLETE, loaded); 
function loaded(event:Event):void 
{ 
    mySound.addEventListener(SampleDataEvent.SAMPLE_DATA, processSound); 
    //mySound.play(); 
} 

var mySound2:Sound = new Sound(); 
var sourceSnd2:Sound = new Sound(); 
var urlReq2:URLRequest = new URLRequest("Track2.mp3"); 
sourceSnd2.load(urlReq2); 
sourceSnd2.addEventListener(Event.COMPLETE, loaded2); 
function loaded2(event:Event):void 
{ 
    mySound2.addEventListener(SampleDataEvent.SAMPLE_DATA, processSound2); 
    mySound2.play(); 
    mySound.play(); 
} 



function processSound(event:SampleDataEvent):void 
{ 
        var bytes:ByteArray = new ByteArray(); 
        sourceSnd.extract(bytes, 8192); 
    event.data.writeBytes(bytes); 
} 

function processSound2(event:SampleDataEvent):void 
{ 
        var bytes:ByteArray = new ByteArray(); 
        sourceSnd2.extract(bytes, 8192); 
    event.data.writeBytes(bytes); 
} 
问题回答

我当时正在制定一个类似的制度,我尽了最大可能给你一些方向:

你的榜样没有真正地将MP3混为一谈——这为通过SampleDataEvent击重的MP3制造了2个更健全的声音。 你们需要做的是仅仅创造一种“产出”。 健全的档案将保存/击退由此产生的混杂声音。 当数据出现时,你可以很容易地拯救这些数据,随后将这一数据作为新的WAV/MP3/what-have-you。

real/psuedo-code (read:lazy) :

output = new Sound();

output.addEventListener( SampleDataEvent.SAMPLE_DATA , mixAudio );

song1 = new Sound / load the first mp3

song2 = new Sound / load the second mp3

// a byteArray for "recording" the output and subsequent file creation
recordedBytes = new ByteArray();

either wait until both mp3 s are completely loaded, or run an enter-frame to determine when both Sounds are no longer buffering (Sound.isBuffering )

标的:

// numbers to store some values

var left1:Number;
var right1:Number;

var left2:Number;
var right2:Number;

// bytearrays for extracting and mixing
var bytes1:ByteArray = new ByteArray( );
var bytes2:ByteArray = new ByteArray( );

// start the show
output.play();


function mixAudio( e:SampleDataEvent ):void{
  //set bytearray positions to 0

  bytes1.position = 0;
  bytes2.position = 0;

  //extract

  song1.extract( bytes1, 8192 );
  song2.extract( bytes2, 8192 );

  // reset bytearray positions to 0 for reading the floats

  bytes1.position = 0;
  bytes2.position = 0;

  // run through all the bytes/floats

  var b:int = 0;

  while( b < 8192 ){

     left1 = bytes1.readFloat();  // gets "left" signal
     right1 = bytes1.readFloat(); // gets "right" signal

     left2 = bytes2.readFloat();
     right2 = bytes2.readFloat();


     // mix!

     var newLeft:Number = ( left1 + left2 ) * .5; 
     var newRight:Number = ( right1 + right2 ) * .5;

     // write the new stuff to the output sound s

     e.data.writeFloat( newLeft );
     e.data.writeFloat( newRight );

     // write numbers to the "recording" byteArray
     recordedBytes.writeFloat( newLeft );
     recordedBytes.writeFloat( newRight );

     b++;

  }
}

是的——你应该真正把可能的产出排在-1/1。 。 这是极不鼓励的!

Ok. so that s the easy part! The tough part is really converting the final byteArray to MP3. The audio exists within Flash as PCM/uncompressed data, MP3 is obviously a compressed format. This "answer" is already way too long and all this info I ve gleaned from several very smart folks.

You can easily adapt MicRecorder to be a generic Sound data recorder: http://www.bytearray.org/?p=1858

转换为MP3是一种itch: Thibault在ByteArray.org设有另一个员额,搜寻LAME MP3。

Excellent example/resource: http://www.anttikupila.com/flash/soundfx-out-of-the-box-audio-filters-with-actionscript-3/

研究关于谷歌代码的安德烈·米歇尔开放源图恩布尔项目。

看看凯文·金匠的博客和实验室——他就利用Pixel Bender和所有这种mad。

希望这一帮助!

PS——从Andre抽取一个杯子,声音缓冲的最佳长度应为3072。 把它用在你的机器上!

如果我正确理解你的问题,你需要阅读每个样本的浮点数据,并加以总结,并将结果的价值写进你的新的音流。 这将使男女比例各占一半。

我现在不能够使用一个拥有汇编机的机器,但应该像这样的机器(假设1和2是两个同等长的拜特阿雷物体):

for (int bcnt = bytes1.size(); bcnt; bcnt--)
    bytes1.setByte(bcnt - 1, bytes2.getByte(bcnt - 1) + bytes1.getByte(bcnt - 1));

当然,你可能希望进行某种超额流动检查,但这应当足以使你走上正确的轨道。

如果您有uncompressed音频,你就可以在中补充各个阵列要素的价值观。 ByteArrays。 但是,你们还必须为最高/最高价值(无超支)进行 ca。 相对而言,将MP3混为一谈,因此,你可能不得不重新编码、混合和编码给MP3。





相关问题
Playing a Sound With Monotouch

No matter what I try (build -> content, NSUrl, filename) I get a null exception : file not found when I try to play a .caf sound file in monotouch. //var path = NSBundle.MainBundle.PathForResource("...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

Play sound in iPhone web app with Javascript?

I m currently creating an iPhone web application for piano chords, and I wanted to add an option that would let the user press a Play button and play the selected chord. However, I m not sure how to ...

热门标签