commit
7df32b5dec
|
@ -1,7 +1,7 @@
|
||||||
extern crate cpal;
|
extern crate cpal;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut channel = cpal::Channel::new();
|
let mut channel = cpal::Voice::new();
|
||||||
|
|
||||||
// producing a sinusoid
|
// producing a sinusoid
|
||||||
let mut data_source =
|
let mut data_source =
|
||||||
|
|
|
@ -4,7 +4,7 @@ extern crate vorbis;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut channel = cpal::Channel::new();
|
let mut channel = cpal::Voice::new();
|
||||||
|
|
||||||
let mut decoder = vorbis::Decoder::new(BufReader::new(include_bin!("music.ogg")))
|
let mut decoder = vorbis::Decoder::new(BufReader::new(include_bin!("music.ogg")))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -3,18 +3,18 @@ extern crate libc;
|
||||||
|
|
||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
|
|
||||||
pub struct Channel {
|
pub struct Voice {
|
||||||
channel: *mut alsa::snd_pcm_t,
|
channel: *mut alsa::snd_pcm_t,
|
||||||
num_channels: u16,
|
num_channels: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Buffer<'a, T> {
|
pub struct Buffer<'a, T> {
|
||||||
channel: &'a mut Channel,
|
channel: &'a mut Voice,
|
||||||
buffer: Vec<T>,
|
buffer: Vec<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Channel {
|
impl Voice {
|
||||||
pub fn new() -> Channel {
|
pub fn new() -> Voice {
|
||||||
unsafe {
|
unsafe {
|
||||||
let name = "default".to_c_str();
|
let name = "default".to_c_str();
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ impl Channel {
|
||||||
|
|
||||||
check_errors(alsa::snd_pcm_prepare(playback_handle)).unwrap();
|
check_errors(alsa::snd_pcm_prepare(playback_handle)).unwrap();
|
||||||
|
|
||||||
Channel {
|
Voice {
|
||||||
channel: playback_handle,
|
channel: playback_handle,
|
||||||
num_channels: 2,
|
num_channels: 2,
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ impl Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Channel {
|
impl Drop for Voice {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
alsa::snd_pcm_close(self.channel);
|
alsa::snd_pcm_close(self.channel);
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -19,11 +19,11 @@ mod cpal_impl;
|
||||||
|
|
||||||
/// Controls a sound output.
|
/// Controls a sound output.
|
||||||
///
|
///
|
||||||
/// Create one `Channel` for each sound that you want to play.
|
/// Create one `Voice` for each sound that you want to play.
|
||||||
///
|
///
|
||||||
/// A channel must be periodically filled with new data by calling `append_data`, or the sound
|
/// A voice must be periodically filled with new data by calling `append_data`, or the sound
|
||||||
/// will stop playing.
|
/// will stop playing.
|
||||||
pub struct Channel(cpal_impl::Channel);
|
pub struct Voice(cpal_impl::Voice);
|
||||||
|
|
||||||
/// Number of channels.
|
/// Number of channels.
|
||||||
pub type ChannelsCount = u16;
|
pub type ChannelsCount = u16;
|
||||||
|
@ -52,11 +52,11 @@ struct RequiredConversion<T> {
|
||||||
to_channels: ChannelsCount,
|
to_channels: ChannelsCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Channel {
|
impl Voice {
|
||||||
/// Builds a new channel.
|
/// Builds a new channel.
|
||||||
pub fn new() -> Channel {
|
pub fn new() -> Voice {
|
||||||
let channel = cpal_impl::Channel::new();
|
let channel = cpal_impl::Voice::new();
|
||||||
Channel(channel)
|
Voice(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of channels.
|
/// Returns the number of channels.
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{mem, ptr};
|
||||||
use std::c_vec::CVec;
|
use std::c_vec::CVec;
|
||||||
|
|
||||||
// TODO: determine if should be NoSend or not
|
// TODO: determine if should be NoSend or not
|
||||||
pub struct Channel {
|
pub struct Voice {
|
||||||
audio_client: *mut winapi::IAudioClient,
|
audio_client: *mut winapi::IAudioClient,
|
||||||
render_client: *mut winapi::IAudioRenderClient,
|
render_client: *mut winapi::IAudioRenderClient,
|
||||||
max_frames_in_buffer: winapi::UINT32,
|
max_frames_in_buffer: winapi::UINT32,
|
||||||
|
@ -24,8 +24,8 @@ pub struct Buffer<'a, T> {
|
||||||
start_on_drop: bool,
|
start_on_drop: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Channel {
|
impl Voice {
|
||||||
pub fn new() -> Channel {
|
pub fn new() -> Voice {
|
||||||
init().unwrap()
|
init().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ impl Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Channel {
|
impl Drop for Voice {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
{
|
{
|
||||||
|
@ -134,7 +134,7 @@ impl<'a, T> Buffer<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init() -> Result<Channel, String> {
|
fn init() -> Result<Voice, String> {
|
||||||
// FIXME: release everything
|
// FIXME: release everything
|
||||||
unsafe {
|
unsafe {
|
||||||
try!(check_result(winapi::CoInitializeEx(::std::ptr::null_mut(), 0)));
|
try!(check_result(winapi::CoInitializeEx(::std::ptr::null_mut(), 0)));
|
||||||
|
@ -229,7 +229,7 @@ fn init() -> Result<Channel, String> {
|
||||||
render_client.as_mut().unwrap()
|
render_client.as_mut().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Channel {
|
Ok(Voice {
|
||||||
audio_client: audio_client,
|
audio_client: audio_client,
|
||||||
render_client: render_client,
|
render_client: render_client,
|
||||||
max_frames_in_buffer: max_frames_in_buffer,
|
max_frames_in_buffer: max_frames_in_buffer,
|
||||||
|
|
Loading…
Reference in New Issue