I’m 99.99% sure this is a me problem, as I’ve found examples with this exact same goal (see QuadEnvelope) - My goal is to output audio, and separate values on the DAC roughly at the same time.
Since updating libdaisy, I now have no DAC output whatsoever, and I’m not sure if extra configuration is needed now. From referencing daisy_patch.cpp, I have modified libdaisy from master, at the time of writing this (f82fe079255160bf62aa7b667de815c9712fbf96) to contain the following:
diff --git a/src/daisy_seed.cpp b/src/daisy_seed.cpp
index 7b903106..83e84595 100644
--- a/src/daisy_seed.cpp
+++ b/src/daisy_seed.cpp
@@ -93,7 +93,7 @@ void DaisySeed::Configure()
// Configure internal peripherals
ConfigureSdram();
ConfigureQspi();
- //ConfigureDac();
+ ConfigureDac();
// Configure the built-in GPIOs.
led.pin.port = SEED_LED_PORT;
led.pin.pin = SEED_LED_PIN;
@@ -291,15 +291,17 @@ void DaisySeed::ConfigureAudio()
}
void DaisySeed::ConfigureDac()
{
+
// This would be the equivalent initialization as previously existed.
// However, not all platforms have the DAC, and many use those pins
// for other things.
- // DacHandle::Config cfg;
- // cfg.bitdepth = DacHandle::Config::BitDepth::BITS_12;
- // cfg.buff_state = DacHandle::Config::BufferState::ENABLED;
- // cfg.mode = DacHandle::Config::Mode::POLLING;
- // cfg.chn = DacHandle::Config::Channel::BOTH;
- // dac.Init(cfg);
+ DacHandle::Config cfg;
+ cfg.bitdepth = DacHandle::BitDepth::BITS_12;
+ cfg.buff_state = DacHandle::BufferState::ENABLED;
+ cfg.mode = DacHandle::Mode::POLLING;
+ cfg.chn = DacHandle::Channel::BOTH;
+ dac.Init(cfg);
+ dac.WriteValue(DacHandle::Channel::BOTH, 0); // changing this to 4095 does nothing
}
DaisySeed::BoardVersion DaisySeed::CheckBoardVersion()
The strange thing, is that I had the DAC working on an earlier version of libdaisy, which commit hash I can not find at the moment. However, it was fairly old.
Here is a small example program I wrote, my assumption was that the DAC would roughly follow the audio outputs. HOWEVER, I’m getting a strange behaviour, where if I write to the DAC right before the AudioCallback, it just dies, there is no output on the Audio pins whatsoever! Any help would be appreciated, and thank you so much for your help in advance - this is a great community
#include "daisy_seed.h"
#include "daisysp.h"
using namespace daisy;
using namespace daisysp;
static DaisySeed seed;
static Oscillator osc;
float sample_rate;
int map(float x, float in_min, float in_max, int out_min, int out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
int cvCh1;
int cvCh2;
void AudioCallback(AudioHandle::InputBuffer in, AudioHandle::OutputBuffer out, size_t size)
{
for (size_t i = 0; i < size; i++)
{
float y = osc.Process();
cvCh1 = map(y, -1.0, 1.0, 0, 4095);
cvCh2 = map(y * -1.0f, -1.0, 1.0, 0, 4095);
out[0][i] = y;
out[1][i] = y * -1.0f;
}
}
int main(void)
{
seed.Configure(); // This should run ConfigureDac()
seed.Init();
sample_rate = seed.AudioSampleRate();
osc.Init(sample_rate);
osc.SetWaveform(osc.WAVE_SIN);
osc.SetFreq(1);
osc.SetAmp(1);
// If uncommented, nothing happens on DAC, AudioCallback will NOT run
// seed.dac.WriteValue(DacHandle::Channel::ONE, 0);
// seed.dac.WriteValue(DacHandle::Channel::TWO, 4095);
seed.StartAudio(AudioCallback);
// If uncommented, nothing happens on DAC, but AudioCallback will run
// seed.dac.WriteValue(DacHandle::Channel::ONE, 0);
// seed.dac.WriteValue(DacHandle::Channel::TWO, 4095);
for(;;)
{
// Send the latest envelope values to the CV outs
// Nothing happens
seed.dac.WriteValue(DacHandle::Channel::ONE, cvCh1);
seed.dac.WriteValue(DacHandle::Channel::TWO, cvCh2);
seed.DelayMs(1);
}
}