2014-06-28 00:51:08 +08:00
|
|
|
#include "audiobuffer.h"
|
|
|
|
|
|
|
|
AudioBuffer::AudioBuffer() :
|
|
|
|
QIODevice(0)
|
|
|
|
{
|
|
|
|
open(QIODevice::ReadOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioBuffer::~AudioBuffer()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 AudioBuffer::readData(char *data, qint64 len)
|
|
|
|
{
|
|
|
|
const qint64 total = qMin((qint64)buffer.size(), len);
|
|
|
|
memcpy(data, buffer.constData(), total);
|
|
|
|
buffer = buffer.mid(total);
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 AudioBuffer::writeData(const char* data, qint64 len)
|
|
|
|
{
|
|
|
|
buffer.append(data, len);
|
2014-06-30 19:49:59 +08:00
|
|
|
return len;
|
2014-06-28 00:51:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 AudioBuffer::bytesAvailable() const
|
|
|
|
{
|
|
|
|
return buffer.size() + QIODevice::bytesAvailable();
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 AudioBuffer::bufferSize() const
|
|
|
|
{
|
|
|
|
return buffer.size();
|
|
|
|
}
|
2014-06-28 02:24:00 +08:00
|
|
|
|
|
|
|
void AudioBuffer::clear()
|
|
|
|
{
|
|
|
|
buffer.clear();
|
|
|
|
}
|