you-apps / RecordYou

Privacy focused recorder app built with MD3
https://you-apps.net
GNU General Public License v3.0
727 stars 30 forks source link

opus codec changes pitch 2,x halftones up #193

Closed secretmango closed 8 months ago

secretmango commented 12 months ago

Steps to reproduce

I tried all codecs and wave, played the same notes and compared.

Actual behavior

Only opus changes the pitch of my tone 2,3 or so halftones up, cuts a small section of the beginning and speeds the audio up.

Just for fun I uploaded my test audios here

Password: recordyou12

Record You version

7.0

Android version

Android 13, GrapheneOS

Other details

No response

Acknowledgements

SilverPuppy commented 11 months ago

I think this is not a bug but a sloppy implementation of Opus. RY defaults to red book sample rates, (22,050, 44,100) which Opus doesn't support. The other available CODECs do, but Opus doesn't. As a result, the audio is sampled at a lower rate during recording, for example 44,100, then replayed at a higher rate, for example 48,000, because Opus had to just assign the closest rate it supported to the data it received, so at playback the pitch sounds higher. Vorbis, released by the same organization as Opus roughly 15 years earlier, does support those sample rates, but Opus does not.

Your solution is to manually assign a sample rate Opus supports to resolve the mismatch. Opus supports sample rates in multiples of 8000 up to 48,000 (possibly not 40,000); I usually use 24,000 for general purpose audio. The other CODECs also support these rates, so there's no harm in leaving it set to one of these all the time.

The long term solution is that RY needs to be adjusted so that the default sample rate(s) used with Opus are rates it supports. Changing the defaults universally to the multiples of 8000 would have no ill effects.