diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 11d7ccbd9ef099be9a94764afbe268286cd556ab..156080db1926252914e378149f9bb52a1caf2322 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -437,7 +437,7 @@ AudioRtpRTX::run () { receiveSessionForSpkr(countTime); // Let's wait for the next transmit cycle - recAudio.recData(spkrDataConverted,_nSamplesSpkr); + recAudio.recData(spkrDataConverted,micData,_nSamplesSpkr,_nSamplesMic); Thread::sleep(TimerPort::getTimer()); TimerPort::incTimer(_layerFrameSize); // 'frameSize' ms diff --git a/src/plug-in/audiorecorder/audiorecord.cpp b/src/plug-in/audiorecorder/audiorecord.cpp index e774db97c209b153c4fd517298c08bca28c4aef9..ef60bc49d16aa7b7b0c7e65c65cac53aaf79ecbb 100644 --- a/src/plug-in/audiorecorder/audiorecord.cpp +++ b/src/plug-in/audiorecorder/audiorecord.cpp @@ -180,3 +180,46 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) { return; } + +void AudioRecord::recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int nSamples_1, int nSamples_2) { + + if (fp == 0){ + _debug("AudioRecord: Can't record data, a file has not yet been opened!\n"); + return; + } + + mixBuffer_ = new SFLDataFormat[nSamples_1]; + + // int size = nSamples * (sizeof(SFLDataFormat)); + // int size = sizeof(buffer); + // int count = sizeof(buffer) / sizeof(SFLDataFormat); + + // printf("AudioRecord : sizeof(buffer) : %d \n",size); + // printf("AudioRecord : sizeof(buffer) / sizeof(SFLDataFormat) : %d \n",count); + // printf("AudioRecord : nSamples : %d \n",nSamples); + // printf("AudioRecord : buffer: %x : ", buffer); + + if ( sndFormat_ == INT16 ) { // TODO change INT16 to SINT16 + for (int k=0; k<nSamples_1; k++){ + + mixBuffer_[k] = (buffer_1[k]+buffer_2[k])/2; + + if ( fwrite(&buffer_1[k], 2, 1, fp) != 1) + _debug("AudioRecord: Could not record data!\n"); + else { + // printf("Buffer : %x \n",*buffer); + fflush(fp); + // _debug("Flushing!\n"); + } + } + } + + + + + byteCounter_ += (unsigned long)(nSamples_1*sizeof(SFLDataFormat)); + + delete [] mixBuffer_; + + return; +} diff --git a/src/plug-in/audiorecorder/audiorecord.h b/src/plug-in/audiorecorder/audiorecord.h index b38eefb29a59be117d896e9c2c6147ff43011ef3..d33dd5f530b9ad3e84ac5efa8b7a37f5435c10b5 100644 --- a/src/plug-in/audiorecorder/audiorecord.h +++ b/src/plug-in/audiorecorder/audiorecord.h @@ -75,7 +75,16 @@ public: * @param buffer The data chunk to be recorded * @param nSamples Number of samples (number of bytes) to be recorded */ - void recData(SFLDataFormat* buffer, int nSamples); // TODO ad the data to rec + void recData(SFLDataFormat* buffer, int nSamples); + + /** + * Record a chunk of data in an openend file, Mix two differnet buffer + * @param buffer_1 The first data chunk to be recorded + * @param buffer_2 The second data chunk to be recorded + * @param nSamples_1 Number of samples (number of bytes) of buffer_1 + * @param nSamples_2 Number of samples (number of bytes) of buffer_2 + */ + void recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int nSamples_1, int nSamples_2); protected: @@ -94,6 +103,11 @@ protected: */ void closeWavFile(); + /** + * Given two buffers, return one mixed audio buffer + */ + void mixBuffers(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int nSamples_1, int nSamples_2); + /** * Pointer to the recorded file */ @@ -124,4 +138,9 @@ protected: */ int sndSmplRate_; + /** + * Buffer used for mixing two channels + */ + SFLDataFormat* mixBuffer_; + };