Buffer now always has the u8 format

This commit is contained in:
Pierre Krieger 2014-12-11 19:02:04 +01:00
parent d6f49a5176
commit 0bdafdab9b
3 changed files with 30 additions and 24 deletions

View file

@ -13,10 +13,13 @@ pub mod cpal_impl;
/// stop playing.
pub struct Channel(cpal_impl::Channel);
/// Number of channels.
pub type ChannelsCount = u16;
/// Represents a buffer that must be filled with audio data.
///
/// A `Buffer` object borrows the channel.
pub struct Buffer<'a, T>(cpal_impl::Buffer<'a, T>);
pub struct Buffer<'a>(cpal_impl::Buffer<'a>);
impl Channel {
pub fn new() -> Channel {
@ -27,7 +30,7 @@ impl Channel {
/// Returns the number of channels.
///
/// 1 for mono, 2 for stereo, etc.
pub fn get_channels(&self) -> u16 {
pub fn get_channels(&self) -> ChannelsCount {
self.0.get_channels()
}
@ -36,19 +39,19 @@ impl Channel {
/// 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
/// of the backend.
pub fn append_data<'a, T>(&'a mut self) -> Buffer<'a, T> {
pub fn append_data<'a>(&'a mut self) -> Buffer<'a> {
Buffer(self.0.append_data())
}
}
impl<'a, T> Deref<[T]> for Buffer<'a, T> {
fn deref(&self) -> &[T] {
impl<'a> Deref<[u8]> for Buffer<'a> {
fn deref(&self) -> &[u8] {
panic!()
}
}
impl<'a, T> DerefMut<[T]> for Buffer<'a, T> {
fn deref_mut(&mut self) -> &mut [T] {
impl<'a> DerefMut<[u8]> for Buffer<'a> {
fn deref_mut(&mut self) -> &mut [u8] {
self.0.get_buffer()
}
}