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::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::~AudioPlayer ( )

Member Function Documentation

◆ audioMaxLevel

void AudioPlayer::audioMaxLevel ( float  aMaxVolume)
signal

signals that communicates max value of a outputted frame

◆ bytesAvailable()

virtual qint64 AudioPlayer::bytesAvailable ( ) const
inlinevirtual

◆ error

void AudioPlayer::error ( int  aError,
const QString &  aExplanation 
)
signal

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

◆ finishedPlaying

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

Notify slot from actual player device

◆ insertAudioFrame

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].

◆ isSequential()

virtual bool AudioPlayer::isSequential ( ) const
inlineprotectedvirtual

◆ notify

void AudioPlayer::notify ( )
slot

notify from audio output device

◆ open()

virtual bool AudioPlayer::open ( OpenMode  mode)
protectedvirtual

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

◆ readData()

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

◆ stop()

void AudioPlayer::stop ( )

method for stopping playback

◆ writeData()

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

◆ iAudioBuffer

QByteArray AudioPlayer::iAudioBuffer
private

first buffered here, then written in chunks

◆ iAudioOutput

QAudioOutput* AudioPlayer::iAudioOutput
private

◆ iFormat

QAudioFormat AudioPlayer::iFormat
private

◆ iFrequency

const int AudioPlayer::iFrequency
private

datamodel

◆ iModel

Model& AudioPlayer::iModel
private

◆ iNeedsToRun

bool AudioPlayer::iNeedsToRun
private

◆ iNumChannels

const int AudioPlayer::iNumChannels
private

◆ iSampleSize

const int AudioPlayer::iSampleSize
private

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