- @Override
- protected void feed(byte[] buffer) {
- sourceDataLine.write(buffer, 0, buffer.length);
- logger.finest(String.format("AudioSink: Wrote %d Bytes.", buffer.length));
+ /** A buffered output stream to ensure correct writing to the source data line. */
+ private OutputStream sourceDataLineOutputStream = new IntegralWriteOutputStream(new OutputStream() {
+
+ @Override
+ public void write(int b) throws IOException {
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException {
+ write(b, 0, b.length);
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ if (sourceDataLine != null) {
+ sourceDataLine.write(b, off, len);
+ }
+ }
+ }, 1024);
+
+ /** Creates a new audio sink. */
+ public AudioSink() {
+ super();
+ volumeFader = new Fader("Volume") {
+
+ @Override
+ protected void valueSet(Double value) {
+ if (sourceDataLine != null) {
+ FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(VOLUME);
+ volumeControl.setValue((float) (value * volumeControl.getMaximum()));