Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add audio #1

Open
leleosilva opened this issue Oct 18, 2022 · 0 comments
Open

Add audio #1

leleosilva opened this issue Oct 18, 2022 · 0 comments

Comments

@leleosilva
Copy link
Owner

The crates rodio or cpal could possibly be used for the audio.

Creating an 'beep' sound with rodio is easy, but a new instance of source is needed everytime the audio is played.

Ex. code for 'beep' in rodio:

use std::time::Duration;
use rodio::{OutputStream, Sink};
use rodio::source::{SineWave, Source};

fn main() {

    let (_stream, stream_handle) = OutputStream::try_default().unwrap();
    let sink = Sink::try_new(&stream_handle).unwrap();

    // Add a dummy source of the sake of the example.
    let source = SineWave::new(440.0).take_duration(Duration::from_secs_f32(0.25)).amplify(0.20);
    sink.append(source);

    // The sound plays in a separate thread. This call will block the current thread until the sink
    // has finished playing all its queued sounds.
    sink.sleep_until_end();
    
}

Things to note:

  • Does rodio (or cpal) affect the timing of the CPU cycle?
  • Does rodio or cpal have WASM support?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant