|
|
@@ -42,11 +42,65 @@ int JackAlsaIOAdapter::Close() |
|
|
|
fThread.Stop(); |
|
|
|
return fAudioInterface.close(); |
|
|
|
} |
|
|
|
|
|
|
|
bool JackAlsaIOAdapter::Init() |
|
|
|
{ |
|
|
|
fAudioInterface.write(); |
|
|
|
fAudioInterface.write(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
bool JackAlsaIOAdapter::Execute() |
|
|
|
{ |
|
|
|
if (fAudioInterface.read() < 0) |
|
|
|
return false; |
|
|
|
|
|
|
|
if (!fRunning) { |
|
|
|
fRunning = true; |
|
|
|
jack_time_t time = jack_get_time(); |
|
|
|
fProducerDLL.Init(time); |
|
|
|
fConsumerDLL.Init(time); |
|
|
|
} |
|
|
|
|
|
|
|
// DLL |
|
|
|
jack_time_t time = jack_get_time(); |
|
|
|
fProducerDLL.IncFrame(time); |
|
|
|
jack_nframes_t time1 = fConsumerDLL.Time2Frames(time); |
|
|
|
jack_nframes_t time2 = fProducerDLL.Time2Frames(time); |
|
|
|
|
|
|
|
double src_ratio_output = double(time2) / double(time1); |
|
|
|
double src_ratio_input = double(time1) / double(time2); |
|
|
|
|
|
|
|
if (src_ratio_input < 0.7f || src_ratio_input > 1.3f) { |
|
|
|
jack_error("src_ratio_input = %f", src_ratio_input); |
|
|
|
src_ratio_input = 1; |
|
|
|
time1 = 1; |
|
|
|
time2 = 1; |
|
|
|
} |
|
|
|
|
|
|
|
if (src_ratio_output < 0.7f || src_ratio_output > 1.3f) { |
|
|
|
jack_error("src_ratio_output = %f", src_ratio_output); |
|
|
|
src_ratio_output = 1; |
|
|
|
time1 = 1; |
|
|
|
time2 = 1; |
|
|
|
} |
|
|
|
|
|
|
|
src_ratio_input = Range(0.7f, 1.3f, src_ratio_input); |
|
|
|
src_ratio_output = Range(0.7f, 1.3f, src_ratio_output); |
|
|
|
jack_log("Callback resampler src_ratio_input = %f src_ratio_output = %f", src_ratio_input, src_ratio_output); |
|
|
|
|
|
|
|
for (int i = 0; i < fCaptureChannels; i++) { |
|
|
|
float* buffer = (float*)fAudioInterface.fInputSoftChannels[i]; |
|
|
|
fCaptureRingBuffer[i]->SetRatio(time1, time2); |
|
|
|
fCaptureRingBuffer[i]->WriteResample(buffer, fBufferSize); |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < fPlaybackChannels; i++) { |
|
|
|
float* buffer = (float*)fAudioInterface.fOutputSoftChannels[i]; |
|
|
|
fPlaybackRingBuffer[i]->SetRatio(time2, time1); |
|
|
|
fPlaybackRingBuffer[i]->ReadResample(buffer, fBufferSize); |
|
|
|
} |
|
|
|
|
|
|
|
if (fAudioInterface.write() < 0) |
|
|
|
return false; |
|
|
|
jack_log("execute"); |
|
|
|