Simple bytebeat-inspired DaisySP wrapper using sox

i’m getting my feet wet with DaisySP, trying to use it on MacOS. I also have the hardware, but I want a faster way to code stuff, without the slow feedback loop + I’m also interested to run it in other ways.

inspired by bytebeat/floatbeat, here’s what i came up with:

(disclaimer: i have no cpp skills, so my way of building might be stupid)

  1. prequisite:
brew install sox # replace with similar command on other platforms
# clone repo
git clone https://github.com/electro-smith/DaisySP.git
cd DaisySP
# build
mkdir build && cd build
cmake .. -DCMAKE_OSX_ARCHITECTURES=arm64
make
cd ..
# create test file:
mkdir hello && touch ./hello/daisy_sine.cpp
  1. create test file
// daisy_sine.cpp
#include <cmath>
#include <cstdio>
#include "daisysp.h"

using namespace daisysp;

#define BUFFER_SIZE 1024

int main()
{
    Oscillator osc;
    osc.Init(48000);
    osc.SetWaveform(osc.WAVE_SIN);
    osc.SetFreq(440.0f);
    float buffer[BUFFER_SIZE];

    while(1)
    {
        for(unsigned int t = 0; t < BUFFER_SIZE; t++)
        {
            float sample = osc.Process();
            buffer[t]    = sample * 0.3;
        }
        fwrite(buffer, sizeof(float), BUFFER_SIZE, stdout);
    }
    return 0;
}
  1. compile
g++ ./hello/daisy_sine.cpp -o ./hello/daisy_sine -I./Source -L./build -ldaisysp # compile
  1. run
./hello/daisy_sine | sox -traw -r48000 -b32 -e float -c 1 - -tcoreaudio # run through sox

maybe someone is looking for this. would be interested to hear if other people are doing this / similar things and how they approach it.

3 Likes

I really want to get this to work but I keep getting errors when I try to compile the file.

➜ daisySP git:(master) ✗ g++ ./hello/daisy_sine.cpp -o ./hello/daisy_sine -I./Source -L./build -ldaisysp # compile

In file included from ./hello/daisy_sine.cpp:3:

In file included from ./Source/daisysp.h:20:

./Source/Control/adsr.h:90:13: error: function definition does not declare parameters

float   sus_level\_{0.f};

        **^**

./Source/Control/adsr.h:91:13: error: function definition does not declare parameters

float   x\_{0.f};

        **^**

./Source/Control/adsr.h:92:13: error: function definition does not declare parameters

float   attackShape\_{-1.f};

        **^**

./Source/Control/adsr.h:93:13: error: function definition does not declare parameters

float   attackTarget\_{0.0f};

        **^**

./Source/Control/adsr.h:94:13: error: function definition does not declare parameters

float   attackTime\_{-1.0f};

        **^**

./Source/Control/adsr.h:95:13: error: function definition does not declare parameters

float   decayTime\_{-1.0f};

        **^**

./Source/Control/adsr.h:96:13: error: function definition does not declare parameters

float   releaseTime\_{-1.0f};

        **^**

./Source/Control/adsr.h:97:13: error: function definition does not declare parameters

float   attackD0\_{0.f};

        **^**

./Source/Control/adsr.h:98:13: error: function definition does not declare parameters

float   decayD0\_{0.f};

        **^**

./Source/Control/adsr.h:99:13: error: function definition does not declare parameters

float   releaseD0\_{0.f};

        **^**

./Source/Control/adsr.h:101:13: error: function definition does not declare parameters

uint8_t mode\_{ADSR_SEG_IDLE};

        **^**

./Source/Control/adsr.h:102:13: error: function definition does not declare parameters

bool    gate\_{false};

        **^**

./Source/Control/adsr.h:78:9: error: use of undeclared identifier ‘sus_level_’; did you mean ‘sus_level’?

    sus_level\_ = sus_level;

    **^\~\~\~\~\~\~\~\~\~**

    sus_level

./Source/Control/adsr.h:74:39: note: ‘sus_level’ declared here

inline void SetSustainLevel(float sus_level)

                                  **^**

./Source/Control/adsr.h:83:49: error: use of undeclared identifier ‘mode_’

inline uint8_t GetCurrentSegment() { return mode\_; }

                                            **^**

./Source/Control/adsr.h:87:44: error: use of undeclared identifier ‘mode_’

inline bool IsRunning() const { return mode\_ != ADSR_SEG_IDLE; }

                                       **^**

In file included from ./hello/daisy_sine.cpp:3:

In file included from ./Source/daisysp.h:24:

In file included from ./Source/Drums/analogbassdrum.h:16:

In file included from ./Source/Synthesis/oscillator.h:13:

./Source/Utility/dsp.h:32:8: error: unknown type name ‘constexpr’

static constexpr float kRandFrac = 1.f / (float)RAND_MAX;

   **^**

./Source/Utility/dsp.h:35:8: error: unknown type name ‘constexpr’

static constexpr float kOneTwelfth = 1.f / 12.f;

   **^**

./Source/Utility/dsp.h:157:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]

enum class Mapping

 **^**

./Source/Utility/dsp.h:177:54: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]

fmap(float in, float min, float max, Mapping curve = Mapping::LINEAR)

                                                 **^**

./Source/Utility/dsp.h:181:14: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]

    case Mapping::EXP:

         **^**

./Source/Utility/dsp.h:181:14: error: integral constant expression must have integral or unscoped enumeration type, not ‘daisysp::Mapping’

    case Mapping::EXP:

         **^\~\~\~\~\~\~\~\~\~\~\~**

./Source/Utility/dsp.h:183:14: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]

    case Mapping::LOG:

         **^**

./Source/Utility/dsp.h:183:14: error: integral constant expression must have integral or unscoped enumeration type, not ‘daisysp::Mapping’

    case Mapping::LOG:

         **^\~\~\~\~\~\~\~\~\~\~\~**

./Source/Utility/dsp.h:188:14: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]

    case Mapping::LINEAR:

         **^**

fatal error: too many errors emitted, stopping now [-ferror-limit=]