0

Can someone explain what the bytes you get by reading an AudioInputStream correspond to? Things like volume or frequency/pitch. I have this code that reads the bytes from the entire file.

int BUFFER_SIZE = 1024;
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
byte[] bytesBuffer = new byte[BUFFER_SIZE];
int bytesRead = -1;
while ((bytesRead = audioStream.read(bytesBuffer)) != -1) {
  for(byte b:bytesBuffer)
    System.out.print(b+" ");
  System.out.println();
}

Currently I am trying to get the maximum volume in the sound file I have. It is a 16 bit PCM wav file.

Jacbo
  • 13
  • 6
  • This post should help https://stackoverflow.com/questions/13039846/what-do-the-bytes-in-a-wav-file-represent – dancingbush Jun 11 '19 at 15:54
  • Oracle sound tutorial info covering this is here. https://docs.oracle.com/javase/tutorial/sound/sampled-overview.html To maximize volume, the entire PCM (sets assume signed shorts) set would be multiplied by a single factor that results in products that lie in between -32767 and 32767. Exceeding that leads to pretty obnoxious distortion pretty quickly. – Phil Freihofner Jun 11 '19 at 21:49
  • So from what I understand, all of the bytes are for amplitude/volume? – Jacbo Jun 12 '19 at 11:37
  • I did some testing and it's every other byte that relates to volume. I still don't know what the other bytes are for though. – Jacbo Jun 12 '19 at 22:20
  • 1
    The two bytes are concatenated into a single PCM value ranging to all values held by a signed short. That is why it is called 16-bit (each byte is 8 bits). This info is in the tutorial linked in an earlier comment. Your sample rate tells how many frames are in one second. Given a Format (tells you how many bytes per frame, related to number of tracks and number of bits per track) you can tell the timing via counting bytes. – Phil Freihofner Jun 13 '19 at 02:08
  • What I did was skip the first 44 bytes then to get the volume I did ```AIS.read(bytesBuffer); for(int i=1;i – Jacbo Jun 15 '19 at 15:21

0 Answers0