Browse Source

fix wav_recorder error

disinfection_machine
zhaohe 2 years ago
parent
commit
dda7872ae7
  1. 38
      core/components/audio/wav_recorder.cpp

38
core/components/audio/wav_recorder.cpp

@ -5,36 +5,36 @@ using namespace core;
void WavRecorder::writeVoice(string filename, uint32_t sample_rate, uint16_t bits_per_sample, uint16_t num_channels,
const char* data, uint32_t size) {
ofstream file;
fstream file;
WAVHeader wavHeader;
// logger->info("writeVoice filename:{} {} {} {} {}", filename, sample_rate, bits_per_sample, num_channels, size);
file.open(filename, ios::out | ios::binary | ios::app);
#if 1
/**
* @brief 44
*/
file.seekp(0, ios::end);
if (file.tellp() < 44) {
file.open(filename, fstream::in | fstream::out | fstream::binary);
if (!file.is_open()) {
file.open(filename, fstream::out | fstream::binary | fstream::trunc);
wavHeader.initialize(sample_rate, bits_per_sample, num_channels, 0);
file.seekp(0, ios::beg);
file.write((char*)wavHeader.data(), wavHeader.size());
file.close();
file.open(filename, fstream::in | fstream::out | fstream::binary);
}
// file.write(data, size);
#if 1
/**
* @brief 44
*/
file.seekp(0, ios::end);
file.write(data, size);
/**
* @brief
*/
{
file.seekp(0, ios::end);
uint32_t filesize = file.tellp();
file.seekp(4, ios::beg);
uint32_t chunk_size = filesize - 8;
file.write((char*)&chunk_size, 4);
file.seekp(40, ios::beg);
uint32_t subchunk2_size = filesize - 44;
file.write((char*)&subchunk2_size, 4);
}
uint32_t filesize = file.tellp();
file.seekp(4, ios::beg);
uint32_t chunk_size = filesize - 8;
file.write((char*)&chunk_size, 4);
file.seekp(40, ios::beg);
uint32_t subchunk2_size = filesize - 44;
file.write((char*)&subchunk2_size, 4);
#endif
file.close();
Loading…
Cancel
Save