Store the format in the public Voice struct

This commit is contained in:
Pierre Krieger 2015-09-22 13:34:06 +02:00
parent 334c22a6f3
commit 8d21f5ff25
5 changed files with 27 additions and 87 deletions

View file

@ -19,10 +19,7 @@ pub struct Voice {
audio_client: *mut winapi::IAudioClient,
render_client: *mut winapi::IAudioRenderClient,
max_frames_in_buffer: winapi::UINT32,
num_channels: winapi::WORD,
bytes_per_frame: winapi::WORD,
samples_per_second: winapi::DWORD,
bits_per_sample: winapi::WORD,
playing: bool,
}
@ -147,34 +144,12 @@ impl Voice {
audio_client: audio_client,
render_client: render_client,
max_frames_in_buffer: max_frames_in_buffer,
num_channels: format.nChannels,
bytes_per_frame: format.nBlockAlign,
samples_per_second: format.nSamplesPerSec,
bits_per_sample: format.wBitsPerSample,
playing: false,
})
}
}
#[inline]
pub fn get_channels(&self) -> ::ChannelsCount {
self.num_channels as ::ChannelsCount
}
#[inline]
pub fn get_samples_rate(&self) -> ::SamplesRate {
::SamplesRate(self.samples_per_second as u32)
}
#[inline]
pub fn get_samples_format(&self) -> ::SampleFormat {
match self.bits_per_sample {
16 => ::SampleFormat::I16,
32 => ::SampleFormat::F32,
_ => panic!("{}-bit format not yet supported", self.bits_per_sample),
}
}
pub fn append_data<'a, T>(&'a mut self, max_elements: usize) -> Buffer<'a, T> {
unsafe {
// obtaining the number of frames that are available to be written