From 477ec6f4e552786a78b49e0a99b1cd0bb94d22a3 Mon Sep 17 00:00:00 2001 From: alexandresavard <alexandresavard@alexandresavard-desktop.(none)> Date: Tue, 27 Jan 2009 18:55:41 -0500 Subject: [PATCH] Overload AudioRecord::recData to get mic and speaker data mixed --- src/audio/audiortp.cpp | 2 +- src/plug-in/audiorecorder/audiorecord.cpp | 43 +++++++++++++++++++++++ src/plug-in/audiorecorder/audiorecord.h | 21 ++++++++++- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 11d7ccbd9e..156080db19 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 e774db97c2..ef60bc49d1 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 b38eefb29a..d33dd5f530 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_; + }; -- GitLab