|
#include <osg/AudioStream>
#include <QDebug>
#include <QAudioFormat>
#include "qtaudiosink.h"
#include "audiothread.h"
QtAudioSink::QtAudioSink(osg::AudioStream *audioStream) :
_started(false), _paused(false),
_audioStream(audioStream)
{
}
QtAudioSink::~QtAudioSink()
{
stop();
}
void QtAudioSink::play()
{
if (_started)
{
if (_paused)
{
_aTh->resume();
_paused = false;
}
return;
}
_started = true;
_paused = false;
createAudioOutput();
}
void QtAudioSink::createAudioOutput()
{
QAudioFormat m_format;
m_format.setFrequency(_audioStream->audioFrequency());
m_format.setChannels(_audioStream->audioNbChannels());
m_format.setSampleSize(16);
m_format.setCodec("audio/pcm");
m_format.setByteOrder(QAudioFormat::LittleEndian);
m_format.setSampleType(QAudioFormat::SignedInt);
_aTh = new AudioThread(NULL,
_audioStream.get(),
m_format);
_aTh->start();
}
void QtAudioSink::pause()
{
if (_started)
{
_aTh->pause();
_paused = true;
}
}
void QtAudioSink::stop()
{
if (_started)
{
_aTh->resume();
if(_aTh)
_aTh->terminate();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.