Example usage for com.badlogic.gdx.audio AudioDevice writeSamples

List of usage examples for com.badlogic.gdx.audio AudioDevice writeSamples

Introduction

In this page you can find the example usage for com.badlogic.gdx.audio AudioDevice writeSamples.

Prototype

public void writeSamples(float[] samples, int offset, int numSamples);

Source Link

Document

Writes the array of float PCM samples to the audio device and blocks until they have been processed.

Usage

From source file:com.heartpirates.harthsip.AsapRadio.java

License:Open Source License

public void start() {
    final ASAP asap = this.asap;
    final AudioDevice device = this.device;

    Thread playbackThread = new Thread(new Runnable() {

        @Override/*w ww. j ava2 s .  c  o m*/
        public void run() {
            byte[] bytes = new byte[1024 << 2];

            int numSamples;

            while ((numSamples = asap.generate(bytes, bytes.length, 1)) > 0) {
                short[] shortPCM = getShortPCM(bytes, numSamples);
                device.writeSamples(shortPCM, 0, shortPCM.length);

                try {
                    Thread.sleep(14);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    playbackThread.setPriority(Thread.NORM_PRIORITY);
    playbackThread.start();
}