What code to change to convert example patch to arduino ide

In the Daisy Seed examples I encountered things like:

#include "daisy_seed.h"
#include "daisysp.h"

// Use the daisy namespace to prevent having to type 
// daisy:: before all libdaisy functions
using namespace daisy;
using namespace daisysp;

1: What do I need to replace them with to be able to get things compiled in the arduino ide?

2: There seems to be a big difference in the definition of the buffers.

If I do not use the arduino ide, I can use

static void AudioCallback(float *in, float *out, size_t size)

as in

static void AudioCallback(float *in, float *out, size_t size)
{
    for (size_t index_2_buf = 0; index_2_buf < size; index_2_buf += 2)
    {
        x[0] = in[index_2_buf]; // This is the left channel.
        y[0] = in[index_2_buf + 1]; // This is the right channel

But if I use the IDE then I need to use:

static void AudioCallback(float **in, float **out, size_t size)

But then addressing the buffer like this:

for (size_t index_2_buf = 0; index_2_buf < size; index_2_buf+= num_channels)
{
      x[0] = in[0][index_2_buf];  // Should be left channel.
      y[0] = in[0][index_2_buf + size];  // should be right channel

does not give me the left and right channel samples.
What am I missing?

They’ve added second type of callback recently. This way working with multi-channel audio is more straightforward. You don’t need to skip samples in your loop iteration to get data for next channel, i.e. it would look like this:

for (size_t index_2_buf = 0; index_2_buf < size; index_2_buf++)
{
      x[0] = in[0][index_2_buf];  // Should be left channel.
      y[0] = in[1][index_2_buf];  // should be right channel

Now you can iterate over elements in a buffer without making things look butt-ugly!

1 Like

Not sure why you’re using x[0] / y[0], probably that would be x[index_buf] / y[index_buf] in real code

Thx for your reply!

x and y are part of 2 filters each with a few taps that process a channel each and serve more as an example here than anything else.

And what do I do with the includes?

#include "daisy_seed.h"
#include "daisysp.h"

First library is for accessing Daisy’s hardware. If you have problem with it, you’ve misconfigured something. The second is optional DSP library, you can use it or write code that doesn’t depend on it.

1 Like

So to sum things up, a bypass would look like so?

#include "DaisyDuino.h"

DaisyHardware hw;

void MyBypass(float **in, float **out, size_t size)
{
    for (size_t i = 0; i < size; i++)
    {
        out[0][i] = in[0][i];
        out[1][i] = in[1][i];        
    }
}

void setup() {
    float samplerate;
    // Initialize for Daisy pod at 48kHz
    hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
    samplerate = DAISY.get_samplerate();

    DAISY.begin(MyBypass);
}

void loop() {
}

Yep this is working!

[Edit] No it is not. Both signals seem to stem from the same input now?

That looks almost exactly like the Bypass example in the Arduino examples, which I have just verified works correctly with my Pod.

It can even be simplified further:

#include "DaisyDuino.h"

void MyCallback(float **in, float **out, size_t size)
{
    for (size_t i = 0; i < size; i++)
    {
      out[0][i] = in[0][i];
      out[1][i] = in[1][i];
    }
}

void setup() {

    DAISY.init(DAISY_SEED, AUDIO_SR_48K);
    DAISY.begin(MyCallback);
}

void loop() {
}

The odd thing is that this does not swap the channels, although I would expect it to:

#include "DaisyDuino.h"

void MyBypass(float **in, float **out, size_t size)
{
    for (size_t i = 0; i < size; i++)
    {
        out[1][i] = in[0][i];
        out[0][i] = in[1][i];        
    }
}

void setup() {
    DAISY.init(DAISY_SEED, AUDIO_SR_48K);
    DAISY.begin(MyBypass);
}

void loop() {
}

Any thoughts?

Daisy Patch has inputs normalization, not sure if that’s also the case with Pod.

That would be normalization of levels, I would assume.

Any thoughts on why the channel swapping doesn’t work?
Or does it on your Daisy Seed?

No, Patch, Petal and Field normalize audio signals - input is passed to next input if nothing is plugged. But Seed and Pod schematics don’t mention having this, so must be some other issue.

I just tried changing this:

out[0][i] = in[0][i];
out[1][i] = in[1][i];
to this:
out[1][i] = in[0][i];
out[0][i] = in[1][i];

And the result was as expected, the inputs switch sides.

Did you compile and upload that bit if code using the arduino IDE?
The odd thing is that if I use a Makefile and avoid using the IDE and the new callback, then it works.

I don’t understand. If nothing is plugged than what is passed as input to the next input?

See here

Yes, I’m using Arduino IDE, DaisyDuino, with Daisy Pod.

Would you be able to try that using the Daisy without the pod?

No, because I don’t have a spare breadboard and jacks on hand. But the Pod schematic clearly shows the input jack connects directly to the Seed’s inputs.

OK, thanks. That would not make much of a difference then.