Commit d893a4dd authored by Alexandre Savard's avatar Alexandre Savard
Browse files

Recording while leaving a message with IAX works fine now!

parent 7f852128
......@@ -44,9 +44,19 @@ AudioRecord::AudioRecord(){
byteCounter_ = 0;
recordingEnabled_ = false;
fp = 0;
nbSamplesMax_ = 3000;
createFilename();
mixBuffer_ = new SFLDataFormat[nbSamplesMax_];
micBuffer_ = new SFLDataFormat[nbSamplesMax_];
spkBuffer_ = new SFLDataFormat[nbSamplesMax_];
}
AudioRecord::~AudioRecord() {
delete [] mixBuffer_;
delete [] micBuffer_;
delete [] spkBuffer_;
}
......@@ -56,7 +66,6 @@ void AudioRecord::setSndSamplingRate(int smplRate){
void AudioRecord::setRecordingOption(FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate, std::string path, std::string id){
// std::string fName;
fileType_ = type;
sndFormat_ = format;
......@@ -64,26 +73,8 @@ void AudioRecord::setRecordingOption(FILE_TYPE type, SOUND_FORMAT format, int sn
sndSmplRate_ = sndSmplRate;
call_id_ = id;
// fName = fileName_;
// fName.append("-"+call_id_);
/*
if (fileType_ == FILE_RAW){
if ( strstr(fileName_, ".raw") == NULL){
printf("AudioRecord::openFile::concatenate .raw file extension: name : %s \n", fileName_);
fName.append(".raw");
}
}
else if (fileType_ == FILE_WAV){
if ( strstr(fileName_, ".wav") == NULL){
printf("AudioRecord::openFile::concatenate .wav file extension: name : %s \n", fileName_);
fName.append(".wav");
}
}
*/
savePath_ = path + "/";
// savePath_.append(fName);
savePath_ = path + "/";
}
......@@ -362,22 +353,10 @@ void AudioRecord::closeWavFile()
_debug("AudioRecord:: Can't closeWavFile, a file has not yet been opened!\n");
return;
}
/*
_debug("AudioRecord::closeWavFile() \n");
if ( fclose( fp ) != 0)
_debug("AudioRecord::closeWavFile()::ERROR: can't close file ab \n");
fp = fopen(fileName_, "rb+");
if ( !fp ) {
_debug("AudioRecord::closeWavFile() : could not open WAV file rb+!\n");
return;
}
*/
SINT32 bytes = byteCounter_ * channels_;
fseek(fp, 40, SEEK_SET); // jump to data length
if (ferror(fp))perror("AudioRecord::closeWavFile()::ERROR: can't reach offset 40\n");
......@@ -397,11 +376,37 @@ void AudioRecord::closeWavFile()
if ( fclose( fp ) != 0)
_debug("AudioRecord::closeWavFile()::ERROR: can't close file\n");
// i = fclose(fp);
// printf("AudioRecord::closeWavFile : indicator i : %i \n",i);
}
void AudioRecord::recSpkrData(SFLDataFormat* buffer, int nSamples) {
if (recordingEnabled_) {
nbSamplesMic_ = nSamples;
for(int i = 0; i < nbSamplesMic_; i++)
micBuffer_[i] = buffer[i];
}
return;
}
void AudioRecord::recMicData(SFLDataFormat* buffer, int nSamples) {
if (recordingEnabled_) {
nbSamplesSpk_ = nSamples;
for(int i = 0; i < nbSamplesSpk_; i++)
spkBuffer_[i] = buffer[i];
}
return;
}
void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) {
......@@ -412,22 +417,13 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) {
return;
}
// 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
if ( fwrite(buffer, sizeof(SFLDataFormat), nSamples, fp) != nSamples)
_debug("AudioRecord: Could not record data! \n");
else {
// printf("Buffer : %x \n",*buffer);
fflush(fp);
// _debug("Flushing!\n");
byteCounter_ += (unsigned long)(nSamples*sizeof(SFLDataFormat));
}
}
......@@ -446,40 +442,25 @@ void AudioRecord::recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int
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)/32767;
mixBuffer_[k] = (buffer_1[k]+buffer_2[k]);
// dsp.getRMS(mixBuffer_[k]);
if ( fwrite(&buffer_1[k], 2, 1, fp) != 1)
if ( fwrite(&mixBuffer_[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));
//printf("AudioRecord::recData():: byteCounter_ : %i \n",(int)byteCounter_ );
delete [] mixBuffer_;
}
return;
}
......@@ -41,6 +41,8 @@ public:
AudioRecord();
~AudioRecord();
void setSndSamplingRate(int smplRate);
void setRecordingOption(FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate, std::string path, std::string id);
......@@ -85,6 +87,21 @@ public:
*/
void stopRecording();
/**
* Record a chunk of data in an internal buffer
* @param buffer The data chunk to be recorded
* @param nSamples Number of samples (number of bytes) to be recorded
*/
void recSpkrData(SFLDataFormat* buffer, int nSamples);
/**
* Record a chunk of data in an internal buffer
* @param buffer The data chunk to be recorded
* @param nSamples Number of samples (number of bytes) to be recorded
*/
void recMicData(SFLDataFormat* buffer, int nSamples);
/**
* Record a chunk of data in an openend file
* @param buffer The data chunk to be recorded
......@@ -101,6 +118,7 @@ public:
*/
void recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int nSamples_1, int nSamples_2);
protected:
/**
......@@ -133,10 +151,6 @@ 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
......@@ -167,6 +181,21 @@ protected:
* Sampling rate
*/
int sndSmplRate_;
/**
* number of samples recorded for mic buffer
*/
int nbSamplesMic_;
/**
* number of samples recorded for speaker buffer
*/
int nbSamplesSpk_;
/**
* Maximum number of samples
*/
int nbSamplesMax_;
/**
* Recording flage
......@@ -177,6 +206,16 @@ protected:
* Buffer used for mixing two channels
*/
SFLDataFormat* mixBuffer_;
/**
* Buffer used to copy mic info
*/
SFLDataFormat* micBuffer_;
/**
* Buffer used to copy spkr info
*/
SFLDataFormat* spkBuffer_;
/**
* Filename for this recording
......@@ -187,7 +226,10 @@ protected:
* Path for this recording
*/
std::string savePath_;
/**
* Path for this recordingId for this call
*/
std::string call_id_;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment