Struct portaudio::pa::PaStream [-]  [+] [src]

pub struct PaStream<S> {
    // some fields omitted
}

Representation of an audio stream, where the format of the stream is defined by the S parameter.

Methods

impl<S> PaStream<S>

fn new(sample_format: PaSampleFormat) -> PaStream<S>

Constructor for PaStream.

Return a new PaStream.

fn open(&mut self, input_parameters: Option<&PaStreamParameters>, output_parameters: Option<&PaStreamParameters>, sample_rate: f64, frames_per_buffer: u32, stream_flags: PaStreamFlags) -> PaError

Opens a stream for either input, output or both.

Arguments

  • input_parameters - A structure that describes the input parameters used by the opened stream.
  • output_parameters - A structure that describes the output parameters used by the opened stream.
  • sample_rate - The desired sample_rate. For full-duplex streams it is the sample rate for both input and output
  • frames_per_buffer - The number of frames passed to the stream callback function.
  • stream_flags -Flags which modify the behavior of the streaming process. This parameter may contain a combination of flags ORed together. Some flags may only be relevant to certain buffer formats.

Upon success returns PaNoError and the stream is inactive (stopped). If fails, a non-zero error code is returned.

fn open_default(&mut self, sample_rate: f64, frames_per_buffer: u32, num_input_channels: i32, num_output_channels: i32, sample_format: PaSampleFormat) -> PaError

A simplified version of open() that opens the default input and/or output devices.

Arguments

  • sample_rate - The desired sample_rate. For full-duplex streams it is the sample rate for both input and output
  • frames_per_buffer - The number of frames passed to the stream callback function
  • num_input_channels - The number of channels of sound that will be supplied to the stream callback or returned by Pa_ReadStream. It can range from 1 to the value of maxInputChannels in the PaDeviceInfo record for the default input device. If 0 the stream is opened as an output-only stream.
  • num_output_channels - The number of channels of sound to be delivered to the stream callback or passed to Pa_WriteStream. It can range from 1 to the value of maxOutputChannels in the PaDeviceInfo record for the default output device. If 0 the stream is opened as an output-only stream.
  • sample_format - The sample_format for the input and output buffers.

Upon success returns PaNoError and the stream is inactive (stopped). If fails, a non-zero error code is returned.

fn close(&mut self) -> PaError

Closes an audio stream. If the audio stream is active it discards any pending buffers as if abort_tream() had been called.

fn start(&mut self) -> PaError

Commences audio processing.

fn stop(&mut self) -> PaError

Terminates audio processing. It waits until all pending audio buffers have been played before it returns.

fn abort(&mut self) -> PaError

Terminates audio processing immediately without waiting for pending buffers to complete.

fn is_stopped(&self) -> PaError

Determine whether the stream is stopped. A stream is considered to be stopped prior to a successful call to start_stream and after a successful call to stop_stream or abort_stream. If a stream callback returns a value other than PaContinue the stream is NOT considered to be stopped.

Return one (1) when the stream is stopped, zero (0) when the stream is running or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

fn is_active(&self) -> Result<bool, PaError>

Determine whether the stream is active. A stream is active after a successful call to start_stream(), until it becomes inactive either as a result of a call to stop_stream() or abort_stream(), or as a result of a return value other than paContinue from the stream callback. In the latter case, the stream is considered inactive after the last buffer has finished playing.

Return Ok(true) when the stream is active (ie playing or recording audio), Ok(false) when not playing or, a Err(PaError) if PortAudio is not initialized or an error is encountered.

fn get_stream_time(&self) -> PaTime

Returns the current time in seconds for a stream according to the same clock used to generate callback PaStreamCallbackTimeInfo timestamps. The time values are monotonically increasing and have unspecified origin.

get_stream_time returns valid time values for the entire life of the stream, from when the stream is opened until it is closed. Starting and stopping the stream does not affect the passage of time returned by Pa_GetStreamTime.

Return the stream's current time in seconds, or 0 if an error occurred.

fn get_stream_cpu_load(&self) -> f64

Retrieve CPU usage information for the specified stream.

The "CPU Load" is a fraction of total CPU time consumed by a callback stream's audio processing routines including, but not limited to the client supplied stream callback. This function does not work with blocking read/write streams.

fn get_stream_read_available(&self) -> i64

Retrieve the number of frames that can be read from the stream without waiting.

Returns a non-negative value representing the maximum number of frames that can be read from the stream without blocking or busy waiting or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

fn get_stream_write_available(&self) -> i64

Retrieve the number of frames that can be written to the stream without waiting.

Return a non-negative value representing the maximum number of frames that can be written to the stream without blocking or busy waiting or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

fn write(&self, output_buffer: Vec<S>, frames_per_buffer: u32) -> PaError

Write samples to an output stream. This function doesn't return until the entire buffer has been consumed - this may involve waiting for the operating system to consume the data.

Arguments

  • output_buffer - The buffer contains samples in the format specified by S.
  • frames_per_buffer - The number of frames in the buffer.

Return PaNoError on success, or a PaError code if fail.

fn get_stream_info(&self) -> PaStreamInfo

Retrieve a PaStreamInfo structure containing information about the specified stream.