mixing 2 sounds from ByteArray

前端 未结 3 556
逝去的感伤
逝去的感伤 2021-01-05 17:36

I have build a mixer and save all the sequence in an array and then play it again, now I want to save the mix as an MP3, I have looked for any way to save the mix and the an

3条回答
  •  自闭症患者
    2021-01-05 18:06

    If I understand your question properly, you need read the floating point data for each sample, sum them, and write the resulting value into your new audio stream. This would give a stright 50/50 mix.

    I don't have access to a machine with a compiler right now, but it should be something like this (assuming bytes1 and bytes2 are two ByteArray objects of equal length):

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

    Of course, you would probably want to do some sort of overflow check, but that should be enough to put you on the right track.

提交回复
热议问题