-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sketch out some wrapper structs in audio
- Loading branch information
1 parent
dbb15cb
commit ace3651
Showing
4 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use super::*; | ||
|
||
pub struct AudioClip { | ||
id: ClipId, | ||
engine: AudioEngine, | ||
} | ||
|
||
impl AudioClip { | ||
pub fn new(engine: &AudioEngine) -> Self { | ||
Self { | ||
id: engine.clip_create().unwrap(), | ||
engine: engine.clone(), | ||
} | ||
} | ||
|
||
pub fn id(&self) -> ClipId { | ||
self.id | ||
} | ||
|
||
pub fn write_data(&self, data: &[u8]) { | ||
self.engine.clip_write_data(self.id, data.as_ptr(), data.len()).unwrap(); | ||
} | ||
} | ||
|
||
impl Drop for AudioClip { | ||
fn drop(&mut self) { | ||
self.engine.clip_delete(self.id).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use super::*; | ||
|
||
pub struct AudioSource { | ||
id: SourceId, | ||
engine: AudioEngine, | ||
} | ||
|
||
impl AudioSource { | ||
pub fn new(engine: &AudioEngine) -> Self { | ||
Self { | ||
id: engine.source_create().unwrap(), | ||
engine: engine.clone(), | ||
} | ||
} | ||
|
||
pub fn id(&self) -> SourceId { | ||
self.id | ||
} | ||
|
||
pub fn is_playing(&self) -> bool { | ||
self.engine.source_is_playing(self.id).unwrap_or_default() | ||
} | ||
|
||
pub fn volume(&self) -> f32 { | ||
self.engine.source_get_volume(self.id).unwrap_or_default() | ||
} | ||
|
||
pub fn set_volume(&mut self, volume: f32) { | ||
self.engine.source_set_volume(self.id, volume).unwrap(); | ||
} | ||
|
||
pub fn play(&self, clip: &AudioClip) { | ||
self.engine.source_set_clip(self.id, clip.id()).unwrap(); | ||
self.engine.source_play(self.id).unwrap() | ||
} | ||
} | ||
|
||
impl Drop for AudioSource { | ||
fn drop(&mut self) { | ||
self.engine.source_delete(self.id).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters