Skip to content

Commit a6d6718

Browse files
authored
Merge pull request #578 from mehcode/obtained-audiospec
Expose obtained AudioSpec on both AudioDevice and AudioQueue
2 parents c3198c9 + d2313c4 commit a6d6718

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/sdl2/audio.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ impl Drop for AudioDeviceID {
477477
pub struct AudioQueue<Channel: AudioFormatNum> {
478478
subsystem: AudioSubsystem,
479479
device_id: AudioDeviceID,
480-
phantom: PhantomData<Channel>
480+
phantom: PhantomData<Channel>,
481+
spec: AudioSpec,
481482
}
482483

483484
impl<Channel: AudioFormatNum> AudioQueue<Channel> {
@@ -495,7 +496,7 @@ impl<Channel: AudioFormatNum> AudioQueue<Channel> {
495496

496497
let iscapture_flag = 0;
497498
let device_id = ll::SDL_OpenAudioDevice(
498-
device_ptr as *const c_char, iscapture_flag, &desired,
499+
device_ptr as *const c_char, iscapture_flag, &desired,
499500
&mut obtained, 0
500501
);
501502
match device_id {
@@ -504,11 +505,13 @@ impl<Channel: AudioFormatNum> AudioQueue<Channel> {
504505
},
505506
id => {
506507
let device_id = AudioDeviceID::PlaybackDevice(id);
508+
let spec = AudioSpec::convert_from_ll(obtained);
507509

508510
Ok(AudioQueue {
509511
subsystem: a.clone(),
510512
device_id: device_id,
511-
phantom: PhantomData::default()
513+
phantom: PhantomData::default(),
514+
spec: spec,
512515
})
513516
}
514517
}
@@ -518,6 +521,9 @@ impl<Channel: AudioFormatNum> AudioQueue<Channel> {
518521
#[inline]
519522
pub fn subsystem(&self) -> &AudioSubsystem { &self.subsystem }
520523

524+
#[inline]
525+
pub fn spec(&self) -> &AudioSpec { &self.spec }
526+
521527
pub fn status(&self) -> AudioStatus {
522528
unsafe {
523529
let status = ll::SDL_GetAudioDeviceStatus(self.device_id.id());
@@ -555,6 +561,7 @@ impl<Channel: AudioFormatNum> AudioQueue<Channel> {
555561
pub struct AudioDevice<CB: AudioCallback> {
556562
subsystem: AudioSubsystem,
557563
device_id: AudioDeviceID,
564+
spec: AudioSpec,
558565
/// Store the callback to keep it alive for the entire duration of `AudioDevice`.
559566
userdata: Box<CB>
560567
}
@@ -584,7 +591,7 @@ impl<CB: AudioCallback> AudioDevice<CB> {
584591

585592
let iscapture_flag = 0;
586593
let device_id = ll::SDL_OpenAudioDevice(
587-
device_ptr as *const c_char, iscapture_flag, &desired,
594+
device_ptr as *const c_char, iscapture_flag, &desired,
588595
&mut obtained, 0
589596
);
590597
match device_id {
@@ -602,7 +609,8 @@ impl<CB: AudioCallback> AudioDevice<CB> {
602609
Ok(AudioDevice {
603610
subsystem: a.clone(),
604611
device_id: device_id,
605-
userdata: userdata
612+
userdata: userdata,
613+
spec: spec,
606614
})
607615
}
608616
}
@@ -612,6 +620,9 @@ impl<CB: AudioCallback> AudioDevice<CB> {
612620
#[inline]
613621
pub fn subsystem(&self) -> &AudioSubsystem { &self.subsystem }
614622

623+
#[inline]
624+
pub fn spec(&self) -> &AudioSpec { &self.spec }
625+
615626
pub fn status(&self) -> AudioStatus {
616627
unsafe {
617628
let status = ll::SDL_GetAudioDeviceStatus(self.device_id.id());

0 commit comments

Comments
 (0)