goxr3plus / goxr3plus/java-stream-player

Some questions and comments on StreamPlayer.call()

Open
#48 0 comments 1 reaction 0 assignees View on GitHub
improvement question
Dominant language
Java
Stars
158
Forks
36
PR merge metrics
No merged PRs in 30d

Description

The cal() method seems to be at the core of StreamPlayer, and it's the one I really want to understand.

How often is it called? Can you tell me the call frequency, or the time between each call, in a typical case, given a normal sample rate of 44100 Hz or whatever your choice.

There's an inner loop, which starts with
https://github.com/goxr3plus/java-stream-player/blob/d32a46a1f7d105a2c5350ae5bd04fdc1edd47baa/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java#L833-L834
How often does this execute? Frequency or time between iterations, in a typical case?

Yet an inner loop: I suspect it would be easier to read as a while-loop, rather than a for-loop. The most important work of the loop is actually in the for-clause, which is unusual and hard to read. I'm referring to "nBytesRead = audioInputStream.read(audioDataBuffer.array(), totalRead, toRead)".
https://github.com/goxr3plus/java-stream-player/blob/d32a46a1f7d105a2c5350ae5bd04fdc1edd47baa/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java#L846-L852

Then comes a part which I think is important for performance. In a not-so-good way.

https://github.com/goxr3plus/java-stream-player/blob/d32a46a1f7d105a2c5350ae5bd04fdc1edd47baa/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java#L872-L882

This is executed for every iteration of the inter loop we are in. The listener operations may take a long time. Do the listeners really have to be called for each iteration of the loop? The iteration frequency is controlled by audio properties in some way I'm asking about above, but the listeners generally deal with graphics. Maybe graphics don't have to update as often.

Compare with the following from JavaFx MediaPlayer:

```
@Override public void onAudioSpectrumEvent(final AudioSpectrumEvent evt) {
Platform.runLater(() -> {
AudioSpectrumListener listener = getAudioSpectrumListener();
if (listener != null) {
listener.spectrumDataUpdate(evt.getTimestamp(),
evt.getDuration(),
magnitudes = evt.getSource().getMagnitudes(magnitudes),
phases = evt.getSource().getPhases(phases));
}
});
}
```

Regrettably, JavaFx MediaPlayer only allows listeners to spectrum events, but the principle could be applied i a more general way. There seem to be some event generator for spectrum events, that run with a different (more slow, I assume) than the audio loop frequency.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.