/** * Constructs an <code>AudioSource</code> that will subscribe to the samples in <code>stream * </code>. It is expected that the stream is using a <code>DataLine</code> for playback. If it is * not, calls to <code>Controller</code>'s methods will result in a <code>NullPointerException * </code>. * * @param istream the <code>AudioStream</code> to subscribe to and wrap */ public AudioSource(AudioStream istream) { super(istream.getControls()); stream = istream; // we gots a buffer for users to poll buffer = new StereoBuffer(stream.getFormat().getChannels(), stream.bufferSize(), this); left = buffer.left; right = buffer.right; mix = buffer.mix; // we gots a signal splitter that we'll add any listeners the user wants splitter = new SignalSplitter(stream.getFormat(), stream.bufferSize()); // we stick our buffer in the signal splitter because we can only set one // listener on the stream splitter.addListener(buffer); // and there it goes. stream.setAudioListener(splitter); // we got an effects chain that we'll add user effects to effects = new EffectsChain(); // we set it as the effect on the stream stream.setAudioEffect(effects); stream.open(); }
@Override public void removeListener(AudioListener listener) { splitter.removeListener(listener); }
@Override public void addListener(AudioListener listener) { splitter.addListener(listener); }