Compare commits
No commits in common. "a362701799d38ab38737c0d6fda7c8fcf9831c48" and "36eb0bb51c645cbc4ce0c80a7057620a8b0a0977" have entirely different histories.
a362701799
...
36eb0bb51c
@ -1,88 +1,16 @@
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::Result;
|
||||||
use psimple::Simple;
|
use psimple::Simple;
|
||||||
use pulse::context::{Context, FlagSet as ContextFlagSet};
|
|
||||||
use pulse::mainloop::standard::{IterateResult, Mainloop};
|
|
||||||
use pulse::sample::{Format, Spec};
|
use pulse::sample::{Format, Spec};
|
||||||
use pulse::stream::Direction;
|
use pulse::stream::Direction;
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::ops::Deref;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
const BUF_SIZE: usize = 1024;
|
const BUF_SIZE: usize = 1024;
|
||||||
const HOP_SIZE: usize = 512;
|
const HOP_SIZE: usize = 512;
|
||||||
const SAMPLE_RATE: u32 = 44100;
|
const SAMPLE_RATE: u32 = 44100;
|
||||||
|
|
||||||
fn get_pulse_default_sink() -> Result<String> {
|
|
||||||
let mainloop = Rc::new(RefCell::new(
|
|
||||||
Mainloop::new().ok_or(anyhow!("Failed to create mainloop"))?,
|
|
||||||
));
|
|
||||||
let ctx = Rc::new(RefCell::new(
|
|
||||||
Context::new(mainloop.borrow().deref(), "gib_default_sink")
|
|
||||||
.ok_or(anyhow!("Failed to create context"))?,
|
|
||||||
));
|
|
||||||
|
|
||||||
ctx.borrow_mut()
|
|
||||||
.connect(None, ContextFlagSet::NOFLAGS, None)?;
|
|
||||||
|
|
||||||
// Wait for context to be ready
|
|
||||||
loop {
|
|
||||||
match mainloop.borrow_mut().iterate(false) {
|
|
||||||
IterateResult::Quit(_) | IterateResult::Err(_) => {
|
|
||||||
return Err(anyhow!("Iterate state was not success"));
|
|
||||||
}
|
|
||||||
IterateResult::Success(_) => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
match ctx.borrow().get_state() {
|
|
||||||
pulse::context::State::Ready => {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pulse::context::State::Failed | pulse::context::State::Terminated => {
|
|
||||||
return Err(anyhow!("Context was in failed/terminated state"));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = Rc::new(RefCell::new(None));
|
|
||||||
let cb_result_ref = result.clone();
|
|
||||||
|
|
||||||
ctx.borrow().introspect().get_server_info(move |info| {
|
|
||||||
*cb_result_ref.borrow_mut() = if let Some(sink_name) = info.default_sink_name.clone() {
|
|
||||||
Some(Ok(sink_name.to_string()))
|
|
||||||
} else {
|
|
||||||
Some(Err(()))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
while result.borrow().is_none() {
|
|
||||||
match mainloop.borrow_mut().iterate(false) {
|
|
||||||
IterateResult::Quit(_) | IterateResult::Err(_) => {
|
|
||||||
return Err(anyhow!("Iterate state was not success"));
|
|
||||||
}
|
|
||||||
IterateResult::Success(_) => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = result.borrow().clone();
|
|
||||||
|
|
||||||
result
|
|
||||||
.unwrap()
|
|
||||||
.map_err(|_| anyhow!("Default sink name was empty"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
println!("AYAYA");
|
|
||||||
let mut default_sink_name = get_pulse_default_sink()?;
|
|
||||||
default_sink_name.push_str(".monitor");
|
|
||||||
println!(
|
|
||||||
"gotted pulse default sink (hopefully): {}",
|
|
||||||
default_sink_name
|
|
||||||
);
|
|
||||||
|
|
||||||
let spec = Spec {
|
let spec = Spec {
|
||||||
format: Format::F32le,
|
format: Format::F32le,
|
||||||
channels: 1,
|
channels: 2,
|
||||||
rate: 44100,
|
rate: 44100,
|
||||||
};
|
};
|
||||||
assert!(spec.is_valid());
|
assert!(spec.is_valid());
|
||||||
@ -91,7 +19,7 @@ fn main() -> Result<()> {
|
|||||||
None,
|
None,
|
||||||
"AAAAAAAA",
|
"AAAAAAAA",
|
||||||
Direction::Record,
|
Direction::Record,
|
||||||
Some(&default_sink_name),
|
None,
|
||||||
"BBBBBBBB",
|
"BBBBBBBB",
|
||||||
&spec,
|
&spec,
|
||||||
None,
|
None,
|
||||||
@ -100,8 +28,6 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let mut tempo = aubio::Tempo::new(aubio::OnsetMode::SpecFlux, BUF_SIZE, HOP_SIZE, SAMPLE_RATE)?;
|
let mut tempo = aubio::Tempo::new(aubio::OnsetMode::SpecFlux, BUF_SIZE, HOP_SIZE, SAMPLE_RATE)?;
|
||||||
|
|
||||||
let mut onset = aubio::Onset::new(aubio::OnsetMode::Energy, BUF_SIZE, HOP_SIZE, SAMPLE_RATE)?;
|
|
||||||
|
|
||||||
let mut data = [0u8; 4 * BUF_SIZE];
|
let mut data = [0u8; 4 * BUF_SIZE];
|
||||||
let mut float_data = [0f32; BUF_SIZE];
|
let mut float_data = [0f32; BUF_SIZE];
|
||||||
|
|
||||||
@ -126,17 +52,5 @@ fn main() -> Result<()> {
|
|||||||
tempo.get_confidence()
|
tempo.get_confidence()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
let r = onset.do_result(&float_data)?;
|
|
||||||
|
|
||||||
if r > 0f32 {
|
|
||||||
println!("onset i guess: {}", onset.get_last());
|
|
||||||
} else {
|
|
||||||
println!("nope")
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user