My end goal is to simultaneously output a wav file and record on a mic and display the two on top of each other on a plot. This does not require low latency, but it does require the two plots to be overlaid in a way that they correctly represent what is happening in real time. If I connect the mic line to the speaker line, the graphs should line up on top of each other relatively well.
Since there seems to be some amount of latency, my solution is to use the time variable given by the callback. This should let me shift the plot appropriately when plotting it to adjust for latency. I am receiving appropriate values for the DAC time and the current time, but ADC time is giving me 0.
def callback(indata, outdata, frames, time, status):
print "ADC time: ", time.inputBufferAdcTime
print "DAC time: ", time.outputBufferDacTime
print "curr time: ", time.currentTime
print "time diff: ", time.outputBufferDacTime - time.currentTime
print "###############"
if status:
print(status)
if len(data[callback.index:]) < frames:
outdata[:len(data[callback.index:])] = data[callback.index:]
outdata[len(data[callback.index:]):] = np.zeros(
((len(outdata) - len(data[callback.index:])), len(args.channels)))
raise sd.CallbackStop
else:
outdata[:] = data[callback.index:callback.index + frames]
q_out.put(outdata[::args.downsample, mapping])
q_in.put(indata[::args.downsample, mapping])
callback.index += frames