GithubHelp home page GithubHelp logo

Comments (8)

mitchmindtree avatar mitchmindtree commented on June 18, 2024 2

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.

mitchmindtree avatar mitchmindtree commented on June 18, 2024 1

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.

mitchmindtree avatar mitchmindtree commented on June 18, 2024

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.

ishitatsuyuki avatar ishitatsuyuki commented on June 18, 2024

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.

mitchmindtree avatar mitchmindtree commented on June 18, 2024

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.

Ralith avatar Ralith commented on June 18, 2024

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.

mitchmindtree avatar mitchmindtree commented on June 18, 2024

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.

Ralith avatar Ralith commented on June 18, 2024

A complete proposal for an improved API has been drafted at #366.

from cpal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.