git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2591 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.90
| @@ -42,6 +42,9 @@ int JackCallbackNetIOAdapter::Process(jack_nframes_t frames, void* arg) | |||
| adapter->fIOAdapter->SetCallbackDeltaTime(adapter->fCurCallbackTime - adapter->fLastCallbackTime); | |||
| //jack_info("ReadSpace = %ld", adapter->fCaptureRingBuffer[0].ReadSpace()); | |||
| //jack_info("WriteSpace = %ld", adapter->fPlaybackRingBuffer[0].WriteSpace()); | |||
| for (i = 0; i < adapter->fCaptureChannels; i++) { | |||
| buffer = static_cast<float*>(jack_port_get_buffer(adapter->fCapturePortList[i], frames)); | |||
| adapter->fCaptureRingBuffer[i].Read(buffer, frames); | |||
| @@ -94,6 +97,9 @@ JackCallbackNetIOAdapter::JackCallbackNetIOAdapter(jack_client_t* jack_client, | |||
| fPlaybackRingBuffer[i].Write(buffer, frames); | |||
| } | |||
| */ | |||
| jack_log("ReadSpace = %ld", fCaptureRingBuffer[0].ReadSpace()); | |||
| jack_log("WriteSpace = %ld", fPlaybackRingBuffer[0].WriteSpace()); | |||
| if (jack_set_process_callback(fJackClient, Process, this) < 0) | |||
| goto fail; | |||
| @@ -83,6 +83,7 @@ namespace Jack | |||
| virtual void SetCallbackDeltaTime(jack_time_t delta_usec) | |||
| { | |||
| jack_log("SetCallbackDeltaTime %ld", delta_usec); | |||
| //printf("SetCallbackDeltaTime %ld\n", delta_usec); | |||
| fDeltaTime = delta_usec; | |||
| } | |||
| @@ -115,10 +115,14 @@ extern "C" | |||
| return 1; | |||
| } else { | |||
| jack_log("Loading NetAudio Adapter"); | |||
| /* | |||
| adapter = new Jack::JackCallbackNetIOAdapter(jack_client, | |||
| new Jack::JackPortAudioIOAdapter(2, 2, jack_get_buffer_size(jack_client), jack_get_sample_rate(jack_client)), 2, 2); | |||
| */ | |||
| #ifdef __APPLE__ | |||
| adapter = new Jack::JackCallbackNetIOAdapter(jack_client, | |||
| new Jack::JackCoreAudioIOAdapter(2, 2, jack_get_buffer_size(jack_client), jack_get_sample_rate(jack_client)), 2, 2); | |||
| //adapter = new Jack::JackCallbackNetIOAdapter(jack_client, | |||
| // new Jack::JackPortAudioIOAdapter(2, 2, jack_get_buffer_size(jack_client), jack_get_sample_rate(jack_client)), 2, 2); | |||
| #endif | |||
| assert(adapter); | |||
| if (adapter->Open() == 0) { | |||
| @@ -29,7 +29,8 @@ JackResampler::JackResampler():fRatio(0) | |||
| if (error != 0) | |||
| jack_error("JackResampler::JackResampler err = %s", src_strerror(error)); | |||
| fRingBuffer = jack_ringbuffer_create(sizeof(float) * DEFAULT_RB_SIZE); | |||
| } | |||
| jack_ringbuffer_read_advance(fRingBuffer, (sizeof(float) * DEFAULT_RB_SIZE) / 2); | |||
| } | |||
| JackResampler::~JackResampler() | |||
| { | |||
| @@ -38,6 +39,16 @@ JackResampler::~JackResampler() | |||
| jack_ringbuffer_free(fRingBuffer); | |||
| } | |||
| unsigned int JackResampler::ReadSpace() | |||
| { | |||
| return jack_ringbuffer_read_space(fRingBuffer); | |||
| } | |||
| unsigned int JackResampler::WriteSpace() | |||
| { | |||
| return jack_ringbuffer_write_space(fRingBuffer); | |||
| } | |||
| int JackResampler::Read(float* buffer, unsigned int frames) | |||
| { | |||
| size_t len = jack_ringbuffer_read_space(fRingBuffer); | |||
| @@ -93,18 +104,24 @@ int JackResampler::ReadResample(float* buffer, unsigned int frames) | |||
| res = src_process(fResampler, &src_data); | |||
| if (res != 0) | |||
| jack_error("JackPortAudioIOAdapter::Render err = %s", src_strerror(res)); | |||
| jack_error("JackResampler::ReadResample err = %s", src_strerror(res)); | |||
| frames_to_write -= src_data.output_frames_gen; | |||
| written_frames += src_data.output_frames_gen; | |||
| if ((src_data.input_frames_used == 0 || src_data.output_frames_gen == 0) && j == 0) { | |||
| jack_error("OUTPUT : j = %d input_frames_used = %ld output_frames_gen = %ld", j, src_data.input_frames_used, src_data.output_frames_gen); | |||
| } | |||
| jack_log("OUTPUT : j = %d input_frames_used = %ld output_frames_gen = %ld", j, src_data.input_frames_used, src_data.output_frames_gen); | |||
| jack_ringbuffer_read_advance(fRingBuffer, src_data.input_frames_used * sizeof(float)); | |||
| } | |||
| } | |||
| if (written_frames < frames) | |||
| jack_error("JackPortAudioIOAdapter::Render error written_frames = %ld", written_frames); | |||
| if (written_frames < frames) { | |||
| jack_error("OUPUT available = %ld", available_frames); | |||
| jack_error("JackResampler::ReadResample error written_frames = %ld", written_frames); | |||
| } | |||
| return written_frames; | |||
| } | |||
| @@ -134,18 +151,24 @@ int JackResampler::WriteResample(float* buffer, unsigned int frames) | |||
| res = src_process(fResampler, &src_data); | |||
| if (res != 0) | |||
| jack_error("JackPortAudioIOAdapter::Render err = %s", src_strerror(res)); | |||
| jack_error("JackResampler::ReadResample err = %s", src_strerror(res)); | |||
| frames_to_read -= src_data.input_frames_used; | |||
| read_frames += src_data.input_frames_used; | |||
| if ((src_data.input_frames_used == 0 || src_data.output_frames_gen == 0) && j == 0) { | |||
| jack_error("INPUT : j = %d input_frames_used = %ld output_frames_gen = %ld", j, src_data.input_frames_used, src_data.output_frames_gen); | |||
| } | |||
| jack_log("INPUT : j = %d input_frames_used = %ld output_frames_gen = %ld", j, src_data.input_frames_used, src_data.output_frames_gen); | |||
| jack_ringbuffer_write_advance(fRingBuffer, src_data.output_frames_gen * sizeof(float)); | |||
| } | |||
| } | |||
| if (read_frames < frames) | |||
| jack_error("JackPortAudioIOAdapter::Render error read_frames = %ld", read_frames); | |||
| if (read_frames < frames) { | |||
| jack_error("INPUT available = %ld", available_frames); | |||
| jack_error("JackResampler::ReadResample error read_frames = %ld", read_frames); | |||
| } | |||
| return read_frames; | |||
| } | |||
| @@ -49,6 +49,9 @@ namespace Jack | |||
| int Read(float* buffer, unsigned int frames); | |||
| int Write(float* buffer, unsigned int frames); | |||
| unsigned int ReadSpace(); | |||
| unsigned int WriteSpace(); | |||
| void SetRatio(double ratio) | |||
| { | |||
| fRatio = ratio; | |||
| @@ -134,6 +134,7 @@ OSStatus JackCoreAudioIOAdapter::Render(void *inRefCon, | |||
| adapter->fProducerFilter.AddValue(adapter->fDeltaTime); | |||
| jack_log("JackCoreAudioIOAdapter::Render delta %ld", adapter->fCurCallbackTime - adapter->fLastCallbackTime); | |||
| //printf("JackCoreAudioIOAdapter::Render delta %ld\n", adapter->fCurCallbackTime - adapter->fLastCallbackTime); | |||
| if (!adapter->fRunning) | |||
| adapter->fRunning = true; | |||
| @@ -143,27 +144,32 @@ OSStatus JackCoreAudioIOAdapter::Render(void *inRefCon, | |||
| double src_ratio_output = double(val1) / double(val2); | |||
| double src_ratio_input = double(val2) / double(val1); | |||
| if (src_ratio_input < 0.8f || src_ratio_input > 1.2f) | |||
| if (src_ratio_input < 0.8f || src_ratio_input > 1.2f) { | |||
| jack_error("src_ratio_input = %f", src_ratio_input); | |||
| src_ratio_input = 1; | |||
| } | |||
| if (src_ratio_output < 0.8f || src_ratio_output > 1.2f) | |||
| if (src_ratio_output < 0.8f || src_ratio_output > 1.2f) { | |||
| jack_error("src_ratio_output = %f", src_ratio_output); | |||
| src_ratio_output = 1; | |||
| } | |||
| src_ratio_input = Range(0.8f, 1.2f, src_ratio_input); | |||
| src_ratio_output = Range(0.8f, 1.2f, src_ratio_output); | |||
| jack_log("Callback resampler src_ratio_input = %f src_ratio_output = %f", src_ratio_input, src_ratio_output); | |||
| //jack_log("Callback resampler src_ratio_input = %f src_ratio_output = %f", src_ratio_input, src_ratio_output); | |||
| //jack_info("Callback resampler src_ratio_input = %f src_ratio_output = %f", src_ratio_input, src_ratio_output); | |||
| for (int i = 0; i < adapter->fCaptureChannels; i++) { | |||
| adapter->fCaptureRingBuffer[i].SetRatio(src_ratio_input); | |||
| //adapter->fCaptureRingBuffer[i].WriteResample((float*)adapter->fInputData->mBuffers[i].mData, inNumberFrames); | |||
| adapter->fCaptureRingBuffer[i].Write((float*)adapter->fInputData->mBuffers[i].mData, inNumberFrames); | |||
| adapter->fCaptureRingBuffer[i].WriteResample((float*)adapter->fInputData->mBuffers[i].mData, inNumberFrames); | |||
| // adapter->fCaptureRingBuffer[i].Write((float*)adapter->fInputData->mBuffers[i].mData, inNumberFrames); | |||
| } | |||
| for (int i = 0; i < adapter->fPlaybackChannels; i++) { | |||
| adapter->fPlaybackRingBuffer[i].SetRatio(src_ratio_output); | |||
| //adapter->fPlaybackRingBuffer[i].ReadResample((float*)ioData->mBuffers[i].mData, inNumberFrames); | |||
| adapter->fPlaybackRingBuffer[i].Read((float*)ioData->mBuffers[i].mData, inNumberFrames); | |||
| adapter->fPlaybackRingBuffer[i].ReadResample((float*)ioData->mBuffers[i].mData, inNumberFrames); | |||
| // adapter->fPlaybackRingBuffer[i].Read((float*)ioData->mBuffers[i].mData, inNumberFrames); | |||
| } | |||
| return noErr; | |||
| @@ -553,7 +559,7 @@ int JackCoreAudioIOAdapter::Open() | |||
| if (err != noErr) | |||
| goto error; | |||
| return noErr; | |||
| return 0; | |||
| error: | |||
| Close(); | |||
| @@ -568,5 +574,4 @@ int JackCoreAudioIOAdapter::Close() | |||
| return 0; | |||
| } | |||
| } | |||
| @@ -49,21 +49,26 @@ int JackPortAudioIOAdapter::Render(const void* inputBuffer, void* outputBuffer, | |||
| double src_ratio_output = double(adapter->fCurCallbackTime - adapter->fLastCallbackTime) / double(adapter->fDeltaTime); | |||
| double src_ratio_input = double(adapter->fDeltaTime) / double(adapter->fCurCallbackTime - adapter->fLastCallbackTime); | |||
| */ | |||
| jack_time_t val1 = adapter->fConsumerFilter.GetVal(); | |||
| jack_time_t val2 = adapter->fProducerFilter.GetVal(); | |||
| jack_time_t val2 = adapter->fConsumerFilter.GetVal(); | |||
| jack_time_t val1 = adapter->fProducerFilter.GetVal(); | |||
| double src_ratio_output = double(val1) / double(val2); | |||
| double src_ratio_input = double(val2) / double(val1); | |||
| if (src_ratio_input < 0.8f || src_ratio_input > 1.2f) | |||
| if (src_ratio_input < 0.8f || src_ratio_input > 1.2f) { | |||
| jack_error("src_ratio_input = %f", src_ratio_input); | |||
| src_ratio_input = 1; | |||
| } | |||
| if (src_ratio_output < 0.8f || src_ratio_output > 1.2f) | |||
| if (src_ratio_output < 0.8f || src_ratio_output > 1.2f) { | |||
| jack_error("src_ratio_output = %f", src_ratio_output); | |||
| src_ratio_output = 1; | |||
| } | |||
| src_ratio_input = Range(0.8f, 1.2f, src_ratio_input); | |||
| src_ratio_output = Range(0.8f, 1.2f, src_ratio_output); | |||
| jack_log("Callback resampler src_ratio_input = %f src_ratio_output = %f", src_ratio_input, src_ratio_output); | |||
| //jack_log("Callback resampler src_ratio_input = %f src_ratio_output = %f", src_ratio_input, src_ratio_output); | |||
| printf("Callback resampler src_ratio_input = %f src_ratio_output = %f\n", src_ratio_input, src_ratio_output); | |||
| paBuffer = (float**)inputBuffer; | |||
| for (int i = 0; i < adapter->fCaptureChannels; i++) { | |||