fix bw_env_gen uninit var + beginning of daisy synth examples
This commit is contained in:
parent
fece83f179
commit
e4d2d984c8
125
examples/common/daisy-seed/synth.cpp
Normal file
125
examples/common/daisy-seed/synth.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include "daisy_seed.h"
|
||||
#include "config.h"
|
||||
#include "config_daisy_seed.h"
|
||||
|
||||
#define BLOCK_SIZE 32
|
||||
|
||||
using namespace daisy;
|
||||
|
||||
DaisySeed hardware;
|
||||
CpuLoadMeter loadMeter;
|
||||
MidiUsbHandler midi;
|
||||
|
||||
P_TYPE instance;
|
||||
|
||||
float buf[2][BLOCK_SIZE];
|
||||
float *bufs[2] = { buf[0], buf[1] };
|
||||
|
||||
static void AudioCallback(
|
||||
AudioHandle::InterleavingInputBuffer in,
|
||||
AudioHandle::InterleavingOutputBuffer out,
|
||||
size_t size) {
|
||||
loadMeter.OnBlockStart();
|
||||
const size_t n = size >> 1;
|
||||
P_PROCESS(&instance, nullptr, bufs, n);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
const size_t j = i << 1;
|
||||
out[j] = buf[0][i];
|
||||
#if NUM_CHANNELS_OUT > 1
|
||||
out[j + 1] = buf[1][i];
|
||||
#else
|
||||
out[j + 1] = 0.f;
|
||||
#endif
|
||||
}
|
||||
loadMeter.OnBlockEnd();
|
||||
}
|
||||
|
||||
int main() {
|
||||
hardware.Configure();
|
||||
hardware.Init();
|
||||
|
||||
hardware.SetAudioBlockSize(BLOCK_SIZE);
|
||||
float sample_rate = hardware.AudioSampleRate();
|
||||
|
||||
P_INIT(&instance);
|
||||
P_SET_SAMPLE_RATE(&instance, sample_rate);
|
||||
|
||||
// hardware.StartLog();
|
||||
|
||||
loadMeter.Init(sample_rate, BLOCK_SIZE);
|
||||
|
||||
P_RESET(&instance);
|
||||
|
||||
MidiUsbHandler::Config midi_cfg;
|
||||
midi_cfg.transport_config.periph = MidiUsbTransport::Config::INTERNAL;
|
||||
midi.Init(midi_cfg);
|
||||
|
||||
hardware.StartAudio(AudioCallback);
|
||||
|
||||
// int i = 0;
|
||||
while (1) {
|
||||
midi.Listen();
|
||||
while (midi.HasEvents()) {
|
||||
MidiEvent ev = midi.PopEvent();
|
||||
switch (ev.type) {
|
||||
case NoteOn:
|
||||
{
|
||||
NoteOnEvent v = ev.AsNoteOn();
|
||||
P_NOTE_ON(&instance, v.note, v.velocity);
|
||||
}
|
||||
break;
|
||||
case NoteOff:
|
||||
{
|
||||
NoteOffEvent v = ev.AsNoteOff();
|
||||
P_NOTE_OFF(&instance, v.note);
|
||||
}
|
||||
break;
|
||||
#ifdef P_PITCH_BEND
|
||||
case PitchBend:
|
||||
{
|
||||
PitchBendEvent v = ev.AsPitchBend();
|
||||
P_PITCH_BEND(&instance, v.value);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case ControlChange:
|
||||
{
|
||||
ControlChangeEvent v = ev.AsControlChange();
|
||||
#ifdef P_MOD_WHEEL
|
||||
if (v.control_number == 1)
|
||||
P_MOD_WHEEL(&instance, v.value);
|
||||
else {
|
||||
#endif
|
||||
for (int i = 0; i < NUM_CCS; i++)
|
||||
if (v.control_number == config_ccs[i].cc)
|
||||
P_SET_PARAMETER(&instance, config_ccs[i].param_index, v.value);
|
||||
#ifdef P_MOD_WHEEL
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
i++;
|
||||
if (i == 500) {
|
||||
const float avgLoad = loadMeter.GetAvgCpuLoad();
|
||||
const float maxLoad = loadMeter.GetMaxCpuLoad();
|
||||
const float minLoad = loadMeter.GetMinCpuLoad();
|
||||
hardware.PrintLine("---");
|
||||
for (int i = 0; i < NUM_PARAMETERS; i++)
|
||||
if (config_parameters[i].out)
|
||||
hardware.PrintLine("%s: %f", config_parameters[i].name, P_GET_PARAMETER(&instance, i));
|
||||
hardware.PrintLine("---");
|
||||
hardware.PrintLine("Processing Load %:");
|
||||
hardware.PrintLine("Max: " FLT_FMT3, FLT_VAR3(maxLoad * 100.0f));
|
||||
hardware.PrintLine("Avg: " FLT_FMT3, FLT_VAR3(avgLoad * 100.0f));
|
||||
hardware.PrintLine("Min: " FLT_FMT3, FLT_VAR3(minLoad * 100.0f));
|
||||
i = 0;
|
||||
}
|
||||
*/
|
||||
System::Delay(1);
|
||||
}
|
||||
}
|
9
examples/synth_mono/daisy-seed/Makefile
Normal file
9
examples/synth_mono/daisy-seed/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
|
||||
TARGET = bw_example_synth_mono
|
||||
|
||||
C_SOURCES += ${ROOT_DIR}/../src/bw_example_synth_mono.c
|
||||
|
||||
SYNTH := yes
|
||||
|
||||
include ${ROOT_DIR}/../../common/daisy-seed/daisy-seed.mk
|
35
examples/synth_mono/daisy-seed/config_daisy_seed.h
Normal file
35
examples/synth_mono/daisy-seed/config_daisy_seed.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 2023 Orastron Srl unipersonale
|
||||
*
|
||||
* Brickworks is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* Brickworks is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* File authors: Stefano D'Angelo
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_DAISY_SEED_H
|
||||
#define _CONFIG_DAISY_SEED_H
|
||||
|
||||
struct config_pin {
|
||||
int param_index;
|
||||
int pin;
|
||||
};
|
||||
|
||||
#define NUM_PINS 1
|
||||
|
||||
static struct config_pin config_pins[NUM_PINS] = {
|
||||
{ 0, 15 }
|
||||
};
|
||||
|
||||
#endif
|
9
examples/synth_simple/daisy-seed/Makefile
Normal file
9
examples/synth_simple/daisy-seed/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
|
||||
TARGET = bw_example_synth_simple
|
||||
|
||||
C_SOURCES += ${ROOT_DIR}/../src/bw_example_synth_simple.c
|
||||
|
||||
SYNTH := yes
|
||||
|
||||
include ${ROOT_DIR}/../../common/daisy-seed/daisy-seed.mk
|
44
examples/synth_simple/daisy-seed/config_daisy_seed.h
Normal file
44
examples/synth_simple/daisy-seed/config_daisy_seed.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 2023 Orastron Srl unipersonale
|
||||
*
|
||||
* Brickworks is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* Brickworks is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* File authors: Stefano D'Angelo
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_DAISY_SEED_H
|
||||
#define _CONFIG_DAISY_SEED_H
|
||||
|
||||
struct config_cc {
|
||||
int param_index;
|
||||
unsigned char cc;
|
||||
};
|
||||
|
||||
#define NUM_CCS 10
|
||||
|
||||
static struct config_cc config_ccs[NUM_CCS] = {
|
||||
{ 0, 32 },
|
||||
{ 1, 33 },
|
||||
{ 2, 34 },
|
||||
{ 3, 35 },
|
||||
{ 4, 36 },
|
||||
{ 5, 37 },
|
||||
{ 6, 38 },
|
||||
{ 7, 39 },
|
||||
{ 8, 40 },
|
||||
{ 9, 41 }
|
||||
};
|
||||
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Brickworks
|
||||
*
|
||||
* Copyright (C) 2022 Orastron Srl unipersonale
|
||||
* Copyright (C) 2022, 2023 Orastron Srl unipersonale
|
||||
*
|
||||
* Brickworks is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
/*!
|
||||
* module_type {{{ dsp }}}
|
||||
* version {{{ 0.2.0 }}}
|
||||
* version {{{ 0.3.0 }}}
|
||||
* requires {{{ bw_config bw_common bw_one_pole bw_math }}}
|
||||
* description {{{
|
||||
* Linear ADSR envelope generator.
|
||||
@ -40,6 +40,12 @@
|
||||
* }}}
|
||||
* changelog {{{
|
||||
* <ul>
|
||||
* <li>Version <strong>0.3.0</strong>:
|
||||
* <ul>
|
||||
* <li>Avoid a warning related to a potentially uninitialized
|
||||
* variable.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Version <strong>0.2.0</strong>:
|
||||
* <ul>
|
||||
* <li>Refactored API.</li>
|
||||
@ -301,7 +307,7 @@ static inline void bw_env_gen_update_state_ctrl(const bw_env_gen_coeffs *BW_REST
|
||||
}
|
||||
|
||||
static inline float bw_env_gen_process1(const bw_env_gen_coeffs *BW_RESTRICT coeffs, bw_env_gen_state *BW_RESTRICT state) {
|
||||
float v;
|
||||
float v = 0.f;
|
||||
switch (state->phase) {
|
||||
case bw_env_gen_phase_attack:
|
||||
v = state->y_z1 + coeffs->attack_inc;
|
||||
|
Loading…
Reference in New Issue
Block a user