mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Merge pull request #198 from saidinesh5/visualizer_plugin
Added support for fetching Audio Data from the AudioEngine.
This commit is contained in:
@@ -159,6 +159,39 @@ AudioEnginePrivate::onStateChanged( Phonon::State newState, Phonon::State oldSta
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AudioEnginePrivate::onAudioDataArrived( QMap<Phonon::AudioDataOutput::Channel, QVector<qint16> > data )
|
||||||
|
{
|
||||||
|
QMap< AudioEngine::AudioChannel, QVector<qint16> > result;
|
||||||
|
|
||||||
|
if(data.contains(Phonon::AudioDataOutput::LeftChannel))
|
||||||
|
{
|
||||||
|
result[AudioEngine::LeftChannel] = QVector<qint16>(data[Phonon::AudioDataOutput::LeftChannel]);
|
||||||
|
}
|
||||||
|
if(data.contains(Phonon::AudioDataOutput::LeftSurroundChannel))
|
||||||
|
{
|
||||||
|
result[AudioEngine::LeftChannel] = QVector<qint16>(data[Phonon::AudioDataOutput::LeftSurroundChannel]);
|
||||||
|
}
|
||||||
|
if(data.contains(Phonon::AudioDataOutput::RightChannel))
|
||||||
|
{
|
||||||
|
result[AudioEngine::RightChannel]= QVector<qint16>(data[Phonon::AudioDataOutput::RightChannel]);
|
||||||
|
}
|
||||||
|
if(data.contains(Phonon::AudioDataOutput::RightSurroundChannel))
|
||||||
|
{
|
||||||
|
result[AudioEngine::LeftChannel] = QVector<qint16>(data[Phonon::AudioDataOutput::RightSurroundChannel]);
|
||||||
|
}
|
||||||
|
if(data.contains(Phonon::AudioDataOutput::CenterChannel))
|
||||||
|
{
|
||||||
|
result[AudioEngine::LeftChannel] = QVector<qint16>(data[Phonon::AudioDataOutput::CenterChannel]);
|
||||||
|
}
|
||||||
|
if(data.contains(Phonon::AudioDataOutput::SubwooferChannel))
|
||||||
|
{
|
||||||
|
result[AudioEngine::LeftChannel] = QVector<qint16>(data[Phonon::AudioDataOutput::SubwooferChannel]);
|
||||||
|
}
|
||||||
|
|
||||||
|
s_instance->audioDataArrived(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AudioEngine* AudioEnginePrivate::s_instance = 0;
|
AudioEngine* AudioEnginePrivate::s_instance = 0;
|
||||||
@@ -192,6 +225,8 @@ AudioEngine::AudioEngine()
|
|||||||
|
|
||||||
d->mediaObject = new Phonon::MediaObject( this );
|
d->mediaObject = new Phonon::MediaObject( this );
|
||||||
d->audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this );
|
d->audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this );
|
||||||
|
d->audioDataOutput = new Phonon::AudioDataOutput(this);
|
||||||
|
|
||||||
d->audioPath = Phonon::createPath( d->mediaObject, d->audioOutput );
|
d->audioPath = Phonon::createPath( d->mediaObject, d->audioOutput );
|
||||||
|
|
||||||
d->mediaObject->setTickInterval( 150 );
|
d->mediaObject->setTickInterval( 150 );
|
||||||
@@ -212,7 +247,6 @@ AudioEngine::AudioEngine()
|
|||||||
initEqualizer();
|
initEqualizer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AudioEngine::~AudioEngine()
|
AudioEngine::~AudioEngine()
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
@@ -323,6 +357,32 @@ AudioEngine::stop( AudioErrorCode errorCode )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AudioEngine::activateDataOutput()
|
||||||
|
{
|
||||||
|
Q_D(AudioEngine);
|
||||||
|
|
||||||
|
d->audioDataPath = Phonon::createPath(d->mediaObject, d->audioDataOutput);
|
||||||
|
connect(d->audioDataOutput, SIGNAL( dataReady(QMap<Phonon::AudioDataOutput::Channel,QVector<qint16> >) ),
|
||||||
|
d_func(), SLOT(onAudioDataArrived(QMap<Phonon::AudioDataOutput::Channel,QVector<qint16> >)));
|
||||||
|
|
||||||
|
return d->audioDataPath.isValid();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AudioEngine::deactivateDataOutput()
|
||||||
|
{
|
||||||
|
Q_D(AudioEngine);
|
||||||
|
|
||||||
|
return d->audioDataPath.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioEngine::audioDataArrived(QMap< AudioEngine::AudioChannel, QVector< qint16 > >& data)
|
||||||
|
{
|
||||||
|
emit audioDataReady(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AudioEngine::previous()
|
AudioEngine::previous()
|
||||||
{
|
{
|
||||||
|
@@ -36,6 +36,7 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
enum AudioErrorCode { StreamReadError, AudioDeviceError, DecodeError, UnknownError, NoError };
|
enum AudioErrorCode { StreamReadError, AudioDeviceError, DecodeError, UnknownError, NoError };
|
||||||
enum AudioState { Stopped = 0, Playing = 1, Paused = 2, Error = 3, Loading = 4 };
|
enum AudioState { Stopped = 0, Playing = 1, Paused = 2, Error = 3, Loading = 4 };
|
||||||
|
enum AudioChannel { LeftChannel, LeftSurroundChannel, RightChannel , RightSurroundChannel, CenterChannel , SubwooferChannel };
|
||||||
|
|
||||||
static AudioEngine* instance();
|
static AudioEngine* instance();
|
||||||
|
|
||||||
@@ -71,6 +72,9 @@ public slots:
|
|||||||
void pause();
|
void pause();
|
||||||
void stop( AudioErrorCode errorCode = NoError );
|
void stop( AudioErrorCode errorCode = NoError );
|
||||||
|
|
||||||
|
bool activateDataOutput();
|
||||||
|
bool deactivateDataOutput();
|
||||||
|
|
||||||
void previous();
|
void previous();
|
||||||
void next();
|
void next();
|
||||||
|
|
||||||
@@ -105,6 +109,8 @@ signals:
|
|||||||
void paused();
|
void paused();
|
||||||
void resumed();
|
void resumed();
|
||||||
|
|
||||||
|
void audioDataReady( QMap< AudioEngine::AudioChannel, QVector<qint16> > data );
|
||||||
|
|
||||||
void stopAfterTrackChanged();
|
void stopAfterTrackChanged();
|
||||||
|
|
||||||
void seeked( qint64 ms );
|
void seeked( qint64 ms );
|
||||||
@@ -147,8 +153,11 @@ private:
|
|||||||
void checkStateQueue();
|
void checkStateQueue();
|
||||||
void queueState( AudioState state );
|
void queueState( AudioState state );
|
||||||
void setState( AudioState state );
|
void setState( AudioState state );
|
||||||
void setCurrentTrackPlaylist( const Tomahawk::playlistinterface_ptr& playlist );
|
void setCurrentTrackPlaylist( const Tomahawk::playlistinterface_ptr& playlist );\
|
||||||
|
|
||||||
void initEqualizer();
|
void initEqualizer();
|
||||||
|
void audioDataArrived( QMap< AudioEngine::AudioChannel, QVector<qint16> >& data );
|
||||||
|
|
||||||
|
|
||||||
Q_DECLARE_PRIVATE( AudioEngine );
|
Q_DECLARE_PRIVATE( AudioEngine );
|
||||||
AudioEnginePrivate* d_ptr;
|
AudioEnginePrivate* d_ptr;
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
|
|
||||||
#include <phonon/MediaObject>
|
#include <phonon/MediaObject>
|
||||||
#include <phonon/AudioOutput>
|
#include <phonon/AudioOutput>
|
||||||
#include <phonon/Path>
|
#include <phonon/AudioDataOutput>
|
||||||
#include <phonon/BackendCapabilities>
|
#include <phonon/BackendCapabilities>
|
||||||
|
#include <phonon/Path>
|
||||||
#include <phonon/Effect>
|
#include <phonon/Effect>
|
||||||
#include <phonon/EffectParameter>
|
#include <phonon/EffectParameter>
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onStateChanged( Phonon::State newState, Phonon::State oldState );
|
void onStateChanged( Phonon::State newState, Phonon::State oldState );
|
||||||
|
void onAudioDataArrived( QMap< Phonon::AudioDataOutput::Channel, QVector<qint16> > data );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<QIODevice> input;
|
QSharedPointer<QIODevice> input;
|
||||||
@@ -40,9 +42,14 @@ private:
|
|||||||
|
|
||||||
Phonon::MediaObject* mediaObject;
|
Phonon::MediaObject* mediaObject;
|
||||||
Phonon::AudioOutput* audioOutput;
|
Phonon::AudioOutput* audioOutput;
|
||||||
|
|
||||||
Phonon::Path audioPath;
|
Phonon::Path audioPath;
|
||||||
Phonon::Effect* audioEffect;
|
Phonon::Effect* audioEffect;
|
||||||
|
|
||||||
|
Phonon::AudioDataOutput* audioDataOutput;
|
||||||
|
Phonon::Path audioDataPath;
|
||||||
|
|
||||||
|
|
||||||
unsigned int timeElapsed;
|
unsigned int timeElapsed;
|
||||||
bool expectStop;
|
bool expectStop;
|
||||||
bool waitingOnNewTrack;
|
bool waitingOnNewTrack;
|
||||||
|
Reference in New Issue
Block a user