Class WavUtils


  • public class WavUtils
    extends java.lang.Object
    Since:
    : 22.02.21
    Version:
    : 1.0
    Author:
    : Enrico Gamil Toros Project name : apt-decoder
    • Constructor Summary

      Constructors 
      Constructor Description
      WavUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int[] convertByteArray​(byte[] audioData, int frameSize, boolean isBigEndian)
      Converts the byte array into an array of integers where each integer corresponds to an audio sample.
      static void saveAudio​(byte[] audio, java.io.File outputFile, javax.sound.sampled.AudioFormat audioFormat)
      Save Wav Audio to given output
      static byte[] stereoToMono​(byte[] stereoAudio, int sampleSizeInBits)
      Convert stereo to mono (ignores second channel)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WavUtils

        public WavUtils()
    • Method Detail

      • convertByteArray

        public static int[] convertByteArray​(byte[] audioData,
                                             int frameSize,
                                             boolean isBigEndian)
                                      throws UnsupportedFrameSizeException
        Converts the byte array into an array of integers where each integer corresponds to an audio sample.
        Parameters:
        audioData - the audio data as bytes
        frameSize - size of frames
        isBigEndian - is big endian
        Returns:
        the corresponding array of integers as samples
        Throws:
        UnsupportedFrameSizeException - If the frame size is > 2
      • stereoToMono

        public static byte[] stereoToMono​(byte[] stereoAudio,
                                          int sampleSizeInBits)
        Convert stereo to mono (ignores second channel)
        Parameters:
        stereoAudio - audio bytes of stereo audio
        sampleSizeInBits - the size of a sample in bits
        Returns:
        byte[] with one channel
      • saveAudio

        public static void saveAudio​(byte[] audio,
                                     java.io.File outputFile,
                                     javax.sound.sampled.AudioFormat audioFormat)
                              throws java.io.IOException
        Save Wav Audio to given output
        Parameters:
        audio - audio to save
        outputFile - output file
        audioFormat - audio format
        Throws:
        java.io.IOException - if any I/O errors