mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
lazy-allocate record buffer for tests
no reason to carry 32kiB of data around for factory tests in "normal" mode.
This commit is contained in:
parent
e112791915
commit
7c231f0955
1 changed files with 44 additions and 29 deletions
|
|
@ -20,7 +20,7 @@ pub struct Test {
|
||||||
state: u32,
|
state: u32,
|
||||||
// audio
|
// audio
|
||||||
codec: codec::Codec,
|
codec: codec::Codec,
|
||||||
recbuf: xous::MemoryRange,
|
recbuf: Option<xous::MemoryRange>,
|
||||||
callback_id: Option<u32>,
|
callback_id: Option<u32>,
|
||||||
callback_conn: u32,
|
callback_conn: u32,
|
||||||
framecount: u32,
|
framecount: u32,
|
||||||
|
|
@ -44,18 +44,11 @@ impl Test {
|
||||||
pub fn new(xns: &xous_names::XousNames) -> Self {
|
pub fn new(xns: &xous_names::XousNames) -> Self {
|
||||||
let codec = codec::Codec::new(xns).unwrap();
|
let codec = codec::Codec::new(xns).unwrap();
|
||||||
|
|
||||||
let recbuf = xous::syscall::map_memory(
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
0x8000,
|
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
|
||||||
).expect("couldn't allocate record buffer");
|
|
||||||
|
|
||||||
let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_SHELLCHAT).unwrap();
|
let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_SHELLCHAT).unwrap();
|
||||||
|
|
||||||
Test {
|
Test {
|
||||||
codec,
|
codec,
|
||||||
recbuf,
|
recbuf: None,
|
||||||
state: 0,
|
state: 0,
|
||||||
callback_id: None,
|
callback_id: None,
|
||||||
callback_conn,
|
callback_conn,
|
||||||
|
|
@ -398,10 +391,20 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
// now do FFT analysis on the sample buffer
|
// now do FFT analysis on the sample buffer
|
||||||
// analyze one channel at a time
|
// analyze one channel at a time
|
||||||
let mut right_samples = Vec::<f32>::new();
|
let mut right_samples = Vec::<f32>::new();
|
||||||
let recslice = self.recbuf.as_slice::<u32>();
|
if self.recbuf.is_none() { // lazy allocate recbuf
|
||||||
for &sample in recslice[recslice.len()-4096..].iter() {
|
self.recbuf = Some(xous::syscall::map_memory(
|
||||||
right_samples.push( ((sample & 0xFFFF) as i16) as f32 );
|
None,
|
||||||
//left_samples.push( (((sample >> 16) & 0xFFFF) as i16) as f32 ); // reminder of how to extract the right channel
|
None,
|
||||||
|
0x8000,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
).expect("couldn't allocate record buffer"));
|
||||||
|
}
|
||||||
|
if let Some(recbuf) = self.recbuf {
|
||||||
|
let recslice = recbuf.as_slice::<u32>();
|
||||||
|
for &sample in recslice[recslice.len()-4096..].iter() {
|
||||||
|
right_samples.push( ((sample & 0xFFFF) as i16) as f32 );
|
||||||
|
//left_samples.push( (((sample >> 16) & 0xFFFF) as i16) as f32 ); // reminder of how to extract the right channel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// only one channel is considered, because in reality the left is just a copy of the right, as
|
// only one channel is considered, because in reality the left is just a copy of the right, as
|
||||||
// we are taking a mono microphone signal and mixing it into both ADCs
|
// we are taking a mono microphone signal and mixing it into both ADCs
|
||||||
|
|
@ -807,23 +810,35 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
self.codec.swap_frames(&mut frames).unwrap();
|
self.codec.swap_frames(&mut frames).unwrap();
|
||||||
|
|
||||||
if !AUDIO_OQC.load(Ordering::Relaxed) {
|
if !AUDIO_OQC.load(Ordering::Relaxed) {
|
||||||
let rec_samples = self.recbuf.as_slice_mut::<u32>();
|
if self.recbuf.is_none() { // lazy allocate recbuf
|
||||||
let rec_len = rec_samples.len();
|
self.recbuf = Some(xous::syscall::map_memory(
|
||||||
loop {
|
None,
|
||||||
if let Some(frame) = frames.dq_frame() {
|
None,
|
||||||
for &sample in frame.iter() {
|
0x8000,
|
||||||
rec_samples[self.rec_sample] = sample;
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
// increment and wrap around on overflow
|
).expect("couldn't allocate record buffer"));
|
||||||
// we should be sampling a continuous tone, so we'll get a small phase discontinutity once in the buffer.
|
}
|
||||||
// should be no problem for the analysis phase.
|
if let Some(mut recbuf) = self.recbuf {
|
||||||
self.rec_sample += 1;
|
let rec_samples = recbuf.as_slice_mut::<u32>();
|
||||||
if self.rec_sample >= rec_len {
|
let rec_len = rec_samples.len();
|
||||||
self.rec_sample = 0;
|
loop {
|
||||||
|
if let Some(frame) = frames.dq_frame() {
|
||||||
|
for &sample in frame.iter() {
|
||||||
|
rec_samples[self.rec_sample] = sample;
|
||||||
|
// increment and wrap around on overflow
|
||||||
|
// we should be sampling a continuous tone, so we'll get a small phase discontinutity once in the buffer.
|
||||||
|
// should be no problem for the analysis phase.
|
||||||
|
self.rec_sample += 1;
|
||||||
|
if self.rec_sample >= rec_len {
|
||||||
|
self.rec_sample = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
break;
|
||||||
break;
|
};
|
||||||
};
|
}
|
||||||
|
} else {
|
||||||
|
panic!("recbuf was not allocated");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let elapsed = env.ticktimer.elapsed_ms();
|
let elapsed = env.ticktimer.elapsed_ms();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue