55 Commits

Author SHA1 Message Date
mitchmindtree
c38bbb26e4 Update to a more general Device and Stream API. Add support for input streams (E.g. microphone). Add default format methods. (#201)
* Update to a more general Device and Stream API

This update prepares for adding input stream support by removing the
`Endpoint` type (which only supports output streams) in favour of a more
general `Device` type which may support any number of input or output
streams. Previously discussed at #117.

The name `Voice` has been replaced with the more ubiquitous name
`Stream`. See #118 for justification.

Also introduces a new `StreamData` which is now passed to the
`EventLoop::run` callback rather than the `UnknownTypeBuffer`.
`StreamData` allows for passing either `Input` data to be read, or
`Output` data to be written.

The `beep.rs` example has been updated for the API changes.

None of the backends have been updated for this API change yet. Backends
will be updated in the following commits.

Closes #117.
Closes #118.

* Update ALSA backend for new `Device` and `Stream` API.

* Update wasapi backend for new `Device` and `Stream` API.

* Update enumerate.rs example for new `Device` and `Stream` API.

* Update coreaudio backend for new `Device` and `Stream` API.

* Fix lib doc tests for Device and Stream API update

* Update emscripten backend for new `Device` and `Stream` API.

* Update null backend for new `Device` and `Stream` API.

* Merge match exprs in beep.rs example

* Add Input variant along with UnknownTypeInputBuffer and InputBuffer

UnknownTypeBuffer and Buffer have been renamed to
UnknownTypeOutputBuffer and OutputBuffer respectively.

No backends have yet been updated for this name change or the addition
of the InputBuffer.

* Update null backend for introduction of InputBuffer

* Update emscripten backend for introduction of InputBuffer

* Make InputBuffer inner field an option to call finish in drop

* Update alsa backend for introduction of InputBuffer

* Update wasapi backend for introduction of InputBuffer

* Update coreaudio backend for introduction of InputBuffer

* Update enumerate.rs example to provide more detail about devices

The enumerate.rs example now also displays:

- Supported input stream formats.
- Default input stream format.
- Default output stream format.

This should also be useful for testing the progress of #201.

* Add `record_wav.rs` example for demonstrating input streams

Records a ~3 second WAV file to `$CARGO_MANIFEST_DIR/recorded.wav` using
the default input device and default input format.

Uses hound 3.0 to create and write to the WAV file.

This should also be useful for testing the input stream implementations
for each different cpal backend.

* Implement input stream support for coreaudio backend

This implements the following for the coreaudio backend:

- Device::supported_input_formats
- Device::default_input_format
- Device::default_output_format
- EventLoop::build_input_stream

The `enumerate.rs` and `record_wav.rs` examples now work successfully on
macos.

* Add `SupportedFormat::cmp_default_heuristics` method

This adds a comparison function which compares two `SupportedFormat`s in
terms of their priority of use as a default stream format.

Some backends (such as ALSA) do not provide a default stream format for
their audio devices. In these cases, CPAL attempts to decide on a
reasonable default format for the user. To do this we use the "greatest"
of all supported stream formats when compared with this method.

* Implement input stream support for ALSA backend

This implements the following for the ALSA backend:

- Device::supported_input_formats
- Device::default_input_format
- Device::default_output_format
- EventLoop::build_input_stream

Note that ALSA itself does not give default stream formats for its
devices. Thus the newly added `SupportedFormat::cmp_default_heuristics`
method is used to determine the most suitable, supported stream format
to use as the default.

The `enumerate.rs` and `record_wav.rs` examples now work successfully on
my linux machine.

* Implement input stream support for wasapi backend

This implements the following for the wasapi backend:

- Device::supported_input_formats
- Device::default_input_format
- Device::default_output_format
- EventLoop::build_input_stream

Note that wasapi does not enumerate supported input/output stream
formats for its devices. Instead, we query the `IsFormatSupported`
method for supported formats ourselves.

* Fix some warnings in the alsa backend

* Update CHANGELOG for introduction of input streams and related items

* Update README to show latest features supported by CPAL

* Simplify beep example using Device::default_output_format

* Remove old commented code from wasapi/stream.rs
2018-02-12 14:10:24 +01:00
mitchmindtree
b47e46a4ac Update winapi version from 0.2 to 0.3 (#202)
Adds only the necessary cargo features to reduce compile time and reduce
the chance of linking errors occurring for unused libraries (e.g.
d3d12.dll fails to link on my win10 VM).

I thought I'd try and land this before before working on the wasapi
backend implementation for #201.

Tested both beep.rs and enumerate.rs and they work fine with the update.
2018-02-07 17:36:59 +01:00
tomaka
91adc3e380 Docs and style improvements (#174)
* Improve the crate root documentation

* Add entry in CHANGELOG

* Run rustfmt on the code

* More improvements to documentation
2017-10-23 16:41:38 +02:00
tomaka
6ae01f437c RFC: Rework the API [WIP] (#165)
* Rework the API to not use futures anymore

* Add some comments

* Update the MacOS backend

* Restore the null implementation

* Add an emscripten backend

* Remove erroneously added feature

* Fix to_f32 formula

* [WIP] Alsa backend

* Alsa backend compiling

* Working ALSA backend

* Fix tests

* Move WASAPI endpoint to endpoint module

* Fix WASAPI warnings

* Rework the WASAPI backend

* Check overflows for voice ID

* Add comments and minor fixes to WASAPI backend

* Add a changelog
2017-10-18 20:24:05 +02:00
tomaka
4b019243c2 Rename the methods of the backend as well (#164) 2017-10-12 11:54:09 +02:00
tomaka
2028d5907f Run rustfmt on the code (#162) 2017-10-11 13:24:49 +02:00
Pierre Krieger
a26a9f5337 Fix compilation on windows 2016-11-16 08:17:11 +01:00
Pierre Krieger
b1add0b12b Fix most warnings 2016-08-12 17:57:06 +02:00
Pierre Krieger
be8310da51 Draft for switching to futures 2016-08-02 18:19:03 +02:00
Pierre Krieger
33dc72ab45 Add device name on WASAPI 2015-09-22 16:05:40 +02:00
Pierre Krieger
ec48453b6f Add endpoint::get_name() and an enumerate example 2015-09-22 14:46:27 +02:00
tomaka
826ad84db4 Merge pull request #66 from tomaka/inline
Add #[inline] attributes
2015-09-22 10:01:59 +02:00
Peter Atashian
61ac0528e7 Update winapi dependency
Signed-off-by: Peter Atashian <retep998@gmail.com>
2015-09-17 14:22:52 -04:00
Peter Atashian
5b1291c215 Unused extern crate libc
Signed-off-by: Peter Atashian <retep998@gmail.com>
2015-09-17 06:29:13 -04:00
Pierre Krieger
75f828b04f Add #[inline] attributes 2015-09-11 10:55:29 +02:00
Pierre Krieger
48282a068d Handle channels positionning 2015-09-10 11:44:19 +02:00
Pierre Krieger
77fb55329e Better error handling in format detection 2015-09-01 15:33:44 +02:00
Pierre Krieger
dc08fc4652 Now decoding the format from the WAVEFORMAT returned by the winapi 2015-09-01 15:32:03 +02:00
Pierre Krieger
bf20431901 Handle F32 formats in Voice::new 2015-09-01 14:51:35 +02:00
Pierre Krieger
98b931edff Add proper error handling 2015-09-01 14:17:57 +02:00
Pierre Krieger
1985c346ac Add supported formats enumeration 2015-09-01 13:53:54 +02:00
Pierre Krieger
47f966bf75 Correctly enumerate audio devices (core + wasapi) 2015-09-01 11:29:00 +02:00
Pierre Krieger
ca72d1d67e Remove the conversion system 2015-08-20 14:44:23 +02:00
Mariusz Ceier
55eec8567e Add more detailed message to panic
When samples format is not supported, cpal panics with "not yet implemented" message, which is not useful in bug reports.
This adds samples format to the message.

Signed-off-by: Mariusz Ceier <mceier+cpal@gmail.com>
2015-08-18 08:54:40 +02:00
Pierre Krieger
2f36175d96 Fix samples signs on win32 2015-07-22 14:28:45 +02:00
Pierre Krieger
48b7278254 Fix the win32 build 2015-07-20 19:06:58 +02:00
Peter Atashian
618ef2a4f9 Use shiny new COM
Signed-off-by: Peter Atashian <retep998@gmail.com>
2015-05-27 12:24:14 -04:00
Pierre Krieger
07b2009dae Update for Rustc 1.0.0 beta 2015-04-04 09:22:23 +02:00
Pierre Krieger
93073f1ff7 Update for change in rustc and winapi 2015-03-30 11:19:03 +02:00
Pierre Krieger
a6c1b14d66 Rustup 2015-03-26 10:03:40 +01:00
Pierre Krieger
84326cb4a7 Rustup 2015-03-25 13:50:52 +01:00
Pierre Krieger
28bd368658 Update for rustc 2015-02-22 11:24:49 +01:00
Pierre Krieger
0fa579d885 Update for rustc 2015-02-19 21:22:22 +01:00
Pierre Krieger
2e6143269a Update for rustc 2015-01-29 14:57:11 +01:00
Pierre Krieger
284f12f1cb Update for winapi 2015-01-20 16:45:47 +01:00
Pierre Krieger
2bc50adf4d Update for rust-1.0 alpha 2015-01-09 21:25:51 +01:00
Pierre Krieger
23e1e0639c Update for Rustc 2015-01-08 21:24:04 +01:00
Pierre Krieger
7adfdb4461 Update for changes in rustc 2014-12-30 08:35:13 +01:00
Pierre Krieger
d947014084 Add play() and pause() functions 2014-12-23 15:25:25 +01:00
Pierre Krieger
04f9aac2c3 Rename Channel to Voice 2014-12-17 09:16:26 +01:00
Pierre Krieger
49636365d8 Switch back to using buffers 2014-12-15 16:32:13 +01:00
Pierre Krieger
1a556514b0 Sound output now works correctly 2014-12-15 16:26:55 +01:00
Pierre Krieger
9598f68d3c Minor fixes 2014-12-15 16:06:37 +01:00
Pierre Krieger
04d07c27dc Modify API to use a "samples" iterator 2014-12-15 15:29:59 +01:00
Pierre Krieger
081912c5fb Implement some samples rate conversions 2014-12-15 11:58:52 +01:00
Pierre Krieger
32bca93cc9 Implement some basic data conversion 2014-12-15 11:45:38 +01:00
Pierre Krieger
b23857a57c Restore variable input format system 2014-12-15 10:29:29 +01:00
Pierre Krieger
f00bb5a2b8 Update for rustc 2014-12-15 10:16:18 +01:00
Pierre Krieger
b4b75f526a Remove old code 2014-12-11 19:42:49 +01:00
Pierre Krieger
8efaf06ec2 Add destructor for wasapi::Channel 2014-12-11 19:42:04 +01:00