Reputation: 31
Goodmornig everyone.
I'm coding a simple wrapper class around the OpenIMAJ library that is able to load a .ogg file audio and give back the data sampled.
Here is the code I've implemented to get a double array as output:
public List<double[]> getDoubleSample() throws AudioSamplerException {
if (audioSampler.getFormat().getJavaAudioFormat().getChannels() != 1)
throw new AudioSamplerException("Cannot decode multichannel track as array");
List<double[]> bufferedSamples = new LinkedList<>();
SampleChunk sc;
SampleBuffer sb;
while ((sc = audioSampler.nextSampleChunk()) != null) {
sb = sc.getSampleBuffer();
double[] data = sb.asDoubleArray();
bufferedSamples.add(data);
}
return bufferedSamples;
}
The code seems to work great but after a debug session I found that the very first buffer decoded have just zeros inside like:
bufferedSamples = {LinkedList@1213} size = 218
0 = {double[96000]@1215}
0 = 0.0
1 = 0.0
2 = 0.0
3 = 0.0
4 = 0.0
5 = 0.0
6 = 0.0
7 = 0.0
and so on...
Is that zeros right to be there or I have done something wrong in decoding the file, or maybe I need an additional step before returning the array?
I've tried to delete this first buffer and the data after are correct, according to the ones extracted with Audacity, but I'm not sure about this workaround.
Thank you in advance for the answer.
Upvotes: 0
Views: 50
Reputation: 841
Not sure why that is happening - I can duplicate it with my own ogg files. It doesn't happen with wav files though. The root cause seems to be somewhere deep inside Xuggler, rather than anything inside the OpenIMAJ codebase.
Upvotes: 0