1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#![feature(arc_new_cyclic)]

/*!
Riddle crate for loading and playing audio data.

Built largely on the back of `::image` and its dependencies.

# Riddle Example

The **recommended** way to use this crate is through the main `riddle` crate.
Riddle exposes this crate through `riddle::audio`.

```no_run
use riddle::*;

fn main() -> Result<(), RiddleError> {
    let rdl =  RiddleLib::new()?;

    // Load the clip
    let clip_bytes = include_bytes!("../../example_assets/boop.wav");
    let clip = audio::Clip::new(&clip_bytes[..])?;

    // Play the clip
    let player = audio::ClipPlayerBuilder::new(&rdl.context().audio())
                    .play(&clip)?;

    let start_time = std::time::Instant::now();
    rdl.run(move |rdl| {
        if std::time::Instant::now() - start_time > std::time::Duration::from_secs(2) {
            rdl.quit()
        }
    })
}
```

# Direct Example

If you don't want to depend on `riddle`, you can use this crate directly.

```no_run
use riddle_audio::*;

fn main() -> Result<(), AudioError> {
    let audio_system = AudioSystem::new()?;

    // Load the clip
    let clip_bytes = include_bytes!("../../example_assets/boop.wav");
    let clip = Clip::new(&clip_bytes[..])?;

    // Play the clip
    let player = ClipPlayerBuilder::new(&audio_system)
                    .play(&clip)?;

    // Let it play for two seconds
    let start_time = std::time::Instant::now();
    while std::time::Instant::now() - start_time < std::time::Duration::from_secs(2) {
        audio_system.process_frame();
        std::thread::sleep_ms(100);
    }
    Ok(())
}
```
*/
mod audio_system;
mod clip;
mod clip_player;
mod error;
mod fades;

pub mod doctest;

use fades::*;
use riddle_common::*;

pub use audio_system::*;
pub use clip::*;
pub use clip_player::*;
pub use error::*;

type Result<R> = std::result::Result<R, AudioError>;