git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2621 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.90
| @@ -93,9 +93,7 @@ JackCallbackNetIOAdapter::JackCallbackNetIOAdapter(jack_client_t* jack_client, | |||
| : JackNetIOAdapter(jack_client, audio_io, input, output) | |||
| { | |||
| int i; | |||
| printf("input , %ld %ld\n", input, output); | |||
| fCaptureRingBuffer = new JackResampler*[fCaptureChannels]; | |||
| fPlaybackRingBuffer = new JackResampler*[fPlaybackChannels]; | |||
| @@ -29,29 +29,29 @@ namespace Jack | |||
| class JackCallbackNetIOAdapter : public JackNetIOAdapter | |||
| { | |||
| private: | |||
| private: | |||
| JackResampler** fCaptureRingBuffer; | |||
| JackResampler** fPlaybackRingBuffer; | |||
| JackResampler** fCaptureRingBuffer; | |||
| JackResampler** fPlaybackRingBuffer; | |||
| static int Process(jack_nframes_t, void* arg); | |||
| static int BufferSize(jack_nframes_t nframes, void *arg); | |||
| static int Process(jack_nframes_t, void* arg); | |||
| static int BufferSize(jack_nframes_t nframes, void *arg); | |||
| void Reset(); | |||
| void Reset(); | |||
| public: | |||
| public: | |||
| JackCallbackNetIOAdapter(jack_client_t* jack_client, | |||
| JackCallbackNetIOAdapter(jack_client_t* jack_client, | |||
| JackIOAdapterInterface* audio_io, | |||
| int input, | |||
| int output); | |||
| ~JackCallbackNetIOAdapter(); | |||
| ~JackCallbackNetIOAdapter(); | |||
| virtual int SetBufferSize(int buffer_size) | |||
| { | |||
| // TODO | |||
| return -1; | |||
| } | |||
| virtual int SetBufferSize(int buffer_size) | |||
| { | |||
| // TODO | |||
| return -1; | |||
| } | |||
| }; | |||
| } | |||
| @@ -18,10 +18,38 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| */ | |||
| #include "JackIOAdapter.h" | |||
| #include <stdio.h> | |||
| namespace Jack | |||
| { | |||
| void MeasureTable::Write(int time1, int time2, float r1, float r2, int pos1, int pos2) | |||
| { | |||
| fTable[fCount].time1 = time1; | |||
| fTable[fCount].time2 = time2; | |||
| fTable[fCount].r1 = r1; | |||
| fTable[fCount].r2 = r2; | |||
| fTable[fCount].pos1 = pos1; | |||
| fTable[fCount].pos2 = pos2; | |||
| fCount++; | |||
| if (fCount == TABLE_MAX) | |||
| fCount--; | |||
| } | |||
| void MeasureTable::Save() | |||
| { | |||
| FILE* file = fopen("JackAlsaIOAdapter.log", "w"); | |||
| for (int i = 1; i < TABLE_MAX; i++) { | |||
| fprintf(file, "%d \t %d \t %d \t %f \t %f \t %d \t %d \n", | |||
| fTable[i].delta, fTable[i+1].time1 - fTable[i].time1, | |||
| fTable[i+1].time2 - fTable[i].time2, | |||
| fTable[i].r1, fTable[i].r2, fTable[i].pos1, fTable[i].pos2); | |||
| } | |||
| fclose(file); | |||
| } | |||
| int JackIOAdapterInterface::Open() | |||
| { | |||
| return 0; | |||
| @@ -26,15 +26,42 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| #include "JackResampler.h" | |||
| #include "JackFilters.h" | |||
| #include <samplerate.h> | |||
| #include <stdio.h> | |||
| namespace Jack | |||
| { | |||
| #define TABLE_MAX 100000 | |||
| struct Measure { | |||
| int delta; | |||
| int time1; | |||
| int time2; | |||
| float r1; | |||
| float r2; | |||
| int pos1; | |||
| int pos2; | |||
| }; | |||
| struct MeasureTable { | |||
| Measure fTable[TABLE_MAX]; | |||
| int fCount; | |||
| MeasureTable():fCount(0) | |||
| {} | |||
| void Write(int time1, int time2, float r1, float r2, int pos1, int pos2); | |||
| void Save(); | |||
| }; | |||
| class JackIOAdapterInterface | |||
| { | |||
| protected: | |||
| MeasureTable fTable; | |||
| int fCaptureChannels; | |||
| int fPlaybackChannels; | |||
| @@ -26,32 +26,33 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| namespace Jack | |||
| { | |||
| class JackNetIOAdapter | |||
| { | |||
| protected: | |||
| int fCaptureChannels; | |||
| int fPlaybackChannels; | |||
| protected: | |||
| int fCaptureChannels; | |||
| int fPlaybackChannels; | |||
| jack_port_t** fCapturePortList; | |||
| jack_port_t** fPlaybackPortList; | |||
| jack_port_t** fCapturePortList; | |||
| jack_port_t** fPlaybackPortList; | |||
| jack_client_t* fJackClient; | |||
| JackIOAdapterInterface* fIOAdapter; | |||
| jack_client_t* fJackClient; | |||
| JackIOAdapterInterface* fIOAdapter; | |||
| void FreePorts(); | |||
| void FreePorts(); | |||
| public: | |||
| public: | |||
| JackNetIOAdapter(jack_client_t* jack_client, | |||
| JackNetIOAdapter(jack_client_t* jack_client, | |||
| JackIOAdapterInterface* audio_io, | |||
| int input, | |||
| int output); | |||
| virtual ~JackNetIOAdapter(); | |||
| virtual ~JackNetIOAdapter(); | |||
| int Open(); | |||
| int Close(); | |||
| int Open(); | |||
| int Close(); | |||
| }; | |||
| } | |||
| @@ -27,7 +27,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| namespace Jack | |||
| { | |||
| #define DEFAULT_RB_SIZE 16384 * 1 | |||
| #define DEFAULT_RB_SIZE 16384 * 4 | |||
| class JackResampler | |||
| { | |||
| @@ -26,7 +26,7 @@ int JackAlsaIOAdapter::Open() | |||
| { | |||
| if (fAudioInterface.open() == 0) { | |||
| fAudioInterface.longinfo(); | |||
| fThread.AcquireRealTime(); | |||
| fThread.AcquireRealTime(85); | |||
| fThread.StartSync(); | |||
| return 0; | |||
| } else { | |||
| @@ -36,6 +36,7 @@ int JackAlsaIOAdapter::Open() | |||
| int JackAlsaIOAdapter::Close() | |||
| { | |||
| fTable.Save(); | |||
| fThread.Stop(); | |||
| return fAudioInterface.close(); | |||
| } | |||
| @@ -68,22 +69,22 @@ bool JackAlsaIOAdapter::Execute() | |||
| 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) { | |||
| if (src_ratio_input < 0.1f || src_ratio_input > 1.9f) { | |||
| 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) { | |||
| if (src_ratio_output < 0.1f || src_ratio_output > 1.9f) { | |||
| 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); | |||
| src_ratio_input = Range(0.1f, 1.9f, src_ratio_input); | |||
| src_ratio_output = Range(0.1f, 1.9f, 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++) { | |||
| @@ -95,6 +96,9 @@ bool JackAlsaIOAdapter::Execute() | |||
| fPlaybackRingBuffer[i]->SetRatio(time2, time1); | |||
| fPlaybackRingBuffer[i]->ReadResample(fAudioInterface.fOutputSoftChannels[i], fBufferSize); | |||
| } | |||
| fTable.Write(time1, time2, src_ratio_input, src_ratio_output, | |||
| fCaptureRingBuffer[0]->ReadSpace(), fPlaybackRingBuffer[0]->WriteSpace()); | |||
| if (fAudioInterface.write() < 0) | |||
| return false; | |||
| @@ -31,7 +31,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| namespace Jack | |||
| { | |||
| inline void* aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size) + 15, sizeof(char))) + 15 & ~15); } | |||
| //inline void* aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb * size) + 15, sizeof(char))) + 15 & ~15); } | |||
| inline void* aligned_calloc(size_t nmemb, size_t size) { return (void*)calloc(nmemb, size); } | |||
| #define max(x,y) (((x)>(y)) ? (x) : (y)) | |||
| #define min(x,y) (((x)<(y)) ? (x) : (y)) | |||
| @@ -133,7 +134,17 @@ namespace Jack | |||
| AudioInterface(int input, int output, jack_nframes_t buffer_size, jack_nframes_t sample_rate) : | |||
| AudioParam(input, output, buffer_size, sample_rate) | |||
| {} | |||
| { | |||
| fInputCardBuffer = 0; | |||
| fOutputCardBuffer = 0; | |||
| for (int i = 0; i < 256; i++) { | |||
| fInputCardChannels[i] = 0; | |||
| fOutputCardChannels[i] = 0; | |||
| fInputSoftChannels[i] = 0; | |||
| fOutputSoftChannels[i] = 0; | |||
| } | |||
| } | |||
| /** | |||
| * Open the audio interface | |||
| @@ -199,6 +210,11 @@ namespace Jack | |||
| int close() | |||
| { | |||
| snd_pcm_hw_params_free(fInputParams); | |||
| snd_pcm_hw_params_free(fOutputParams); | |||
| snd_pcm_close(fInputDevice); | |||
| snd_pcm_close(fOutputDevice); | |||
| for (unsigned int i = 0; i < fChanInputs; i++) { | |||
| if (fInputSoftChannels[i]) | |||
| free(fInputSoftChannels[i]); | |||
| @@ -208,29 +224,22 @@ namespace Jack | |||
| if (fOutputSoftChannels[i]) | |||
| free(fOutputSoftChannels[i]); | |||
| } | |||
| for (unsigned int i = 0; i < fCardInputs; i++) { | |||
| if (fInputCardChannels[i]) | |||
| free(fInputCardChannels[i]); | |||
| } | |||
| for (unsigned int i = 0; i < fCardOutputs; i++) { | |||
| if (fCardOutputs[i]) | |||
| free(fCardOutputs[i]); | |||
| if (fOutputCardChannels[i]) | |||
| free(fOutputCardChannels[i]); | |||
| } | |||
| if (fInputCardBuffer) | |||
| free(fInputCardBuffer); | |||
| if (fOutputCardBuffer) | |||
| free(fOutputCardBuffer); | |||
| snd_pcm_hw_params_free(fInputParams); | |||
| snd_pcm_hw_params_free(fOutputParams); | |||
| snd_pcm_close(fInputDevice); | |||
| snd_pcm_close(fOutputDevice); | |||
| return 0; | |||
| } | |||