stuff
This commit is contained in:
parent
67e4b2382b
commit
37bb77bc88
7 changed files with 78 additions and 49 deletions
|
@ -6,8 +6,6 @@
|
||||||
#define AUDIOC_LOG (daisy_hw.PrintLine)
|
#define AUDIOC_LOG (daisy_hw.PrintLine)
|
||||||
extern daisy::DaisySeed daisy_hw;
|
extern daisy::DaisySeed daisy_hw;
|
||||||
|
|
||||||
#define AUDIOC_DEBUG
|
|
||||||
|
|
||||||
#ifdef AUDIOC_DEBUG
|
#ifdef AUDIOC_DEBUG
|
||||||
|
|
||||||
#define AUDIOC_DBG_IND() (daisy_hw.SetLed(true))
|
#define AUDIOC_DBG_IND() (daisy_hw.SetLed(true))
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#include "audioc.hpp"
|
|
||||||
#include "scope.hpp"
|
#include "scope.hpp"
|
||||||
#include "osclsk.hpp"
|
#include "osclsk.hpp"
|
||||||
|
|
||||||
|
#define AUDIOC_DEBUG
|
||||||
|
#include "audioc.hpp"
|
||||||
|
|
||||||
|
|
||||||
#define _HUUUGE_FLOAT (std::numeric_limits<float>::infinity())
|
#define _HUUUGE_FLOAT (std::numeric_limits<float>::infinity())
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -166,15 +169,14 @@ osclsk_scope::sample(const float *sig, size_t num)
|
||||||
trig_lkb_num = 0;
|
trig_lkb_num = 0;
|
||||||
sample_trigger(&sig[i], num - i);
|
sample_trigger(&sig[i], num - i);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
break;
|
|
||||||
case osc_state::TRIGGER:
|
case osc_state::TRIGGER:
|
||||||
case osc_state::SAMPLE_DONE:
|
case osc_state::SAMPLE_DONE:
|
||||||
case osc_state::RENDER:
|
case osc_state::RENDER:
|
||||||
case osc_state::RENDER_DONE:
|
case osc_state::RENDER_DONE:
|
||||||
case osc_state::READY:
|
case osc_state::READY:
|
||||||
sample_trigger(sig, num);
|
sample_trigger(sig, num);
|
||||||
break;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -200,21 +202,39 @@ osclsk_scope::is_triggering(float sample)
|
||||||
void
|
void
|
||||||
osclsk_scope::trig_lkb_wr_block(void)
|
osclsk_scope::trig_lkb_wr_block(void)
|
||||||
{
|
{
|
||||||
size_t lkb_i, n;
|
size_t lkb_start, n;
|
||||||
|
size_t lkb_cpy, lkb_cpy_part;
|
||||||
|
|
||||||
lkb_i = trig_lkb_idx >= trig_lkb_amount ?
|
if (trig_mode == osc_trig_mode::INSTANT)
|
||||||
trig_lkb_idx - (trig_lkb_amount) :
|
lkb_cpy = trig_lkb_num;
|
||||||
OSCLSK_TRIG_LOOKBACK + trig_lkb_idx - (trig_lkb_amount);
|
else
|
||||||
|
lkb_cpy = std::min(trig_lkb_num, trig_lkb_amount);
|
||||||
|
|
||||||
|
lkb_start = trig_lkb_idx >= lkb_cpy ? trig_lkb_idx - lkb_cpy :
|
||||||
|
OSCLSK_TRIG_LOOKBACK + trig_lkb_idx - lkb_cpy;
|
||||||
|
|
||||||
|
lkb_cpy_part = OSCLSK_TRIG_LOOKBACK - lkb_start >= lkb_cpy ? lkb_cpy :
|
||||||
|
OSCLSK_TRIG_LOOKBACK - lkb_start;
|
||||||
|
|
||||||
block_fill = 0;
|
block_fill = 0;
|
||||||
for (n = 0; n < trig_lkb_amount; n++) {
|
|
||||||
block_y_max[block_fill] = trig_lkb_y_max[lkb_i];
|
|
||||||
block_y_min[block_fill] = trig_lkb_y_min[lkb_i];
|
|
||||||
|
|
||||||
block_fill++;
|
std::copy(trig_lkb_y_max + lkb_start,
|
||||||
lkb_i = (lkb_i + 1) & (OSCLSK_TRIG_LOOKBACK - 1);
|
trig_lkb_y_max + lkb_start + lkb_cpy_part, block_y_max);
|
||||||
|
std::copy(trig_lkb_y_min + lkb_start,
|
||||||
|
trig_lkb_y_min + lkb_start + lkb_cpy_part, block_y_min);
|
||||||
|
|
||||||
|
block_fill += lkb_cpy_part;
|
||||||
|
|
||||||
|
lkb_cpy -= lkb_cpy_part;
|
||||||
|
if (lkb_cpy > 0) {
|
||||||
|
std::copy(trig_lkb_y_max, trig_lkb_y_max + lkb_cpy,
|
||||||
|
block_y_max + lkb_cpy_part);
|
||||||
|
std::copy(trig_lkb_y_min, trig_lkb_y_min + lkb_cpy,
|
||||||
|
block_y_min + lkb_cpy_part);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
block_fill += lkb_cpy;
|
||||||
|
|
||||||
/* we wanna resume sampling from right after the lookback data,
|
/* we wanna resume sampling from right after the lookback data,
|
||||||
* so we write partial data points to block as well */
|
* so we write partial data points to block as well */
|
||||||
block_y_max[block_fill] = trig_lkb_y_max[trig_lkb_idx];
|
block_y_max[block_fill] = trig_lkb_y_max[trig_lkb_idx];
|
||||||
|
@ -247,21 +267,22 @@ osclsk_scope::sample_trigger(const float *sig, size_t num)
|
||||||
trig_lkb_idx_nsamp++;
|
trig_lkb_idx_nsamp++;
|
||||||
if (trig_lkb_idx_nsamp >= OSCLSK_RATE_DIV) {
|
if (trig_lkb_idx_nsamp >= OSCLSK_RATE_DIV) {
|
||||||
trig_lkb_idx++;
|
trig_lkb_idx++;
|
||||||
|
trig_lkb_idx = trig_lkb_idx &
|
||||||
|
(OSCLSK_TRIG_LOOKBACK - 1);
|
||||||
trig_lkb_idx_nsamp = 0;
|
trig_lkb_idx_nsamp = 0;
|
||||||
}
|
|
||||||
|
|
||||||
trig_lkb_num = std::min(trig_lkb_num + 1,
|
trig_lkb_num = std::min(trig_lkb_num + 1,
|
||||||
OSCLSK_TRIG_LOOKBACK);
|
OSCLSK_TRIG_LOOKBACK);
|
||||||
|
}
|
||||||
trig_lkb_idx =
|
|
||||||
trig_lkb_idx & (OSCLSK_TRIG_LOOKBACK - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* only do triggering checks in TRIGGER state and out lookback buffer is
|
/* only do triggering checks in TRIGGER state and if out lookback buffer
|
||||||
* full enough */
|
* is full enough */
|
||||||
if (st != osc_state::TRIGGER || trig_lkb_num < trig_lkb_amount)
|
if (st != osc_state::TRIGGER ||
|
||||||
|
(trig_mode != osc_trig_mode::INSTANT &&
|
||||||
|
trig_lkb_num < trig_lkb_amount)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* trigger needs to be in NO_TRIG before TRIG state for e.g.
|
/* trigger needs to be in NO_TRIG before TRIG state for e.g.
|
||||||
* RISING_EDGE trigger mode */
|
* RISING_EDGE trigger mode */
|
||||||
|
|
|
@ -12,7 +12,8 @@ using namespace daisy;
|
||||||
#define OSCLSK_SCREEN_YSZ ILI9341_TFTWIDTH
|
#define OSCLSK_SCREEN_YSZ ILI9341_TFTWIDTH
|
||||||
|
|
||||||
|
|
||||||
#define OSCLSK_RATE_DIV 32
|
#define OSCLSK_RATE_DIV 64
|
||||||
|
#define OSCLSK_LKB_AMOUNT 32
|
||||||
|
|
||||||
#define OSCLSK_BLOCK_LEN OSCLSK_SCREEN_XSZ
|
#define OSCLSK_BLOCK_LEN OSCLSK_SCREEN_XSZ
|
||||||
#define OSCLSK_TRIG_LOOKBACK 0x100u
|
#define OSCLSK_TRIG_LOOKBACK 0x100u
|
||||||
|
@ -86,7 +87,7 @@ struct osclsk_scope {
|
||||||
osclsk_scope(void) : st(osc_state::INIT),
|
osclsk_scope(void) : st(osc_state::INIT),
|
||||||
block_fill(0), block_fill_nsamp(0),
|
block_fill(0), block_fill_nsamp(0),
|
||||||
trig_lkb_idx(0), trig_lkb_idx_nsamp(0),
|
trig_lkb_idx(0), trig_lkb_idx_nsamp(0),
|
||||||
trig_lkb_amount(2),
|
trig_lkb_amount(OSCLSK_LKB_AMOUNT),
|
||||||
trig_margin(.01f), trig_num(0),
|
trig_margin(.01f), trig_num(0),
|
||||||
trig_num_req(2),
|
trig_num_req(2),
|
||||||
trig_state(osc_trig_state::INIT),
|
trig_state(osc_trig_state::INIT),
|
||||||
|
|
|
@ -8,13 +8,17 @@ using namespace daisy;
|
||||||
using namespace daisysp;
|
using namespace daisysp;
|
||||||
|
|
||||||
#define DMA_AREA_SIZE (1 << 12)
|
#define DMA_AREA_SIZE (1 << 12)
|
||||||
#define SCOPE_RING_BUF_SIZE 1024
|
#define SCOPE_RING_BUF_SIZE 4096
|
||||||
#define AUDIO_BLOCK_SIZE 2
|
#define AUDIO_BLOCK_SIZE 2
|
||||||
|
|
||||||
|
#define AUDIOC_DEBUG
|
||||||
|
|
||||||
/* declarations */
|
/* declarations */
|
||||||
DaisySeed daisy_hw;
|
DaisySeed daisy_hw;
|
||||||
|
|
||||||
|
#ifdef AUDIOC_DEBUG
|
||||||
CpuLoadMeter load_meter;
|
CpuLoadMeter load_meter;
|
||||||
|
#endif
|
||||||
|
|
||||||
osclsk_scope scope;
|
osclsk_scope scope;
|
||||||
|
|
||||||
|
@ -39,7 +43,9 @@ audio_cb(AudioHandle::InputBuffer in,
|
||||||
float osc_out, noise_out, snr_env_out, kck_env_out;
|
float osc_out, noise_out, snr_env_out, kck_env_out;
|
||||||
float sig[AUDIO_BLOCK_SIZE];
|
float sig[AUDIO_BLOCK_SIZE];
|
||||||
|
|
||||||
// load_meter.OnBlockStart();
|
#ifdef AUDIOC_DEBUG
|
||||||
|
load_meter.OnBlockStart();
|
||||||
|
#endif
|
||||||
//Get rid of any bouncing
|
//Get rid of any bouncing
|
||||||
snare.Debounce();
|
snare.Debounce();
|
||||||
kick.Debounce();
|
kick.Debounce();
|
||||||
|
@ -89,7 +95,9 @@ audio_cb(AudioHandle::InputBuffer in,
|
||||||
|
|
||||||
scope_in.Overwrite(sig, sz);
|
scope_in.Overwrite(sig, sz);
|
||||||
|
|
||||||
// load_meter.OnBlockEnd();
|
#ifdef AUDIOC_DEBUG
|
||||||
|
load_meter.OnBlockEnd();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -143,14 +151,15 @@ main(void)
|
||||||
{
|
{
|
||||||
size_t read;
|
size_t read;
|
||||||
float s[AUDIO_BLOCK_SIZE];
|
float s[AUDIO_BLOCK_SIZE];
|
||||||
uint32_t load_tick;
|
|
||||||
daisy_hw.Configure();
|
daisy_hw.Configure();
|
||||||
daisy_hw.Init();
|
daisy_hw.Init();
|
||||||
daisy_hw.StartLog(false); /* true = wait for usb connection */
|
daisy_hw.StartLog(false); /* true = wait for usb connection */
|
||||||
daisy_hw.SetAudioBlockSize(AUDIO_BLOCK_SIZE);
|
daisy_hw.SetAudioBlockSize(AUDIO_BLOCK_SIZE);
|
||||||
|
|
||||||
//load_meter.Init(daisy_hw.AudioSampleRate(), daisy_hw.AudioBlockSize());
|
#ifdef AUDIOC_DEBUG
|
||||||
//load_tick = LOAD_METER_TICKS;
|
load_meter.Init(daisy_hw.AudioSampleRate(), daisy_hw.AudioBlockSize());
|
||||||
|
uint32_t load_tick = LOAD_METER_TICKS;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (scope.init(dma_area, sizeof(dma_area)) == -1)
|
if (scope.init(dma_area, sizeof(dma_area)) == -1)
|
||||||
daisy_hw.PrintLine("scope.init failed");
|
daisy_hw.PrintLine("scope.init failed");
|
||||||
|
@ -188,18 +197,20 @@ main(void)
|
||||||
scope.sample(s, read);
|
scope.sample(s, read);
|
||||||
|
|
||||||
|
|
||||||
// if (--load_tick == 0) {
|
#ifdef AUDIOC_DEBUG
|
||||||
// load_tick = LOAD_METER_TICKS;
|
if (--load_tick == 0) {
|
||||||
// // get the current load (smoothed value and peak values)
|
load_tick = LOAD_METER_TICKS;
|
||||||
// const float avgLoad = load_meter.GetAvgCpuLoad();
|
// get the current load (smoothed value and peak values)
|
||||||
// const float maxLoad = load_meter.GetMaxCpuLoad();
|
const float avgLoad = load_meter.GetAvgCpuLoad();
|
||||||
// const float minLoad = load_meter.GetMinCpuLoad();
|
const float maxLoad = load_meter.GetMaxCpuLoad();
|
||||||
// // print it to the serial connection (as percentages)
|
const float minLoad = load_meter.GetMinCpuLoad();
|
||||||
// daisy_hw.PrintLine("Processing Load %:");
|
// print it to the serial connection (as percentages)
|
||||||
// daisy_hw.PrintLine("Max: " FLT_FMT3, FLT_VAR3(maxLoad * 100.0f));
|
daisy_hw.PrintLine("Processing Load %:");
|
||||||
// daisy_hw.PrintLine("Avg: " FLT_FMT3, FLT_VAR3(avgLoad * 100.0f));
|
daisy_hw.PrintLine("Max: " FLT_FMT3, FLT_VAR3(maxLoad * 100.0f));
|
||||||
// daisy_hw.PrintLine("Min: " FLT_FMT3, FLT_VAR3(minLoad * 100.0f));
|
daisy_hw.PrintLine("Avg: " FLT_FMT3, FLT_VAR3(avgLoad * 100.0f));
|
||||||
// }
|
daisy_hw.PrintLine("Min: " FLT_FMT3, FLT_VAR3(minLoad * 100.0f));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,5 @@
|
||||||
#define _SCOPE_HPP
|
#define _SCOPE_HPP
|
||||||
|
|
||||||
#include "daisy_seed.h"
|
#include "daisy_seed.h"
|
||||||
#include "audioc.hpp"
|
|
||||||
|
|
||||||
#endif /* _SCOPE_HPP */
|
#endif /* _SCOPE_HPP */
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
#include "tft.hpp"
|
#include "tft.hpp"
|
||||||
|
|
||||||
|
#define AUDIOC_DEBUG
|
||||||
|
#include "audioc.hpp"
|
||||||
|
|
||||||
using namespace daisy;
|
using namespace daisy;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
#define _TFT_HPP
|
#define _TFT_HPP
|
||||||
|
|
||||||
#include "daisy.h"
|
#include "daisy.h"
|
||||||
|
|
||||||
#include "scope.hpp"
|
#include "scope.hpp"
|
||||||
#include "audioc.hpp"
|
|
||||||
|
|
||||||
using namespace daisy;
|
using namespace daisy;
|
||||||
|
|
||||||
|
@ -133,8 +131,6 @@ struct tft_cmd {
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
AUDIOC_ASSERT(param_len <= sizeof(_param_bytes));
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (auto par : params) {
|
for (auto par : params) {
|
||||||
_param_bytes[i++] = par;
|
_param_bytes[i++] = par;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue