samer@0
|
1 /*
|
samer@0
|
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
3 * All rights reserved.
|
samer@0
|
4 *
|
samer@0
|
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
6 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
7 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
8 */
|
samer@0
|
9
|
samer@0
|
10 package samer.units;
|
samer@0
|
11
|
samer@0
|
12 import samer.maths.*;
|
samer@0
|
13 import samer.core.*;
|
samer@0
|
14 import samer.core.types.*;
|
samer@0
|
15 import samer.audio.*;
|
samer@0
|
16 import samer.tools.*;
|
samer@0
|
17 import javax.sound.sampled.*;
|
samer@0
|
18
|
samer@0
|
19 /**
|
samer@0
|
20 A class which takes real valued samples from a VVector, converts
|
samer@0
|
21 them to 16 bit integer samples, and writes them to an audio
|
samer@0
|
22 device.
|
samer@0
|
23
|
samer@0
|
24 <p>
|
samer@0
|
25 Can optionally output only a sub-window of input vector
|
samer@0
|
26 This window is adjustable on the fly, so, for example, we can
|
samer@0
|
27 output the last M samples of a sliding window.
|
samer@0
|
28
|
samer@0
|
29 */
|
samer@0
|
30
|
samer@0
|
31 public class LineOut implements Task
|
samer@0
|
32 {
|
samer@0
|
33 AudioSink sink;
|
samer@0
|
34 Task writer=new NullTask();
|
samer@0
|
35
|
samer@0
|
36 Vec vec;
|
samer@0
|
37 int i0, i1;
|
samer@0
|
38
|
samer@0
|
39 public LineOut(Vec buf, AudioSink sink) throws Exception {
|
samer@0
|
40 this.sink=sink; setInput(buf);
|
samer@0
|
41 }
|
samer@0
|
42
|
samer@0
|
43 public Vec input() { return vec; }
|
samer@0
|
44 public AudioSink getSink() { return sink; }
|
samer@0
|
45 public void setSink(AudioSink sink) { this.sink=sink; setWindow(i0,i1); }
|
samer@0
|
46 public void setInput(Vec vec) { this.vec=vec; setWindow(0,vec.size()); }
|
samer@0
|
47 public void setWindow(int a,int b) {
|
samer@0
|
48 i0=a; i1=b; writer=sink.writer(vec.array(),i0,i1-i0);
|
samer@0
|
49 }
|
samer@0
|
50
|
samer@0
|
51 public void dispose() { writer.dispose(); sink.dispose(); }
|
samer@0
|
52 public void starting() { writer.starting(); }
|
samer@0
|
53 public void stopping() { writer.stopping(); }
|
samer@0
|
54 public void run() throws Exception { writer.run(); }
|
samer@0
|
55 }
|
samer@0
|
56
|