Oboe
A library for creating real-time audio apps on Android
Loading...
Searching...
No Matches
Public Member Functions | List of all members
oboe::FullDuplexStream Class Referenceabstract

#include <FullDuplexStream.h>

Inheritance diagram for oboe::FullDuplexStream:
oboe::AudioStreamDataCallback

Public Member Functions

void setInputStream (AudioStream *stream)
 
void setSharedInputStream (std::shared_ptr< AudioStream > &stream)
 
AudioStreamgetInputStream ()
 
void setOutputStream (AudioStream *stream)
 
void setSharedOutputStream (std::shared_ptr< AudioStream > &stream)
 
AudioStreamgetOutputStream ()
 
virtual Result start ()
 
virtual Result stop ()
 
virtual ResultWithValue< int32_treadInput (int32_t numFrames)
 
virtual DataCallbackResult onBothStreamsReady (const void *inputData, int numInputFrames, void *outputData, int numOutputFrames)=0
 
DataCallbackResult onAudioReady (AudioStream *, void *audioData, int numFrames)
 
void setNumInputBurstsCushion (int32_t numBursts)
 
int32_t getNumInputBurstsCushion () const
 
void setMinimumFramesBeforeRead (int32_t numFrames)
 
int32_t getMinimumFramesBeforeRead () const
 
- Public Member Functions inherited from oboe::AudioStreamDataCallback
virtual DataCallbackResult onAudioReady (AudioStream *audioStream, void *audioData, int32_t numFrames)=0
 

Detailed Description

FullDuplexStream can be used to synchronize an input and output stream.

For the builder of the output stream, call setDataCallback() with this object.

When both streams are ready, onAudioReady() of the output stream will call onBothStreamsReady(). Callers must override onBothStreamsReady().

To ensure best results, open an output stream before the input stream. Call inputBuilder.setBufferCapacityInFrames(mOutputStream->getBufferCapacityInFrames() * 2). Also, call inputBuilder.setSampleRate(mOutputStream->getSampleRate()).

Callers must call setInputStream() and setOutputStream(). Call start() to start both streams and stop() to stop both streams. Caller is responsible for closing both streams.

Callers should handle error callbacks with setErrorCallback() for the output stream. When an error callback occurs for the output stream, Oboe will stop and close the output stream. The caller is responsible for stopping and closing the input stream. The caller should also reopen and restart both streams when the error callback is ErrorDisconnected. See the LiveEffect sample as an example of this.

Member Function Documentation

◆ getInputStream()

AudioStream * oboe::FullDuplexStream::getInputStream ( )
inline

Gets the current input stream. This function tries to return the shared input stream if it is set before the raw input stream.

Returns
pointer to an output stream or nullptr.

◆ getMinimumFramesBeforeRead()

int32_t oboe::FullDuplexStream::getMinimumFramesBeforeRead ( ) const
inline

Gets the minimum number of frames in the input stream buffer before calling readInput().

Returns
minimum number of frames before reading

◆ getNumInputBurstsCushion()

int32_t oboe::FullDuplexStream::getNumInputBurstsCushion ( ) const
inline

Get the number of bursts left in the input buffer as a cushion.

Returns
number of bursts in the input buffer as a cushion

◆ getOutputStream()

AudioStream * oboe::FullDuplexStream::getOutputStream ( )
inline

Gets the current output stream. This function tries to return the shared output stream if it is set before the raw output stream.

Returns
pointer to an output stream or nullptr.

◆ onAudioReady()

DataCallbackResult oboe::FullDuplexStream::onAudioReady ( AudioStream ,
void audioData,
int  numFrames 
)
inline

Called when the output stream is ready to process audio. This in return calls onBothStreamsReady() when data is available on both streams. Callers should call this function when the output stream is ready. Callers must override onBothStreamsReady().

Parameters
audioStreampointer to the associated stream
audioDataa place to put output data
numFramesnumber of frames to be processed
Returns
DataCallbackResult::Continue or DataCallbackResult::Stop

◆ onBothStreamsReady()

virtual DataCallbackResult oboe::FullDuplexStream::onBothStreamsReady ( const void inputData,
int  numInputFrames,
void outputData,
int  numOutputFrames 
)
pure virtual

Called when data is available on both streams. Caller should override this method. numInputFrames and numOutputFrames may be zero.

Parameters
inputDatabuffer containing input data
numInputFramesnumber of input frames
outputDataa place to put output data
numOutputFramesnumber of output frames
Returns
DataCallbackResult::Continue or DataCallbackResult::Stop

◆ readInput()

virtual ResultWithValue< int32_t > oboe::FullDuplexStream::readInput ( int32_t  numFrames)
inlinevirtual

Reads input from the input stream. Callers should not call this directly as this is called in onAudioReady().

Parameters
numFrames
Returns
result of the operation

◆ setInputStream()

void oboe::FullDuplexStream::setInputStream ( AudioStream stream)
inline

Sets the input stream.

Deprecated:
Call setSharedInputStream(std::shared_ptr<AudioStream> &stream) instead.
Parameters
streamthe output stream

◆ setMinimumFramesBeforeRead()

void oboe::FullDuplexStream::setMinimumFramesBeforeRead ( int32_t  numFrames)
inline

Minimum number of frames in the input stream buffer before calling readInput().

Parameters
numFramesnumber of bursts in the input buffer as a cushion

◆ setNumInputBurstsCushion()

void oboe::FullDuplexStream::setNumInputBurstsCushion ( int32_t  numBursts)
inline

This is a cushion between the DSP and the application processor cursors to prevent collisions. Typically 0 for latency measurements or 1 for glitch tests.

Parameters
numBurstsnumber of bursts to leave in the input buffer as a cushion

◆ setOutputStream()

void oboe::FullDuplexStream::setOutputStream ( AudioStream stream)
inline

Sets the output stream.

Deprecated:
Call setSharedOutputStream(std::shared_ptr<AudioStream> &stream) instead.
Parameters
streamthe output stream

◆ setSharedInputStream()

void oboe::FullDuplexStream::setSharedInputStream ( std::shared_ptr< AudioStream > &  stream)
inline

Sets the input stream. Calling this is mandatory.

Parameters
streamthe output stream

◆ setSharedOutputStream()

void oboe::FullDuplexStream::setSharedOutputStream ( std::shared_ptr< AudioStream > &  stream)
inline

Sets the output stream. Calling this is mandatory.

Parameters
streamthe output stream

◆ start()

virtual Result oboe::FullDuplexStream::start ( )
inlinevirtual

Attempts to start both streams. Please call setInputStream() and setOutputStream() before calling this function.

Returns
result of the operation

◆ stop()

virtual Result oboe::FullDuplexStream::stop ( )
inlinevirtual

Stops both streams. Returns Result::OK if neither stream had an error during close.

Returns
result of the operation

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