Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QAudioInput Class

TheQAudioInput class provides an interface for receiving audio data from an audio input device.More...

Header:#include <QAudioInput>
Since: Qt 4.6
Inherits:QObject

Public Functions

QAudioInput(const QAudioFormat & format = QAudioFormat(), QObject * parent = 0)
QAudioInput(const QAudioDeviceInfo & audioDevice, const QAudioFormat & format = QAudioFormat(), QObject * parent = 0)
~QAudioInput()
intbufferSize() const
intbytesReady() const
qint64elapsedUSecs() const
QAudio::Errorerror() const
QAudioFormatformat() const
intnotifyInterval() const
intperiodSize() const
qint64processedUSecs() const
voidreset()
voidresume()
voidsetBufferSize(int value)
voidsetNotifyInterval(int ms)
voidstart(QIODevice * device)
QIODevice *start()
QAudio::Statestate() const
voidstop()
voidsuspend()
  • 29 public functions inherited fromQObject

Signals

voidnotify()
voidstateChanged(QAudio::State state)

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 7 static public members inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQAudioInput class provides an interface for receiving audio data from an audio input device.

You can construct an audio input with the system'sdefault audio input device. It is also possible to createQAudioInput with a specificQAudioDeviceInfo. When you create the audio input, you should also send in theQAudioFormat to be used for the recording (see theQAudioFormat class description for details).

To record to a file:

QAudioInput lets you record audio with an audio input device. The default constructor of this class will use the systems default audio device, but you can also specify aQAudioDeviceInfo for a specific device. You also need to pass in theQAudioFormat in which you wish to record.

Starting up theQAudioInput is simply a matter of callingstart() with aQIODevice opened for writing. For instance, to record to a file, you can:

QFile outputFile;// class member.QAudioInput*audioInput;// class member.    ...void startRecording()    {        outputFile.setFileName("/tmp/test.raw");        outputFile.open(QIODevice::WriteOnly|QIODevice::Truncate );QAudioFormat format;// set up the format you want, eg.        format.setFrequency(8000);        format.setChannels(1);        format.setSampleSize(8);        format.setCodec("audio/pcm");        format.setByteOrder(QAudioFormat::LittleEndian);        format.setSampleType(QAudioFormat::UnSignedInt);QAudioDeviceInfo info=QAudioDeviceInfo::defaultInputDevice();if (!info.isFormatSupported(format)) {qWarning()<<"default format not supported try to use nearest";            format= info.nearestFormat(format);        }        audioInput=newQAudioInput(format,this);QTimer::singleShot(3000,this, SLOT(stopRecording()));        audioInput->start(&outputFile);// Records audio for 3000ms    }

This will start recording if the format specified is supported by the input device (you can check this withQAudioDeviceInfo::isFormatSupported(). In case there are any snags, use theerror() function to check what went wrong. We stop recording in thestopRecording() slot.

void stopRecording()    {        audioInput->stop();        outputFile.close();delete audioInput;    }

At any point in time,QAudioInput will be in one of four states: active, suspended, stopped, or idle. These states are specified by theQAudio::State enum. You can request a state change directly throughsuspend(),resume(),stop(),reset(), andstart(). The current state is reported bystate().QAudioOutput will also signal you when the state changes (stateChanged()).

QAudioInput provides several ways of measuring the time that has passed since thestart() of the recording. TheprocessedUSecs() function returns the length of the stream in microseconds written, i.e., it leaves out the times the audio input was suspended or idle. TheelapsedUSecs() function returns the time elapsed sincestart() was called regardless of which states theQAudioInput has been in.

If an error should occur, you can fetch its reason witherror(). The possible error reasons are described by theQAudio::Error enum. TheQAudioInput will enter theStoppedState when an error is encountered. Connect to thestateChanged() signal to handle the error:

void stateChanged(QAudio::State newState)    {switch(newState) {caseQAudio::StoppedState:if (audioInput->error()!=QAudio::NoError) {// Perform error handling            }else {            }break;

Symbian Platform Security Requirements

On Symbian, processes which use this class must have theUserEnvironment platform security capability. If the client process lacks this capability, calls to either overload ofstart() will fail. This failure is indicated by theQAudioInput object setting itserror() value toQAudio::OpenError and then emitting astateChanged(QAudio::StoppedState) signal.

Platform security capabilities are added via theTARGET.CAPABILITY qmake variable.

See alsoQAudioOutput andQAudioDeviceInfo.

Member Function Documentation

QAudioInput::QAudioInput(constQAudioFormat & format = QAudioFormat(),QObject * parent = 0)

Construct a new audio input and attach it toparent. The default audio input device is used with the outputformat parameters.

QAudioInput::QAudioInput(constQAudioDeviceInfo & audioDevice, constQAudioFormat & format = QAudioFormat(),QObject * parent = 0)

Construct a new audio input and attach it toparent. The device referenced byaudioDevice is used with the inputformat parameters.

QAudioInput::~QAudioInput()

Destroy this audio input.

int QAudioInput::bufferSize() const

Returns the audio buffer size in milliseconds.

If called beforestart(), returns platform default value. If called beforestart() butsetBufferSize() was called prior, returns value set bysetBufferSize(). If called afterstart(), returns the actual buffer size being used. This may not be what was set previously bysetBufferSize().

See alsosetBufferSize().

int QAudioInput::bytesReady() const

Returns the amount of audio data available to read in bytes.

NOTE: returned value is only valid while inQAudio::ActiveState orQAudio::IdleState state, otherwise returns zero.

qint64 QAudioInput::elapsedUSecs() const

Returns the microseconds sincestart() was called, including time in Idle and Suspend states.

QAudio::Error QAudioInput::error() const

Returns the error state.

QAudioFormat QAudioInput::format() const

Returns theQAudioFormat being used.

[signal]void QAudioInput::notify()

This signal is emitted when x ms of audio data has been processed the interval set bysetNotifyInterval(x).

int QAudioInput::notifyInterval() const

Returns the notify interval in milliseconds.

See alsosetNotifyInterval().

int QAudioInput::periodSize() const

Returns the period size in bytes.

Note: This is the recommended read size in bytes.

qint64 QAudioInput::processedUSecs() const

Returns the amount of audio data processed sincestart() was called in microseconds.

void QAudioInput::reset()

Drops all audio data in the buffers, resets buffers to zero.

void QAudioInput::resume()

Resumes processing audio data after asuspend().

Setserror() toQAudio::NoError. Setsstate() toQAudio::ActiveState if you previously called start(QIODevice*). Setsstate() toQAudio::IdleState if you previously calledstart(). emitsstateChanged() signal.

void QAudioInput::setBufferSize(int value)

Sets the audio buffer size tovalue milliseconds.

Note: This function can be called anytime beforestart(), calls to this are ignored afterstart(). It should not be assumed that the buffer size set is the actual buffer size used, callingbufferSize() anytime afterstart() will return the actual buffer size being used.

See alsobufferSize().

void QAudioInput::setNotifyInterval(int ms)

Sets the interval fornotify() signal to be emitted. This is based on thems of audio data processed not on actual real-time. The minimum resolution of the timer is platform specific and values should be checked withnotifyInterval() to confirm actual value being used.

See alsonotifyInterval().

void QAudioInput::start(QIODevice * device)

Uses thedevice as theQIODevice to transfer data. Passing aQIODevice allows the data to be transferred without any extra code. All that is required is to open theQIODevice.QAudioInput does not take ownership ofdevice.

TheQAudioInput will write to the device when new data is available. You can subclassQIODevice and reimplementwriteData() if you wish to access the data. If you simply want to save data to a file, you can pass aQFile to this function.

If able to successfully get audio data from the systems audio device thestate() is set to eitherQAudio::ActiveState orQAudio::IdleState,error() is set toQAudio::NoError and thestateChanged() signal is emitted.

If a problem occurs during this process theerror() is set toQAudio::OpenError,state() is set toQAudio::StoppedState andstateChanged() signal is emitted.

QAudioInput#Symbian Platform Security Requirements

See alsoQIODevice.

QIODevice * QAudioInput::start()

Returns a pointer to a newQIODevice that will be used to handle the data transfer. ThisQIODevice can be used toread() audio data directly. You will typically connect to thereadyRead() signal, and read from the device in the slot you connect to.QAudioInput keeps ownership of the device.

If able to access the systems audio device thestate() is set toQAudio::IdleState,error() is set toQAudio::NoError and thestateChanged() signal is emitted.

If a problem occurs during this process theerror() is set toQAudio::OpenError,state() is set toQAudio::StoppedState andstateChanged() signal is emitted.

QAudioInput#Symbian Platform Security Requirements

See alsoQIODevice.

QAudio::State QAudioInput::state() const

Returns the state of audio processing.

[signal]void QAudioInput::stateChanged(QAudio::State state)

This signal is emitted when the devicestate has changed.

void QAudioInput::stop()

Stops the audio input, detaching from the system resource.

Setserror() toQAudio::NoError,state() toQAudio::StoppedState and emitstateChanged() signal.

void QAudioInput::suspend()

Stops processing audio data, preserving buffered audio data.

Setserror() toQAudio::NoError,state() toQAudio::SuspendedState and emitstateChanged() signal.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp