125 lines
2.7 KiB
C++
125 lines
2.7 KiB
C++
#include "daisy_seed.h"
|
|
#include "daisysp.h"
|
|
|
|
#include "scope.hpp"
|
|
#include "osclsk.hpp"
|
|
|
|
using namespace daisy;
|
|
using namespace daisysp;
|
|
|
|
#define DMA_AREA_SIZE (1 << 12)
|
|
#define SCOPE_RING_BUF_SIZE 4096
|
|
#define AUDIO_BLOCK_SIZE 2
|
|
|
|
/* declarations */
|
|
DaisySeed daisy_hw;
|
|
System sys;
|
|
|
|
#ifdef AUDIOC_DEBUG
|
|
CpuLoadMeter load_meter;
|
|
#endif
|
|
|
|
osclsk_scope scope;
|
|
|
|
uint8_t DMA_BUFFER_MEM_SECTION dma_area[DMA_AREA_SIZE];
|
|
|
|
static void audio_cb(AudioHandle::InputBuffer in,
|
|
AudioHandle::OutputBuffer out, size_t sz);
|
|
|
|
RingBuffer<float, SCOPE_RING_BUF_SIZE> scope_in;
|
|
|
|
void
|
|
audio_cb(AudioHandle::InputBuffer in,
|
|
AudioHandle::OutputBuffer out, size_t sz)
|
|
{
|
|
#ifdef AUDIOC_DEBUG
|
|
load_meter.OnBlockStart();
|
|
#endif
|
|
float sig[AUDIO_BLOCK_SIZE];
|
|
size_t i;
|
|
|
|
for (i = 0; i < sz; i++) {
|
|
sig[i] = in[0][i];
|
|
}
|
|
|
|
/* write to output */
|
|
for (i = 0; i < sz; i++) {
|
|
out[0][i] = sig[i];
|
|
out[1][i] = sig[i];
|
|
}
|
|
|
|
scope_in.Overwrite(sig, sz);
|
|
|
|
#ifdef AUDIOC_DEBUG
|
|
load_meter.OnBlockEnd();
|
|
#endif
|
|
}
|
|
|
|
#define LOAD_FREQ 5
|
|
#define LOAD_PERIOD (1000u / LOAD_FREQ)
|
|
int
|
|
main(void)
|
|
{
|
|
size_t read;
|
|
float s[AUDIO_BLOCK_SIZE];
|
|
daisy_hw.Configure();
|
|
daisy_hw.Init();
|
|
daisy_hw.StartLog(false); /* true = wait for usb connection */
|
|
daisy_hw.SetAudioBlockSize(AUDIO_BLOCK_SIZE);
|
|
|
|
#ifdef AUDIOC_DEBUG
|
|
load_meter.Init(daisy_hw.AudioSampleRate(), daisy_hw.AudioBlockSize());
|
|
uint32_t load_tick = sys.GetNow();
|
|
uint32_t t;
|
|
#endif
|
|
|
|
if (scope.init(dma_area, sizeof(dma_area)) == -1)
|
|
daisy_hw.PrintLine("scope.init failed");
|
|
|
|
scope_in.Init();
|
|
|
|
daisy_hw.StartAudio(audio_cb);
|
|
|
|
while (true) {
|
|
|
|
switch (scope.state()) {
|
|
case osclsk_scope::osc_state::SAMPLE_DONE:
|
|
scope.render_block();
|
|
break;
|
|
case osclsk_scope::osc_state::RENDER:
|
|
scope.render_block();
|
|
break;
|
|
case osclsk_scope::osc_state::RENDER_DONE:
|
|
scope.prep();
|
|
break;
|
|
case osclsk_scope::osc_state::READY:
|
|
scope.trig();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
read = scope_in.readable();
|
|
read = (read <= sizeof(s)/sizeof(*s)) ? read :
|
|
sizeof(s)/sizeof(*s);
|
|
scope_in.ImmediateRead(s, read);
|
|
scope.sample(s, read);
|
|
|
|
|
|
#ifdef AUDIOC_DEBUG
|
|
if ((t = sys.GetNow()) > load_tick + LOAD_PERIOD) {
|
|
load_tick = t;
|
|
// get the current load (smoothed value and peak values)
|
|
const float avgLoad = load_meter.GetAvgCpuLoad();
|
|
const float maxLoad = load_meter.GetMaxCpuLoad();
|
|
const float minLoad = load_meter.GetMinCpuLoad();
|
|
// print it to the serial connection (as percentages)
|
|
daisy_hw.PrintLine("Processing Load %:");
|
|
daisy_hw.PrintLine("Max: " FLT_FMT3, FLT_VAR3(maxLoad * 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
|
|
}
|
|
}
|
|
|