Log in

View Full Version : Real-time 432hz Audio Auto-Pitching


MysteryX
16th November 2015, 06:16
How can I use AviSynth to do real-time 432hz audio auto-pitching as described in this article?
http://www.roelhollander.eu/en/432-tuning/432-music-players/

If I'm already using SVP, then I'm pretty sure I can edit the script to achieve that. I just have to figure out how.

What script would do this?

MysteryX
16th November 2015, 07:21
Actually... it's easy.

AssumeFPS(FrameRate*.981818, true)

Question is: is there another way to do it that will give a better audio quality?

raffriff42
16th November 2015, 07:29
yes, there is:

TimeStretch (http://avisynth.nl/index.php/TimeStretch)(pitch=100.0 * 0.981818)

EDIT I believe AssumeFPS simply changes the "playback rate" without resampling anything, and therefore it has the best possible quality. However:
* video frame rate is lower
* audio sample rate is lower
* running time is longer

MysteryX
16th November 2015, 09:46
TimeStretch is doing some weird distortion on some videos.

AssumeFPS is definitely doing a better tuning...

StainlessS
16th November 2015, 16:11
I believe AssumeFPS simply changes the "playback rate" without resampling anything, and therefore it has the best possible quality.

Yes (with sync_audio = true, without, audio sample rate remains same ie video/audio length mismatch)

However:
* video frame rate is lower
* audio sample rate is lower
* running time is longer

And result is non standard audio SampleRate, requires eg ReSampleAudio(48000).

MysteryX
16th November 2015, 19:49
It doesn't seem SVP can do that, or process the audio in any way.

For offline conversion, however, Rubberband works
http://rubberbandaudio.com/

rubberband.exe -p -0.3176665363342977 Oon-Jai.wav Oon-Jai-2.wav

StainlessS
16th November 2015, 21:37
Maybe something like this would work, untested


# ORG=Original Rate Video/Audio SVP is new FrameRate video
NewAudio = AssumeFPS(ORG,SVP.FrameRate,sync_audio=true).ReSampleAudio(ORG.AudioRate)
NewvideoAndAudio = AudioDub(SVP,NewAudio)


EDIT: Nah, think I screwed that up :(

StainlessS
16th November 2015, 22:04
Can someone check this out and say If I did screw up or not, I aint sure.


Avisource("E:\V\Starwars.avi").Trim(25000,-60*25) # 25FPS
ORG=Last

SVP=ChangeFPS(FrameRate*0.981818) # simulate some other framerate

# ORG=Original Rate Video/Audio SVP is new FrameRate video
NewAudio = AssumeFPS(ORG,SVP.FrameRate,sync_audio=true).ReSampleAudio(ORG.AudioRate)
NewvideoAndAudio = AudioDub(SVP,NewAudio)

NewvideoAndAudio.Info


EDIT: If you select eg ChangeFPS(FrameRate*2.0) you get Donald Duck type audio, not sure if that is whats intended.
EDIT: Nah, still think I screwed that up :(

MysteryX
16th November 2015, 22:13
Can someone check this out and say If I did screw up or not, I aint sure.
Audio and video length are different.

Wilbert
16th November 2015, 22:14
TimeStretch is doing some weird distortion on some videos.
Please post a video where this is the case.
The plugin in http://forum.doom9.org/showthread.php?p=1722472#post1722472 shouldn't have any issues.

StainlessS
16th November 2015, 22:26
MysteryX, not sure what you were trying to do, is this correct

You want to change framerate to eg double original, and then slow video (together with synced audio) to 0.9xxxxx of new framerate,

if so then maybe somthing like this


Avisource("E:\V\Starwars.avi").Trim(25000,-60*25) # 25FPS
ORG=Last

SVP=ChangeFPS(ORG.FrameRate*2.0) # simulate some other framerate as via SVP

NEWV=AssumeFps(SVP,SVP.FrameRate*0.981818,sync_audio=true).ReSampleAudio(ORG.AudioRate)

NewV.Info

MysteryX
16th November 2015, 22:49
Please post a video where this is the case.
The plugin in http://forum.doom9.org/showthread.php?p=1722472#post1722472 shouldn't have any issues.
This version sounds better.

I have compared the TimeStretchPlugin vs Rubberband, and Rubbersounds better and clearer. TimeStretchPlugin sounds muffier.

Rubberband.exe
https://mega.nz/#!nAwjSaSb!ZQkQk5vcSOyarttwIqfVu8IznGAkgckkIQJIv9NCDsY
TimeStretchPlugin.dll
https://mega.nz/#!2IJRwYaA!sa3RJYOClW3P-f7zAMIQwJt_DMKMaL2GBZRDWEPMse8

That being said, TimeStretchPlugin.dll would definitely be good enough for live playback! If I can find a way to insert that into the chain when playing videos.

MysteryX
17th November 2015, 05:36
Is it possible to add custom metadata to the video such as "Pitch=432hz" in such a way that I can re-access that custom metadata later with MediaInfo?

MysteryX
17th November 2015, 05:37
I also found out to do live re-pitching. I create a simple script file and play that instead of the video file. My software can generate that script file.

LoadPlugin("TimeStretch.dll")
SetMTMode(3,8)
DirectShowSource("F:\NaturalGrounding\Apink\Good Morning Baby.mkv", audio=true, pixel_type="YV12")
SetMTMode(2)
TimeStretchPlugin(pitch=100.0 * 0.981818)

However, for files that were already re-tuned, I don't want to do it again.

MysteryX
17th November 2015, 06:49
It appears FPS argument must be specified on DirectShowSource. If it's not written, then the audio and video don't sync very well. If I add FPS, then they match much better.

foxyshadis
17th November 2015, 16:09
Is it possible to add custom metadata to the video such as "Pitch=432hz" in such a way that I can re-access that custom metadata later with MediaInfo?

You can add any tags you want in mkv and mp4. The splitter isn't obligated to pass them on and the player will ignore them anyway, but they're there.

MysteryX
17th November 2015, 20:00
Rubberband normally gives better audio quality but can also cause distortion. Here's a sample clip with extreme distortion with TimeStretch, some distortion with Rubberband and it plays fine with TimeStretchPlugin.

Original
https://mega.nz/#!PBQXyaoa!khk1eG8d-vwzBUgZFeEaTQLFEoClav8UWKeoN6sYNR8
Rubberband
https://mega.nz/#!nNQDABzK!zv_ff0-Bp7EWoIoHAOsTJiOfORnPD89VDeWDjcd7WVE
TimeStretch(pitch=100.0 * 0.981818)
https://mega.nz/#!nMQjjLQY!AOya4aN2FyNLYmIvOyxNyLZLD1hP5Kh-6utzt4QRR6E
TimeStretchPlugin
https://mega.nz/#!vFBA3arI!ZSkHJUiBLlX1KcxYghfNYyyCo9EnQtDPzEsFuRn26xM

AssumeFps doesn't give the same pitch... not sure which one is the right 432hz pitch.
AssumeFps(FrameRate*.981818).ResampleAudio(48000)
https://mega.nz/#!PNBCiKyJ!MiSwHd84wpnm4TJwNEr6tywYM1DhD6E5SDKDuiqM0QQ

This approach gives another pitch in-between the 2 previous ones
SemiTone = -0.3176665363342977
TimeStretchPlugin(pitch = 100.0*pow(2.0, SemiTone/12.0))
https://mega.nz/#!LR5U2aoK!162M-DBp_i2zydyn1J9ucO72yX53jW0F7FYrQ471MVQ

raffriff42
17th November 2015, 21:17
Before you say TimeStretch (http://avisynth.nl/index.php/TimeStretch) is NFG, you must test all possible combinations of sequence, seekwindow, overlap, and aa!

(I don't think I could "relax" to something I have pitch-shifted. I'd go crazy listening for artifacts.)

MysteryX
18th November 2015, 00:40
If I'm auto-tuning, I can't adjust the advanced parameters individually.

Out of Rubberband, TimeStretch and TimeStretchPlugin, the only one that doesn't cause distortion in that sample is TimeStretchPlugin. And it works.

I also just saw that I get considerably better quality if I first resample to 48000hz.

This is my script for real-time auto-tuning

PluginPath=""
LoadPlugin(PluginPath+"ffms2.dll")
LoadPlugin(PluginPath+"TimeStretch.dll")
SetMTMode(3,4)
FFmpegSource2(source="Oon-Jai.mkv", atrack=-1, cache=false, threads=1)
SetMTMode(2)
ResampleAudio(48000)
SemiTone = -0.3176665363342977
TimeStretchPlugin(pitch = 100.0 * pow(2.0, SemiTone / 12.0))

Considering the loss of quality for re-encoding, plus the loss of quality for re-pitching, and considering it can be done 'live', I don't think it would be wise to re-encode the audios in such a way. Better keep the audios intact and process it live.