Classified ads
Public Slots | Signals | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
AudioPlayer Class Reference

Class for playback of audio stream, via speaker or other audio dev. More...

#include <audioplayer.h>

Inheritance diagram for AudioPlayer:
Inheritance graph
[legend]
Collaboration diagram for AudioPlayer:
Collaboration graph
[legend]

Public Slots

void insertAudioFrame (const QByteArray &aFrame)
 
void finishedPlaying (QAudio::State aState)
 
void notify ()
 

Signals

void error (int aError, const QString &aExplanation)
 
void audioMaxLevel (float aMaxVolume)
 

Public Member Functions

 AudioPlayer (Model &aModel, int aFrequency=8000, int aNumChannels=1, int aSampleSize=16)
 
 ~AudioPlayer ()
 
void stop ()
 
virtual qint64 bytesAvailable () const
 

Protected Member Functions

virtual qint64 writeData (const char *data, qint64 maxSize)
 
virtual qint64 readData (char *data, qint64 maxSize)
 
virtual bool open (OpenMode mode)
 
virtual bool isSequential () const
 

Private Attributes

QAudioFormat iFormat
 
QAudioOutput * iAudioOutput
 
QByteArray iAudioBuffer
 
bool iNeedsToRun
 
ModeliModel
 
const int iFrequency
 
const int iNumChannels
 
const int iSampleSize
 

Detailed Description

Class for playback of audio stream, via speaker or other audio dev.

This class encapsulates audio output device and expects input as array of floats.

Constructor & Destructor Documentation

AudioPlayer::AudioPlayer ( Model aModel,
int  aFrequency = 8000,
int  aNumChannels = 1,
int  aSampleSize = 16 
)

Constructor. Currently only samplesize 16 is supported, all other sizes will output only noise. Also see input data format at insertAudioFrame method.

Parameters
aFrequencyis number of samples per second
aNumChannelsis number of channels in stream
aSampleSizeis number of bits in each sample. As currently the audio format is in array of floats that are anyway in native format and in [-1,1] range this parameter is a little bit meaningless.
AudioPlayer::~AudioPlayer ( )

Member Function Documentation

void AudioPlayer::audioMaxLevel ( float  aMaxVolume)
signal

signals that communicates max value of a outputted frame

virtual qint64 AudioPlayer::bytesAvailable ( ) const
inlinevirtual
void AudioPlayer::error ( int  aError,
const QString &  aExplanation 
)
signal

this is not method but signal ; if in error, get emit()ted

void AudioPlayer::finishedPlaying ( QAudio::State  aState)
slot

Notify slot from actual player device

void AudioPlayer::insertAudioFrame ( const QByteArray &  aFrame)
slot

Method/slot for playing back snippet of audio.

Parameters
aFrame32-bit, native-encoding, floating point format audio/pcm data in 8kHz. Floating point range in [-1,1].
virtual bool AudioPlayer::isSequential ( ) const
inlineprotectedvirtual
void AudioPlayer::notify ( )
slot

notify from audio output device

virtual bool AudioPlayer::open ( OpenMode  mode)
protectedvirtual

method for opening QIODevice: sets the open mode that's about it.

virtual qint64 AudioPlayer::readData ( char *  data,
qint64  maxSize 
)
protectedvirtual

From QIODevice: method that QAudioOutput class instance will use to read the actual audio data. Data comes from internal buffer and is inserted into buffer using insertAudioFrame.

Parameters
datapointer to buffer where data will be written
maxSizemax data size available in buffer
Returns
number of bytes actually written into buffer
void AudioPlayer::stop ( )

method for stopping playback

virtual qint64 AudioPlayer::writeData ( const char *  data,
qint64  maxSize 
)
protectedvirtual

Write-method of QIODevice - QIODevice here is used for feeding the player and data is actually written using insertAudioFrame method so implementation of this method is actually empty.

Parameters
datathat will not be written anywhere.
maxSizemax data size to be not written
Returns
always 0

Member Data Documentation

QByteArray AudioPlayer::iAudioBuffer
private

first buffered here, then written in chunks

QAudioOutput* AudioPlayer::iAudioOutput
private
QAudioFormat AudioPlayer::iFormat
private
const int AudioPlayer::iFrequency
private

datamodel

Model& AudioPlayer::iModel
private
bool AudioPlayer::iNeedsToRun
private
const int AudioPlayer::iNumChannels
private
const int AudioPlayer::iSampleSize
private

The documentation for this class was generated from the following file: