Skip to content

Commit

Permalink
Pimp my PlayReverseExample
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias <[email protected]>
  • Loading branch information
Hangman committed Aug 22, 2023
1 parent 153ec43 commit 92d1469
Showing 1 changed file with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,72 @@

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;

import de.pottgames.tuningfork.Audio;
import de.pottgames.tuningfork.SoundBuffer;
import de.pottgames.tuningfork.SoundBufferLoader;
import de.pottgames.tuningfork.SoundBufferLoader.SoundBufferLoaderParameter;
import de.pottgames.tuningfork.SoundSource;
import de.pottgames.tuningfork.WaveLoader;

public class PlayReverseExample extends ApplicationAdapter {
private Audio audio;
private SoundBuffer sound;
private boolean jobDone = false;
private AssetManager assetManager;
private Audio audio;
private SoundBuffer sound;
private SoundBuffer asyncLoadedSound;
private SoundSource source;


@Override
public void create() {
this.audio = Audio.init();

this.setupAssetManager();
this.load();
this.loadAsync();
this.source = this.audio.obtainSource(this.sound);
this.source.play();
}


public void setupAssetManager() {
this.assetManager = new AssetManager();
final FileHandleResolver resolver = new InternalFileHandleResolver();
this.assetManager.setLoader(SoundBuffer.class, new SoundBufferLoader(resolver));
}


public void load() {
// use any of these

// this.sound = AiffLoader.loadReverse(Gdx.files.internal("numbers.aiff"));
// this.sound = FlacLoader.loadReverse(Gdx.files.internal("numbers_16bit_stereo.flac"));
// this.sound = Mp3Loader.loadReverse(Gdx.files.internal("numbers.mp3"));
// this.sound = OggLoader.loadReverse(Gdx.files.internal("numbers2.ogg"));
this.sound = WaveLoader.loadReverse(Gdx.files.internal("numbers.wav"));
this.sound.play();
}


private void loadAsync() {
final SoundBufferLoaderParameter parameter = new SoundBufferLoaderParameter();
parameter.reverse = true;
this.assetManager.load("carnivalrides.ogg", SoundBuffer.class, parameter);
}


@Override
public void render() {
// we chill in a black window
if (!this.jobDone && this.assetManager.update() && !this.source.isPlaying()) {
this.asyncLoadedSound = this.assetManager.get("carnivalrides.ogg");
this.asyncLoadedSound.play();
this.jobDone = true;
}
}


Expand Down

0 comments on commit 92d1469

Please sign in to comment.