Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Allow high quality opus recording #273

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Allow high quality opus recording #273

merged 4 commits into from
Mar 12, 2024

Conversation

pvagner
Copy link
Contributor

@pvagner pvagner commented Mar 10, 2024

Opus codec supports low latency and high quality audio recording. I think we should make more reasonable defaults and allow more fine grained control for people who know what they are doing. Another stab at fixing #193.
Since #235 as an addition to disabling sample rate control setting up the bitrate is no longer working for opus file recordings.
These sample rates are natively supported by the opus encoder with no resampling involved: 8, 12, 16, 24, or 48 kHz. See this FAQ answer and a few follow up answers https://wiki.xiph.org/OpusFAQ#What_is_Opus_Custom?
When not specifying the sample rate at all resulting files have some kind of default sample rate that severely degrades audio quality. When inspecting files with ffmpeg the sample rate is always displayed as 48000. I have verified that setting the sample rate it increases audio quality though. Changes based off of this:

  • Again respect bitrate setting when recording into opus. Bitrate of 32000, 40000 or 48000 sound very goot for casual recordings sampled at 48000 Hz.
  • Allow setting sample rate for opus encoding when specifying one of the supported values.

Opus codec supports low latency and high quality audio recording. I think we should make more reasonable defaults and allow more fine grained control for people who know what they are doing.
Another stab at fixing you-apps#193.
Since you-apps#235 as an addition to disabling sample rate control setting up the bitrate is no longer working for opus file recordings.
    These sample rates are natively supported by the opus encoder with no resampling involved: 8, 12, 16, 24, or 48 kHz. See this FAQ answer and a few follow up answers https://wiki.xiph.org/OpusFAQ#What_is_Opus_Custom?
When not specifying the sample rate at all resulting files have some kind of default sample rate that severely degrades audio quality. When inspecting files with ffmpeg the sample rate is always displayed as 48000. I have verified that setting the sample rate it increases audio quality though.
Changes based off of this:
* Again respect bitrate setting when recording into opus. Bitrate of 32000,
40000 or 48000 sound very goot for casual recordings sampled at 48000 Hz.
* Allow setting sample rate for opus encoding when specifying one of the supported values.
if (audioFormat.codec != MediaRecorder.AudioEncoder.OPUS) {
Preferences.prefs.getInt(Preferences.audioSampleRateKey, -1).takeIf { it > 0 }
?.let {
Preferences.prefs.getInt(Preferences.audioSampleRateKey, -1).takeIf { it > 0 }
Copy link
Member

Choose a reason for hiding this comment

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

We should extract this and the bitrate preference to variables first, that would make things cleaner.

Copy link
Contributor Author

@pvagner pvagner Mar 11, 2024

Choose a reason for hiding this comment

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

Bitrate preference is exactly as all the other preferences even before the issue with opus recording was discovered so I haven't yet touched that one. If you insist I will change that of course.
As for the sample rate I have extracted it to a variable but I am not sure it's the way you would like to have it. I don't want to introduce more conditions so the change is just minimal.

Copy link
Member

@Bnyro Bnyro left a comment

Choose a reason for hiding this comment

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

I've just pushed some minor code simplifications.

Thanks!

@Bnyro Bnyro merged commit 427831e into you-apps:main Mar 12, 2024
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants