Latest changes
This commit is contained in:
parent
15eacbd20f
commit
3c7df5fc6e
26 changed files with 1917 additions and 709 deletions
|
|
@ -4,7 +4,7 @@ mod pvrecorder;
|
|||
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
use crate::{DB, config, config::structs::RecorderType};
|
||||
use crate::{config, config::structs::RecorderType, DB};
|
||||
|
||||
static RECORDER_TYPE: OnceCell<RecorderType> = OnceCell::new();
|
||||
static FRAME_LENGTH: OnceCell<u32> = OnceCell::new();
|
||||
|
|
@ -14,23 +14,35 @@ pub fn init() -> Result<(), ()> {
|
|||
// @TODO. Make it configurable?
|
||||
RECORDER_TYPE.set(config::DEFAULT_RECORDER_TYPE).unwrap();
|
||||
|
||||
// some info
|
||||
info!("Loading recorder ...");
|
||||
info!("Available audio_devices are:\n{:?}", get_audio_devices());
|
||||
|
||||
// load given recorder
|
||||
match RECORDER_TYPE.get().unwrap() {
|
||||
RecorderType::PvRecorder => {
|
||||
// Init Pv Recorder
|
||||
info!("Initializing PvRecorder recording backend.");
|
||||
FRAME_LENGTH.set(512u32).unwrap(); // pvrecorder requires frame buffer of 512
|
||||
match pvrecorder::init_microphone(get_selected_microphone_index(), FRAME_LENGTH.get().unwrap().to_owned()) {
|
||||
let selected_microphone = get_selected_microphone_index();
|
||||
match pvrecorder::init_microphone(
|
||||
selected_microphone,
|
||||
FRAME_LENGTH.get().unwrap().to_owned(),
|
||||
) {
|
||||
false => {
|
||||
error!("Recorder initialization failed.");
|
||||
|
||||
return Err(())
|
||||
},
|
||||
return Err(());
|
||||
}
|
||||
_ => {
|
||||
info!("Recorder initialization success.");
|
||||
info!(
|
||||
"Recorder initialization success. Listening to microphone ({}): {}",
|
||||
selected_microphone,
|
||||
get_audio_device_name(selected_microphone)
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
RecorderType::PortAudio => {
|
||||
// Init PortAudio
|
||||
info!("Initializing PortAudio recording backend");
|
||||
|
|
@ -42,7 +54,7 @@ pub fn init() -> Result<(), ()> {
|
|||
// },
|
||||
// _ => ()
|
||||
// }
|
||||
},
|
||||
}
|
||||
RecorderType::Cpal => {
|
||||
// Init CPAL
|
||||
info!("Initializing CPAL recording backend");
|
||||
|
|
@ -64,11 +76,11 @@ pub fn read_microphone(frame_buffer: &mut [i16]) {
|
|||
match RECORDER_TYPE.get().unwrap() {
|
||||
RecorderType::PvRecorder => {
|
||||
pvrecorder::read_microphone(frame_buffer);
|
||||
},
|
||||
}
|
||||
RecorderType::PortAudio => {
|
||||
todo!();
|
||||
// portaudio::read_microphone(frame_buffer);
|
||||
},
|
||||
}
|
||||
RecorderType::Cpal => {
|
||||
// cpal::read_microphone(frame_buffer);
|
||||
panic!("Cpal should be used via callback assignment");
|
||||
|
|
@ -79,12 +91,15 @@ pub fn read_microphone(frame_buffer: &mut [i16]) {
|
|||
pub fn start_recording() -> Result<(), ()> {
|
||||
match RECORDER_TYPE.get().unwrap() {
|
||||
RecorderType::PvRecorder => {
|
||||
return pvrecorder::start_recording(get_selected_microphone_index(), FRAME_LENGTH.get().unwrap().to_owned());
|
||||
},
|
||||
return pvrecorder::start_recording(
|
||||
get_selected_microphone_index(),
|
||||
FRAME_LENGTH.get().unwrap().to_owned(),
|
||||
);
|
||||
}
|
||||
RecorderType::PortAudio => {
|
||||
todo!();
|
||||
// portaudio::start_recording(get_selected_microphone_index(), FRAME_LENGTH.load(Ordering::SeqCst));
|
||||
},
|
||||
}
|
||||
RecorderType::Cpal => {
|
||||
todo!();
|
||||
// cpal::start_recording(get_selected_microphone_index(), FRAME_LENGTH.load(Ordering::SeqCst));
|
||||
|
|
@ -94,13 +109,11 @@ pub fn start_recording() -> Result<(), ()> {
|
|||
|
||||
pub fn stop_recording() -> Result<(), ()> {
|
||||
match RECORDER_TYPE.get().unwrap() {
|
||||
RecorderType::PvRecorder => {
|
||||
pvrecorder::stop_recording()
|
||||
},
|
||||
RecorderType::PvRecorder => pvrecorder::stop_recording(),
|
||||
RecorderType::PortAudio => {
|
||||
todo!();
|
||||
// portaudio::stop_recording();
|
||||
},
|
||||
}
|
||||
RecorderType::Cpal => {
|
||||
todo!();
|
||||
// cpal::stop_recording();
|
||||
|
|
@ -110,4 +123,28 @@ pub fn stop_recording() -> Result<(), ()> {
|
|||
|
||||
pub fn get_selected_microphone_index() -> i32 {
|
||||
DB.get().unwrap().microphone
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_audio_devices() -> Vec<String> {
|
||||
match RECORDER_TYPE.get().unwrap() {
|
||||
RecorderType::PvRecorder => pvrecorder::list_audio_devices(),
|
||||
RecorderType::PortAudio => {
|
||||
todo!();
|
||||
}
|
||||
RecorderType::Cpal => {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_audio_device_name(idx: i32) -> String {
|
||||
match RECORDER_TYPE.get().unwrap() {
|
||||
RecorderType::PvRecorder => pvrecorder::get_audio_device_name(idx),
|
||||
RecorderType::PortAudio => {
|
||||
todo!();
|
||||
}
|
||||
RecorderType::Cpal => {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue