Changed some methods in OpenALStreamPlayer to synchornized methods.
Seems to work with ogg now too. Hopefully this fixes it, but I don't actually know much about concurrency. However it stills throws "Could not clear SoundStore sources, err" and so it remains removed.
This commit is contained in:
@@ -79,15 +79,15 @@ public class MusicController {
|
|||||||
|
|
||||||
switch (OsuParser.getExtension(osu.audioFilename.getName())) {
|
switch (OsuParser.getExtension(osu.audioFilename.getName())) {
|
||||||
case "ogg":
|
case "ogg":
|
||||||
//trackLoader = new Thread() {
|
trackLoader = new Thread() {
|
||||||
// @Override
|
@Override
|
||||||
// public void run() {
|
public void run() {
|
||||||
//Loading ogg async seems to screw up
|
//Loading ogg async seems to screw up
|
||||||
//So does mp3, but much less
|
//So does mp3, but much less
|
||||||
loadTrack(osu.audioFilename, osu.previewTime, loop);
|
loadTrack(osu.audioFilename, osu.previewTime, loop);
|
||||||
// }
|
}
|
||||||
//};
|
};
|
||||||
//trackLoader.start();
|
trackLoader.start();
|
||||||
break;
|
break;
|
||||||
case "mp3":
|
case "mp3":
|
||||||
trackLoader = new Thread() {
|
trackLoader = new Thread() {
|
||||||
@@ -133,13 +133,14 @@ public class MusicController {
|
|||||||
public static void playAt(final int position, final boolean loop) {
|
public static void playAt(final int position, final boolean loop) {
|
||||||
if (trackExists()) {
|
if (trackExists()) {
|
||||||
setVolume(Options.getMusicVolume() * Options.getMasterVolume());
|
setVolume(Options.getMusicVolume() * Options.getMasterVolume());
|
||||||
player.setPosition(position / 1000f);
|
|
||||||
trackEnded = false;
|
trackEnded = false;
|
||||||
pauseTime = 0f;
|
pauseTime = 0f;
|
||||||
if (loop)
|
if (loop)
|
||||||
player.loop();
|
player.loop();
|
||||||
else
|
else
|
||||||
player.play();
|
player.play();
|
||||||
|
player.setPosition(position / 1000f);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,8 +340,14 @@ public class MusicController {
|
|||||||
// TODO: properly interrupt instead of using deprecated Thread.stop();
|
// TODO: properly interrupt instead of using deprecated Thread.stop();
|
||||||
// interrupt the conversion/track loading
|
// interrupt the conversion/track loading
|
||||||
if (isTrackLoading())
|
if (isTrackLoading())
|
||||||
|
try {
|
||||||
|
trackLoader.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
// trackLoader.interrupt();
|
// trackLoader.interrupt();
|
||||||
trackLoader.stop();
|
//trackLoader.stop();
|
||||||
trackLoader = null;
|
trackLoader = null;
|
||||||
|
|
||||||
// delete temporary WAV file
|
// delete temporary WAV file
|
||||||
|
|||||||
@@ -278,14 +278,14 @@ public class Music {
|
|||||||
currentMusic.fireMusicSwapped(this);
|
currentMusic.fireMusicSwapped(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
playing = true;
|
|
||||||
currentMusic = this;
|
|
||||||
if (volume < 0.0f)
|
if (volume < 0.0f)
|
||||||
volume = 0.0f;
|
volume = 0.0f;
|
||||||
if (volume > 1.0f)
|
if (volume > 1.0f)
|
||||||
volume = 1.0f;
|
volume = 1.0f;
|
||||||
|
|
||||||
sound.playAsMusic(pitch, volume, loop);
|
sound.playAsMusic(pitch, volume, loop);
|
||||||
|
playing = true;
|
||||||
|
currentMusic = this;
|
||||||
setVolume(volume);
|
setVolume(volume);
|
||||||
if (requiredPosition != -1) {
|
if (requiredPosition != -1) {
|
||||||
setPosition(requiredPosition);
|
setPosition(requiredPosition);
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public class OpenALStreamPlayer {
|
|||||||
/**
|
/**
|
||||||
* Clean up the buffers applied to the sound source
|
* Clean up the buffers applied to the sound source
|
||||||
*/
|
*/
|
||||||
private void removeBuffers() {
|
private synchronized void removeBuffers() {
|
||||||
IntBuffer buffer = BufferUtils.createIntBuffer(1);
|
IntBuffer buffer = BufferUtils.createIntBuffer(1);
|
||||||
//int queued = AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED);
|
//int queued = AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED);
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ public class OpenALStreamPlayer {
|
|||||||
*
|
*
|
||||||
* Most of the time this should be reasonably quick
|
* Most of the time this should be reasonably quick
|
||||||
*/
|
*/
|
||||||
public void update() {
|
public synchronized void update() {
|
||||||
if (done) {
|
if (done) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -259,7 +259,7 @@ public class OpenALStreamPlayer {
|
|||||||
* @param bufferId The ID of the buffer to fill
|
* @param bufferId The ID of the buffer to fill
|
||||||
* @return True if another section was available
|
* @return True if another section was available
|
||||||
*/
|
*/
|
||||||
public boolean stream(int bufferId) {
|
public synchronized boolean stream(int bufferId) {
|
||||||
//Thread.dumpStack();
|
//Thread.dumpStack();
|
||||||
try {
|
try {
|
||||||
int count = audio.read(buffer);
|
int count = audio.read(buffer);
|
||||||
@@ -303,13 +303,14 @@ public class OpenALStreamPlayer {
|
|||||||
* @param position Position in seconds.
|
* @param position Position in seconds.
|
||||||
* @return True if the setting of the position was successful
|
* @return True if the setting of the position was successful
|
||||||
*/
|
*/
|
||||||
public boolean setPosition(float position) {
|
public synchronized boolean setPosition(float position) {
|
||||||
try {
|
try {
|
||||||
//int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
|
//int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
|
||||||
//AL10.alSourceStop(source);
|
//AL10.alSourceStop(source);
|
||||||
|
|
||||||
long samplePos = (long) (position*sampleRate)*sampleSize;
|
long samplePos = (long) (position*sampleRate)*sampleSize;
|
||||||
|
|
||||||
|
//System.out.println("offset:"+samplePos%sampleSize);
|
||||||
if(streamPos > samplePos){//(getPosition() > position) {
|
if(streamPos > samplePos){//(getPosition() > position) {
|
||||||
initStreams();
|
initStreams();
|
||||||
}
|
}
|
||||||
@@ -334,6 +335,8 @@ public class OpenALStreamPlayer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//System.out.println("offset2:"+samplePos%sampleSize);
|
||||||
|
|
||||||
/*while(streamPos%sampleSize!=0){
|
/*while(streamPos%sampleSize!=0){
|
||||||
audio.read();
|
audio.read();
|
||||||
streamPos++;
|
streamPos++;
|
||||||
|
|||||||
Reference in New Issue
Block a user