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

* #8968: audiorecord: added debug, clarified wave header creation

parent 6ec86926
No related branches found
No related tags found
No related merge requests found
...@@ -245,6 +245,27 @@ bool AudioRecord::setRawFile() ...@@ -245,6 +245,27 @@ bool AudioRecord::setRawFile()
return true; return true;
} }
namespace {
std::string header_to_string(const wavhdr &hdr)
{
std::stringstream ss;
ss << hdr.riff << "\0 "
<< hdr.file_size << " "
<< hdr.wave << "\0 "
<< hdr.fmt << "\0 "
<< hdr.chunk_size << " "
<< hdr.format_tag << " "
<< hdr.num_chans << " "
<< hdr.sample_rate << " "
<< hdr.bytes_per_sec << " "
<< hdr.bytes_per_samp << " "
<< hdr.bits_per_samp << " "
<< hdr.data << "\0 "
<< hdr.data_length;
return ss.str();
}
}
bool AudioRecord::setWavFile() bool AudioRecord::setWavFile()
{ {
DEBUG("AudioRecord: Create new wave file %s, sampling rate: %d", savePath_.c_str(), sndSmplRate_); DEBUG("AudioRecord: Create new wave file %s, sampling rate: %d", savePath_.c_str(), sndSmplRate_);
...@@ -259,23 +280,29 @@ bool AudioRecord::setWavFile() ...@@ -259,23 +280,29 @@ bool AudioRecord::setWavFile()
/* The text fields are NOT supposed to be null terminated, so we have to /* The text fields are NOT supposed to be null terminated, so we have to
* write them as arrays since strings enclosed in quotes include a * write them as arrays since strings enclosed in quotes include a
* null character */ * null character */
wavhdr hdr = {{'R', 'I', 'F', 'F'}, 44, {'W', 'A', 'V', 'E'}, wavhdr hdr = {{'R', 'I', 'F', 'F'},
{'f','m', 't', ' '}, 16, 1, 1, sndSmplRate_, 0, 2, 16, 44,
{'d', 'a', 't', 'a'}, 0}; {'W', 'A', 'V', 'E'},
{'f','m', 't', ' '},
hdr.num_chans = channels_; 16,
hdr.bits_per_samp = 16; 1,
hdr.bytes_per_samp = static_cast<SINT16>(channels_ * hdr.bits_per_samp / 8); channels_,
hdr.bytes_per_sec = static_cast<SINT32>(hdr.sample_rate * hdr.bytes_per_samp); sndSmplRate_,
-1, /* initialized below */
-1, /* initialized below */
16,
{'d', 'a', 't', 'a'},
0};
hdr.bytes_per_samp = channels_ * hdr.bits_per_samp / 8;
hdr.bytes_per_sec = hdr.sample_rate * hdr.bytes_per_samp;
if (fwrite(&hdr, 4, 11, fileHandle_) != 11) { if (fwrite(&hdr, 4, 11, fileHandle_) != 11) {
WARN("AudioRecord: Error: could not write WAV header for file. "); WARN("AudioRecord: Error: could not write WAV header for file. ");
return false; return false;
} }
DEBUG("AudioRecord: created WAV file successfully, file size=%d," DEBUG("AudioRecord: Wrote wave header \"%s\"", header_to_string(hdr).c_str());
"chunk size=%d, fmt=%d, data length=%d", hdr.file_size,
hdr.chunk_size, hdr.format_tag, hdr.data_length);
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment