Skip to content

Commit bf15059

Browse files
authored
Merge pull request #13 from pavhofman/master
API: Derived Debug, PartialEq for public enums.
2 parents aa83ab3 + ade831f commit bf15059

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

src/api.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,30 @@ pub fn initialize_sta() -> Result<(), windows::core::Error> {
6868
}
6969

7070
/// Audio direction, playback or capture.
71-
#[derive(Clone)]
71+
#[derive(Clone, Debug, PartialEq)]
7272
pub enum Direction {
7373
Render,
7474
Capture,
7575
}
7676

77+
impl fmt::Display for Direction {
78+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79+
match *self {
80+
Direction::Render => write!(f, "Render"),
81+
Direction::Capture => write!(f, "Capture"),
82+
}
83+
}
84+
}
85+
7786
/// Sharemode for device
78-
#[derive(Clone)]
87+
#[derive(Clone, Debug, PartialEq)]
7988
pub enum ShareMode {
8089
Shared,
8190
Exclusive,
8291
}
8392

8493
/// Sample type, float or integer
85-
#[derive(Clone)]
94+
#[derive(Clone, Debug, PartialEq)]
8695
pub enum SampleType {
8796
Float,
8897
Int,
@@ -162,7 +171,7 @@ impl DeviceCollection {
162171
/// Struct wrapping an [IMMDevice](https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nn-mmdeviceapi-immdevice).
163172
pub struct Device {
164173
device: IMMDevice,
165-
direction: Direction,
174+
pub direction: Direction,
166175
}
167176

168177
impl Device {
@@ -476,7 +485,7 @@ pub struct AudioSessionControl {
476485
}
477486

478487
/// States of an AudioSession
479-
#[derive(Debug)]
488+
#[derive(Debug, PartialEq)]
480489
pub enum SessionState {
481490
Active,
482491
Inactive,
@@ -612,6 +621,7 @@ impl AudioRenderClient {
612621
}
613622

614623
/// Struct representing the [ _AUDCLNT_BUFFERFLAGS enums](https://docs.microsoft.com/en-us/windows/win32/api/audioclient/ne-audioclient-_audclnt_bufferflags).
624+
#[derive(Debug)]
615625
pub struct BufferFlags {
616626
/// AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY
617627
pub data_discontinuity: bool,

src/events.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,27 @@ impl IAudioSessionEvents_Impl for AudioSessionEvents {
239239
trace!("New channel volume for channel: {}", changedchannel);
240240
let volslice =
241241
unsafe { slice::from_raw_parts(newchannelvolumearray, channelcount as usize) };
242-
let newvol = volslice[changedchannel as usize];
243242
if let Some(callbacks) = &mut self.callbacks.upgrade() {
244243
if let Some(callback) = &callbacks.channel_volume {
245244
let context = unsafe { *eventcontext };
246-
callback(changedchannel as usize, newvol, context);
245+
if changedchannel == u32::MAX {
246+
// special meaning by specs: (DWORD)(-1) - "more than one channel have changed"
247+
// using all channels
248+
for (idx, newvol) in volslice.iter().enumerate() {
249+
callback(idx, *newvol, context);
250+
}
251+
}
252+
if (changedchannel as usize) < volslice.len() {
253+
let newvol = volslice[changedchannel as usize];
254+
callback(changedchannel as usize, newvol, context);
255+
} else {
256+
warn!(
257+
"OnChannelVolumeChanged: received unsupported changedchannel value {} for volume array length of {}",
258+
changedchannel,
259+
volslice.len()
260+
);
261+
return Ok(());
262+
}
247263
}
248264
}
249265
Ok(())

src/waveformat.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ impl WaveFormat {
6262
SampleType::Float => KSDATAFORMAT_SUBTYPE_IEEE_FLOAT,
6363
SampleType::Int => KSDATAFORMAT_SUBTYPE_PCM,
6464
};
65-
let mut mask = 0;
66-
for n in 0..channels {
67-
mask += 1 << n;
68-
}
65+
// only max 18 mask channel positions are defined (https://www.ambisonic.net/mulchaud.html#_Toc446153101)
66+
let mask = match channels {
67+
ch if ch <= 18 => {
68+
// setting bit for each channel
69+
(1 << ch) - 1
70+
}
71+
_ => 0,
72+
};
6973
let wave_fmt = WAVEFORMATEXTENSIBLE {
7074
Format: wave_format,
7175
Samples: sample,

0 commit comments

Comments
 (0)