reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

Gives access to audio input and output devices. More...

#include <ofSoundStream.h>

Public Member Functions

 ofSoundStream ()
 
void setSoundStream (std::shared_ptr< ofBaseSoundStream > soundStreamPtr)
 
std::shared_ptr< ofBaseSoundStreamgetSoundStream ()
 
void printDeviceList () const
 Prints a list of available audio devices to the console.
 
std::vector< ofSoundDevicegetDeviceList (ofSoundDevice::Api api=ofSoundDevice::Api::DEFAULT) const
 Retrieves a list of available audio devices.
 
std::vector< ofSoundDevicegetMatchingDevices (const std::string &name, unsigned int inChannels=UINT_MAX, unsigned int outChannels=UINT_MAX, ofSoundDevice::Api api=ofSoundDevice::Api::DEFAULT) const
 Get all devices which match the arguments (name can be a partial match)
 
 OF_DEPRECATED_MSG ("Use an ofSoundStreamSettings object instead of directly passing the parameters", void setDeviceID(int deviceID))
 sets the device represented by the stream, see ofSoundStream::getDeviceList().
 
 OF_DEPRECATED_MSG ("Use an ofSoundStreamSettings object instead of directly passing the parameters", void setDevice(const ofSoundDevice &device))
 sets the device represented by the stream, see ofSoundStream::getDeviceList().
 
bool setup (const ofSoundStreamSettings &settings)
 
 OF_DEPRECATED_MSG ("Use an ofSoundStreamSettings object instead of directly passing the parameters", bool setup(ofBaseApp *app, int outChannels, int inChannels, int sampleRate, int bufferSize, int nBuffers))
 
 OF_DEPRECATED_MSG ("Use an ofSoundStreamSettings object instead of directly passing the parameters", bool setup(int outChannels, int inChannels, int sampleRate, int bufferSize, int nBuffers))
 
void setInput (ofBaseSoundInput *soundInput)
 Sets the object which will have audioIn() called when the device receives audio.
 
void setInput (ofBaseSoundInput &soundInput)
 Sets the object which will have audioIn() called when the device receives audio.
 
void setOutput (ofBaseSoundOutput *soundOutput)
 Sets the object which will have audioOut() called when the device requests audio.
 
void setOutput (ofBaseSoundOutput &soundOutput)
 Sets the object which will have audioOut() called when the device requests audio.
 
void start ()
 Starts a stream (note that setup() will start the stream on its own).
 
void stop ()
 Stops the stream.
 
void close ()
 stops the stream and cleans up its resources.
 
uint64_t getTickCount () const
 Queries the number of "ticks" passed since the stream started.
 
int getNumInputChannels () const
 Queries the stream's number of input channels.
 
int getNumOutputChannels () const
 Queries the stream's number of output channels.
 
int getSampleRate () const
 Queries the stream's sample rate.
 
int getBufferSize () const
 Queries the stream's buffer size.
 
 OF_DEPRECATED_MSG ("Use printDeviceList instead", std::vector< ofSoundDevice > listDevices() const)
 Retrieves a list of available audio devices and prints device descriptions to the console.
 

Protected Attributes

std::shared_ptr< ofBaseSoundStreamsoundStream
 
int tmpDeviceId = -1
 

Detailed Description

Gives access to audio input and output devices.

ofSoundStream controls access to your computer's audio input and output devices. For example, you could use an ofSoundStream to get live input from a microphone, or generate sound in realtime for your computer's speakers.

A typical openFrameworks app will use just one ofSoundStream, and you might not even need to use this class directly at all if you don't need to query things like the sample rate or buffer size. In order to start receiving or generating audio, your ofApp should implement either ofBaseApp::audioIn() or ofBaseApp::audioOut() respectively, and then call ofSoundStreamSetup(). You can find examples of this in either the audioInputExample or the audioOutputExample.

Starting a stream with 0 input or output channels will prevent audioIn() or audioOut() from being called, respectively.

Some platforms (iOS, for example) will expose additional platform-specific sound stream functionality. See the platform-specific examples for demos.

Warning
Be aware that audioIn() and audioOut() will be called on a different thread from your app's update() / draw() thread.

Constructor & Destructor Documentation

◆ ofSoundStream()

ofSoundStream::ofSoundStream ( )

Member Function Documentation

◆ close()

void ofSoundStream::close ( )

stops the stream and cleans up its resources.

◆ getBufferSize()

int ofSoundStream::getBufferSize ( ) const

Queries the stream's buffer size.

Returns
the current buffer size of the stream.

◆ getDeviceList()

vector< ofSoundDevice > ofSoundStream::getDeviceList ( ofSoundDevice::Api  api = ofSoundDevice::Api::DEFAULT) const

Retrieves a list of available audio devices.

◆ getMatchingDevices()

vector< ofSoundDevice > ofSoundStream::getMatchingDevices ( const std::string &  name,
unsigned int  inChannels = UINT_MAX,
unsigned int  outChannels = UINT_MAX,
ofSoundDevice::Api  api = ofSoundDevice::Api::DEFAULT 
) const

Get all devices which match the arguments (name can be a partial match)

◆ getNumInputChannels()

int ofSoundStream::getNumInputChannels ( ) const

Queries the stream's number of input channels.

Returns
the number of input channels (e.g. 2 for stereo).

◆ getNumOutputChannels()

int ofSoundStream::getNumOutputChannels ( ) const

Queries the stream's number of output channels.

Returns
the number of output channels (e.g. 2 for stereo).

◆ getSampleRate()

int ofSoundStream::getSampleRate ( ) const

Queries the stream's sample rate.

Returns
the current sample rate of the stream
Note
The returned sample rate may differ from the requested sample rate.

◆ getSoundStream()

shared_ptr< ofBaseSoundStream > ofSoundStream::getSoundStream ( )

◆ getTickCount()

uint64_t ofSoundStream::getTickCount ( ) const

Queries the number of "ticks" passed since the stream started.

This is a representation of how many buffers have passed through the stream since it started. This can be converted to seconds with the following formula:

secondsOfPlayback = (tickCount * bufferSize) / sampleRate

Returns
number of buffers passed through the stream since it started.

◆ OF_DEPRECATED_MSG() [1/5]

ofSoundStream::OF_DEPRECATED_MSG ( "Use an ofSoundStreamSettings object instead of directly passing the parameters"  ,
bool   setupint outChannels, int inChannels, int sampleRate, int bufferSize, int nBuffers 
)

◆ OF_DEPRECATED_MSG() [2/5]

ofSoundStream::OF_DEPRECATED_MSG ( "Use an ofSoundStreamSettings object instead of directly passing the parameters"  ,
bool   setupofBaseApp *app, int outChannels, int inChannels, int sampleRate, int bufferSize, int nBuffers 
)

◆ OF_DEPRECATED_MSG() [3/5]

ofSoundStream::OF_DEPRECATED_MSG ( "Use an ofSoundStreamSettings object instead of directly passing the parameters"  ,
void   setDeviceconst ofSoundDevice &device 
)

sets the device represented by the stream, see ofSoundStream::getDeviceList().

◆ OF_DEPRECATED_MSG() [4/5]

ofSoundStream::OF_DEPRECATED_MSG ( "Use an ofSoundStreamSettings object instead of directly passing the parameters"  ,
void   setDeviceIDint deviceID 
)

sets the device represented by the stream, see ofSoundStream::getDeviceList().

◆ OF_DEPRECATED_MSG() [5/5]

ofSoundStream::OF_DEPRECATED_MSG ( "Use printDeviceList instead"  ,
std::vector< ofSoundDevice > listDevices() const   
)

Retrieves a list of available audio devices and prints device descriptions to the console.

◆ printDeviceList()

void ofSoundStream::printDeviceList ( ) const

Prints a list of available audio devices to the console.

◆ setInput() [1/2]

void ofSoundStream::setInput ( ofBaseSoundInput soundInput)

Sets the object which will have audioIn() called when the device receives audio.

◆ setInput() [2/2]

void ofSoundStream::setInput ( ofBaseSoundInput soundInput)

Sets the object which will have audioIn() called when the device receives audio.

◆ setOutput() [1/2]

void ofSoundStream::setOutput ( ofBaseSoundOutput soundOutput)

Sets the object which will have audioOut() called when the device requests audio.

◆ setOutput() [2/2]

void ofSoundStream::setOutput ( ofBaseSoundOutput soundOutput)

Sets the object which will have audioOut() called when the device requests audio.

◆ setSoundStream()

void ofSoundStream::setSoundStream ( std::shared_ptr< ofBaseSoundStream soundStreamPtr)

◆ setup()

bool ofSoundStream::setup ( const ofSoundStreamSettings settings)

◆ start()

void ofSoundStream::start ( )

Starts a stream (note that setup() will start the stream on its own).

◆ stop()

void ofSoundStream::stop ( )

Stops the stream.

Member Data Documentation

◆ soundStream

std::shared_ptr<ofBaseSoundStream> ofSoundStream::soundStream
protected

◆ tmpDeviceId

int ofSoundStream::tmpDeviceId = -1
protected

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