Skip to content
Snippets Groups Projects
Commit f18f7d6c authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #9897: audiorecord cleanup

parent fb2671d0
Branches
Tags
No related merge requests found
...@@ -392,7 +392,7 @@ void AudioRecord::closeWavFile() ...@@ -392,7 +392,7 @@ void AudioRecord::closeWavFile()
WARN("AudioRecord: Error: can't close file"); WARN("AudioRecord: Error: can't close file");
} }
void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) void AudioRecord::recData(SFLDataFormat* buffer, size_t nSamples)
{ {
if (recordingEnabled_) { if (recordingEnabled_) {
if (fileHandle_ == 0) { if (fileHandle_ == 0) {
...@@ -400,11 +400,11 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) ...@@ -400,11 +400,11 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples)
return; return;
} }
if (fwrite(buffer, sizeof(SFLDataFormat), nSamples, fileHandle_) != (unsigned int) nSamples) if (fwrite(buffer, sizeof(SFLDataFormat), nSamples, fileHandle_) != nSamples)
WARN("AudioRecord: Could not record data! "); WARN("AudioRecord: Could not record data! ");
else { else {
fflush(fileHandle_); fflush(fileHandle_);
byteCounter_ += (unsigned long)(nSamples*sizeof(SFLDataFormat)); byteCounter_ += nSamples * sizeof(SFLDataFormat);
} }
} }
} }
...@@ -102,7 +102,7 @@ class AudioRecord { ...@@ -102,7 +102,7 @@ class AudioRecord {
* @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); void recData(SFLDataFormat* buffer, size_t nSamples);
protected: protected:
......
...@@ -58,14 +58,13 @@ AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread() ...@@ -58,14 +58,13 @@ AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : ost::Thread()
*/ */
void AudioRecorder::run() void AudioRecorder::run()
{ {
int bufferLength = 10000; const size_t BUFFER_LENGTH = 10000;
SFLDataFormat buffer[bufferLength]; SFLDataFormat buffer[BUFFER_LENGTH];
while (isRunning()) { while (isRunning()) {
int availBytes = mbuffer_->availForGet(recorderId_); size_t availBytes = mbuffer_->availForGet(recorderId_);
int toGet = (availBytes < bufferLength) ? availBytes : bufferLength;
mbuffer_->getData(buffer, toGet, recorderId_); mbuffer_->getData(buffer, std::min(availBytes, BUFFER_LENGTH), recorderId_);
if (availBytes > 0) if (availBytes > 0)
arecord_->recData(buffer, availBytes / sizeof(SFLDataFormat)); arecord_->recData(buffer, availBytes / sizeof(SFLDataFormat));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment