Restore variable input format system
This commit is contained in:
parent
f00bb5a2b8
commit
b23857a57c
|
@ -22,12 +22,11 @@ fn main() {
|
||||||
loop {
|
loop {
|
||||||
let mut buffer = channel.append_data();
|
let mut buffer = channel.append_data();
|
||||||
|
|
||||||
for sample in buffer.chunks_mut(4) {
|
for sample in buffer.chunks_mut(2) {
|
||||||
let value = data_source.next().unwrap();
|
let value = data_source.next().unwrap();
|
||||||
|
|
||||||
let mut writer = std::io::BufWriter::new(sample);
|
sample[0] = value;
|
||||||
writer.write_le_u16(value).unwrap();
|
sample[1] = value;
|
||||||
writer.write_le_u16(value).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -19,7 +19,7 @@ pub type ChannelsCount = u16;
|
||||||
/// Represents a buffer that must be filled with audio data.
|
/// Represents a buffer that must be filled with audio data.
|
||||||
///
|
///
|
||||||
/// A `Buffer` object borrows the channel.
|
/// A `Buffer` object borrows the channel.
|
||||||
pub struct Buffer<'a>(cpal_impl::Buffer<'a>);
|
pub struct Buffer<'a, T>(cpal_impl::Buffer<'a, T>);
|
||||||
|
|
||||||
/// Format that each sample has.
|
/// Format that each sample has.
|
||||||
#[deriving(Clone, Copy, Show, PartialEq, Eq)]
|
#[deriving(Clone, Copy, Show, PartialEq, Eq)]
|
||||||
|
@ -62,19 +62,19 @@ impl Channel {
|
||||||
/// This function returns a `Buffer` object that must be filled with the audio data.
|
/// This function returns a `Buffer` object that must be filled with the audio data.
|
||||||
/// You can't know in advance the size of the buffer, as it depends on the current state
|
/// You can't know in advance the size of the buffer, as it depends on the current state
|
||||||
/// of the backend.
|
/// of the backend.
|
||||||
pub fn append_data<'a>(&'a mut self) -> Buffer<'a> {
|
pub fn append_data<'a, T>(&'a mut self) -> Buffer<'a, T> {
|
||||||
Buffer(self.0.append_data())
|
Buffer(self.0.append_data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Deref<[u8]> for Buffer<'a> {
|
impl<'a, T> Deref<[T]> for Buffer<'a, T> {
|
||||||
fn deref(&self) -> &[u8] {
|
fn deref(&self) -> &[T] {
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DerefMut<[u8]> for Buffer<'a> {
|
impl<'a, T> DerefMut<[T]> for Buffer<'a, T> {
|
||||||
fn deref_mut(&mut self) -> &mut [u8] {
|
fn deref_mut(&mut self) -> &mut [T] {
|
||||||
self.0.get_buffer()
|
self.0.get_buffer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@ pub struct Channel {
|
||||||
started: bool,
|
started: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Buffer<'a> {
|
pub struct Buffer<'a, T> {
|
||||||
audio_client: *mut winapi::IAudioClient,
|
audio_client: *mut winapi::IAudioClient,
|
||||||
render_client: *mut winapi::IAudioRenderClient,
|
render_client: *mut winapi::IAudioRenderClient,
|
||||||
buffer: CVec<u8>,
|
buffer: CVec<T>,
|
||||||
frames: winapi::UINT32,
|
frames: winapi::UINT32,
|
||||||
start_on_drop: bool,
|
start_on_drop: bool,
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ impl Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_data<'a>(&'a mut self) -> Buffer<'a> {
|
pub fn append_data<'a, T>(&'a mut self) -> Buffer<'a, T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
loop {
|
loop {
|
||||||
//
|
//
|
||||||
|
@ -63,7 +63,7 @@ impl Channel {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loading buffer
|
// loading buffer
|
||||||
let buffer: CVec<u8> = {
|
let buffer: CVec<T> = {
|
||||||
let mut buffer: *mut winapi::BYTE = mem::uninitialized();
|
let mut buffer: *mut winapi::BYTE = mem::uninitialized();
|
||||||
let f = self.render_client.as_mut().unwrap().lpVtbl.as_ref().unwrap().GetBuffer;
|
let f = self.render_client.as_mut().unwrap().lpVtbl.as_ref().unwrap().GetBuffer;
|
||||||
let hresult = f(self.render_client, frames_available,
|
let hresult = f(self.render_client, frames_available,
|
||||||
|
@ -71,8 +71,9 @@ impl Channel {
|
||||||
check_result(hresult).unwrap();
|
check_result(hresult).unwrap();
|
||||||
assert!(!buffer.is_null());
|
assert!(!buffer.is_null());
|
||||||
|
|
||||||
CVec::new(buffer as *mut u8,
|
CVec::new(buffer as *mut T,
|
||||||
frames_available as uint * self.bytes_per_frame as uint)
|
frames_available as uint * self.bytes_per_frame as uint
|
||||||
|
/ mem::size_of::<T>())
|
||||||
};
|
};
|
||||||
|
|
||||||
let buffer = Buffer {
|
let buffer = Buffer {
|
||||||
|
@ -106,14 +107,14 @@ impl Drop for Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Buffer<'a> {
|
impl<'a, T> Buffer<'a, T> {
|
||||||
pub fn get_buffer(&mut self) -> &mut [u8] {
|
pub fn get_buffer(&mut self) -> &mut [T] {
|
||||||
self.buffer.as_mut_slice()
|
self.buffer.as_mut_slice()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
impl<'a> Drop for Buffer<'a> {
|
impl<'a, T> Drop for Buffer<'a, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// releasing buffer
|
// releasing buffer
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in New Issue