test_sdk/hw/gtl_hw_recorder_wav.cpp

119 lines
3.6 KiB
C++
Raw Normal View History

#include "gtl_hw_recorder_wav.h"
namespace gtl
{
namespace hw
{
recorder_wav::recorder_wav(const std::vector<gtl::analog_data*> &ad, qreal time, QString comment, QString dir, QString file, QObject *parent)
: recorder(ad, time, comment, dir, file, "wav", parent)
, _is_finished(false)
{
if(!is_success())
return;
*_stream << (quint32)0x46464952; // RIFF
*_stream << (quint32)0x00000000;
*_stream << (quint32)0x45564157; //WAVE
*_stream << (quint32)0x4b4e554a; //JUNK
*_stream << (quint32)28;
for (int i = 0; i < 7; i++)
*_stream << (quint32)0;
*_stream << (quint32)0x20746d66; //fmt
*_stream << (quint32)16;
*_stream << (quint16)(3);
*_stream << (quint16)_ad.size();
*_stream << (quint32)qRound(_device->rate());
*_stream << (quint32)(_device->rate()*_ad.size() * 4);
*_stream << (quint16)(_ad.size() * 4);
*_stream << (quint16)32;
/*
*_stream << (quint16)(_coding == float_32_bit ? 3 : 1);
*_stream << (quint16)_signals.size();
*_stream << (quint32)_rate;
if (_coding == signed_16_bit_pcm)
{
*_stream << (quint32)(_rate*_signals.size() * 2);
*_stream << (quint16)(_signals.size() * 2);
*_stream << (quint16)16;
}
else if (_coding == signed_24_bit_pcm)
{
*_stream << (quint32)(_rate*_signals.size() * 3);
*_stream << (quint16)(_signals.size() * 3);
*_stream << (quint16)24;
}
else if (_coding == signed_32_bit_pcm | _coding == float_32_bit)
{
*_stream << (quint32)(_rate*_signals.size() * 4);
*_stream << (quint16)(_signals.size() * 4);
*_stream << (quint16)32;
}
else if (_coding == unsigned_8_bit_pcm)
{
*_stream << (quint32)(_rate*_signals.size() * 1);
*_stream << (quint16)(_signals.size() * 1);
*_stream << (quint16)8;
}
*/
*_stream << (quint32)0x61746164; //data
*_stream << (quint32)0x00000000;
}
recorder_wav::~recorder_wav()
{
if(!_is_finished)
finish_writing();
}
void recorder_wav::finish_writing()
{
if(_file == nullptr)
return;
quint64 size_file = _file->size() - 8;
if (size_file < 0xffffffff)
{
_file->seek(4);
quint32 size = (quint32)size_file;
*_stream << size;
_file->seek(40 + 36);
size -= 36 + 36;
*_stream << size;
}
else
{
_file->seek(4);
*_stream << (quint32) -1;
_file->seek(40 + 36);
*_stream << (quint32)-1;
_file->seek(12);
*_stream << 0x34367364;
_file->seek(20);
*_stream << (quint32) (size_file & 0xffffffff);
*_stream << (quint32)((size_file >> 32) & 0xffffffff);
size_file -= 36 + 36;
*_stream << (quint32)(size_file & 0xffffffff);
*_stream << (quint32)((size_file >> 32) & 0xffffffff);
}
_is_finished = true;
}
}
}