2014-07-14 05:03:36 +08:00
|
|
|
#include "audiooutputproxy.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
2014-07-19 00:36:02 +08:00
|
|
|
#define RING_SIZE 11025
|
2014-07-14 05:03:36 +08:00
|
|
|
|
|
|
|
AudioOutputProxy::AudioOutputProxy(QObject *parent) :
|
|
|
|
QIODevice(parent),
|
2014-07-14 21:16:44 +08:00
|
|
|
ring_buffer(new MemRing<int16_t>(RING_SIZE))
|
2014-07-14 05:03:36 +08:00
|
|
|
{
|
2014-07-19 00:36:02 +08:00
|
|
|
open(QIODevice::ReadOnly | QIODevice::Unbuffered);
|
2014-07-14 21:16:44 +08:00
|
|
|
qDebug() << "AudioOutputProxy::AudioOutputProxy";
|
2014-07-14 05:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioOutputProxy::~AudioOutputProxy()
|
|
|
|
{
|
|
|
|
if (ring_buffer) {
|
|
|
|
delete ring_buffer;
|
|
|
|
ring_buffer = 0;
|
|
|
|
}
|
|
|
|
close();
|
2014-07-14 21:16:44 +08:00
|
|
|
qDebug() << "AudioOutputProxy::~AudioOutputProxy";
|
2014-07-14 05:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 AudioOutputProxy::readData(char *data, qint64 len)
|
|
|
|
{
|
2014-07-14 21:16:44 +08:00
|
|
|
qDebug() << "AudioOutputProxy::read" << len;
|
|
|
|
return ring_buffer->pull((int16_t*)data, len/2)*2;
|
2014-07-14 05:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 AudioOutputProxy::writeData(const char* data, qint64 len)
|
|
|
|
{
|
2014-07-14 21:16:44 +08:00
|
|
|
// qDebug() << "AudioOutputProxy::write" << len;
|
|
|
|
return ring_buffer->push((int16_t*)data, len/2)*2;
|
2014-07-14 05:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 AudioOutputProxy::bytesAvailable() const
|
|
|
|
{
|
|
|
|
return ring_buffer->readSpace() + QIODevice::bytesAvailable();
|
|
|
|
}
|
2014-07-14 21:16:44 +08:00
|
|
|
|
|
|
|
bool AudioOutputProxy::isSequential() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|