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

[audio] Improve audio duration computation #3675

Merged

Conversation

dalgwen
Copy link
Contributor

@dalgwen dalgwen commented Jun 30, 2023

Add another way of computing sound duration (using information from the AudioFormat class)

Allows the use of a "Sizeable" interface (for AudioStream that we know the length of, but we cannot clone). We can then improve the success of the duration detection, for example for the pulseaudio sink (PR coming after). We can also give the length information to sink in more cases, even if we cannot clone the stream.

Add the support of the mark / reset methods to some common AudioStream. We then allow more stream analysis for sink requiring it (Stream analysis often requires to get back in time after consuming a few bytes)

@dalgwen dalgwen requested a review from a team as a code owner June 30, 2023 13:52
@dalgwen dalgwen force-pushed the improve_audio_duration_computation branch from 3e0275a to 58244bd Compare June 30, 2023 14:07
@@ -102,7 +104,9 @@ public AudioFormat getFormat() {

@Override
public int read() throws IOException {
return inputStream.read();
int read = inputStream.read();
alreadyRead++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it rather alreadyRead += read; ?

Copy link
Contributor Author

@dalgwen dalgwen Jul 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "alreadyRead" counter is the amount of bytes read.
The read() method reads only one byte and return the value of this byte.
So just +1 at every call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

logger.debug("Cannot compute the duration of input stream with method java stream sound analysis",
e);
Integer bitRate = audioFormat.getBitRate();
Integer channel = audioFormat.getChannels();
Copy link
Contributor

@lolodomo lolodomo Jul 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channel is then apparently not used, is it normal ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I used this on a previous try but it is not needed.
I will remove it.

Allows the use of a Sizeable interface (for AudioStream that we know the length of, but we cannot clone). We can then improve the duration detection, for example for the pulseaudio sink (PR coming after).
We can also give the length information to sink in more cases.

Add the support of the mark / reset methods to some common AudioStream. We then allow more stream analysis for sink requiring it (Stream analysis often requires to get back in time after consuming a few bytes)

Signed-off-by: Gwendal Roulleau <[email protected]>
@dalgwen dalgwen force-pushed the improve_audio_duration_computation branch from 58244bd to 5fd27ca Compare July 1, 2023 14:38
@lolodomo
Copy link
Contributor

lolodomo commented Jul 2, 2023

Build failed in "Automation Integration Tests". Not sure it have any link with your PR.
@openhab/core-maintainers : can one of you trigger a new build please ?
Except that problem, code LGTM.

@kaikreuzer kaikreuzer added rebuild Triggers the Jenkins PR build and removed rebuild Triggers the Jenkins PR build labels Jul 2, 2023
@kaikreuzer kaikreuzer merged commit 3ec1457 into openhab:main Jul 2, 2023
2 checks passed
@kaikreuzer kaikreuzer added this to the 4.0 milestone Jul 2, 2023
@kaikreuzer kaikreuzer added the enhancement An enhancement or new feature of the Core label Jul 2, 2023
@dalgwen dalgwen deleted the improve_audio_duration_computation branch July 3, 2023 09:22
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
Allows the use of a Sizeable interface (for AudioStream that we know the length of, but we cannot clone). We can then improve the duration detection, for example for the pulseaudio sink (PR coming after).
We can also give the length information to sink in more cases.

Add the support of the mark / reset methods to some common AudioStream. We then allow more stream analysis for sink requiring it (Stream analysis often requires to get back in time after consuming a few bytes)

Signed-off-by: Gwendal Roulleau <[email protected]>
GitOrigin-RevId: 3ec1457
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants