Reputation:
I have used code from to create a buffer from a wav file in which data is read in blocks of 100 frames.
Please see link below for original code:
http://www.labbookpages.co.uk/audio/javaWavFiles.html
I now need to create an ArrayList in which each element consists of 100 frames from the wav file (The first element 0-99, the second 100-199 etc...)
I am having trouble figuring out how to implement this into the code I've currently tried:
// Display information about the wav file
wavFile.display();
// Get the number of audio channels in the wav file
int numChannels = wavFile.getNumChannels();
// Create a buffer of 100 frames
double[] buffer = new double[100 * numChannels];
int framesRead;
do
{
// Read frames into buffer
framesRead = wavFile.readFrames(buffer, 100);
}
while (framesRead != 0);
// Close the wavFile
wavFile.close();
I am not sure what way in which I should construct the Array List, or populate it.
Any advice about how I can achieve this would be greatly appreciated.
Upvotes: 0
Views: 97
Reputation: 4667
I made a class for the frames assuming they are stored as an int
array(can easily be modified for double
or any other type you want stored). The idea of this code is to create a container class of Frames
that will be used to create the ArrayList
, which will make it easy to access your arrays of 100 stored values later.
public class Frames {
private int[] frames;
public Frames() {
}
public Frames(int[] frames)
{
this.frames = frames;
}
public int[] getFrames() {
return frames;
}
public void setFrames(int[] frames) {
this.frames = frames;
}
}
This would be used in your method like this as an example:
ArrayList<Frames> list = new ArrayList<Frames>();
//This would be your 100 values stored as an array
int[] arr = {123,234,2342,1234124,12341};
Frames frames = new Frames(arr);
//Add the frames to the list(you will be doing this in a loop to continue adding them)
list.add(frames);
It will just need to be modified to add the values you are getting from your loop. Every time you get your array of 100 values, you declare new Frames(yourValues)
and then just add that to the ArrayList
Upvotes: 0