Skip to content

Commit

Permalink
improve piped stream implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
  • Loading branch information
GiviMAD committed Jan 5, 2024
1 parent 33b9703 commit df76007
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.LinkedList;
import java.util.Objects;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -111,13 +112,18 @@ protected PipedOutputStream getOutputStream() {
/**
* Creates a new piped stream group used to open new streams and write data to them.
*
* Internal pipe size 1s.
* Internal pipe size 0.5s.
*
* @param format the audio format of the group audio streams
* @return a group instance.
*/
public static Group newGroup(AudioFormat format) {
return new Group(format, 1024 * 10);
int pipeSize = Math.round(( //
(float) Objects.requireNonNull(format.getFrequency()) * //
(float) Objects.requireNonNull(format.getBitDepth()) * //
(float) Objects.requireNonNull(format.getChannels()) //
) / 2f);
return new Group(format, pipeSize);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class AudioPlayer extends Thread {
/**
* Constructs an AudioPlayer to play the passed AudioStream
*
* @param audioStream The audio stream to play
* @param audioStream The AudioStream to play
*/
public AudioPlayer(AudioStream audioStream) {
this.audioStream = audioStream;
Expand Down

0 comments on commit df76007

Please sign in to comment.