Mix byte array android

Rocé Tarentula

I would like to mix audio byte array, but I didn't succeed to sum the array.(note i already added some silent bytes of 0 as padding before). I have an ArrayList of byte[] which contains:

  • the first byte[] is header (44 bytes).
  • Following byte[] are raw data byte array to be mixed

Here is my code:

ArrayList<byte[]> ListAudio = new ArrayList<byte[]>();
byte[] header= WriteHeader(); //wav header 44 bytes
ListAudio.add(header);
for (byte[] b : audioTreatment.ListDataByte) {
      ListAudio.add(b);
 }
 //calculate total length of audio
 int length = 0;
 for (byte[] array : ListAudio) {
 length += array.length;
 }

 final int len = length;
 final byte[] mixBytes = new byte[len];
 for (byte[] array : ListAudio) {
 for (int i = 44; i < len; ++i) {
     mixBytes[i] += array[i];
   // mixBytes[i]=(byte) ((bytes1[i]+bytes2[i]) / 2);

     }
}

I found somewhere that the method to mix digital byte array is :

mixBytes[i]=(byte) ((bytes1[i]+bytes2[i]) / 2);

I don't arrive to include the calcul above, to sum the byte array. How can i sum the bytes array from my ArrayList ?

Martin Frank

you have to declare your sources to merge them

byte[] source1 = ListAudio.get(0); //first from list
byte[] source2 = ListAudio.get(1); //second from list

int length = Math.min(source1.length, source2.length);//length of new array
length = length - 44; //skipping 44 byte

byte[] dest = new byte[length];
for(int index = 0; index < length; index ++){
    byte b1 = source1[index+44];
    byte b2 = source2[index+44];
    dest[index] = (byte) ((b1+b2) / 2);
}

That would merge the first two byte[] from your list.

If you want to merge other sources you can change them by selecting other byte[] from your List.

HINT
The length of the destination is declared as Math.min(a,b) but you can fill missing bytes with zeros if you want...

if you want to merge all arrays, you have to adjust your merge operation

mixing two bytes: mixBytes[i]=(byte) ((bytes1[i]+bytes2[i]) / 2);

mixing three bytes: mixBytes[i]=(byte) ((bytes1[i]+bytes2[i]+bytes3[i]) / 3);

mixing N bytes: mixBytes[i]=(byte) ((bytes1[i]+bytes2[i]+bytes3[i]+...+bytesN[i]) / N);

ok, for your code snipped it would be:

int length = ...;//length of result, either min or max as mentioned above, see HINT
byte[] mixBytes = new byte[length]; 

int amountAudio = ListAudio.size(); //amount of tracks in your list aka 'N' 

int sum;
for(int index = 0; index < length; index++){
    sum = 0;
    for(byte[] source: ListAudio){
        //adding all byte into one big integer
        sum = sum + source[index]; //NOTE: watch for indexOutOfBoundsException
    }
    //afterward divide the big int through amount of Audio tracks in your list
    mixBytes[index] = (byte)(sum / amountAudio);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

InputStream read to byte array - will it mix messages

From Dev

converting image to byte array in android

From Dev

return byte array in jni android?

From Dev

Android: byte array to decimal string

From Dev

converting image to byte array in android

From Dev

Android: Convert byte array to integer array

From Dev

How to extract amplitude from byte array in android?

From Dev

Sending drawable as byte array to jni part of android

From Dev

Byte array to string decode java android

From Dev

Converting an image from drawable to byte array in Android

From Dev

Android | How Read file to byte array?

From Dev

analysis byte array to class in android or java

From Dev

jpeg ImageFormat byte array to Bitmap in android

From Dev

How to input a byte array in an Edittext Dialog in Android

From Dev

Android save gif from byte array

From Dev

Is conversion of image to byte array in android heavy task?

From Dev

Mix (or sort) JS array

From Dev

Convert BYTE* to Array<byte>^

From Dev

GreenDAO on Android: Byte Array as Primary Key / Building Query Containing Where Clause on Byte Array Property

From Dev

Android BLE: writing >20 bytes characteristics missing the last byte array

From Dev

Read byte array in Android using k-soap2

From Dev

Android NDK return byte array of bitmap's pixels

From Dev

How to generate a fixed byte array for a fixed IMEI in android

From Dev

How to convert byte[] in Android to uint8_T array in C?

From Dev

converting from byte array to drawable image gives corrupt image: Android

From Dev

Android: How to return huge byte array as activity's result?

From Dev

how to get byte array from camera preview in java android?

From Dev

Passing a byte array from java to python on Android using Chaquopy

From Dev

How Can I convert an imageview to byte array in Android Studio?

Related Related

  1. 1

    InputStream read to byte array - will it mix messages

  2. 2

    converting image to byte array in android

  3. 3

    return byte array in jni android?

  4. 4

    Android: byte array to decimal string

  5. 5

    converting image to byte array in android

  6. 6

    Android: Convert byte array to integer array

  7. 7

    How to extract amplitude from byte array in android?

  8. 8

    Sending drawable as byte array to jni part of android

  9. 9

    Byte array to string decode java android

  10. 10

    Converting an image from drawable to byte array in Android

  11. 11

    Android | How Read file to byte array?

  12. 12

    analysis byte array to class in android or java

  13. 13

    jpeg ImageFormat byte array to Bitmap in android

  14. 14

    How to input a byte array in an Edittext Dialog in Android

  15. 15

    Android save gif from byte array

  16. 16

    Is conversion of image to byte array in android heavy task?

  17. 17

    Mix (or sort) JS array

  18. 18

    Convert BYTE* to Array<byte>^

  19. 19

    GreenDAO on Android: Byte Array as Primary Key / Building Query Containing Where Clause on Byte Array Property

  20. 20

    Android BLE: writing >20 bytes characteristics missing the last byte array

  21. 21

    Read byte array in Android using k-soap2

  22. 22

    Android NDK return byte array of bitmap's pixels

  23. 23

    How to generate a fixed byte array for a fixed IMEI in android

  24. 24

    How to convert byte[] in Android to uint8_T array in C?

  25. 25

    converting from byte array to drawable image gives corrupt image: Android

  26. 26

    Android: How to return huge byte array as activity's result?

  27. 27

    how to get byte array from camera preview in java android?

  28. 28

    Passing a byte array from java to python on Android using Chaquopy

  29. 29

    How Can I convert an imageview to byte array in Android Studio?

HotTag

Archive