So my goal here is to store the y values from the Fourier Transform of a sound file into a byte array.
NOTE: I am trying to avoid importing javax
I did this by simply storing the bytes of the sound file into a byte array. But I'm not sure if this is the correct way to approach it.
Here is my code:
public static void main ( String[] args ) {
try{
File f = new File("C:/Users/Maxwell/Desktop/TestSoundFile.m4a");
byte[] bytesFromFile = getBytes(f);
System.out.println(Arrays.toString(bytesFromFile));
}
catch(Exception e) {
System.out.println("Nope. Just nope.");
}
}
public static byte[] getBytes(File f) throws FileNotFoundException, IOException {
byte[] buffer = new byte[1024];
ByteArrayOutputStream os = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(f);
int read;
while((read = fis.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
fis.close();
os.close();
return os.toByteArray();
}
The main function here is the getBytes() function.
What I did was simply store the bytes from the sound file into an array.
In the main() function, the print statement prints a large array of integers. It looks right to me, but I'm not entirely sure if it actually worked, or the values have nothing to do with the sound.
I'm kind of a newb when working with sound on Java.
Have I achieved my goal?