4 Replies Latest reply: Aug 15, 2012 5:39 PM by 955926 RSS

    How to get sound volumes

    955926
      Hi all.
      I've been looking all over the internet and cant get a easy way of doing what i need. (I cant get my head round the sound API in java)

      All i want is to get the max volume for each frame in a wav file i.e something like this

      waveFile = new File("test.wav");
      for(int i = 0; i < num of frames; i++){
           System.out.println("Frame " + i + frame volume/db);
      }

      Any help apretiated and if anyone could provide a working example that would be even better. Im a complete begginer when it comes to sound in java
        • 1. Re: How to get sound volumes
          gimbal2
          952923 wrote:
          Hi all.
          I've been looking all over the internet and cant get a easy way of doing what i need. (I cant get my head round the sound API in java)
          Also here?

          http://www.jsresources.org/
          • 2. Re: How to get sound volumes
            955926
            Thanks for the link but its just as confusing as the articles ive read, nothing even explains how to convert to byte array let alone how to get the volume from that. Its been 2 days of reading articles and so far all i managed to work out is:

            File file = new File("c:/test.wav");
                           AudioInputStream ais = AudioSystem.getAudioInputStream(file);
                           
                           int frameLength = (int) ais.getFrameLength();
                           int frameSize = (int) ais.getFormat().getFrameSize();

                           System.out.println("Frame Size: "+frameSize);// = 4
                           System.out.println("Frame Length: "+frameLength);
                           
                           for(int offset = 0; offset < ais.getFrameLength(); offset++){
                                
                                System.out.println(ais.read());
                                /*int sample =
                                     (buffer[offset + 0] & 0xFF)
                                     | ((buffer[offset + 1] & 0xFF) << 8)
                                     | ((buffer[offset + 2] & 0xFF) << 16)
                                     | (buffer[offset + 3] << 24);
                                */
                           }

            Im completely lost and dont even know where to start
            • 3. Re: How to get sound volumes
              gimbal2
              Perhaps you're just searching for the wrong thing. I'm guessing you're looking for copy/paste code while what you should be looking for is knowledge. It just can't be that you don't understand ALL the reference material you're finding, then you're simply not paying attention to what you're reading. The fix is simple: stop being in a hurry.
              • 4. Re: How to get sound volumes
                955926
                I think i got it now, i was getting confused cause the byte was unsigned and i was struggling with the concept of calling classes and then not referring to them later. Seems some classes you set the values then ignore them, other classes you call use them but dont reference them in the code. Not used to that. Thanks for your help; i wasnt looking for a copy paste just an example that would clearly show how and why. I found a converter class for mp3s that gave a clearer understanding of how the api works, now i get the concept it makes a little more sense i think i was also having trouble with the terminology. I can be thick sometimes

                Thanks again, appreciate the link (it makes a bit more sense now)