33import javax .sound .sampled .*;
44import java .util .logging .Logger ;
55
6+ /**
7+ * Owner of the SourceDataLine which is the output line of the player.
8+ * Also owns controls for the SourceDataLine.
9+ * Future goal is to move all handling of the SourceDataLine to here,
10+ * so that the StreamPlayer doesn't have to call {@link #getSourceDataLine()}.
11+ * Another goal is to remove some of the setter and getter methods of this class,
12+ * by moving all code that needs them to this class.
13+ */
614public class Outlet {
715
816 private final Logger logger ;
@@ -12,47 +20,82 @@ public class Outlet {
1220 private FloatControl panControl ;
1321 private SourceDataLine sourceDataLine ;
1422
23+ /**
24+ * @param logger used to log messages
25+ */
1526 public Outlet (Logger logger ) {
1627 this .logger = logger ;
1728 }
1829
1930
31+ /**
32+ * @return the balance control of the {@link #sourceDataLine}
33+ */
2034 public FloatControl getBalanceControl () {
2135 return balanceControl ;
2236 }
2337
38+ /**
39+ * @return the gain control of the {@link #sourceDataLine}
40+ */
2441 public FloatControl getGainControl () {
2542 return gainControl ;
2643 }
2744
45+ /**
46+ * @return the mute control of the {@link #sourceDataLine}
47+ */
2848 public BooleanControl getMuteControl () {
2949 return muteControl ;
3050 }
3151
52+ /**
53+ * @return the pan control of the {@link #sourceDataLine}
54+ */
3255 public FloatControl getPanControl () {
3356 return panControl ;
3457 }
3558
59+ /**
60+ * @return the {@link #sourceDataLine}, which is the output audio signal of the player
61+ */
3662 public SourceDataLine getSourceDataLine () {
3763 return sourceDataLine ;
3864 }
3965
66+
67+ /**
68+ * @param balanceControl to be set on the {@link #sourceDataLine}
69+ */
4070 public void setBalanceControl (FloatControl balanceControl ) {
4171 this .balanceControl = balanceControl ;
4272 }
4373
74+ /**
75+ * @param gainControl to be set on the {@link #sourceDataLine}
76+ */
4477 public void setGainControl (FloatControl gainControl ) {
4578 this .gainControl = gainControl ;
4679 }
4780
81+ /**
82+ * @param muteControl to be set on the {@link #sourceDataLine}
83+ */
4884 public void setMuteControl (BooleanControl muteControl ) {
4985 this .muteControl = muteControl ;
5086 }
5187
88+ /**
89+ * @param panControl to be set on the {@link #sourceDataLine}
90+ */
5291 public void setPanControl (FloatControl panControl ) {
5392 this .panControl = panControl ;
5493 }
5594
95+ /**
96+ * @param sourceDataLine representing the audio output of the player.
97+ * Usually taken from {@link AudioSystem#getLine(Line.Info)}.
98+ */
5699 public void setSourceDataLine (SourceDataLine sourceDataLine ) {
57100 this .sourceDataLine = sourceDataLine ;
58101 }
@@ -84,6 +127,10 @@ public float getGainValue() {
84127 }
85128 }
86129
130+ /**
131+ * Stop the {@link #sourceDataLine} in a nice way.
132+ * Also nullify it. (Is that necessary?)
133+ */
87134 void drainStopAndFreeDataLine () {
88135 // Free audio resources.
89136 if (sourceDataLine != null ) {
@@ -94,34 +141,56 @@ void drainStopAndFreeDataLine() {
94141 }
95142 }
96143
97- void stopAndFreeDataLine () {
144+ /**
145+ * Flush and close the {@link #sourceDataLine} in a nice way.
146+ * Also nullify it. (Is that necessary?)
147+ */
148+ void flushAndFreeDataLine () {
98149 if (sourceDataLine != null ) {
99150 sourceDataLine .flush ();
100151 sourceDataLine .close ();
101152 this .sourceDataLine = null ; // TODO: Is this necessary? Will it not be garbage collected?
102153 }
103154 }
104155
156+ /**
157+ * Flush and stop the {@link #sourceDataLine}, if it's running.
158+ */
105159 void flushAndStop () {
106160 // Flush and stop the source data line
107- if (sourceDataLine != null && sourceDataLine .isRunning ()) {
161+ if (sourceDataLine != null && sourceDataLine .isRunning ()) { // TODO: Risk for NullPointerException?
108162 sourceDataLine .flush ();
109163 sourceDataLine .stop ();
110164 }
111165 }
112166
167+ /**
168+ * @return true if the {@link #sourceDataLine} is startable.
169+ */
113170 boolean isStartable () {
114171 return sourceDataLine != null && !sourceDataLine .isRunning ();
115172 }
173+
174+
175+ /**
176+ * Start the {@link #sourceDataLine}
177+ */
116178 void start () {
117179 sourceDataLine .start ();
118180 }
119181
120- void open (AudioFormat audioFormat , int currentLineBufferSize ) throws LineUnavailableException {
182+ /**
183+ * Open the {@link #sourceDataLine}.
184+ * Also create controls for it.
185+ * @param format The wanted audio format.
186+ * @param bufferSize the desired buffer size for the {@link #sourceDataLine}
187+ * @throws LineUnavailableException
188+ */
189+ void open (AudioFormat format , int bufferSize ) throws LineUnavailableException {
121190 logger .info ("Entered OpenLine()!:\n " );
122191
123192 if (sourceDataLine != null ) {
124- sourceDataLine .open (audioFormat , currentLineBufferSize );
193+ sourceDataLine .open (format , bufferSize );
125194
126195 // opened?
127196 if (sourceDataLine .isOpen ()) {
0 commit comments