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

add analog audio frequency setting - and support neg values for line-… #740

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion ld-decode
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ parser.add_argument(
help="RF sampling frequency in source file (default is 40MHz)",
)

parser.add_argument(
"--analog_audio_frequency",
dest="analog_audio_freq",
metavar="AFREQ",
type=int,
default=44100,
help="RF sampling frequency in source file (default is 44100hz)",
)

parser.add_argument(
"--video_bpf_high",
dest="vbpf_high",
Expand Down Expand Up @@ -299,7 +308,7 @@ ldd = LDdecode(
loader,
logger,
est_frames=req_frames,
analog_audio=0 if args.daa else 44.100,
analog_audio=0 if args.daa else args.analog_audio_freq,
digital_audio=not args.noefm,
system=system,
doDOD=not args.nodod,
Expand Down
32 changes: 25 additions & 7 deletions lddecode/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,17 +1226,37 @@ def setparams(self, params):

# Downscales to 16bit/44.1khz. It might be nice when analog audio is better to support 24/96,
# but if we only support one output type, matching CD audio/digital sound is greatly preferable.
def downscale_audio(audio, lineinfo, rf, linecount, timeoffset=0, freq=48000.0, scale = 32):
def downscale_audio(audio, lineinfo, rf, linecount, timeoffset=0, freq=44100):
''' downscale audio for output.

Parameters:
audio (float): Raw audio samples from RF demodulator
lineinfo (list(float)): line locations
rf (RFDecode): rf class
linecount (int): # of lines in field
timeoffset (float): time of first audio sample (ignored w/- frequency)
freq (int): Output frequency (negative values are multiple of HSYNC frequency)
Returns: (tuple)
output16 (np.array(int)): Array of 16-bit integers, ready for output
next_timeoffset (float): Time to start pulling samples in the next frame (ignore if sync4x)
'''
failed = False
scale = rf.Filters['audio_fdiv']

if freq < 0:
# Override timeoffset value and set frequency to a multiple horizontal line clock
timeoffset = 0
freq = (1000000 / rf.SysParams["line_period"]) * -freq

frametime = linecount / (1000000 / rf.SysParams["line_period"])
soundgap = 1 / freq

# include one extra 'tick' to interpolate the last one and use as a return value
# for the next frame
arange = np.arange(
timeoffset, frametime + (soundgap / 2), soundgap, dtype=np.double
)

locs = np.zeros(len(arange), dtype=np.float)
swow = np.zeros(len(arange), dtype=np.float)

Expand Down Expand Up @@ -1307,7 +1327,6 @@ def __init__(
rf,
decode,
audio_offset=0,
keepraw=True,
prevfield=None,
initphase=False,
fields_written=0,
Expand Down Expand Up @@ -2344,15 +2363,14 @@ def downscale(
(l - lineoffset) * outwidth : (l + 1 - lineoffset) * outwidth
] = self.rf.SysParams["ire0"]

if audio > 0 and self.rf.decode_analog_audio:
if audio != 0 and self.rf.decode_analog_audio:
self.dsaudio, self.audio_next_offset = downscale_audio(
self.data["audio"],
lineinfo,
self.rf,
self.linecount,
self.audio_offset,
freq=audio,
scale = self.rf.Filters['audio_fdiv']
freq=audio
)

if self.rf.decode_digital_audio:
Expand Down Expand Up @@ -3187,7 +3205,7 @@ def __init__(

self.blackIRE = 0

self.analog_audio = int(analog_audio * 1000)
self.analog_audio = int(analog_audio)
self.digital_audio = digital_audio
self.write_rf_tbc = extra_options.get("write_RF_TBC", False)

Expand Down