まず、実際にオーディオが16ビットの場合、バイトごとに追加しても機能しません。他の人がこれについてコメントしました。この問題を処理する方法については、ここで私の答えを見ることができます。
AndroidのAudioTrackを使用してサウンドサンプルのバイトを結合すると、ノイズが発生します
次に、それを「正規化」するには、最初にピークを見つけてから、すべての結果をその値にスケーリングする必要があります。つまり、2つのループがあります。1つは「ピーク」を見つけるためのもので、もう1つは値を追加して、新しいピークに合わせてスケーリングするためのものです。このようなもの:
//this is the raw audio data -- no header
short[] audioData1 , short[] audioData2
//find the max:
float max = 0;
for( int i = 0 ; i < audioData1.length ; i++) {
if( Math.abs( audioData1[i] + audioData2[i] ) > max )
max = Math.abs( audioData1[i] + audioData2[i] );
}
//now find the result, with scaling:
for( int i = 0 ; i < audioData1.length ; i++) {
audioData1[i] = Math.Round(Short.MAX_VALUE * ( audioData1[i] + audioData2[i] ) / max) ;
}
//normalized result in audioData1