package org.sdsai.dsp;

import org.junit.Test;
import org.junit.Ignore;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.LineUnavailableException;

import java.io.IOException;
import java.io.ByteArrayOutputStream;

public class BpskOutputStreamTest {

    @Test
    public void writeToSpeakers() throws IOException, LineUnavailableException {
        BpskGenerator psk = new BpskGenerator(700, 11025, 31.25);

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final SourceDataLine        sdl  = AudioSystem.getSourceDataLine(psk.getAudioFormat());
        final BpskOutputStream      os   = new BpskOutputStream(baos, psk);

        os.preamble(10);
        os.write("This is a very nice test.".getBytes());
        os.postamble(10);
        os.close();

        sdl.open(psk.getAudioFormat());
        sdl.start();

        final byte[] b = baos.toByteArray();

        sdl.write(b, 0, b.length);

        sdl.drain();
        sdl.stop();
        sdl.close();

        java.io.FileOutputStream fos = new java.io.FileOutputStream("a.raw");
        fos.write(b);
        fos.close();
    }
}
@@ -406,16 +406,22 @@
         
+final 
 BpskGene
@@ -430,12 +430,21 @@
 tor 
+        
 psk 
+ 
 = ne
@@ -479,17 +479,16 @@
 31.25);%0A
-%0A
         
@@ -551,24 +551,25 @@
 ream();%0A
+%0A
         
 final So
@@ -564,95 +564,21 @@
     
-final SourceDataLine        sdl  = AudioSystem.getSourceDataLine(psk.getAudioFormat());
+/* Output. */
 %0A   
@@ -650,17 +650,16 @@
 , psk);%0A
-%0A
         
@@ -792,16 +792,86 @@
     
-sdl.open
+/* Audio. */%0A        final SourceDataLine sdl  = AudioSystem.getSourceDataLine
 (psk
@@ -906,26 +906,44 @@
 sdl.
-star
+open(psk.getAudioForma
 t()
+)
 ;%0A
-%0A
         
 fina
@@ -942,46 +942,21 @@
     
-final byte%5B%5D b = baos.toByteArray
+sdl.start
 ();%0A
-%0A
     
@@ -974,25 +974,44 @@
 te(b
-, 0, b.length
+aos.toByteArray(), 0, baos.size()
 );%0A
-%0A
     
@@ -1072,29 +1072,212 @@
 ();%0A
-%0A        java.io.File
+    %7D%0A%0A    @Test%0A    public void writeToSpeakers2x() throws IOException, LineUnavailableException %7B%0A        final BpskGenerator         psk  = new BpskGenerator(700, 11025, 62.50);%0A        final ByteArray
 Outp
@@ -1285,17 +1285,18 @@
 tStream 
-f
+ba
 os = new
@@ -1300,76 +1300,540 @@
 new 
-java.io.FileOutputStream(%22a.raw%22);%0A        fos.write(b);%0A        fos
+ByteArrayOutputStream();%0A%0A        /* Output. */%0A        final BpskOutputStream      os   = new BpskOutputStream(baos, psk);%0A        os.preamble(10);%0A        os.write(%22This is a very nice test.%22.getBytes());%0A        os.postamble(10);%0A        os.close();%0A%0A        /* Audio. */%0A        final SourceDataLine sdl  = AudioSystem.getSourceDataLine(psk.getAudioFormat());%0A        sdl.open(psk.getAudioFormat());%0A        sdl.start();%0A        sdl.write(baos.toByteArray(), 0, baos.size());%0A        sdl.drain();%0A        sdl.stop();%0A        sdl
 .clo

Remove writing test files.