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: add a pitch-shifting feature #11214

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Conversation

myQwil
Copy link
Contributor

@myQwil myQwil commented Jan 27, 2023

Uses resampling in tandem with any time-stretching audio filter (scaletempo, scaletempo2, rubberband) to change the audio's pitch while leaving its tempo intact.

@kasper93
Copy link
Contributor

kasper93 commented May 7, 2024

Needs rebase and interface changes update.

@myQwil myQwil force-pushed the pitch_shift branch 2 times, most recently from d52cd77 to 7c4b471 Compare May 7, 2024 23:53
Copy link

github-actions bot commented May 8, 2024

Download the artifacts for this pull request:

Windows
macOS

Copy link
Member

@Dudemanguy Dudemanguy left a comment

Choose a reason for hiding this comment

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

Seems to have been forgotten, but works well and is potentially useful.

Copy link
Member

@Dudemanguy Dudemanguy left a comment

Choose a reason for hiding this comment

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

Sorry I forgot something as always. Could you put the old bindings for the curly braces in restore-old-bindings.conf?

etc/mplayer-input.conf Outdated Show resolved Hide resolved
@guidocella
Copy link
Contributor

I would prefer to keep changing the speed with {} as it's way more useful than changing pitch.

@llyyr
Copy link
Contributor

llyyr commented Aug 2, 2024

Yeah I think this is too niche to have a default keybind, users can configure it themselves if they want this feature

@myQwil myQwil force-pushed the pitch_shift branch 2 times, most recently from 9fdd0b4 to 64729be Compare August 2, 2024 10:24
@myQwil
Copy link
Contributor Author

myQwil commented Aug 2, 2024

keybinding changes have been taken out

player/audio.c Outdated
double drop = 1.0;

if (!mpctx->opts->pitch_correction) {
resample *= speed;
speed = 1.0;
}

speed /= mpctx->opts->playback_pitch;

if (mpctx->display_sync_active) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this expected this new feature will not work correctly with -adrop and -tempo sync modes?

Copy link
Contributor Author

@myQwil myQwil Aug 2, 2024

Choose a reason for hiding this comment

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

I think this is to be expected.
-tempo prevents resampling and forces the pitch to be corrected.
-adrop prevents both resampling and the time-stretcher.

EDIT: actually, for -adrop, we could probably add something like this:

-                drop *= speed * resample;
-                resample = speed = 1.0;
+                drop *= speed * mpctx->speed_factor_a;
+                resample = mpctx->opts->playback_pitch;
+                speed = 1.0;

player/audio.c Outdated Show resolved Hide resolved
@myQwil myQwil force-pushed the pitch_shift branch 6 times, most recently from 5e34c09 to 67a07dd Compare August 3, 2024 15:36
@kasper93
Copy link
Contributor

kasper93 commented Aug 6, 2024

Just last thing is missing, note in DOCS/interface-changes

player/audio.c Outdated
break;
default: goto normal;
Copy link
Contributor

@kasper93 kasper93 Aug 7, 2024

Choose a reason for hiding this comment

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

I don't like this goto here. How about

int video_sync = mpctx->display_sync_active ? mpctx->video_out->opts->video_sync : VS_NONE;
switch (video_sync) {
...

and put

        resample *= pitch;
        speed /= pitch;

into default case.

Uses resampling in tandem with a time-stretching audio filter to
change the audio's pitch while leaving its tempo intact.
@myQwil myQwil changed the title add a pitch-shifting feature audio: add a pitch-shifting feature Aug 7, 2024
@kasper93 kasper93 merged commit 88885c0 into mpv-player:master Aug 7, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants