Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd January 2019, 12:45   #1  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
Unusual audio damage - every 3rd sample

BACKGROUND: Sometimes my DVR creates a strange artifact on the audio output that is inaudible to me. It's not til after I capture the video and extract the video and .wav files for Avisynth processing that I discover the problem. (And I worked hard to trace down that it was the DVR causing it, which is solved temporarily by rebooting the DVR. But eventually it slips into artifact mode again without warning.) If I catch it before I've erased the program from the DVR, I can simply recapture. However, I've capped and done a bunch of deleting, so I cannot go back and recapture.

THE NEED: What I need is a way to massage the audio. I need to subtract the value 16,384 from every 3rd sample in the right channel, starting at a specified offset (which will be 0, 1 or 2). Is there some way in Avisynth to do this with my audio track???

I open my audio like this:

audio=wavsource("myvideo.wav")

Last edited by TCmullet; 2nd January 2019 at 13:11.
TCmullet is offline   Reply With Quote
Old 2nd January 2019, 14:09   #2  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
Would some kind of usage of BeFa be in order? But man, that filter is cryptic, even if you use Google Chrome to translate from the original Japanese.
TCmullet is offline   Reply With Quote
Old 2nd January 2019, 14:33   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,087
BeFa English doc:- http://web.archive.org/web/200711050...sROOM.htm#Befa

Linked from wiki, External filters:- http://avisynth.nl/index.php/Externa...#Audio_Filters
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 2nd January 2019, 14:40   #4  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
Stainless, yes I saw that. But I discovered that Chrome's real-time (when I tell it to) translation of the original reads a lot better. But it's still cryptic. Have you or anyone ever used BeFa?

Every 3rd sample of my 48khz audio equates to a tone of 16000 cycles per second. By looking at the waveform in Audacity is how I determined that whatever is causing this is adding a fixed value to my signal. And it looks very closely like the value is 16384.

I'm worried that the only practical way to solve this is to write a C++ program to read the bad wave file as input and write out a new one with 16384 subtracted from every 3rd sample in the right channel.
TCmullet is offline   Reply With Quote
Old 2nd January 2019, 14:49   #5  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
I posted a graphic of the view in Audacity here:
https://forum.audacityteam.org/viewt...?f=46&t=102710

The solution that I reported there was to recapture from the DVR after rebooting. But now I'm dealing with files old enough that they no longer can be recaptured. So I DO need a way to fix the corrupted waveform.
TCmullet is offline   Reply With Quote
Old 2nd January 2019, 16:35   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,087
Quote:
Originally Posted by TCmullet View Post
Have you or anyone ever used BeFa?
Cant speak for anyone, just for me, no never even heard of it.

Give me a little time to finish a few other things and I'll see what I can do.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 2nd January 2019, 19:06   #7  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 1,810
What happens when the underlying samples have a high enough value that adding 16384 would push them over the top?

By the way I'd say your left channel needs a smaller amount (2000) adding every three samples as well. And I don't think the offset on the right channel is 16384 - it's more like 20000.

StainlessS: I've got this one covered if you don't want to spend any (more) time on it Just waiting on an answer to the above question before finalising.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 2nd January 2019 at 19:17.
wonkey_monkey is offline   Reply With Quote
Old 2nd January 2019, 19:16   #8  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
Quote:
Originally Posted by davidhorman View Post
What happens when the underlying samples have a high enough value that adding 16384 would push them over the top?
I had wondered that too. This is a cable TV signal, and the volume never increased high enough to cause the tone to go above the max (+32767?) That made me think it was intentional. But rebooting killed it.

Also I just learned today it's not happening immediately and at 16384, but starts gradually after audio starts, taking a few seconds to reach max value. (16384 is my educated guess.)
TCmullet is offline   Reply With Quote
Old 2nd January 2019, 19:24   #9  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 1,810
Well that makes things trickier. What do you mean by "after audio starts"? If there's a period of silence, does the offset reset to 0, and then start climbing when the period of silence ends?
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 2nd January 2019, 19:48   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,087
Quote:
StainlessS: I've got this one covered
Lovely, was not looking forward to it.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 2nd January 2019, 20:18   #11  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
Quote:
Originally Posted by davidhorman View Post
Well that makes things trickier. What do you mean by "after audio starts"? If there's a period of silence, does the offset reset to 0, and then start climbing when the period of silence ends?
No, after a couple seconds audio, it's stable the rest of the recording, even hours long. I think it ties to the DVR's start of playback. It takes 2-3 sec. maybe to ramp up to it's normal constant of ~16384. (I could probably measure it.)
TCmullet is offline   Reply With Quote
Old 2nd January 2019, 20:44   #12  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 1,810
Can you upload a longer sample? I've just realised I forgot to allow for something which I can't test without a longer sample. A few seconds should do.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 3rd January 2019, 03:36   #13  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
Longer sample? You mean a sample longer than the one I didn't send or include? Uh, well I guess you must be talking about the 300 sample file I put up on the Audacity board earlier. Okay, I can give 10 sec. if I leave it in the captured AAC format, then you can decompress to .wav to view it. It (the aac file) is contained in a zip file attached. This is the 1st 10 seconds of audio in the capture.

I think I was wrong about it taking 2+ seconds for the amplitude of introduced 16k tone (which shows as every 3rd sample being boosted by a fixed large amount, 16k-20k). It's not 2 sec, but rather .02 seconds. After that time, the amplitude is the constant value (16k or 20k) Before that, the amplitude starts at 0 and rapidly (over .02 sec.) ramps up to the high value constant thru the rest. I'm not try to stop the ramp up. I'd simply skip over it to apply whatever fix to everything BUT the 1st .02 or .03 seconds.
Attached Files
File Type: zip First-10sec.bad-right-ch.zip (268.6 KB, 5 views)
TCmullet is offline   Reply With Quote
Old 3rd January 2019, 03:41   #14  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
A reason I'd like an Avisynth solution is that I don't discover the problem until I have set up a script for processing and I SEE the boosted right channel. If I had nothing to do to the audio, I could let it go unchanged. But you can see that if I need to do something as simple as normalizing, the normalizing won't work as those inaudible spikes every 3 samples max out the normalizing logic, that is, normalizer cannot boost it any more as the louder ones are already maxed out.

Edit: Also, I have a lot of files to process, and adding a line of code in the Avisynth script (if there is such a line) is much faster than doing an Audacity step to process and fix the audio file before finalizing (and running) my Avisynth script. Plus I'm not crazy about notching out something.

Last edited by TCmullet; 3rd January 2019 at 14:31.
TCmullet is offline   Reply With Quote
Old 3rd January 2019, 12:04   #15  |  Link
Groucho2004
►◄
 
Groucho2004's Avatar
 
Join Date: Mar 2006
Location: A wretched hive of scum and villainy
Posts: 4,394
Quote:
Originally Posted by TCmullet View Post
A reason I'd like an Avisynth solution is that I don't discover the problem until I have set up a script for processing and I SEE the boosted right channel.
How so? You can load the audio in Audacity, run a FFT and display the frequency spectrum. That should make it easy to identify the spurious signal. Then apply a notch filter. This was already suggested to you in the Audacity forum.

Working on this problem in the time domain seems rather error prone, not to mention that there is no software or Avisynth plugin (of which I am aware) that can do this.
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline   Reply With Quote
Old 3rd January 2019, 14:25   #16  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
Let's call the amount by which the signal is erroneously boosted every 3rd sample "boosted value" or BV. My thought process when I first saw this close up was, if I follow the path of the waveform and when one of the 3rd-samples would cross the x-axis (the time domain) if it had not been boosted, then the value of that boosted sample would be BV. I could see that subtracting BV from every 3rd sample would restore all the boosted samples to their original values. So, what could be error-prone about that? It's exactly every 3rd sample, and once we nail down the value of BV, it is constant throughout (except for the first fraction of second where it is ramping up).
Attached Images
 

Last edited by TCmullet; 3rd January 2019 at 14:28.
TCmullet is offline   Reply With Quote
Old 4th January 2019, 17:36   #17  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 1,810
Okay, the start is a bit more complicated because it looks like there's another aberrant signal at a different offset which fades in and then fades out, but this should help for the rest of the audio:

http://horman.net/avisynth/download/audiofix.zip

If you're not sure which DLL you need, you're probably using 32-bit Avisynth so you want audiofix(x86).dll

Parameters:

Code:
offset   - bad sample offset
step     - defaults to 3
add      - amount to add to selected samples
channels - AF_LEFT, AF_RIGHT, or AF_BOTH (default)
ramp     - number of samples to ramp up over at start
Code to mostly fix the longer sample:

Code:
convertaudioto16bit # it only works with 16-bit audio
audiofix(offset=2,add=-20000,channels=AF_RIGHT,ramp=1000)
audiofix(offset=2,add=2000,channels=AF_LEFT,ramp=1000)
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 4th January 2019, 18:24   #18  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
Wow, thank you, David! I look forward to trying this soon.
TCmullet is offline   Reply With Quote
Old 4th January 2019, 18:30   #19  |  Link
TCmullet
Registered User
 
Join Date: Nov 2003
Posts: 316
I was puzzled why you did something in left channel. but on looking more closely, it appears that yes, the left DOES have a disruption, albeit much smaller in amplitude that the right channel disruption.

If I start my frames of concern far into the clip, can I set the ramp to zero? In most cases, I don't need the footage at the start. But in at least one case, I probably do. (It was something where no audio started until the real audio for the program did.)

I was puzzled at first by "offset", but I think that is the means to sync processing to where it's now every 3rd (the step parameter) sample.

Also, how accurate are your BV values (-20000 for the right, 2000 for the left)? Do you feel they're the best possible estimates, or do I need to work to get them more accurate?

Last edited by TCmullet; 4th January 2019 at 18:48.
TCmullet is offline   Reply With Quote
Old 4th January 2019, 19:28   #20  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 1,810
Yes, you can set ramp to zero so it has no effect. The BV values are pretty accurate as far as I can tell, probably within 1% for the right channel. Ideally you should check a recording which has a period of complete silence (on an ad break, if there are any, for example) so you can be certain of the value.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:46.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.