I'm trying to read from an ADC when I hold PTT and hear it live on the DAC,
I am facing delay issues when writing to the DAC, it sounds like the first chunk of samples is being repeated over and over for about 4 seconds and then I begin to hear the rest of the data with delay, I have tried many solutions online, none of them worked perfectly without delay and clear audio.
The logic is quite simple, I always read the PTT which returns 0 if I am pressing PTT, if I do, I want to transmit the audio from the ADC to the DAC so I can hear it, once I released the PTT, I stop the DAC.
I wrote a simple program demonstrating my issue:
import nidaqmx
from nidaqmx.constants import AcquisitionType
def read_write():
sample_rate = 32e3
samples_size = 7680
task_ai = nidaqmx.Task()
task_ai.ai_channels.add_ai_voltage_chan("ADC/ai0")
task_ai.timing.cfg_samp_clk_timing(sample_rate, sample_mode=AcquisitionType.CONTINUOUS, samps_per_chan=samples_size)
task_dac = nidaqmx.Task()
task_dac.ai_channels.add_ai_voltage_chan("DAC/ao0")
task_dac.timing.cfg_samp_clk_timing(sample_rate, sample_mode=AcquisitionType.CONTINUOUS, samps_per_chan=samples_size)
task_io = nidaqmx.Task() # 0 - Pushing PTT | 1 - Nothing
task_io.di_channels.add_di_chan("ADC/port0/line0") # PTT Channel
task_ai.start() # Start reading from the ADC
old_ptt_state = 1
while True:
ptt_in = task_io.read()
samples = task_ai.read(number_of_samples_per_channel=samples_size)
if ptt_in == 0: # Pushed PTT
task_dac.write(samples, auto_start=True)
old_ptt_state = 0
elif old_ptt_state == 0:
task_dac.stop()
old_ptt_state = 1
read_write()