mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
audio working, trying out longer samples
This commit is contained in:
parent
fe6b417643
commit
15fc4a6c36
6 changed files with 36 additions and 32 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -329,6 +329,7 @@ dependencies = [
|
|||
"rkyv 0.4.3",
|
||||
"susres",
|
||||
"ticktimer-server",
|
||||
"trng",
|
||||
"utralib",
|
||||
"xous",
|
||||
"xous-ipc",
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ xous-names = { path = "../xous-names" }
|
|||
log = "0.4"
|
||||
susres = {path = "../susres"}
|
||||
llio = {path = "../llio"}
|
||||
trng = {path = "../trng"}
|
||||
|
||||
xous-ipc = {path="../../xous-ipc"}
|
||||
num-derive = {version = "0.3", default-features = false}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,11 @@ impl FrameRing {
|
|||
self.wr_frame = 0;
|
||||
self.rec_ptr = 0;
|
||||
}
|
||||
pub fn reset_ptrs(&mut self) {
|
||||
self.rd_frame = 0;
|
||||
self.wr_frame = 0;
|
||||
self.rec_ptr = 0;
|
||||
}
|
||||
/*
|
||||
empty: rd_frame == wr_frame
|
||||
full: wr_frame == (rd_frame - 1) || (rd_frame == 0) && (wr_frame == F-1)
|
||||
|
|
|
|||
|
|
@ -418,9 +418,9 @@ impl Codec {
|
|||
|
||||
self.w(86, &[
|
||||
0b1_011_0000, // AGC enabled, target level = -12dB
|
||||
0b00_10001_0, // hysteresis 1dB, noise threshold = -((value-1)*2 + 30), 17 => -64dB
|
||||
0b00_10101_0, // hysteresis 1dB, noise threshold = -((value-1)*2 + 30): 21 => -70dB
|
||||
100, // max gain = code/2 dB
|
||||
0b_00101_000, // attack time = 0b_acode_mul = (acode*32*mul)/Fs
|
||||
0b_00010_000, // attack time = 0b_acode_mul = (acode*32*mul)/Fs
|
||||
0b_01101_000, // decay time = 0b_dcode_mul = (dcode*32*mul)/Fs
|
||||
0x01, // noise debounce time = code*4 / fs
|
||||
0x01, // signal debounce time = code*4 / fs
|
||||
|
|
@ -430,13 +430,15 @@ impl Codec {
|
|||
|
||||
/// set up the betrusted-side signals
|
||||
pub fn audio_i2s_start(&mut self) {
|
||||
/*
|
||||
self.csr.wfo(utra::audio::RX_CTL_RESET, 1);
|
||||
self.csr.wfo(utra::audio::TX_CTL_RESET, 1);
|
||||
|
||||
*/
|
||||
let volatile_audio = self.fifo.as_mut_ptr() as *mut u32;
|
||||
for _ in 0..FIFO_DEPTH*2 {
|
||||
unsafe { (volatile_audio).write(ZERO_PCM as u32 | (ZERO_PCM as u32) << 16); } // prefill TX fifo with zero's
|
||||
}
|
||||
|
||||
// enable interrupts on the RX_READY
|
||||
self.csr.wfo(utra::audio::EV_PENDING_RX_READY, 1); // clear any pending interrupt
|
||||
self.csr.wfo(utra::audio::EV_ENABLE_RX_READY, 1);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ fn xmain() -> ! {
|
|||
// register a suspend/resume listener
|
||||
let sr_cid = xous::connect(codec_sid).expect("couldn't create suspend callback connection");
|
||||
let mut susres = susres::Susres::new(&xns, api::Opcode::SuspendResume as u32, sr_cid).expect("couldn't create suspend/resume object");
|
||||
/*
|
||||
let trng = trng::Trng::new(&xns).unwrap();
|
||||
let mut noise: [u32; codec::FIFO_DEPTH] = [0; codec::FIFO_DEPTH];
|
||||
for i in 0..noise.len() {
|
||||
noise[i] = trng.get_u32().unwrap();
|
||||
}
|
||||
*/
|
||||
|
||||
let mut audio_cb_conns: [Option<ScalarCallback>; 32] = [None; 32];
|
||||
loop {
|
||||
|
|
@ -118,6 +125,7 @@ fn xmain() -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
framering.reset_ptrs();
|
||||
loop {
|
||||
if let Some(frame) = codec.dq_rec_frame() {
|
||||
if !framering.is_full() {
|
||||
|
|
|
|||
|
|
@ -24,9 +24,10 @@ pub struct Audio {
|
|||
impl Audio {
|
||||
pub fn new(xns: &xous_names::XousNames) -> Self {
|
||||
let sample = xous::syscall::map_memory(
|
||||
// 0x2634_0000 is the long sample. 0x2600_0000 is the short sample.
|
||||
Some(core::num::NonZeroUsize::new(0x2600_0000).unwrap()), // it's here, because we know it's here!
|
||||
None,
|
||||
0x8_0000,
|
||||
0x8_0000, // 0x8_0000 is length of short sample, 0x1C4_0000 is the long sample
|
||||
xous::MemoryFlags::R,
|
||||
).expect("couldn't map in the audio sample");
|
||||
let mut codec = codec::Codec::new(xns).unwrap();
|
||||
|
|
@ -85,42 +86,26 @@ impl<'a> ShellCmdApi<'a> for Audio {
|
|||
self.callback_id = Some(cb_id);
|
||||
}
|
||||
|
||||
write!(ret, "Playing sample...").unwrap();
|
||||
// load the initial sample data
|
||||
let (play_free, _) = self.codec.free_frames().unwrap();
|
||||
|
||||
let mut frames: FrameRing = FrameRing::new();
|
||||
let frames_to_push = if frames.writeable_count() < play_free {
|
||||
frames.writeable_count()
|
||||
if self.play_or_rec_n == true {
|
||||
write!(ret, "Playing sample...").unwrap();
|
||||
} else {
|
||||
play_free
|
||||
};
|
||||
log::info!("loading up {} frames", frames_to_push);
|
||||
write!(ret, "Playing previous microphone recording...").unwrap();
|
||||
}
|
||||
self.play_ptr_bytes = 0;
|
||||
self.rec_ptr_words = 0;
|
||||
self.framecount = frames_to_push as u32;
|
||||
for i in 0..frames_to_push {
|
||||
let mut frame: [u32; codec::FIFO_DEPTH] = [codec::ZERO_PCM as u32 | (codec::ZERO_PCM as u32) << 16; codec::FIFO_DEPTH];
|
||||
if self.play_or_rec_n {
|
||||
for sample in frame.iter_mut() {
|
||||
*sample = unsafe{self.raw_data.add(i).read_volatile()};
|
||||
}
|
||||
} else {
|
||||
for sample in frame.iter_mut() {
|
||||
*sample = unsafe{self.rec_data.add(i).read_volatile()};
|
||||
}
|
||||
}
|
||||
self.play_ptr_bytes += codec::FIFO_DEPTH * 4;
|
||||
frames.nq_frame(frame).unwrap();
|
||||
}
|
||||
log::debug!("pushing frames");
|
||||
self.codec.swap_frames(&mut frames).unwrap();
|
||||
// start the playing
|
||||
|
||||
log::info!("starting playback");
|
||||
self.codec.resume().unwrap();
|
||||
|
||||
// we'll get a callback that demands the next data...
|
||||
}
|
||||
"stop" => {
|
||||
self.codec.pause().unwrap(); // this should stop callbacks from occurring too.
|
||||
write!(ret, "Playback stopped at {} frames.", self.framecount).unwrap();
|
||||
self.framecount = 0;
|
||||
self.play_ptr_bytes = 0;
|
||||
self.rec_ptr_words = 0;
|
||||
}
|
||||
"fromrec" => {
|
||||
self.play_or_rec_n = false;
|
||||
write!(ret, "playing back from record buffer").unwrap();
|
||||
|
|
@ -196,6 +181,8 @@ impl<'a> ShellCmdApi<'a> for Audio {
|
|||
unsafe{*self.rec_data.add(i + self.rec_ptr_words as usize) = frame[i]};
|
||||
}
|
||||
self.rec_ptr_words += codec::FIFO_DEPTH as u32;
|
||||
} else {
|
||||
// just silently toss any overrun for now
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in a new issue