Skip to main content

game_toolkit_dosaudio/
lib.rs

1//! DOS-era sound devices sharing one timestamped hardware timeline.
2//!
3//! Game code owns [`DosAudio`]; an audio callback owns [`AudioEngine`]. Port
4//! commands cross a bounded queue with [`Tick`] timestamps from
5//! `game-toolkit-dosbus`. Music is prepared before playback and sequenced on the
6//! audio thread. [`OfflineMachine`] uses the same renderer without audio I/O.
7//!
8//! ```
9//! use game_toolkit_dosaudio::{OfflineMachine, SoundConfig};
10//! use std::time::Duration;
11//!
12//! let mut machine = OfflineMachine::new(SoundConfig::none().speaker(true), 48_000)?;
13//! machine.sound(440.0)?;
14//! machine.render_for(Duration::from_millis(100))?;
15//! machine.nosound()?;
16//! machine.render_for(Duration::from_millis(20))?;
17//! let wav_bytes = machine.finish().to_bytes()?;
18//! assert_eq!(&wav_bytes[..4], b"RIFF");
19//! # Ok::<(), game_toolkit_dosaudio::Error>(())
20//! ```
21#![forbid(unsafe_code)]
22
23mod bus;
24mod capture;
25mod config;
26mod device;
27#[cfg(feature = "sb")]
28mod dma;
29mod engine;
30mod error;
31#[cfg(feature = "formats")]
32pub mod formats;
33pub mod midi;
34pub mod music;
35mod offline;
36mod speaker;
37pub use speaker::{Melody, SpeakerHandle, speaker_pwm};
38#[cfg(feature = "opl")]
39mod opl;
40#[cfg(feature = "sb")]
41pub mod sfx;
42
43pub use bus::DosAudio;
44pub use capture::{Capture, MusicCapture, PortWrite};
45pub use config::{OplBackend, OplChip, SbModel, SoundBlasterConfig, SoundConfig};
46#[cfg(feature = "opl")]
47pub use device::opl::OplCore;
48#[cfg(feature = "psg")]
49pub use device::psg::Psg;
50#[cfg(feature = "sb")]
51pub use dma::{ConventionalMemory, DmaCompletion, DmaController, DmaUnit};
52pub use engine::{AudioEngine, EngineStats};
53pub use error::{Error, Result};
54pub use game_toolkit_dosbus::{
55    DmaChannel, DmaDirection, DmaRequest, DmaWidth, IoDevice, IrqLine, IrqRequest, PortRange, Tick,
56    TickAccumulator,
57};
58#[cfg(feature = "gm")]
59pub use midi::{GmSynth, SoundFont};
60pub use midi::{MidiBackend, MidiMessage, MidiSynth};
61#[cfg(feature = "mt32")]
62pub use midi::{Mt32Model, Mt32Roms, Mt32Synth};
63pub use music::{
64    MusicController, MusicDevice, MusicEvent, MusicHandle, MusicTarget, PlayOptions, PreparedMusic,
65    Sequence, Soundtrack, TimedEvent,
66};
67pub use offline::{OfflineMachine, Wav};
68#[cfg(feature = "opl")]
69pub use opl::{
70    Drum, Note, Opl, OplBank, OplBankEntry, OplBankKey, OplInstrument, OplMidiDriver, OplOperator,
71    OplPatch,
72};
73#[cfg(feature = "sb")]
74pub use sfx::{SfxHandle, SfxMixer, SfxVoiceHandle};
75
76/// A stereo PCM frame, with each channel in -1 through 1.
77pub type Frame = [f32; 2];
78
79/// Common machine, device and music types.
80pub mod prelude {
81    #[cfg(feature = "formats")]
82    pub use crate::formats::{Dro, Imf, Smf, Vgm};
83    pub use crate::{
84        AudioEngine, DmaChannel, DosAudio, Frame, IoDevice, MusicController, MusicEvent,
85        MusicHandle, MusicTarget, OfflineMachine, OplBackend, OplChip, PlayOptions, PreparedMusic,
86        SbModel, Sequence, SoundBlasterConfig, SoundConfig, Tick, TimedEvent,
87    };
88    #[cfg(feature = "sb")]
89    pub use crate::{
90        ConventionalMemory, DmaController, DmaUnit, SfxHandle, SfxMixer, SfxVoiceHandle,
91    };
92    #[cfg(feature = "opl")]
93    pub use crate::{
94        Drum, Note, Opl, OplBank, OplBankEntry, OplBankKey, OplInstrument, OplMidiDriver,
95        OplOperator, OplPatch,
96    };
97    pub use crate::{MusicDevice, Soundtrack};
98}
99
100// Compiles the README examples, which use default-feature APIs.
101#[cfg(all(doctest, feature = "sb", feature = "formats", feature = "toolkit"))]
102#[doc = include_str!("../README.md")]
103struct ReadmeDoctests;