Comments (8)
I'm currently looking into implementing this now that #354 has landed.
As a part of this change, I'm thinking about how to best approach the "callback" API for the new Device::build_input_stream/build_output_stream
methods.
Rather than the current signature that looks like this:
FnMut(crate::StreamData) + Send + 'static
I'm imagining we could go with something like this.
Input:
FnMut(InputData<T>, &StreamInfo) + Send + 'static
Output:
FnMut(OutputData<T>, &StreamInfo) + Send + 'static
where the *Data
type represents the audio data and StreamInfo
provides access to other potentially useful information about the stream such as timing information or flags.
The reason I'm thinking we provide a type around the "data" is in case we decide to add support for non-interleaved data in the future. Currently on platforms that only support non-interleaved data (ASIO comes to mind, not sure if there are others) we do the conversion to interleaved behind the scenes, but I can imagine we might want to provide a more transparent API for this in the future.
As for StreamInfo
, I might leave this out for now. I plan on looking into adding stream timing in a follow-up API - I might add the StreamInfo
type then. I'm also open to better names for this type if anything comes to mind.
from cpal.
I wonder if it is also worth removing the data_type: SampleFormat
field from the Format
struct? The Format
type is solely used to specify the desired format when calling build_input/output_stream
, however with these changes the desired SampleFormat
can be inferred from the sample type used within the user's data callback function.
from cpal.
This has become impossible to implement since the introduction of the EventLoop
type, as all streams must now be handled within a single callback, and each stream might be of some different sample format depending on the device it is associated with. #278 may make this possible again, but some serious thought has to be put into how to achieve this while being able to support web audio APIs (see this comment).
from cpal.
I think I'll implement this sometime after the EventLoop deal, but one question is: is there a "default" format that we should expose? I think on most platforms you can choose arbitrary format, but if we need to provide "default" then it would be polymorphic, which doesn't play well with generic API design.
from cpal.
On second thoughts, the Format
type is also used to specify the default format via the Device::default_input/output_format
methods.
One option would be to remove the data_type
field and have the default_input/output_format
return a (Format, SampleFormat)
?
An alternative option might be to leave the Format
type as is, and instead change the build_input/output_stream
methods to take sample rate and number of channels as individual arguments.
Otherwise, we could just leave it as is and assert_eq!(format.data_type, T::FORMAT)
at the beginning of each of the build_input/output_stream
methods.
from cpal.
I don't think this has been fixed; as of #359 every relevant example still contains SampleFormat
check or an equivalent unwrap in the main loop.
from cpal.
For anyone following I've responded at #359 here. I'm happy to re-open this if it's decided this is still worth tackling.
from cpal.
A complete proposal for an improved API has been drafted at #366.
from cpal.
Related Issues (20)
- [ASIO] Pre build script HOT 1
- Memory leak in WASAPI `input_devices`
- trying to compile the wasm example...issue HOT 1
- append HOT 1
- Crash on default_output_config when using cpal with Flutter using Dart FFI HOT 1
- Pausing a stream doesn't clear out sample buffers
- emscripten support is broken (since wasm-bindgen does not work there?) HOT 7
- No devices on default host on WASM32, specifically Chromium HOT 1
- What would it take to make WebAssembly audio inputs happen?
- CPal doesn't list mac speakers as an output device HOT 1
- [Android/Arm64] Can't compile cpal
- Main crate example doesn't compile HOT 4
- Having accumulated delay on wasapi HOT 2
- Implement `Send` for `Stream` HOT 2
- Does it make sense for Device to be cloneable? HOT 2
- alsa error HOT 6
- Why is build_output_stream data length different every time? HOT 1
- migrate WASM example and documentation+Wiki from webpack to trunk HOT 3
- [ALSA] Unable to query max channel count for MOTU UltraLite-mk5 (class compliant)
- Support for wasm32-wasi-* targets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpal.