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

HiFi Decode fixes and improvements #120

Merged
merged 175 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
b4b72a3
Merge of vhs_decode branch
VideoMem Mar 23, 2021
0756c7c
typo glitch fix
VideoMem Mar 23, 2021
a9d9471
DC restore intro
VideoMem Mar 26, 2021
ca2e427
DC restore, before sync restore
VideoMem Mar 26, 2021
25086fc
DC restore improved metrics
VideoMem Mar 26, 2021
f37d4b0
DC restore improved metrics, pre merge check
VideoMem Mar 27, 2021
6fab92b
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Mar 27, 2021
2498807
Added chroma trap option to cvbs-decode
VideoMem Mar 27, 2021
6e94ede
Auto-sync level, first try
VideoMem Mar 29, 2021
13c7a2c
Auto-sync level, added to cvbs + wavesink
VideoMem Mar 30, 2021
13dc289
Auto-sync level (block level, not working) , added to cvbs + wavesink
VideoMem Mar 31, 2021
997edff
Auto-sync level (block level, not working) , added to cvbs + wavesink
VideoMem Mar 31, 2021
3c51017
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Mar 31, 2021
e5c8e63
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Mar 31, 2021
a692707
Some dead code removal
VideoMem Mar 31, 2021
b571a05
Previous merge commit
VideoMem Apr 9, 2021
79d8c3e
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 9, 2021
20444ee
Merge of oyvindln/vhs_decode changes
VideoMem Apr 9, 2021
41cb814
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 15, 2021
b0e0248
Resync
VideoMem Apr 17, 2021
90a9afb
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Apr 17, 2021
12fa31f
Moved experimental sync separator code to resync branch
VideoMem Apr 17, 2021
7f68321
Merge remote-tracking branch 'upstream/vhs_decode' into resync
VideoMem Apr 17, 2021
9532e76
Merge branch 'vhs_decode' into resync
VideoMem Apr 17, 2021
0c293c9
Restored deleted files
VideoMem Apr 17, 2021
22de0b8
Comment typo fix
VideoMem Apr 17, 2021
713b963
Comment typo fix
VideoMem Apr 17, 2021
6268034
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Apr 22, 2021
1439865
Merge branch 'vhs_decode' into resync
VideoMem Apr 22, 2021
b186a26
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Apr 23, 2021
9bc0bbb
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Apr 23, 2021
ef117c6
Added -palm -pm command line switches and RFParams_MPAL_VHS on format…
VideoMem Apr 25, 2021
ab39624
cvbs-decode / vhs-decode common options deduplication + preliminary P…
VideoMem Apr 25, 2021
921350a
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 25, 2021
9735931
cvbs-decode / vhs-decode common options deduplication + preliminary P…
VideoMem Apr 25, 2021
728767b
Merge branch 'vhs_decode' into resync
VideoMem Apr 26, 2021
d221cf2
VBI serration detection test
VideoMem Apr 26, 2021
5d1ea4e
Merge of vhs_decode branch
VideoMem Mar 23, 2021
dcd838f
typo glitch fix
VideoMem Mar 23, 2021
fc23fd0
Added chroma trap option to cvbs-decode
VideoMem Mar 27, 2021
a497a0f
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Mar 31, 2021
d1075a4
Some dead code removal
VideoMem Mar 31, 2021
f548509
Merge of oyvindln/vhs_decode changes
VideoMem Apr 9, 2021
ba7972e
Comment typo fix
VideoMem Apr 17, 2021
ca2398a
Comment typo fix
VideoMem Apr 17, 2021
ed0fe1b
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Apr 23, 2021
485fd29
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Apr 23, 2021
34415e6
Added -palm -pm command line switches and RFParams_MPAL_VHS on format…
VideoMem Apr 25, 2021
d69238d
cvbs-decode / vhs-decode common options deduplication + preliminary P…
VideoMem Apr 25, 2021
81e64a3
cvbs-decode / vhs-decode common options deduplication + preliminary P…
VideoMem Apr 25, 2021
55bc94a
Merge remote-tracking branch 'origin/vhs_decode' into vhs_decode
VideoMem Apr 26, 2021
619d02d
Changes cleanup (vhs-decode/cvbs-decode command line deduplication + …
VideoMem Apr 26, 2021
7d53e05
vsync_levels pre-cleanup
VideoMem Apr 26, 2021
23480a2
VBI vsync autolevels testing
VideoMem Apr 27, 2021
7b0e9c6
Temporarly disabled extra-diff code to force zero crossings, it can b…
VideoMem Apr 28, 2021
6d7e625
Added demodblock() envelope (env) zeroes check, to avoid potential di…
VideoMem Apr 28, 2021
f758599
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 29, 2021
5bdcf3d
- Changed the replace_spikes function as shown before.
VideoMem Apr 29, 2021
14f6375
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 29, 2021
eea6548
- Changed the replace_spikes function to use np.where instead np.argw…
VideoMem Apr 29, 2021
33a2887
- Changed the replace_spikes function to use np.where instead np.argw…
VideoMem Apr 29, 2021
69805a9
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Apr 29, 2021
8596303
- Changed the replace_spikes function to use np.where instead np.argw…
VideoMem Apr 29, 2021
3dbb7ce
Bad signal / 'Chewed tape' sample (preliminary fix) (#24)
VideoMem Apr 25, 2021
c0df694
getpulses_override() keep the last valid blacklevel, synclevel, and v…
VideoMem Mar 23, 2021
194ff0c
Merge remote-tracking branch 'origin/vhs_decode' into vhs_decode
VideoMem Apr 30, 2021
cc5acb0
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 1, 2021
a9cf66c
fixup!
VideoMem May 2, 2021
e404463
Changed min valid levels to report valid serration levels
VideoMem May 2, 2021
93b5a48
Merge branch 'vhs_decode' into resync
VideoMem May 2, 2021
5d96161
chroma loss sample fails
VideoMem May 2, 2021
004c3d7
RuntimeWarning: Div by zero prevented at lddecode/utils.calczc_do()
VideoMem May 3, 2021
77cb1f6
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 3, 2021
f2b16a4
RuntimeWarning: Div by zero prevented at lddecode/utils.calczc_do()
VideoMem May 3, 2021
f3e4df6
Regenerates the sync pulses amplitude
VideoMem May 3, 2021
fdfb2be
Seems to sort a lot of edge cases, saving this
VideoMem May 3, 2021
14f38a9
Merge remote-tracking branch 'origin/resync' into resync
VideoMem May 3, 2021
f6a2861
Added resync branch getpulses_override() logic
VideoMem May 4, 2021
c7814be
Safe clips the bottom of the sync pulses but leaves picture area unch…
VideoMem May 5, 2021
c44e499
Nosync sample decodes
VideoMem May 5, 2021
8e92eea
Serration levels detection adjustments (produces new frames on chewed…
VideoMem May 5, 2021
a6ecc6a
Suggested oyvindln changes over replace_spikes() on diff_demod
VideoMem May 6, 2021
244c35b
Added ldd.core logger, changed the name of the Vsync class to VsyncSe…
VideoMem May 6, 2021
9350ce0
Disabled serration detection in cvbs-decode
VideoMem May 6, 2021
1b84b1a
Encapsulated all the sync search and the serration search into Resync…
VideoMem May 6, 2021
5297a58
Merged resync branch changes
VideoMem May 6, 2021
79b67aa
Merge remote-tracking branch 'origin/vhs_decode' into vhs_decode
VideoMem May 6, 2021
2b99876
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 6, 2021
41406cf
- Corrected the fallback sync logic when serrations not found.
VideoMem May 7, 2021
890228a
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem May 7, 2021
8c5c116
- added a note on what I mean with fallback sync logic
VideoMem May 7, 2021
c1042e2
- Added more debugging if show_decoded is enabled on VsyncSerration()…
VideoMem May 8, 2021
f330c83
Merging oyvindln/vhs_decode updates
VideoMem May 9, 2021
a028776
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem May 15, 2021
be42d96
Added field hash debug info for SysParams and field.data["video"]["de…
VideoMem May 15, 2021
46bb6e6
Added some checks for SysParams consistency, and found the AGC change…
VideoMem May 15, 2021
89d6884
Refactored the moving average filter for re-utilisation on other code…
VideoMem May 16, 2021
064cdf4
Modified fallback sync/levels logic
VideoMem May 16, 2021
a28eb8f
vsync_envelope_simple() not so tested corrections
VideoMem May 17, 2021
880984e
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 17, 2021
6a539f7
Added experimental changes to vsync_envelope_simple(), merged oyvindl…
VideoMem May 17, 2021
d563067
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 17, 2021
d90eff8
fallback logic getLevels fixes + oyvindln process.py changes
VideoMem May 18, 2021
047c548
Some tape batch tests script intro
VideoMem May 22, 2021
16389d0
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 22, 2021
d1f5702
Tape batch tests improvements
VideoMem May 22, 2021
3030325
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 22, 2021
375f89e
Tape batch tests improvements
VideoMem May 23, 2021
3b02962
Passed the optional debug flag to the resync code.
VideoMem May 25, 2021
a4584c4
Restored vsync_envelope_simple() logic, to fix bicycle sample start p…
VideoMem May 25, 2021
188425e
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem May 29, 2021
9de0e63
Merged from vhs_decode upstream.
VideoMem May 30, 2021
69847ce
ChromaAFC introduction
VideoMem Jun 1, 2021
e3cb9a9
ChromaAFC enable flag -cafc
VideoMem Jun 1, 2021
73413aa
Improved Chroma AFC
VideoMem Jun 5, 2021
8c9dadf
Chroma AFC, now it does something
VideoMem Jun 5, 2021
c08e241
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jun 6, 2021
107835a
Merge of upstream and Chroma AFC changes
VideoMem Jun 6, 2021
659075f
Chroma AFC measure smoothing changes
VideoMem Jun 6, 2021
38750cc
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jun 9, 2021
24c0b29
Serration fixes
VideoMem Jun 9, 2021
e027152
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jun 12, 2021
0c2d602
Added --sync_clip optional flag
VideoMem Jun 12, 2021
e6ff840
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jun 12, 2021
6918ff6
Improved -cafc
VideoMem Jun 13, 2021
1108e8a
-cafc (only phase, not freq)
VideoMem Jun 19, 2021
51660c4
-cafc (only phase, not freq), enables in try_detect_track
VideoMem Jun 19, 2021
04b7fd0
If -cafc filters chroma after TBC + chroma related refactor
VideoMem Jun 20, 2021
b186fee
Changes IGNORED_LINES in burst phase detection
VideoMem Jun 21, 2021
7ed62ea
-cafc selects the nearest peak harmonic from the chroma channel as ca…
VideoMem Jun 21, 2021
36c7222
-cafc more interesting results
VideoMem Jun 21, 2021
e46c514
-cafc some corrections
VideoMem Jun 21, 2021
8db1264
-cafc searchs peak carrier
VideoMem Jun 26, 2021
2b4ebe5
-cafc max carried dev adjusted to +- 8%
VideoMem Jun 26, 2021
285617e
-cafc restores nearest center carrier selection logic
VideoMem Jun 26, 2021
ef317e8
-cafc fraction of fh selector
VideoMem Jul 4, 2021
6e1c3bc
serration/AGC moving average window adjustments
VideoMem Jul 4, 2021
3e89603
serration/AGC moving average window adjustments
VideoMem Jul 4, 2021
5b56a80
serration/AGC moving average window adjustments
VideoMem Jul 4, 2021
d7aa342
Chroma AFC changes, serration changes, chroma trap regression.
VideoMem Jul 9, 2021
559c6f1
Sync levels adjustments
VideoMem Jul 10, 2021
19b650f
Sync logic fixes and cleanups
VideoMem Jul 10, 2021
8cb54da
Chewed tape case review
VideoMem Jul 10, 2021
434c345
Infinite loop fix
VideoMem Jul 10, 2021
c1e71fb
Cleanup
VideoMem Jul 11, 2021
aed302f
Readme fixes
VideoMem Jul 11, 2021
e2d7c38
Readme fixes
VideoMem Jul 11, 2021
2501727
IGNORED_LINES parameter reversion
VideoMem Jul 17, 2021
0eb5182
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Jul 17, 2021
ba96dcf
Added -cshift option and updated advanced_flags.md
VideoMem Jul 25, 2021
c5641dd
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Aug 5, 2021
9289362
Reverts some auto-format code, adds pdb-attach to pip3 install in REA…
VideoMem Aug 7, 2021
80f140e
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Aug 22, 2021
478c7af
Merge of upstream +
VideoMem Aug 22, 2021
cab24f0
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Sep 25, 2021
2ec912a
Fix typo on gen_chroma_vid_ntsc.sh
VideoMem Sep 25, 2021
6c16c3f
First attempts at HiFi decoding
VideoMem Oct 17, 2021
e154f3b
HiFi code cleanup
VideoMem Oct 17, 2021
2d8f6ec
Merge branch 'vhs_decode_upstream' into vhs_decode
VideoMem Feb 19, 2023
334319b
Updates to main fork changes
VideoMem Feb 19, 2023
f964151
Adds hifi-decode to main branch
VideoMem Feb 19, 2023
3683a59
Adds hifi-decode to setup.py
VideoMem Feb 20, 2023
e30edab
Fixes unwanted changes on cmdcommons.py
VideoMem Feb 20, 2023
6a6596b
Merge remote-tracking branch 'upstream/vhs_decode' into vhs_decode
VideoMem Dec 31, 2023
9284b80
Adds stdin input using - as input filename.
VideoMem Jan 1, 2024
e29494a
Reconfigures NR sidechain gain to higher value.
VideoMem Jan 3, 2024
b994f6e
Fixes --audio_rate parameter.
VideoMem Jan 14, 2024
945f51a
Merge branch 'vhs_decode' of github.com:oyvindln/ld-decode into vhs_d…
VideoMem Jan 14, 2024
b67e369
Updates HiFiDecode header text comment
VideoMem Jan 15, 2024
397252c
Overrides file close method for stdin to do nothing.
VideoMem Jan 15, 2024
cff7233
Fixes crackling sound when reading from stdin.
VideoMem Jan 15, 2024
f85d2c4
Merge from oln's branch
VideoMem Jan 15, 2024
10e9897
Adjusts block size for speed improvements.
VideoMem Jan 15, 2024
8e6f445
Fixes bug in --preview parameter
VideoMem Jan 15, 2024
796f5c9
Fixes bug in audio dc bias cancel
VideoMem Jan 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions vhsdecode/hifi/HiFiDecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ def __init__(self, options=None):
if options is None:
options = dict()
self.options = options
self.sample_rate = options['input_rate']
self.sample_rate: int = options['input_rate']
self.options = options
self.if_rate = 8388608
self.audio_rate = 192000
self.if_rate: int = 8388608
self.audio_rate: int = 192000

# main deemphasis time constant
self.tau = 56e-6
Expand All @@ -408,14 +408,15 @@ def __init__(self, options=None):
self.audioRes_denominator = self.getResamplingRatios()

# block overlap and edge discard
self.blocks_second = 8
self.block_size = int(self.sample_rate / self.blocks_second)
self.block_audio_size = int(self.audio_rate / self.blocks_second)
self.block_overlap_audio = 192 if not self.options['preview'] else 0
self.block_overlap = round(
self.block_overlap_audio *
self.audioRes_denominator * self.ifresample_denominator /
(self.audioRes_numerator * self.ifresample_numerator)
self.blocks_second: int = 8
self.block_size: int = int(self.sample_rate / self.blocks_second)
self.block_audio_size: int = int(self.audio_rate / self.blocks_second)
self.block_overlap_audio: int = int(self.audio_rate / 5e2)
audio_final_rate = ((self.options['audio_rate'] / self.audio_rate) *
(self.audioRes_numerator / self.audioRes_denominator))
self.block_overlap: int = round(
self.block_overlap_audio * self.ifresample_denominator /
(self.ifresample_numerator * audio_final_rate)
)

# start of filter design stuff
Expand Down Expand Up @@ -528,8 +529,8 @@ def demodblock(self, data):
preL = samplerate_resample(preAudioResampleL, self.audioRes_numerator, self.audioRes_denominator)
preR = samplerate_resample(preAudioResampleR, self.audioRes_numerator, self.audioRes_denominator)

dcL = self.dcCancelL.work(np.mean(audioL))
dcR = self.dcCancelR.work(np.mean(audioR))
dcL = np.mean(audioL)
dcR = np.mean(audioR)

return dcL, dcR, (audioL + preL) / 2, (audioR + preR) / 2, preL, preR

Expand Down Expand Up @@ -558,7 +559,8 @@ def notchFreq(self) -> float:
return self.standard.Hfreq

@staticmethod
def cancelDC(c, dc):
@njit(cache=True, fastmath=True, nogil=True)
def cancelDC(c: np.array, dc: np.array):
return c - dc

@staticmethod
Expand Down
121 changes: 75 additions & 46 deletions vhsdecode/hifi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
f"Range (20~100): 100 being a hard gate effect",
)

parser.add_argument(
"--gain",
dest="gain",
type=float,
default=1.0,
help="Sets the gain/volume of the output audio (default is 1.0)",
)

parser.add_argument(
"--h8", dest="H8", action="store_true", default=False, help="Video8/Hi8, 8mm tape format"
)
Expand Down Expand Up @@ -160,12 +168,14 @@ def read(self, samples, frames=-1, dtype='float64', always_2d=False,
out = np.asarray(np.frombuffer(data, dtype=np.int16), dtype=dtype)
return out

def _read_next_chunk(self, blocksize, overlap, dtype):
data = self.file_path.read(blocksize)
def _read_next_chunk(self, blocksize, overlap, dtype) -> np.array:
data = self.file_path.read(blocksize - overlap)
assert len(data) % 2 == 0, "data is misaligned"
out = np.asarray(np.frombuffer(data, dtype=np.int16), dtype=dtype)
self._overlap = np.copy(out[-overlap:]) if np.size(self._overlap) == 0 else self._overlap
result = np.concatenate((self._overlap, out))
self._overlap = np.copy(out[-overlap:])
return np.concatenate((self._overlap, out))
return result

# yields infinite generator for _read_next_chunk
def blocks(self, blocksize=None, overlap=0, frames=-1, dtype='float64',
Expand Down Expand Up @@ -284,7 +294,7 @@ def seconds_to_str(seconds: float) -> str:

def log_decode(start_time: datetime, frames: int, decode_options: dict):
elapsed_time: timedelta = datetime.now() - start_time
audio_time: float = frames / decode_options["input_rate"]
audio_time: float = frames / (2 * decode_options["input_rate"])
relative_speed: float = audio_time / elapsed_time.total_seconds()
elapsed_time_format: str = seconds_to_str(elapsed_time.total_seconds())
audio_time_format: str = seconds_to_str(audio_time)
Expand All @@ -296,6 +306,40 @@ def log_decode(start_time: datetime, frames: int, decode_options: dict):
)


def gain_adjust(audio: np.array, gain: float) -> np.array:
return np.multiply(audio, gain)


def prepare_stereo(l: np.array, r: np.array, noise_reduction: NoiseReduction, decode_options: dict):
if decode_options["noise_reduction"]:
stereo = noise_reduction.stereo(
gain_adjust(l, decode_options["gain"]),
gain_adjust(r, decode_options["gain"])
)
else:
stereo = list(map(
list,
zip(gain_adjust(l, decode_options["gain"]),
gain_adjust(r, decode_options["gain"]))
))
return stereo


def post_process(audioL: np.array, audioR: np.array, audio_rate: int, decode_options: dict):
left_audio = samplerate_resample(audioL,
decode_options["audio_rate"],
audio_rate,
"sinc_fastest") \
if decode_options["audio_rate"] != audio_rate else audioL
right_audio = samplerate_resample(audioR,
decode_options["audio_rate"],
audio_rate,
"sinc_fastest") \
if decode_options["audio_rate"] != audio_rate else audioR

return left_audio, right_audio


def decode(decoder, input_file, decode_options, output_file):
start_time = datetime.now()
noise_reduction = NoiseReduction(
Expand All @@ -316,27 +360,18 @@ def decode(decoder, input_file, decode_options, output_file):
current_block, audioL, audioR = decoder.block_decode(
block, block_count=current_block
)
left_audio = samplerate_resample(audioL,
decode_options["audio_rate"],
decoder.audioRate,
"sinc_fastest") \
if decode_options["audio_rate"] != decoder.audioRate else audioL
right_audio = samplerate_resample(audioR,
decode_options["audio_rate"],
decoder.audioRate,
"sinc_fastest") \
if decode_options["audio_rate"] != decoder.audioRate else audioR

if decode_options["noise_reduction"]:
stereo = noise_reduction.stereo(left_audio, right_audio)
else:
stereo = list(map(list, zip(left_audio, right_audio)))
left_audio, right_audio = post_process(audioL, audioR, decoder.audioRate, decode_options)
stereo = prepare_stereo(left_audio, right_audio, noise_reduction, decode_options)

if decode_options["auto_fine_tune"]:
log_bias(decoder)

current_block += 1
log_decode(start_time, f.tell(), decode_options)
w.write(stereo)
try:
w.write(stereo)
except ValueError:
pass

elapsed_time = datetime.now() - start_time
dt_string = elapsed_time.total_seconds()
Expand Down Expand Up @@ -380,33 +415,24 @@ def decode_parallel(decoders: List[HiFiDecode],
while len(futures_queue) > threads:
future = futures_queue.pop(0)
blocknum, audioL, audioR = future.result()
left_audio = samplerate_resample(audioL,
decode_options["audio_rate"],
decoder.audioRate,
"sinc_fastest") \
if decode_options["audio_rate"] != decoder.audioRate else audioL
right_audio = samplerate_resample(audioR,
decode_options["audio_rate"],
decoder.audioRate,
"sinc_fastest") \
if decode_options["audio_rate"] != decoder.audioRate else audioR
if decode_options["noise_reduction"]:
stereo = noise_reduction.stereo(left_audio, right_audio)
else:
stereo = list(map(list, zip(left_audio, right_audio)))
left_audio, right_audio = post_process(audioL, audioR, decoder.audioRate, decode_options)
stereo = prepare_stereo(left_audio, right_audio, noise_reduction, decode_options)
log_decode(start_time, f.tell(), decode_options)
w.write(stereo)
try:
w.write(stereo)
except ValueError:
pass

print("Emptying the decode queue ...")
while len(futures_queue) > 0:
future = futures_queue.pop(0)
blocknum, audioL, audioR = future.result()
if decode_options["noise_reduction"]:
stereo = noise_reduction.stereo(audioL, audioR)
else:
stereo = list(map(list, zip(audioL, audioR)))
log_decode(start_time, f.tell(), decode_options)
w.write(stereo)
left_audio, right_audio = post_process(audioL, audioR, decoder.audioRate, decode_options)
stereo = prepare_stereo(left_audio, right_audio, noise_reduction, decode_options)
try:
w.write(stereo)
except ValueError:
pass

elapsed_time = datetime.now() - start_time
dt_string = elapsed_time.total_seconds()
Expand Down Expand Up @@ -445,7 +471,7 @@ def log_bias(decoder: HiFiDecode):
)


def main():
def main() -> int:
args = parser.parse_args()

system = select_system(args)
Expand All @@ -461,6 +487,7 @@ def main():
"nr_side_gain": args.NR_side_gain,
"grc": args.GRC,
"audio_rate": args.rate,
"gain": args.gain,
}

filename, outname, _, _ = get_basics(args)
Expand All @@ -470,7 +497,7 @@ def main():
"Existing decode files found, remove them or run command with --overwrite"
)
print("\t", outname)
sys.exit(1)
return 1

print("Initializing ...")
if decode_options["format"] == "vhs":
Expand All @@ -484,7 +511,7 @@ def main():
decoder = HiFiDecode(decode_options)
LCRef, RCRef = decoder.standard.LCarrierRef, decoder.standard.RCarrierRef
if args.BG:
LCRef, RCRef = guess_bias(decoder, filename, decoder.blockSize)
LCRef, RCRef = guess_bias(decoder, filename, int(decoder.sample_rate))
decoder.updateAFE(LCRef, RCRef)

if args.threads > 1 and not args.GRC:
Expand All @@ -497,10 +524,12 @@ def main():
)
else:
decode(decoder, filename, decode_options, outname)
print('Decode finished successfully')
return 0
else:
print("No sample rate specified")
sys.exit(0)
return 0


if __name__ == "__main__":
main()
sys.exit(main())
Loading