Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test with reset() behaves oddly #39

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9c1721b
Target class, field in target class
HelgeStenstrom Sep 9, 2019
2c087f5
gainControl moved to outet
HelgeStenstrom Sep 9, 2019
4f1a789
balancecontrol moved to Outlet
HelgeStenstrom Sep 9, 2019
32dca21
Minor cleanup
HelgeStenstrom Sep 9, 2019
f54066d
Test for pan
HelgeStenstrom Sep 9, 2019
57b28e2
pan control moved
HelgeStenstrom Sep 9, 2019
3847ec6
Update StreamPlayerMethodsTest.java
HelgeStenstrom Sep 9, 2019
18e55fd
Test for mute
HelgeStenstrom Sep 9, 2019
2452944
Mute moved; last control.
HelgeStenstrom Sep 9, 2019
bc1cc50
SourceDataLine moved
HelgeStenstrom Sep 9, 2019
f89aa04
SourceDataLine tested, getter restored in StreamPlayer
HelgeStenstrom Sep 9, 2019
6eef319
StreamPlayerInterface implemented, so that I can maintain compatibility.
HelgeStenstrom Sep 10, 2019
89114b9
Update StreamPlayerInterface.java
HelgeStenstrom Sep 10, 2019
db4c713
Update Outlet.java
HelgeStenstrom Sep 10, 2019
fdb191d
hasControl moved to Outlet
HelgeStenstrom Sep 10, 2019
2da2d78
hasControl signature simplified
HelgeStenstrom Sep 10, 2019
b21b6bb
getGainValue moved, thin wrapper left in place.
HelgeStenstrom Sep 10, 2019
409bf9b
Step towards testing reset() and moving a couple of methods
HelgeStenstrom Sep 10, 2019
266f97b
Test with reset() behaves oddly
HelgeStenstrom Sep 10, 2019
ea55285
Revert "Step towards testing reset() and moving a couple of methods"
HelgeStenstrom Sep 10, 2019
8df75ce
Extracted stopAndFreeDataLine from call(), moved it to Outlet
HelgeStenstrom Sep 11, 2019
7c411f8
Update SourceDataLineTest.java
HelgeStenstrom Sep 11, 2019
2a7747f
flushAndStop extracted from SteamPlayer.call() into Outlet class
HelgeStenstrom Sep 11, 2019
2e68045
stopAndFreeDataLine extracted from StreamPlayer.reset()
HelgeStenstrom Sep 11, 2019
fec1005
Outlet.start(), used now in StreamPlayer.play()
HelgeStenstrom Sep 11, 2019
2fc083c
Removed some calls of outlet.getSourceDataLine()
HelgeStenstrom Sep 11, 2019
460f7db
Revert outlet.getSourceDataLine() --> sourceDataLine, more or less
HelgeStenstrom Sep 11, 2019
ed25d8f
openLine() ready for move
HelgeStenstrom Sep 11, 2019
e12f0b3
openLine() moved to outlet:open()
HelgeStenstrom Sep 11, 2019
c437025
inline calls to getSourceDataLine() in Outlet
HelgeStenstrom Sep 11, 2019
96a52e3
JavaDoc for Outlet methods
HelgeStenstrom Sep 11, 2019
634c991
Merge pull request #40 from HelgeStenstrom/extractClassFromStreamPlayer
goxr3plus Sep 11, 2019
90c3dc2
Test with reset() behaves oddly
HelgeStenstrom Sep 10, 2019
771e825
Merge branch 'resetWhenPlaying' of https://github.com/HelgeStenstrom/…
HelgeStenstrom Sep 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.goxr3plus.streamplayer.enums.Status;
import com.goxr3plus.streamplayer.stream.StreamPlayer;
import com.goxr3plus.streamplayer.stream.StreamPlayerEvent;
import com.goxr3plus.streamplayer.stream.StreamPlayerInterface;
import com.goxr3plus.streamplayer.stream.StreamPlayerListener;

import java.io.File;
Expand All @@ -16,10 +17,10 @@ public class AnotherDemoApplication {

private final String audioFileName = "Logic - Ballin [Bass Boosted].mp3";

private StreamPlayer streamPlayer;
private StreamPlayerInterface streamPlayer;
private StreamPlayerListener listener;

public AnotherDemoApplication(StreamPlayer streamPlayer) {
public AnotherDemoApplication(StreamPlayerInterface streamPlayer) {
this.streamPlayer = streamPlayer;
this.listener = new AnotherStreamPlayerListener(audioFileName, streamPlayer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.goxr3plus.streamplayer.application;

import com.goxr3plus.streamplayer.stream.StreamPlayer;
import com.goxr3plus.streamplayer.stream.StreamPlayerInterface;
import com.goxr3plus.streamplayer.stream.StreamPlayerListener;

public class AnotherMain {
public static void main(String[] args) {

final StreamPlayer streamPlayer = new StreamPlayer();
final StreamPlayerInterface streamPlayer = new StreamPlayer();
final AnotherDemoApplication application = new AnotherDemoApplication(streamPlayer);
application.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import com.goxr3plus.streamplayer.enums.Status;
import com.goxr3plus.streamplayer.stream.StreamPlayer;
import com.goxr3plus.streamplayer.stream.StreamPlayerEvent;
import com.goxr3plus.streamplayer.stream.StreamPlayerInterface;
import com.goxr3plus.streamplayer.stream.StreamPlayerListener;

import java.util.Map;

class AnotherStreamPlayerListener implements StreamPlayerListener {

private final String audioFileName;
private StreamPlayer streamPlayer;
private StreamPlayerInterface streamPlayer;


public AnotherStreamPlayerListener(String audioFileName, StreamPlayer streamPlayer) {
public AnotherStreamPlayerListener(String audioFileName, StreamPlayerInterface streamPlayer) {
this.audioFileName = audioFileName;
this.streamPlayer = streamPlayer;
}
Expand Down
224 changes: 224 additions & 0 deletions src/main/java/com/goxr3plus/streamplayer/stream/Outlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
package com.goxr3plus.streamplayer.stream;

import javax.sound.sampled.*;
import java.util.logging.Logger;

/**
* Owner of the SourceDataLine which is the output line of the player.
* Also owns controls for the SourceDataLine.
* Future goal is to move all handling of the SourceDataLine to here,
* so that the StreamPlayer doesn't have to call {@link #getSourceDataLine()}.
* Another goal is to remove some of the setter and getter methods of this class,
* by moving all code that needs them to this class.
*/
public class Outlet {

private final Logger logger;
private FloatControl balanceControl;
private FloatControl gainControl;
private BooleanControl muteControl;
private FloatControl panControl;
private SourceDataLine sourceDataLine;

/**
* @param logger used to log messages
*/
public Outlet(Logger logger) {
this.logger = logger;
}


/**
* @return the balance control of the {@link #sourceDataLine}
*/
public FloatControl getBalanceControl() {
return balanceControl;
}

/**
* @return the gain control of the {@link #sourceDataLine}
*/
public FloatControl getGainControl() {
return gainControl;
}

/**
* @return the mute control of the {@link #sourceDataLine}
*/
public BooleanControl getMuteControl() {
return muteControl;
}

/**
* @return the pan control of the {@link #sourceDataLine}
*/
public FloatControl getPanControl() {
return panControl;
}

/**
* @return the {@link #sourceDataLine}, which is the output audio signal of the player
*/
public SourceDataLine getSourceDataLine() {
return sourceDataLine;
}


/**
* @param balanceControl to be set on the {@link #sourceDataLine}
*/
public void setBalanceControl(FloatControl balanceControl) {
this.balanceControl = balanceControl;
}

/**
* @param gainControl to be set on the {@link #sourceDataLine}
*/
public void setGainControl(FloatControl gainControl) {
this.gainControl = gainControl;
}

/**
* @param muteControl to be set on the {@link #sourceDataLine}
*/
public void setMuteControl(BooleanControl muteControl) {
this.muteControl = muteControl;
}

/**
* @param panControl to be set on the {@link #sourceDataLine}
*/
public void setPanControl(FloatControl panControl) {
this.panControl = panControl;
}

/**
* @param sourceDataLine representing the audio output of the player.
* Usually taken from {@link AudioSystem#getLine(Line.Info)}.
*/
public void setSourceDataLine(SourceDataLine sourceDataLine) {
this.sourceDataLine = sourceDataLine;
}


/**
* Check if the <b>Control</b> is Supported by m_line.
*
* @param control the control
* @param component the component
*
* @return true, if successful
*/
public boolean hasControl(final Control.Type control, final Control component) {
return component != null && (sourceDataLine != null) && (sourceDataLine.isControlSupported(control));
}

/**
* Returns Gain value.
*
* @return The Gain Value
*/
public float getGainValue() {

if (hasControl(FloatControl.Type.MASTER_GAIN, getGainControl())) {
return getGainControl().getValue();
} else {
return 0.0F;
}
}

/**
* Stop the {@link #sourceDataLine} in a nice way.
* Also nullify it. (Is that necessary?)
*/
void drainStopAndFreeDataLine() {
// Free audio resources.
if (sourceDataLine != null) {
sourceDataLine.drain();
sourceDataLine.stop();
sourceDataLine.close();
this.sourceDataLine = null; // TODO: Is this necessary? Will it not be garbage collected?
}
}

/**
* Flush and close the {@link #sourceDataLine} in a nice way.
* Also nullify it. (Is that necessary?)
*/
void flushAndFreeDataLine() {
if (sourceDataLine != null) {
sourceDataLine.flush();
sourceDataLine.close();
this.sourceDataLine = null; // TODO: Is this necessary? Will it not be garbage collected?
}
}

/**
* Flush and stop the {@link #sourceDataLine}, if it's running.
*/
void flushAndStop() {
// Flush and stop the source data line
if (sourceDataLine != null && sourceDataLine.isRunning()) { // TODO: Risk for NullPointerException?
sourceDataLine.flush();
sourceDataLine.stop();
}
}

/**
* @return true if the {@link #sourceDataLine} is startable.
*/
boolean isStartable() {
return sourceDataLine != null && !sourceDataLine.isRunning();
}


/**
* Start the {@link #sourceDataLine}
*/
void start() {
sourceDataLine.start();
}

/**
* Open the {@link #sourceDataLine}.
* Also create controls for it.
* @param format The wanted audio format.
* @param bufferSize the desired buffer size for the {@link #sourceDataLine}
* @throws LineUnavailableException
*/
void open(AudioFormat format, int bufferSize) throws LineUnavailableException {
logger.info("Entered OpenLine()!:\n");

if (sourceDataLine != null) {
sourceDataLine.open(format, bufferSize);

// opened?
if (sourceDataLine.isOpen()) {

// Master_Gain Control?
if (sourceDataLine.isControlSupported(FloatControl.Type.MASTER_GAIN))
setGainControl((FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN));
else setGainControl(null);

// PanControl?
if (sourceDataLine.isControlSupported(FloatControl.Type.PAN))
setPanControl((FloatControl) sourceDataLine.getControl(FloatControl.Type.PAN));
else setPanControl(null);

// Mute?
BooleanControl muteControl1 = sourceDataLine.isControlSupported(BooleanControl.Type.MUTE)
? (BooleanControl) sourceDataLine.getControl(BooleanControl.Type.MUTE)
: null;
setMuteControl(muteControl1);

// Speakers Balance?
FloatControl balanceControl = sourceDataLine.isControlSupported(FloatControl.Type.BALANCE)
? (FloatControl) sourceDataLine.getControl(FloatControl.Type.BALANCE)
: null;
setBalanceControl(balanceControl);
}
}
logger.info("Exited OpenLine()!:\n");
}

}
Loading