Search code examples
javaaudioiomp3bytestream

How ByteStream works?


How raw data is divided into bytes.

As present audio contains 32bit(2^32 tones) it ranges from 2^0 - 2^32.

ex -> 6710497.. (Considering decimal)

how is it divided to

67 104 97

Does FileInputStream has a method to check like

if(671>256){send 67 , next append 1}

try(FileInputStream fis=new FileInputStream("We_Dont_Talk_Anymore.mp3")) { //audio file

        int i;
        while((i=fis.read())!=-1)
            System.out.println(i);  
} catch(Exception e) {
    System.out.println(e);
}

o/p-

73 68 51 3 0 0 0 0 1 9 84 73 84 50 0 0 0 76 0 0 0 67 104 97 114 108 105 101 32 80 . . .

EDIT

Is this correct

i/p -> text '$4-'

36 52 45 (ascii decimal)

00100100 00110100 00101101 (ascii binary)

i/p -> image pixel(rgb) '0,255,100'

00000000 11111111 1100100

i/p -> audio(32 bit, 2^32 tones) '1073741822'

111111111111111111111111111110 (binary form)

00111111 11111111 11111111 11111110 (divide into bytes) [one tone]

63 255 255 254


Solution

  • fis.read() reads a byte of data from input stream and represent it as int. So let's say your file has 2 bytes of binary data: 0100001101101000

    First call of fis.read() will read 01000011 (and it is 67 in decimal)

    second call of fis.read() will read 01101000(and it is 104 in decimal).

    So that's why you see output like 67 104 ...