sound_stream icon indicating copy to clipboard operation
sound_stream copied to clipboard

SoundStream API Reform Draft

Open mitchmindtree opened this issue 10 years ago • 0 comments

Currently SoundStream currently offers very limited options for setup - It constructs a duplex, ordered stream with no options to choose any devices other than the defaults. Here I'm going to try and list all of the options we'd like to expose to the user that are currently unexposed:

Pre-SoundStream construction

  • Retrieve a list of available hosts along with their IDs.
  • Retrieve a list of available devices along with their IDs.
  • Default host.
  • Default device.

For these, we should be able to provide simple functions:

let hosts = sound_stream::available_hosts();
let devices = sound_stream::available_devices();

Where each is an iterator over structs containing ID and info about each host/device.

SoundStream construction

  • Blocking / Non-blocking.
  • Duplex / Input-only / Output-only.
  • If Duplex, unique input and output parameters.
  • pa::StreamFlags.

Here is what I imagine constructing a custom duplex, non-blocking stream would look like:

let stream = SoundStream::new()
    .input(Some(input_device_id), Params { ... })
    .output(Some(output_device_id), Params { ... })
    .flags(flags)
    .callback(|args| { ... });

Duplex / Input / Output could be determined by whether both input and output, only input or only output methods have been called respectively. If neither method is called, the default output device will be constructed with two channels (unless there is a max of 1, in which case 1 channel), f32 sample format and default latency.

Blocking / Non-Blocking could be determined by whether .callback is given as the last method or .blocking. .callback could return a handle to the stream (with methods for checking whether or not it's still running, stopping/starting the stream, etc).

mitchmindtree avatar Apr 23 '15 04:04 mitchmindtree