D6(fprintf(debug_file," FPGA time == %ld:%06ld\n",fpga_tv.tv_sec,fpga_tv.tv_usec));
D6(fprintf(debug_file,"AUDIO sys time == %ld:%06ld\n",audio->ctx_a.time_last.tv_sec,audio->ctx_a.time_last.tv_usec););
// audio_last = audio->ctx_a.time_last;
// if (m_len.tv_sec > audio_last.tv_sec) {
// m_len.tv_sec--;
// m_len.tv_usec += 1000000;
// }
// m_len.tv_sec -= audio_last.tv_sec;
// m_len.tv_usec -= audio_last.tv_usec;
// time_normalize(&m_len);
// long to_finish_us = time_to_us(&m_len);
av_diff=time_sub(&m_len,&audio->ctx_a.time_last);
frame_period=us_to_time(audio->frame_period);
av_diff=time_add(&av_diff,&frame_period);// plus duration of the last video frame
longto_finish_us=time_to_us(&av_diff);
floatperiod_us=(1.0/audio->audio_rate)*1000000;
// D6(fprintf(debug_file, "... and now we need to save audio for this time: %ld:%06ld - i.e. %06ld usecs\n", m_len.tv_sec, m_len.tv_usec, to_finish_us));
D6(fprintf(debug_file,"... and now we need to save audio for this time: %ld:%06ld - i.e. %06ld usecs\n",av_diff.tv_sec,av_diff.tv_usec,to_finish_us));