Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QAudioInput Class Reference
[QtBluetoothModule, QtMediaModule, QtPimModule, QtTelephonyModule]

The QAudioInput class provides an interface to read raw audio data from a microphone input. More...

    #include <QAudioInput>

Inherits QIODevice.

Public Functions

Protected Functions

Additional Inherited Members


Detailed Description

The QAudioInput class provides an interface to read raw audio data from a microphone input.

Client applications that need direct access to the microphone should use QAudioInput to capture raw audio samples for further processing. This class abstracts the details of the underlying operating system, so that clients do not need to be aware of whether the operating system uses OSS or Alsa.

The usual sequence for opening the microphone is as follows:

    QAudioInput *audio = new QAudioInput();
    audio->setFrequency( 11025 );
    audio->setChannels( 1 );
    if ( audio->open( QIODevice::ReadOnly ) )
        audio->read( buffer, sizeof( buffer ) );

You must call read() at least once just after opening because some devices will not start recording until the first read is performed.

The audio data will be normalized to signed 16-bit samples in host byte order, regardless of what the underlying device supports.

Use the readyRead() signal to be notified of new input.

See also QAudioOutput.


Member Function Documentation

QAudioInput::QAudioInput ( const QByteArray & device, QObject * parent = 0 )

Construct a new audio input stream and attach it to parent. The device that is opened is specified by device. The default parameters are 44100 Hz Stereo, with 16-bit samples.

The device parameter is implementation-specific, and might not be honored by all implementations. It is usually an Alsa device name such as plughw:0,0. The string default can be passed for device if the client application wishes to use the default device and is not concerned with what that default device may be called.

QAudioInput::QAudioInput ( QObject * parent = 0 )

Construct a new audio input stream and attach it to parent. The default parameters are 44100 Hz Stereo, with 16-bit samples.

QAudioInput::~QAudioInput ()

Destroy this audio input stream.

qint64 QAudioInput::bytesAvailable () const   [virtual]

Returns the number of bytes that are available for reading.

Reimplemented from QIODevice.

See also read().

int QAudioInput::channels () const

Returns the number of playback channels. The default value is 2.

See also setChannels().

void QAudioInput::close ()   [virtual]

Closes this audio input stream.

Reimplemented from QIODevice.

int QAudioInput::frequency () const

Returns the current frequency of audio samples. The default value is 44100.

See also setFrequency().

bool QAudioInput::isSequential () const   [virtual]

Determines if this QIODevice is sequential. Always returns true.

Reimplemented from QIODevice.

bool QAudioInput::open ( QIODevice::OpenMode mode )

Opens this audio input stream in mode. Returns true if the audio input stream could be opened; false otherwise.

qint64 QAudioInput::readData ( char * data, qint64 maxlen )   [virtual protected]

Reads a block of raw audio samples from the input device into data. The samples are guaranteed to be signed, 16 bits in size, and in host byte order. The maxlen value is the maximum buffer size in bytes, which is twice the number of logical samples.

Returns the number of bytes read, or zero if none are currently available. This function will not block.

If the device is mono, then the number of raw samples is the same as the number of logical samples. If the device is stereo, then the number of raw samples is twice the number of logical samples.

This function may reduce the length to a logical device buffer size. Use bytesAvailable() to determine if there are still bytes left to be read.

Reimplemented from QIODevice.

int QAudioInput::samplesPerBlock () const

Returns the number of samples per block that the audio input stream will attempt to deliver upon each read. The default value is -1, which indicates that the hardware should dictate the block size.

See also setSamplesPerBlock().

void QAudioInput::setChannels ( int value )

Sets the number of playback channels to value. Should be called before open().

See also channels().

void QAudioInput::setFrequency ( int value )

Sets the frequency of audio samples to value. Should be called before open().

See also frequency().

void QAudioInput::setSamplesPerBlock ( int value )

Sets the number of samples per block that the audio input stream will attempt to deliver upon each read to value. The value -1 indicates that the hardware should dictate the block size. Should be called before open().

See also samplesPerBlock().

qint64 QAudioInput::writeData ( const char * data, qint64 len )   [virtual protected]

Writes len bytes from data to this QIODevice. Not used for audio input devices.

Reimplemented from QIODevice.


Copyright © 2009 Trolltech Trademarks
Qt Extended 4.4.3