I am trying to use an AudioStream to play audio supply via an OutputStream feeding an InputStream connected to the AudioStream connected to an AudioNode.
My init code look like so:
[java]ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); AudioStream audioStream = new AudioStream(); int chans = 1; int bits = 16; int rate = 8000; audioStream.setupFormat(chans, bits, rate); audioStream.updateData(inputStream, -1f); AudioNode audioNode = new AudioNode(audioStream, null); audioNode.setPositional(true); getRootNode().attachChild(audioNode); audioNode.setLocalTranslation(Vector3f.ZERO);
I’d like to be able to programmatically just write() PCM data into outputStream and have the AudioNode play it.
Nothing is happening, which leads me to believe I have failed to understand something important. What am I missing?
Also,I do have some questions:
- Do I have to at any time tell the AudioNode to play()?
- What happens if the data I supply falls idle? Do I need to do anything to restart it, or do I merely write() more data into outputStream? I’m hoping it just falls to a zero sample when starved of data.