Skip to content

Instantly share code, notes, and snippets.

@volalex volalex/ Secret
Created Mar 26, 2016

What would you like to do?
private static byte[] mixSignals(byte[] signal, byte[] noise) {
ByteBuffer bb = ByteBuffer.wrap(signal);
ShortBuffer sb = bb.asShortBuffer();
short[] signalArray = new short[sb.capacity()];
ByteBuffer bb2 = ByteBuffer.wrap(noise);
ShortBuffer sb2 = bb2.asShortBuffer();
short[] noiseArray = new short[sb2.capacity()];
float max = 0;
for (int i=0;i<signalArray.length;i++){
if (noiseArray.length>i){
if (Math.abs(signalArray[i] + noiseArray[i])>max){
max = Math.abs(signalArray[i]+noiseArray[i]);
int a,b,c;
for (int i=0;i<signalArray.length;i++){
a = signalArray[i];
b = noiseArray[i];
c = Math.round(Short.MAX_VALUE *
(a + b) / max);
if (c>Short.MAX_VALUE){
c = Short.MAX_VALUE;
else if(c<Short.MIN_VALUE){
c = Short.MIN_VALUE;
signalArray[i] = (short) c;
byte[] result = new byte[signalArray.length*2];
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.