Modifying code: C++ build error

Hardware- Patch.Init()
OS- Linux Ubuntu 22.04 LTS
:japanese_goblin:
Hello!
I’m trying to modify the patch_sm Triple Saw example in C++ and I’m having trouble when it comes to building my code. I usedthe Python helper to create the folder with everything in it but when I go ahead and Build the example in VSCode I get the following error/Problem:

identifier “DaisyPatchSM” is undefined

Output from Terminal:

[5/25/2022, 3:35:03 PM] Unable to resolve configuration with compilerPath “/usr/local/bin/arm-none-eabi-g++”. Using “/home/pc84/Developer/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc” instead.

Any ideas on where the DaisyPatchSm went?
I’m familiar with Python and only just now grappling with C++ so it seems like a pointer is missing or something in my path isn’t linked?
Thanks in advance!

Ps: For those curious all I’ve done in the code is change two of three wave forms. It’s the only thing I could make sense of and understand how to change so far (I think! LOL):

osc_a.SetWaveform(Oscillator::WAVE_POLYBLEP_SAW);
osc_b.SetWaveform(Oscillator::WAVE_POLYBLEP_TRI);
osc_c.SetWaveform(Oscillator::WAVE_POLYBLEP_SQUARE);

Hi! Sorry to hear you’re having trouble.

When using the helper with the PatchSM it’s important to set the board flag.
python helper.py create -b patch_sm <name>

To me, it sounds like the patch_sm board support file isn’t being included.
You should have #include "patch_sm.h" at the top of your file.

Hope that helps, otherwise we can keep trying figure it out!
It might be helpful to post your full code here, as well as the complete terminal output.

1 Like

Here’s the way i ran the helper on my terminal:

sudo ./helper.py create MyProjects/SoundBlaster9000 --board patch_sm

and here’s how I edited the TripleSaw_comments.cpp file :

#include "daisy_patch_sm.h"
#include "daisysp.h"

/** These are namespaces for the daisy libraries.
 *  These lines allow us to omit the "daisy::" and "daisysp::" before
 * referencing modules, and functions within the daisy libraries.
 */
using namespace daisy;
using namespace daisysp;

/** Our hardware board class handles the interface to the actual DaisyPatchSM
 * hardware. */
DaisyPatchSM hw;

/** A few Oscillators to build up a simple synthesizer
 *
 *  This is a generic oscillator class that can synthesize
 *  different waveforms, and has inputs for sync as well as FM
 */
Oscillator osc_a, osc_b, osc_c;

/** Callback for processing and synthesizing audio
 *
 *  The audio buffers are arranged as arrays of samples for each channel.
 *  For example, to access the left input you would use:
 *    in[0][n]
 *  where n is the specific sample.
 *  There are "size" samples in each array.
 *
 *  The default size is very small (just 4 samples per channel). This means the
 * callback is being called at 16kHz.
 *
 *  This size is acceptable for many applications, and provides an extremely low
 * latency from input to output. However, you can change this size by calling
 * hw.SetAudioBlockSize(desired_size). When running complex DSP it can be more
 * efficient to do the processing on larger chunks at a time.
 *
 */
void AudioCallback(AudioHandle::InputBuffer  in,
                   AudioHandle::OutputBuffer out,
                   size_t                    size)
{
    /** First we'll tell the hardware to process the 8 analog inputs */
    hw.ProcessAnalogControls();

    /** We'll get a nice frequency control knob by using midi note numbers */
    float coarse_tune = 12.f + (hw.GetAdcValue(0) * 72.f);

    /** Using the second analog input we'll use a fine tune of the primary
   * frequency. */
    float fine_tune = hw.GetAdcValue(1) * 10.f;

    /** Convert those values from midi notes to frequency */
    float freq_a = mtof(coarse_tune + fine_tune);

    /** Our third control will detune the voices from each other */
    float detune_amt = hw.GetAdcValue(2);

    /**  Detuning each of the other oscillators by upto 5% of the primary
   * frequency */
    float freq_b = freq_a + (0.05 * freq_a * detune_amt);
    float freq_c = freq_a - (0.05 * freq_a * detune_amt);

    /** Set the oscillators to those frequencies */
    osc_a.SetFreq(freq_a);
    osc_b.SetFreq(freq_b);
    osc_c.SetFreq(freq_c);

    /** This loop will allow us to process the individual samples of audio */
    for(size_t i = 0; i < size; i++)
    {
        /** We'll combine both oscillator signals using simple addition
     *
     *  All of the DSP modules within DaisySP feature a "Process" function
     *  that will return the next sample of the synthesized sound, or effect.
     */
        float sig = osc_a.Process() + osc_b.Process() + osc_c.Process();

        /** In this example both outputs will be the same */
        out[0][i] = out[1][i] = sig;
    }
}

int main(void)
{
    /** Initialize the hardware */
    hw.Init();

    /** Initialize the oscillator modules */
    osc_a.Init(hw.AudioSampleRate());
    osc_b.Init(hw.AudioSampleRate());
    osc_c.Init(hw.AudioSampleRate());

    /** Let's set some specific parameters that won't change during the example
   *  I'm updating this for the first time to out put 3 DIFFERENT waveforms.-pc84
   *  The POLYBLEP waveforms are bandlimited which means that they won't alias.
   */
    osc_a.SetWaveform(Oscillator::WAVE_POLYBLEP_SAW);
    osc_b.SetWaveform(Oscillator::WAVE_POLYBLEP_TRI);
    osc_c.SetWaveform(Oscillator::WAVE_POLYBLEP_SQUARE);

    /** Start Processing the audio */
    hw.StartAudio(AudioCallback);
    while(1) {}
}

When I run the build the terminal says:

> Executing task: make clean; make <

rm -fR build
mkdir build
mkdir: cannot create directory ‘build’: Permission denied
make: *** [../../libDaisy//core/Makefile:250: build] Error 1
The terminal process "/usr/bin/bash '-c', 'make clean; make'" failed to launch (exit code: 2).

Terminal will be reused by tasks, press any key to close it.

Thanks!

you probably shouldn’t use sudo in the first place. It messed up your folder permission, thus you getting “Permission denied” errors

1 Like

@brbrr That was definitely an issue. Thank you. I remade the folder and now I’m getting a different error. Thank you for the help, I’ll get there eventually!
Even though the error only sites the first .h file, the editor has them both highlighted as ‘not found’.
Will moving the .h files(helper files right?) into the same directory solve this or should it know how to find them where they live?

> Executing task: C/C++: arm-none-eabi-g++ build active file <

Starting build...
/home/pc84/Developer/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-g++ -fdiagnostics-color=always -g /home/pc84/Desktop/DaisyExamples/NewProjects/SoundBlaster9000/SoundBlaster9000.cpp -o /home/pc84/Desktop/DaisyExamples/NewProjects/SoundBlaster9000/SoundBlaster9000
/home/pc84/Desktop/DaisyExamples/NewProjects/SoundBlaster9000/SoundBlaster9000.cpp:1:10: fatal error: daisy_patch_sm.h: No such file or directory
    1 | #include "daisy_patch_sm.h"
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.

Build finished with error(s).

Terminal will be reused by tasks, press any key to close it.