fixed issue caused by misunderstanding(?) of samplerate
This commit is contained in:
@@ -38,7 +38,7 @@ public class Mp3Manager implements MusicManager {
|
||||
private int sampleRate;
|
||||
private long sampleCount;
|
||||
private double durationInSeconds;
|
||||
private byte channels;
|
||||
private int channels;
|
||||
Bitstream bitstream;
|
||||
MP3Decoder decoder;
|
||||
OutputBuffer sampleBuffer;
|
||||
@@ -63,10 +63,13 @@ public class Mp3Manager implements MusicManager {
|
||||
Logger.getLogger("org.jaudiotagger").setLevel(Level.OFF);
|
||||
try {
|
||||
MP3File mp3File = new MP3File(audioFile.file());
|
||||
sampleCount = MathUtils.round(Float.valueOf((float) (mp3File.getAudioHeader().getSampleRateAsNumber()*mp3File.getMP3AudioHeader().getPreciseTrackLength())));
|
||||
sampleRate = mp3File.getMP3AudioHeader().getSampleRateAsNumber();
|
||||
durationInSeconds = mp3File.getMP3AudioHeader().getPreciseTrackLength();
|
||||
|
||||
channels = mp3File.getAudioHeader().getChannels().equals("Mono") ? 1:2;
|
||||
sampleCount = MathUtils.round(Float.valueOf((float) (sampleRate*durationInSeconds))) * channels;
|
||||
|
||||
//Rounding error probably?
|
||||
sampleCount += readWindowSize*2;
|
||||
} catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -86,7 +89,7 @@ public class Mp3Manager implements MusicManager {
|
||||
} catch (BitstreamException e) {
|
||||
throw new GdxRuntimeException("error while preloading mp3", e);
|
||||
}
|
||||
|
||||
|
||||
playbackMusic = Gdx.audio.newMusic(audioFile);
|
||||
|
||||
}
|
||||
@@ -118,7 +121,7 @@ public class Mp3Manager implements MusicManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readSamples(float[] samples) {
|
||||
public int readSampleFrames(float[] samples) {
|
||||
readIndex++;
|
||||
int framesRead = 0;
|
||||
for (int sid = 0; sid < samples.length; sid++) {
|
||||
|
@@ -63,10 +63,10 @@ public class WAVManager implements MusicManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readSamples(float[] samples) {
|
||||
public int readSampleFrames(float[] samples) {
|
||||
try {
|
||||
readIndex++;
|
||||
return d.readSamples(samples);
|
||||
return d.readSamplesAsFrames(samples);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class WAVManager implements MusicManager {
|
||||
|
||||
@Override
|
||||
public long getSampleCount() {
|
||||
return ais.getFrameLength();
|
||||
return ais.getFrameLength()*d.getChannels();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user