Skip to content

hifi-decode: Muting during carrier loss#199

Merged
oyvindln merged 3 commits intooyvindln:vhs_decodefrom
eshaz:hifi-decode-muting
Mar 4, 2025
Merged

hifi-decode: Muting during carrier loss#199
oyvindln merged 3 commits intooyvindln:vhs_decodefrom
eshaz:hifi-decode-muting

Conversation

@eshaz
Copy link

@eshaz eshaz commented Mar 1, 2025

Changes

  • Add option to mute audio when the Hifi carrier is lost.
    • This works by detecting broadband noise in the frequency area above the audible range.
    • When the noise reaches a threshold (currently set to 100%, i.e. clipping), and the standard deviation of the fft is greater than 1, the audio is muted
    • Each mute is padded with a fade out / fade in to prevent pops and harmonics from the mute transition.

Example

  • Small example clip of decoded audio with and without muting. I shuttled the tape around a bit during the capture to demonstrate the granularity of the muting.

With Muting

https://discord.com/channels/665557267189334046/665834485975351307/1345259858466701443

Without Muting

https://discord.com/channels/665557267189334046/665834485975351307/1345259899025625090

@Inky1003
Copy link

Inky1003 commented Mar 1, 2025

For some reason this branch is not working for me. Tried to decode a 40MSPS flac and this happened:

Process Process-1:
Traceback (most recent call last):
  File "/home/inky/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/home/inky/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 1453, in hifi_decode_worker
    decode_next_block()
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 1430, in decode_next_block
    audioL, audioR = decoder.block_decode(raw_data, decoder_state.post_audio_len, measure_perf)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 1327, in block_decode
    preL, dcL, perf_measurements_l = HiFiDecode.demod_process_audio(filterL, self.fmL, self.audio_process_params, measure_perf)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 1255, in demod_process_audio
    fm.work(filtered, audio)
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 283, in work
    DecoderSharedMemory.copy_data_float32(self.htdeFM(input, self.samp_rate), output, len(output))
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 208, in htdeFM
    return unwrap_hilbert(hilbert(data), samp_rate)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/numba/core/dispatcher.py", line 424, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/numba/core/dispatcher.py", line 365, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function ediff1d at 0x73a08e931b20>) found for signature:
 
 >>> ediff1d(array(float32, 1d, C), to_begin=Literal[int](0))
 
There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload in function 'np_ediff1d': File: numba/np/old_arraymath.py: Line 2128.
    With argument(s): '(array(float32, 1d, C), to_begin=int64)':
   Rejected as the implementation raised a specific error:
     NumbaTypeError: dtype of to_begin must be compatible with input ary
  raised from /home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/numba/np/old_arraymath.py:2148

During: resolving callee type: Function(<function ediff1d at 0x73a08e931b20>)
During: typing of call at /home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/lddecode/utils.py (764)


File "lib/python3.12/site-packages/lddecode/utils.py", line 764:
    def unwrap_hilbert(hilbert, freq_hz):
        <source elided>
        tangles = np.angle(hilbert)
        dangles = np.ediff1d(tangles, to_begin=0).real
        ^

During: Pass nopython_type_inference
Process Process-3:
Traceback (most recent call last):
  File "/home/inky/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/home/inky/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 1453, in hifi_decode_worker
    decode_next_block()
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 1430, in decode_next_block
    audioL, audioR = decoder.block_decode(raw_data, decoder_state.post_audio_len, measure_perf)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 1327, in block_decode
    preL, dcL, perf_measurements_l = HiFiDecode.demod_process_audio(filterL, self.fmL, self.audio_process_params, measure_perf)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 1255, in demod_process_audio
    fm.work(filtered, audio)
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 283, in work
    DecoderSharedMemory.copy_data_float32(self.htdeFM(input, self.samp_rate), output, len(output))
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/vhsdecode/hifi/HiFiDecode.py", line 208, in htdeFM
    return unwrap_hilbert(hilbert(data), samp_rate)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/numba/core/dispatcher.py", line 424, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/numba/core/dispatcher.py", line 365, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function ediff1d at 0x73a08e931b20>) found for signature:
 
 >>> ediff1d(array(float32, 1d, C), to_begin=Literal[int](0))
 
There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload in function 'np_ediff1d': File: numba/np/old_arraymath.py: Line 2128.
    With argument(s): '(array(float32, 1d, C), to_begin=int64)':
   Rejected as the implementation raised a specific error:
     NumbaTypeError: dtype of to_begin must be compatible with input ary
  raised from /home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/numba/np/old_arraymath.py:2148

During: resolving callee type: Function(<function ediff1d at 0x73a08e931b20>)
During: typing of call at /home/inky/Downloads/vhs-decode_eshaz_branch/lib/python3.12/site-packages/lddecode/utils.py (764)


File "lib/python3.12/site-packages/lddecode/utils.py", line 764:
    def unwrap_hilbert(hilbert, freq_hz):
        <source elided>
        tangles = np.angle(hilbert)
        dangles = np.ediff1d(tangles, to_begin=0).real
        ^

During: Pass nopython_type_inference

CLI was

python3.12 vhsdecode/hifi/main.py --ar 96000 --normalize --original --noise_reduction on --auto_fine_tune on --pm --muting on (infile) (outfile)

@eshaz
Copy link
Author

eshaz commented Mar 2, 2025

@Inky1003 Try removing the --original from your cli command.

I have had issues with --original for some time now, and it's not related to this PR. I can probably fix it though. I'll take a look.

@eshaz
Copy link
Author

eshaz commented Mar 3, 2025

@Inky1003 I fixed the --original parameter. Try out this commit eshaz@614567b.

I've removed the changes in this PR, so there won't be any merge conflicts when the latest ld-decode changes get pulled in by @oyvindln. The --original parameter will work after this PR is merged, and then after happycube@614567b from ld-decode is pulled in.

eshaz added a commit to eshaz/vhs-decode that referenced this pull request Mar 3, 2025
happycube added a commit to happycube/ld-decode that referenced this pull request Mar 3, 2025
fix datatype miss-match for hifi-decode see oyvindln#199
@eshaz eshaz force-pushed the hifi-decode-muting branch from 5e74368 to 1d58397 Compare March 3, 2025 05:02
@eshaz eshaz force-pushed the hifi-decode-muting branch from 1d58397 to 84cc61c Compare March 3, 2025 05:03
@oyvindln oyvindln merged commit df1a814 into oyvindln:vhs_decode Mar 4, 2025
@eshaz eshaz deleted the hifi-decode-muting branch March 8, 2025 16:49
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.

3 participants