diff options
author | Phil Burk <[email protected]> | 2022-01-30 12:14:35 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2022-01-30 11:14:35 -0800 |
commit | e792b44d99676a363bc5e6e6d5c42881e756f956 (patch) | |
tree | cad74da4bf7e2d12052f943bf51256c340502c41 /src/test/java/com/jsyn/engine/TestFifo.java | |
parent | c43a8e222c9a51046c2b11c9549ffa76204d1eb5 (diff) |
WaveRecorder: fix hang in StreamingThread (#106)
The read() could hang forever waiting for data when the
WaveRecorder was stopped.
Now it terminates the thread.
Also fix bug in AudioFifo when partially full. It would not read any data!
Fixes #105
Diffstat (limited to 'src/test/java/com/jsyn/engine/TestFifo.java')
-rw-r--r-- | src/test/java/com/jsyn/engine/TestFifo.java | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/test/java/com/jsyn/engine/TestFifo.java b/src/test/java/com/jsyn/engine/TestFifo.java index 1c681fb..3c57053 100644 --- a/src/test/java/com/jsyn/engine/TestFifo.java +++ b/src/test/java/com/jsyn/engine/TestFifo.java @@ -34,7 +34,7 @@ public class TestFifo { fifo.allocate(8); assertEquals(0, fifo.available(), "start empty"); - assertEquals(Double.NaN, fifo.read(), "read back Nan when emopty"); + assertEquals(Double.NaN, fifo.read(), "read back Nan when empty"); fifo.write(1.0); assertEquals(1, fifo.available(), "added one value"); @@ -52,6 +52,29 @@ public class TestFifo { watchdog.interrupt(); } + @Test + public void testReadAvailable() { + Thread watchdog = startWatchdog(600); + + AudioFifo fifo = new AudioFifo(); + fifo.setReadWaitEnabled(false); + fifo.allocate(8); + + final double x1 = 0.234; + fifo.write(x1); + final double x2 = 0.750; + fifo.write(x2); + assertEquals(2, fifo.available(), "added two values"); + + double[] buffer = new double[6]; + int numRead = fifo.read(buffer, 2, buffer.length - 2); + assertEquals(2, numRead, "should have read two values"); + assertEquals(x1, buffer[2], "read x1"); + assertEquals(x2, buffer[3], "read x2"); + + watchdog.interrupt(); + } + /** * Wrap around several times to test masking. */ |