Commit Graph

89 Commits

Author SHA1 Message Date
mitchmindtree 960b1d5a40 Remove unnecessary panic! from OutputBuffer Deref impl
Since #269 this `panic!` is certainly unnecessary as `InputBuffer` and
`OutputBuffer` are a thin wrapper around a slice. That said, I'm
struggling to understand exactly why this `panic!` was necessary in the
first place.

This closes #228.
2019-06-07 21:05:14 +02:00
mitchmindtree 72fd027f57
Merge pull request #269 from ishitatsuyuki/better-buffer
Better buffer handling
2019-06-04 19:51:45 +02:00
mitchmindtree 7861dd84da
Merge pull request #248 from RoflCopter24/master
Added error handling for unknown ALSA device errors
2019-05-30 23:56:43 +02:00
Tatsuyuki Ishi 4d3fe57fe3 Improved buffer management
- ALSA backend: reuse the buffers
- Make `InputBuffer` and `OutputBuffer` types just a wrapper of slice
  * Buffer is now submitted at the end of callback
2019-05-30 17:45:16 +09:00
Simon Repp c2c7089d1a
Minor textual corrections in crate documentation intro 2019-04-22 13:55:42 +02:00
Chris Morgan 2679ea845f impl Debug for Device (#253)
The internal alsa, null and emscripten Device implementations already
implemented Debug; but the coreaudio and wasapi ones, and therefore
also the wrapper, did not.

I decided to eschew the `Device(…)` wrapping in the outer layer
(hence a custom implementation rather than `#[derive(Debug)]`),
because `Device(Device)`, `Device(Device { … })` and so forth all
look better without the extra `Device(…)` wrapping.

On the wasapi and coreaudio implementations I put both the pointer and
name. Name because it’s useful, pointer because on Windows at least
I believe duplicated names are possible. (e.g. two monitors that include
monitors, of the same type; I haven’t strictly confirmed this, because I
killed those off harshly on my machine and don’t want to reinstate
them.)

I do not have access to a macOS device to confirm that the coreaudio
implementation is sane, but I think it is.
2019-03-22 21:27:17 +01:00
Florian Vick 5cb45bfd7e
Added error handling for unknown ALSA device errors (#1)
Instead of taking the easy way out and killing the whole program by panicking, device enumeration and stream creation will now report the error variant 'Unknown'
2018-11-06 21:01:03 +01:00
Nitori 77ce5eba06 Implement Display and Error for DefaultFormatError (#230) 2018-06-30 11:51:24 +02:00
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 fcc75f4566 Rename `SamplesRate` to `SampleRate` and `ChannelsCount` to `ChannelCount` (#199)
* Rename SamplesRate to SampleRate and samples_rate to sample_rate

* Rename ChannelsCount to ChannelCount

* Update CHANGELOG for SamplesRate and ChannelsCount renaming
2018-02-04 13:02:16 +01:00
mitchmindtree f2728f6bdf Remove unused `ChannelPosition` API (update all backends and examples accordingly) (#198)
* Remove ChannelPosition API

This removes the ChannelPosition API from the lib root and updates the
ALSA backend and examples accordingly. The other backends have not yet
been updated.

Related discussion at #187.

* Update windows backend to removal of ChannelPosition API

The windows backend now assumes the channel position order is equal to
the channel position mask order. E.g. channel 0 will always be front
left, channel 1 will always be front right, etc.

Compiled and ran both examples successfully.

* Update coreaudio backend to removal of ChannelPosition API

Compiled and ran both examples successfully.

* Update emscriptem backend for removal of ChannelPosition API

* Update CHANGELOG for ChannelPosition removal
2018-02-04 10:38:06 +01:00
Andriy Symonovych 37016e612c Fix macos build (#186)
* fix compile error

* fix missing function error

* fix undefined behavior issue

* require callback to be `Send`
2017-12-06 12:13:36 +01:00
Eidolon e9856c07ed [coreaudio] Remove intermediate buffer (#182)
* [coreaudio] Remove intermediate buffer

Fixes #181

* [coreaudio] Create voice id after setting format
2017-11-03 10:51:02 +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 c524f63000 Improve the emscripten backend (#172)
* Use the js! macro from stdweb

* Rework the Buffer::finish method

* Use references from stdweb

* Fix emscripten warnings

* Rework the run() method to use stdweb

* Adjust timings

* Add entry in CHANGELOG
2017-10-22 14:17:25 +02:00
tomaka 87949d859b Add SupportedFormat (#168) 2017-10-20 21:18:40 +02:00
tomaka c28407b26d Fix warnings and reduce scope of libc (#166) 2017-10-19 12:44:14 +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
tomaka cdcef96279 Remove the `get_` prefix of methods (#151)
* Remove the `get_` prefix of methods

* Fix overlooks
2017-10-11 10:39:44 +02:00
egnehots 33a8cde056 Minimal ios support 2017-10-10 18:24:53 +02:00
Johannes Lundberg e86ffce712 Fixes for *BSDs
Replace linux-only eventfd() with pipe() to enable use on *BSDs for alsa.
Add FreeBSD to supported OSes.
2017-07-13 15:59:40 +02:00
Pierre Krieger c291ab13f1 Mark deprecated functions as deprecated 2016-11-16 08:32:02 +01:00
thiolliere e031025abe update to futures 0.1.1: alsa wasapi 2016-10-01 00:44:22 +02:00
Pierre Krieger c2f89d8b2d Update documentation 2016-08-03 13:06:23 +02:00
Pierre Krieger be8310da51 Draft for switching to futures 2016-08-02 18:19:03 +02:00
Pierre Krieger c4bf6e91da Fix the android build 2016-04-22 17:31:24 +02:00
Pierre Krieger c93ffcff6c Add Voice::get_period() 2015-09-27 13:00:17 +02:00
Pierre Krieger 44e9dce43f Add Voice::get_pending_samples 2015-09-22 17:59:36 +02:00
Pierre Krieger 73906885f9 Fix bug and filter out devices that are not "Output" 2015-09-22 15:04:32 +02:00
Pierre Krieger ec48453b6f Add endpoint::get_name() and an enumerate example 2015-09-22 14:46:27 +02:00
Pierre Krieger 8d21f5ff25 Store the format in the public `Voice` struct 2015-09-22 13:34:06 +02:00
tomaka d3e610a614 Merge pull request #64 from tomaka/underflowed
Add an underflow() method to Voice
2015-09-22 10:02:41 +02:00
Pierre Krieger 75f828b04f Add #[inline] attributes 2015-09-11 10:55:29 +02:00
Pierre Krieger 3dd7a8abe7 Add UnknownBufferType::len() 2015-09-10 21:24:41 +02:00
Pierre Krieger c5e2cdd3c5 Add an underflow() method to Voice 2015-09-10 21:03:40 +02:00
Pierre Krieger d9eae23023 Restore the null implementation and compile it every time 2015-09-10 18:42:42 +02:00
Pierre Krieger 48282a068d Handle channels positionning 2015-09-10 11:44:19 +02:00
Pierre Krieger d7a31b4762 Fix doctests 2015-09-01 17:47:55 +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
Ronald Kinard 6389ab3ece Remove use of box syntax.
Allows build on stable/beta rust.
2015-07-25 17:13:51 -05:00
Ronald Kinard 157011182a Add box syntax feature annotation.
Fixes build.
2015-07-25 17:08:31 -05: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
mitchmindtree 1d66e18d7e Fixed coreaudio callback to send proper buffersize, removed code in lib where sampleformat affected buffersize 2015-03-03 18:17:21 +11:00