Skip to content
Snippets Groups Projects
Commit 477ec6f4 authored by alexandresavard's avatar alexandresavard
Browse files

Overload AudioRecord::recData to get mic and speaker data mixed

parent f1b2fd9b
No related branches found
No related tags found
No related merge requests found
...@@ -437,7 +437,7 @@ AudioRtpRTX::run () { ...@@ -437,7 +437,7 @@ AudioRtpRTX::run () {
receiveSessionForSpkr(countTime); receiveSessionForSpkr(countTime);
// Let's wait for the next transmit cycle // Let's wait for the next transmit cycle
recAudio.recData(spkrDataConverted,_nSamplesSpkr); recAudio.recData(spkrDataConverted,micData,_nSamplesSpkr,_nSamplesMic);
Thread::sleep(TimerPort::getTimer()); Thread::sleep(TimerPort::getTimer());
TimerPort::incTimer(_layerFrameSize); // 'frameSize' ms TimerPort::incTimer(_layerFrameSize); // 'frameSize' ms
......
...@@ -180,3 +180,46 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) { ...@@ -180,3 +180,46 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) {
return; 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;
}
...@@ -75,7 +75,16 @@ public: ...@@ -75,7 +75,16 @@ public:
* @param buffer The data chunk to be recorded * @param buffer The data chunk to be recorded
* @param nSamples Number of samples (number of bytes) 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: protected:
...@@ -94,6 +103,11 @@ protected: ...@@ -94,6 +103,11 @@ protected:
*/ */
void closeWavFile(); 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 * Pointer to the recorded file
*/ */
...@@ -124,4 +138,9 @@ protected: ...@@ -124,4 +138,9 @@ protected:
*/ */
int sndSmplRate_; int sndSmplRate_;
/**
* Buffer used for mixing two channels
*/
SFLDataFormat* mixBuffer_;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment