mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 11:05:49 +00:00
Port parts of peaks to a pure adsr module
This commit is contained in:
parent
8aaef81a9a
commit
27eba61c2f
17 changed files with 1505 additions and 0 deletions
0
pure_adsr/__init__.py
Normal file
0
pure_adsr/__init__.py
Normal file
43
pure_adsr/bootloader/bootloader.cc
Executable file
43
pure_adsr/bootloader/bootloader.cc
Executable file
|
@ -0,0 +1,43 @@
|
||||||
|
// Copyright 2011 Emilie Gillet.
|
||||||
|
//
|
||||||
|
// This program 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, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Bootloader supporting MIDI SysEx update.
|
||||||
|
//
|
||||||
|
// Caveat: assumes the firmware flashing is always done from first to last
|
||||||
|
// block, in increasing order. Random access flashing is not supported!
|
||||||
|
|
||||||
|
#include <avr/boot.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/delay.h>
|
||||||
|
|
||||||
|
#include "avrlib/gpio.h"
|
||||||
|
#include "avrlib/serial.h"
|
||||||
|
#include "avrlib/watchdog_timer.h"
|
||||||
|
|
||||||
|
using namespace avrlib;
|
||||||
|
|
||||||
|
void (*main_entry_point)(void) = 0x0000;
|
||||||
|
|
||||||
|
inline void Init() {
|
||||||
|
cli();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
ResetWatchdog();
|
||||||
|
Init();
|
||||||
|
_delay_ms(40);
|
||||||
|
main_entry_point();
|
||||||
|
}
|
29
pure_adsr/bootloader/makefile
Executable file
29
pure_adsr/bootloader/makefile
Executable file
|
@ -0,0 +1,29 @@
|
||||||
|
# Copyright 2011 Emilie Gillet.
|
||||||
|
#
|
||||||
|
# This program 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, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
VERSION = 0.1
|
||||||
|
MCU_NAME = 328
|
||||||
|
TARGET = pure_adsr_bootloader
|
||||||
|
PACKAGES = avrlib pure_adsr/bootloader avr_audio_bootloader/fsk
|
||||||
|
EXTRA_DEFINES = -funsigned-char -fno-inline-small-functions
|
||||||
|
EXTRA_LD_FLAGS = ,--section-start=.text=0x7000,--relax
|
||||||
|
PROGRAMMER = atmelice_isp
|
||||||
|
|
||||||
|
LFUSE = ff
|
||||||
|
HFUSE = d8
|
||||||
|
EFUSE = 05
|
||||||
|
LOCK = ff
|
||||||
|
|
||||||
|
include avrlib/makefile.mk
|
||||||
|
|
||||||
|
include $(DEP_FILE)
|
71
pure_adsr/drivers/gate_input.h
Normal file
71
pure_adsr/drivers/gate_input.h
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
// Copyright 2013 Emilie Gillet.
|
||||||
|
//
|
||||||
|
// Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
// See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Driver for the 2 gate inputs.
|
||||||
|
|
||||||
|
#ifndef PEAKS_DRIVERS_GATE_INPUT_H_
|
||||||
|
#define PEAKS_DRIVERS_GATE_INPUT_H_
|
||||||
|
|
||||||
|
#include "avrlib/gpio.h"
|
||||||
|
|
||||||
|
namespace pure_adsr {
|
||||||
|
|
||||||
|
enum GateInputState {
|
||||||
|
INPUT_1_GATE = 0x01,
|
||||||
|
INPUT_1_RAISING = 0x02,
|
||||||
|
INPUT_1_FALLING = 0x04
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename DigitalInput>
|
||||||
|
class GateInput {
|
||||||
|
public:
|
||||||
|
GateInput() { }
|
||||||
|
~GateInput() { }
|
||||||
|
|
||||||
|
void Init() {
|
||||||
|
DigitalInput::Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Read() {
|
||||||
|
uint32_t result = 0;
|
||||||
|
result |= !DigitalInput::Read();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool ReadInput1() {
|
||||||
|
return !DigitalInput::Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t ReadBits();
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(GateInput);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace peaks
|
||||||
|
|
||||||
|
#endif // PEAKS_DRIVERS_GATE_INPUT_H_
|
||||||
|
|
76
pure_adsr/drivers/switches.h
Executable file
76
pure_adsr/drivers/switches.h
Executable file
|
@ -0,0 +1,76 @@
|
||||||
|
// Copyright 2016 Emilie Gillet.
|
||||||
|
//
|
||||||
|
// Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
// See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Driver for the 2 switches.
|
||||||
|
|
||||||
|
#ifndef PLAITS_DRIVERS_SWITCHES_H_
|
||||||
|
#define PLAITS_DRIVERS_SWITCHES_H_
|
||||||
|
|
||||||
|
#include "avrlib/gpio.h"
|
||||||
|
|
||||||
|
namespace pure_adsr {
|
||||||
|
|
||||||
|
template <typename DigitalInput>
|
||||||
|
class Switch {
|
||||||
|
public:
|
||||||
|
Switch() {}
|
||||||
|
~Switch() {}
|
||||||
|
|
||||||
|
void Init() { DigitalInput::Init(); }
|
||||||
|
void Debounce()
|
||||||
|
{
|
||||||
|
switch_state_ = (switch_state_ << 1) | Switch::pressed_immediate();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool released()
|
||||||
|
{
|
||||||
|
return switch_state_ == 0x7f;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool just_pressed()
|
||||||
|
{
|
||||||
|
return switch_state_ == 0x80;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool pressed()
|
||||||
|
{
|
||||||
|
return switch_state_ == 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool pressed_immediate()
|
||||||
|
{
|
||||||
|
return DigitalInput::Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t switch_state_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(Switch);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace plaits
|
||||||
|
|
||||||
|
#endif // PLAITS_DRIVERS_SWITCHES_H_
|
68
pure_adsr/gate_processor.h
Normal file
68
pure_adsr/gate_processor.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// Copyright 2013 Emilie Gillet.
|
||||||
|
//
|
||||||
|
// Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
// See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// General declarations used by all trigger/gate processors.
|
||||||
|
|
||||||
|
#ifndef PEAKS_GATE_PROCESSOR_H_
|
||||||
|
#define PEAKS_GATE_PROCESSOR_H_
|
||||||
|
|
||||||
|
#include <avrlib/avrlib.h>
|
||||||
|
|
||||||
|
namespace pure_adsr {
|
||||||
|
|
||||||
|
enum ControlMode {
|
||||||
|
CONTROL_MODE_FULL,
|
||||||
|
CONTROL_MODE_HALF
|
||||||
|
};
|
||||||
|
|
||||||
|
enum GateFlagsBits {
|
||||||
|
GATE_FLAG_LOW = 0,
|
||||||
|
GATE_FLAG_HIGH = 1,
|
||||||
|
GATE_FLAG_RISING = 2,
|
||||||
|
GATE_FLAG_FALLING = 4,
|
||||||
|
GATE_FLAG_FROM_BUTTON = 8,
|
||||||
|
|
||||||
|
GATE_FLAG_AUXILIARY_LOW = 0,
|
||||||
|
GATE_FLAG_AUXILIARY_HIGH = 16,
|
||||||
|
GATE_FLAG_AUXILIARY_RISING = 32,
|
||||||
|
GATE_FLAG_AUXILIARY_FALLING = 64,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef uint8_t GateFlags;
|
||||||
|
|
||||||
|
inline GateFlags ExtractGateFlags(GateFlags previous, bool current) {
|
||||||
|
previous &= GATE_FLAG_HIGH;
|
||||||
|
if (current) {
|
||||||
|
return previous ? GATE_FLAG_HIGH : (GATE_FLAG_RISING | GATE_FLAG_HIGH);
|
||||||
|
} else {
|
||||||
|
return previous ? GATE_FLAG_FALLING : GATE_FLAG_LOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace peaks
|
||||||
|
|
||||||
|
#endif // PEAKS_GATE_PROCESSOR_H_
|
||||||
|
|
103
pure_adsr/io_buffer.h
Normal file
103
pure_adsr/io_buffer.h
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
// Copyright 2015 Emilie Gillet.
|
||||||
|
//
|
||||||
|
// Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
// See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// I/O Buffering.
|
||||||
|
|
||||||
|
#ifndef PEAKS_IO_BUFFER_H_
|
||||||
|
#define PEAKS_IO_BUFFER_H_
|
||||||
|
|
||||||
|
#include "pure_adsr/gate_processor.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
namespace pure_adsr {
|
||||||
|
|
||||||
|
const size_t kNumBlocks = 2;
|
||||||
|
const size_t kNumChannels = 1;
|
||||||
|
const size_t kBlockSize = 2;
|
||||||
|
|
||||||
|
class IOBuffer {
|
||||||
|
public:
|
||||||
|
struct Block {
|
||||||
|
GateFlags input[kNumChannels][kBlockSize];
|
||||||
|
uint16_t output[kNumChannels][kBlockSize];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Slice {
|
||||||
|
Block* block;
|
||||||
|
size_t frame_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ProcessFn(Block* block, size_t size);
|
||||||
|
|
||||||
|
IOBuffer() {}
|
||||||
|
~IOBuffer() {}
|
||||||
|
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
io_block_ = 0;
|
||||||
|
render_block_ = kNumBlocks / 2;
|
||||||
|
io_frame_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Process(ProcessFn* fn)
|
||||||
|
{
|
||||||
|
while (render_block_ != io_block_) {
|
||||||
|
(*fn)(&block_[render_block_], kBlockSize);
|
||||||
|
render_block_ = (render_block_ + 1) % kNumBlocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Slice NextSlice(size_t size)
|
||||||
|
{
|
||||||
|
Slice s;
|
||||||
|
s.block = &block_[io_block_];
|
||||||
|
s.frame_index = io_frame_;
|
||||||
|
io_frame_ += size;
|
||||||
|
if (io_frame_ >= kBlockSize) {
|
||||||
|
io_frame_ -= kBlockSize;
|
||||||
|
io_block_ = (io_block_ + 1) % kNumBlocks;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool new_block() const
|
||||||
|
{
|
||||||
|
return io_frame_ == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Block block_[kNumBlocks];
|
||||||
|
|
||||||
|
size_t io_frame_;
|
||||||
|
volatile size_t io_block_;
|
||||||
|
volatile size_t render_block_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(IOBuffer);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace peaks
|
||||||
|
|
||||||
|
#endif // PEAKS_IO_BUFFER_H_
|
43
pure_adsr/makefile
Normal file
43
pure_adsr/makefile
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
# Copyright 2012 Emilie Gillet.
|
||||||
|
#
|
||||||
|
# This program 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, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
VERSION = 0.1
|
||||||
|
MCU_NAME = 328
|
||||||
|
TARGET = pure_adsr
|
||||||
|
PACKAGES = avrlib avrlib/devices pure_adsr pure_adsr/drivers
|
||||||
|
RESOURCES = pure_adsr/resources
|
||||||
|
PROGRAMMER = atmelice_isp
|
||||||
|
|
||||||
|
LFUSE = ef
|
||||||
|
HFUSE = d8
|
||||||
|
EFUSE = 05
|
||||||
|
LOCK = ff
|
||||||
|
|
||||||
|
include avrlib/makefile.mk
|
||||||
|
|
||||||
|
include $(DEP_FILE)
|
||||||
|
|
||||||
|
# Rule for building the firmware update file
|
||||||
|
wav: $(TARGET_BIN)
|
||||||
|
python avr_audio_bootloader/fsk/encoder.py \
|
||||||
|
-s 40000 -b 16 -n 8 -z 4 -p 128 -g 128 -k 10 \
|
||||||
|
$(TARGET_BIN)
|
||||||
|
|
||||||
|
bootstrap_all:
|
||||||
|
make -f pure_adsr/makefile
|
||||||
|
make -f pure_adsr/bootloader/makefile
|
||||||
|
make -f pure_adsr/bootloader/makefile fuses
|
||||||
|
$(AVRDUDE) -B 1 $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \
|
||||||
|
-U flash:w:build/pure_adsr/pure_adsr.hex:i \
|
||||||
|
-U flash:w:build/pure_adsr_bootloader/pure_adsr_bootloader.hex:i \
|
||||||
|
-U lock:w:0xff:m
|
93
pure_adsr/multistage_envelope.cc
Normal file
93
pure_adsr/multistage_envelope.cc
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
// Copyright 2013 Emilie Gillet.
|
||||||
|
//
|
||||||
|
// Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
// See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Multistage envelope.
|
||||||
|
|
||||||
|
#include "pure_adsr/multistage_envelope.h"
|
||||||
|
|
||||||
|
#include "pure_adsr/resources.h"
|
||||||
|
inline uint16_t Interpolate824(const uint16_t* table, uint32_t phase)
|
||||||
|
__attribute__((always_inline));
|
||||||
|
inline uint16_t Interpolate824(const uint16_t* table, uint32_t phase)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace pure_adsr {
|
||||||
|
|
||||||
|
void MultistageEnvelope::Init()
|
||||||
|
{
|
||||||
|
set_adsr(0, 8192, 16384, 32767);
|
||||||
|
segment_ = num_segments_;
|
||||||
|
phase_ = 0;
|
||||||
|
phase_increment_ = 0;
|
||||||
|
start_value_ = 0;
|
||||||
|
value_ = 0;
|
||||||
|
hard_reset_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultistageEnvelope::Process(
|
||||||
|
const GateFlags* gate_flags, int16_t* out, size_t size)
|
||||||
|
{
|
||||||
|
while (size--) {
|
||||||
|
GateFlags gate_flag = *gate_flags++;
|
||||||
|
if (gate_flag & GATE_FLAG_RISING) {
|
||||||
|
start_value_ = (segment_ == num_segments_ || hard_reset_)
|
||||||
|
? level_[0]
|
||||||
|
: value_;
|
||||||
|
segment_ = 0;
|
||||||
|
phase_ = 0;
|
||||||
|
} else if (gate_flag & GATE_FLAG_FALLING && sustain_point_) {
|
||||||
|
start_value_ = value_;
|
||||||
|
segment_ = sustain_point_;
|
||||||
|
phase_ = 0;
|
||||||
|
} else if (phase_ < phase_increment_) {
|
||||||
|
start_value_ = level_[segment_ + 1];
|
||||||
|
++segment_;
|
||||||
|
phase_ = 0;
|
||||||
|
if (segment_ == loop_end_) {
|
||||||
|
segment_ = loop_start_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool done = segment_ == num_segments_;
|
||||||
|
bool sustained = sustain_point_ && segment_ == sustain_point_ && gate_flag & GATE_FLAG_HIGH;
|
||||||
|
|
||||||
|
phase_increment_ = sustained || done ? 0 : pgm_read_dword(lut_res_env_increments + (time_[segment_] >> 8));
|
||||||
|
|
||||||
|
int32_t a = start_value_;
|
||||||
|
int32_t b = level_[segment_ + 1];
|
||||||
|
|
||||||
|
uint32_t x = pgm_read_word(lookup_table_table[LUT_RES_ENV_LINEAR + shape_[segment_]] + (phase_ >> 24));
|
||||||
|
uint32_t y = pgm_read_word(lookup_table_table[LUT_RES_ENV_LINEAR + shape_[segment_]] + (phase_ >> 24) + 1);
|
||||||
|
uint16_t t = x + ((y - x) * static_cast<uint32_t>((phase_ >> 8) & 0xffff) >> 16);
|
||||||
|
|
||||||
|
value_ = a + ((b - a) * (t >> 1) >> 15);
|
||||||
|
phase_ += phase_increment_;
|
||||||
|
*out++ = value_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace peaks
|
320
pure_adsr/multistage_envelope.h
Normal file
320
pure_adsr/multistage_envelope.h
Normal file
|
@ -0,0 +1,320 @@
|
||||||
|
// Copyright 2013 Emilie Gillet.
|
||||||
|
//
|
||||||
|
// Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
// See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Multistage envelope.
|
||||||
|
|
||||||
|
#ifndef PEAKS_MODULATIONS_MULTISTAGE_ENVELOPE_H_
|
||||||
|
#define PEAKS_MODULATIONS_MULTISTAGE_ENVELOPE_H_
|
||||||
|
|
||||||
|
#include <avrlib/avrlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "pure_adsr/gate_processor.h"
|
||||||
|
|
||||||
|
namespace pure_adsr {
|
||||||
|
|
||||||
|
enum EnvelopeShape {
|
||||||
|
ENV_SHAPE_LINEAR = 0,
|
||||||
|
ENV_SHAPE_EXPONENTIAL = 1,
|
||||||
|
ENV_SHAPE_QUARTIC = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint16_t kMaxNumSegments = 8;
|
||||||
|
|
||||||
|
class MultistageEnvelope {
|
||||||
|
public:
|
||||||
|
MultistageEnvelope() { }
|
||||||
|
~MultistageEnvelope() { }
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void Process(const GateFlags* gate_flags, int16_t* out, size_t size);
|
||||||
|
|
||||||
|
void Configure(uint16_t* parameter, ControlMode control_mode) {
|
||||||
|
if (control_mode == CONTROL_MODE_HALF) {
|
||||||
|
set_ad(parameter[0], parameter[1]);
|
||||||
|
} else {
|
||||||
|
set_adsr(parameter[0], parameter[1], parameter[2] >> 1, parameter[3]);
|
||||||
|
}
|
||||||
|
if (segment_ > num_segments_) {
|
||||||
|
segment_ = 0;
|
||||||
|
phase_ = 0;
|
||||||
|
value_ = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_time(uint16_t segment, uint16_t time) {
|
||||||
|
time_[segment] = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_level(uint16_t segment, int16_t level) {
|
||||||
|
level_[segment] = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_num_segments(uint16_t num_segments) {
|
||||||
|
num_segments_ = num_segments;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_sustain_point(uint16_t sustain_point) {
|
||||||
|
sustain_point_ = sustain_point;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_adsr(
|
||||||
|
uint16_t attack,
|
||||||
|
uint16_t decay,
|
||||||
|
uint16_t sustain,
|
||||||
|
uint16_t release) {
|
||||||
|
num_segments_ = 3;
|
||||||
|
sustain_point_ = 2;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = sustain;
|
||||||
|
level_[3] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
time_[2] = release;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_QUARTIC;
|
||||||
|
shape_[1] = ENV_SHAPE_EXPONENTIAL;
|
||||||
|
shape_[2] = ENV_SHAPE_EXPONENTIAL;
|
||||||
|
|
||||||
|
loop_start_ = loop_end_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_ad(uint16_t attack, uint16_t decay) {
|
||||||
|
num_segments_ = 2;
|
||||||
|
sustain_point_ = 0;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_EXPONENTIAL;
|
||||||
|
shape_[1] = ENV_SHAPE_EXPONENTIAL;
|
||||||
|
|
||||||
|
loop_start_ = loop_end_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_adr(
|
||||||
|
uint16_t attack,
|
||||||
|
uint16_t decay,
|
||||||
|
uint16_t sustain,
|
||||||
|
uint16_t release) {
|
||||||
|
num_segments_ = 3;
|
||||||
|
sustain_point_ = 0;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = sustain;
|
||||||
|
level_[3] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
time_[2] = release;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[1] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[2] = ENV_SHAPE_LINEAR;
|
||||||
|
|
||||||
|
loop_start_ = loop_end_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_ar(uint16_t attack, uint16_t decay) {
|
||||||
|
num_segments_ = 2;
|
||||||
|
sustain_point_ = 1;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[1] = ENV_SHAPE_LINEAR;
|
||||||
|
|
||||||
|
loop_start_ = loop_end_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_adsar(
|
||||||
|
uint16_t attack,
|
||||||
|
uint16_t decay,
|
||||||
|
uint16_t sustain,
|
||||||
|
uint16_t release) {
|
||||||
|
num_segments_ = 4;
|
||||||
|
sustain_point_ = 2;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = sustain;
|
||||||
|
level_[3] = 32767;
|
||||||
|
level_[4] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
time_[2] = attack;
|
||||||
|
time_[3] = release;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[1] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[2] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[3] = ENV_SHAPE_LINEAR;
|
||||||
|
|
||||||
|
loop_start_ = loop_end_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_adar(
|
||||||
|
uint16_t attack,
|
||||||
|
uint16_t decay,
|
||||||
|
uint16_t sustain,
|
||||||
|
uint16_t release) {
|
||||||
|
num_segments_ = 4;
|
||||||
|
sustain_point_ = 0;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = sustain;
|
||||||
|
level_[3] = 32767;
|
||||||
|
level_[4] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
time_[2] = attack;
|
||||||
|
time_[3] = release;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[1] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[2] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[3] = ENV_SHAPE_LINEAR;
|
||||||
|
|
||||||
|
loop_start_ = loop_end_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_ad_loop(uint16_t attack, uint16_t decay) {
|
||||||
|
num_segments_ = 2;
|
||||||
|
sustain_point_ = 0;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[1] = ENV_SHAPE_LINEAR;
|
||||||
|
|
||||||
|
loop_start_ = 0;
|
||||||
|
loop_end_ = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_adr_loop(
|
||||||
|
uint16_t attack,
|
||||||
|
uint16_t decay,
|
||||||
|
uint16_t sustain,
|
||||||
|
uint16_t release) {
|
||||||
|
num_segments_ = 3;
|
||||||
|
sustain_point_ = 0;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = sustain;
|
||||||
|
level_[3] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
time_[2] = release;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[1] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[2] = ENV_SHAPE_LINEAR;
|
||||||
|
|
||||||
|
loop_start_ = 0;
|
||||||
|
loop_end_ = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_adar_loop(
|
||||||
|
uint16_t attack,
|
||||||
|
uint16_t decay,
|
||||||
|
uint16_t sustain,
|
||||||
|
uint16_t release) {
|
||||||
|
num_segments_ = 4;
|
||||||
|
sustain_point_ = 0;
|
||||||
|
|
||||||
|
level_[0] = 0;
|
||||||
|
level_[1] = 32767;
|
||||||
|
level_[2] = sustain;
|
||||||
|
level_[3] = 32767;
|
||||||
|
level_[4] = 0;
|
||||||
|
|
||||||
|
time_[0] = attack;
|
||||||
|
time_[1] = decay;
|
||||||
|
time_[2] = attack;
|
||||||
|
time_[3] = release;
|
||||||
|
|
||||||
|
shape_[0] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[1] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[2] = ENV_SHAPE_LINEAR;
|
||||||
|
shape_[3] = ENV_SHAPE_LINEAR;
|
||||||
|
|
||||||
|
loop_start_ = 0;
|
||||||
|
loop_end_ = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_hard_reset(bool hard_reset) {
|
||||||
|
hard_reset_ = hard_reset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int16_t level_[kMaxNumSegments];
|
||||||
|
uint16_t time_[kMaxNumSegments];
|
||||||
|
EnvelopeShape shape_[kMaxNumSegments];
|
||||||
|
|
||||||
|
int16_t segment_;
|
||||||
|
int16_t start_value_;
|
||||||
|
int16_t value_;
|
||||||
|
|
||||||
|
uint32_t phase_;
|
||||||
|
uint32_t phase_increment_;
|
||||||
|
|
||||||
|
uint16_t num_segments_;
|
||||||
|
uint16_t sustain_point_;
|
||||||
|
uint16_t loop_start_;
|
||||||
|
uint16_t loop_end_;
|
||||||
|
|
||||||
|
bool hard_reset_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(MultistageEnvelope);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace peaks
|
||||||
|
|
||||||
|
#endif // PEAKS_MODULATIONS_MULTISTAGE_ENVELOPE_H_
|
||||||
|
|
149
pure_adsr/pure_adsr.cc
Normal file
149
pure_adsr/pure_adsr.cc
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
#include "avrlib/adc.h"
|
||||||
|
#include "avrlib/avrlib.h"
|
||||||
|
#include "avrlib/boot.h"
|
||||||
|
#include "avrlib/devices/mcp492x.h"
|
||||||
|
#include "avrlib/gpio.h"
|
||||||
|
#include "avrlib/spi.h"
|
||||||
|
#include "avrlib/time.h"
|
||||||
|
#include "avrlib/timer.h"
|
||||||
|
#include "avrlib/watchdog_timer.h"
|
||||||
|
#include "pure_adsr/drivers/gate_input.h"
|
||||||
|
#include "pure_adsr/drivers/switches.h"
|
||||||
|
#include "pure_adsr/gate_processor.h"
|
||||||
|
#include "pure_adsr/io_buffer.h"
|
||||||
|
#include "pure_adsr/multistage_envelope.h"
|
||||||
|
|
||||||
|
using namespace avrlib;
|
||||||
|
using namespace pure_adsr;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MODE_ADSR,
|
||||||
|
MODE_SEQ,
|
||||||
|
MODE_LFO
|
||||||
|
} Mode;
|
||||||
|
|
||||||
|
typedef SpiMaster<Gpio<PortB, 2>, MSB_FIRST, 2> dac1Spi;
|
||||||
|
typedef Dac<dac1Spi, UNBUFFERED_REFERENCE, 1> dac;
|
||||||
|
|
||||||
|
GateInput<DigitalInput<Gpio<PortD, 2>>> gate_input;
|
||||||
|
GateFlags gate_flags;
|
||||||
|
|
||||||
|
DigitalInput<Gpio<PortD, 6>> switchIn0;
|
||||||
|
DigitalInput<Gpio<PortD, 7>> switchIn1;
|
||||||
|
|
||||||
|
Switch<DigitalInput<Gpio<PortD, 3>>> button_input;
|
||||||
|
|
||||||
|
typedef AdcInputScanner AnalogInputs;
|
||||||
|
|
||||||
|
MultistageEnvelope envelope;
|
||||||
|
|
||||||
|
IOBuffer io_buffer;
|
||||||
|
int16_t output_buffer[kBlockSize];
|
||||||
|
const size_t kNumPots = 4;
|
||||||
|
|
||||||
|
uint16_t pot_values[kNumPots];
|
||||||
|
|
||||||
|
Mode mode;
|
||||||
|
|
||||||
|
void Process(IOBuffer::Block* block, size_t size)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < kNumPots; i++) {
|
||||||
|
uint16_t read_value = AnalogInputs::Read(kNumPots - 1 - i) << 6;
|
||||||
|
if (read_value != pot_values[i]) { // TODO: apply filtering
|
||||||
|
pot_values[i] = read_value;
|
||||||
|
envelope.Configure(pot_values, CONTROL_MODE_FULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < kNumChannels; ++i) {
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case MODE_ADSR:
|
||||||
|
envelope.Process(block->input[i], output_buffer, size);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t j = 0; j < size; ++j) {
|
||||||
|
block->output[i][j] = output_buffer[j] >> 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
Timer<2>::set_prescaler(1); // 9.765 kHz??????
|
||||||
|
Timer<2>::set_mode(TIMER_PWM_PHASE_CORRECT);
|
||||||
|
|
||||||
|
dac::Init();
|
||||||
|
AnalogInputs::Init();
|
||||||
|
|
||||||
|
AnalogInputs::set_num_inputs(4);
|
||||||
|
|
||||||
|
gate_input.Init();
|
||||||
|
button_input.Init();
|
||||||
|
switchIn0.Init();
|
||||||
|
switchIn1.Init();
|
||||||
|
|
||||||
|
io_buffer.Init();
|
||||||
|
envelope.Init();
|
||||||
|
|
||||||
|
uint16_t pots[4];
|
||||||
|
for (size_t i = 0; i < 4; i++)
|
||||||
|
pots[4 - (i + 1)] = AnalogInputs::Read8(i) << 8;
|
||||||
|
envelope.Configure(pots, CONTROL_MODE_FULL);
|
||||||
|
Timer<2>::Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
Boot(true);
|
||||||
|
|
||||||
|
Init();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
ResetWatchdog();
|
||||||
|
io_buffer.Process(&Process);
|
||||||
|
AnalogInputs::Scan();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TIMER_0_TICK
|
||||||
|
{
|
||||||
|
TickSystemClock();
|
||||||
|
button_input.Debounce();
|
||||||
|
uint8_t mode_value = switchIn1.Read() << 1 | switchIn0.Read();
|
||||||
|
switch (mode_value) {
|
||||||
|
case 0:
|
||||||
|
mode = MODE_SEQ;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
mode = MODE_THREE;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
mode = MODE_ADSR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TIMER_2_TICK
|
||||||
|
{
|
||||||
|
static uint8_t clock_divider_midi = 0;
|
||||||
|
|
||||||
|
--clock_divider_midi;
|
||||||
|
if (!clock_divider_midi) {
|
||||||
|
uint32_t gate_inputs = gate_input.Read();
|
||||||
|
gate_inputs |= button_input.pressed();
|
||||||
|
IOBuffer::Slice slice = io_buffer.NextSlice(1);
|
||||||
|
for (size_t i = 0; i < kNumChannels; ++i) {
|
||||||
|
gate_flags = ExtractGateFlags(
|
||||||
|
gate_flags,
|
||||||
|
gate_inputs & (1 << i));
|
||||||
|
dac::Write(slice.block->output[i][slice.frame_index]);
|
||||||
|
slice.block->input[i][slice.frame_index] = gate_flags;
|
||||||
|
}
|
||||||
|
clock_divider_midi = 16;
|
||||||
|
}
|
||||||
|
}
|
225
pure_adsr/resources.cc
Normal file
225
pure_adsr/resources.cc
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
// Copyright 2019 Jan-Henrik Bruhn.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This program 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, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Resources definitions.
|
||||||
|
//
|
||||||
|
// Automatically generated with:
|
||||||
|
// make resources
|
||||||
|
|
||||||
|
|
||||||
|
#include "pure_adsr/resources.h"
|
||||||
|
|
||||||
|
namespace pure_adsr {
|
||||||
|
|
||||||
|
static const prog_char str_res_dummy[] PROGMEM = "dummy";
|
||||||
|
|
||||||
|
|
||||||
|
const prog_char* const string_table[] = {
|
||||||
|
str_res_dummy,
|
||||||
|
};
|
||||||
|
|
||||||
|
const prog_uint16_t lut_res_env_linear[] PROGMEM = {
|
||||||
|
0, 257, 514, 771, 1028, 1285, 1542, 1799,
|
||||||
|
2056, 2313, 2570, 2827, 3084, 3341, 3598, 3855,
|
||||||
|
4112, 4369, 4626, 4883, 5140, 5397, 5654, 5911,
|
||||||
|
6168, 6425, 6682, 6939, 7196, 7453, 7710, 7967,
|
||||||
|
8224, 8481, 8738, 8995, 9252, 9509, 9766, 10023,
|
||||||
|
10280, 10537, 10794, 11051, 11308, 11565, 11822, 12079,
|
||||||
|
12336, 12593, 12850, 13107, 13364, 13621, 13878, 14135,
|
||||||
|
14392, 14649, 14906, 15163, 15420, 15677, 15934, 16191,
|
||||||
|
16448, 16705, 16962, 17219, 17476, 17733, 17990, 18247,
|
||||||
|
18504, 18761, 19018, 19275, 19532, 19789, 20046, 20303,
|
||||||
|
20560, 20817, 21074, 21331, 21588, 21845, 22102, 22359,
|
||||||
|
22616, 22873, 23130, 23387, 23644, 23901, 24158, 24415,
|
||||||
|
24672, 24929, 25186, 25443, 25700, 25957, 26214, 26471,
|
||||||
|
26728, 26985, 27242, 27499, 27756, 28013, 28270, 28527,
|
||||||
|
28784, 29041, 29298, 29555, 29812, 30069, 30326, 30583,
|
||||||
|
30840, 31097, 31354, 31611, 31868, 32125, 32382, 32639,
|
||||||
|
32896, 33153, 33410, 33667, 33924, 34181, 34438, 34695,
|
||||||
|
34952, 35209, 35466, 35723, 35980, 36237, 36494, 36751,
|
||||||
|
37008, 37265, 37522, 37779, 38036, 38293, 38550, 38807,
|
||||||
|
39064, 39321, 39578, 39835, 40092, 40349, 40606, 40863,
|
||||||
|
41120, 41377, 41634, 41891, 42148, 42405, 42662, 42919,
|
||||||
|
43176, 43433, 43690, 43947, 44204, 44461, 44718, 44975,
|
||||||
|
45232, 45489, 45746, 46003, 46260, 46517, 46774, 47031,
|
||||||
|
47288, 47545, 47802, 48059, 48316, 48573, 48830, 49087,
|
||||||
|
49344, 49601, 49858, 50115, 50372, 50629, 50886, 51143,
|
||||||
|
51400, 51657, 51914, 52171, 52428, 52685, 52942, 53199,
|
||||||
|
53456, 53713, 53970, 54227, 54484, 54741, 54998, 55255,
|
||||||
|
55512, 55769, 56026, 56283, 56540, 56797, 57054, 57311,
|
||||||
|
57568, 57825, 58082, 58339, 58596, 58853, 59110, 59367,
|
||||||
|
59624, 59881, 60138, 60395, 60652, 60909, 61166, 61423,
|
||||||
|
61680, 61937, 62194, 62451, 62708, 62965, 63222, 63479,
|
||||||
|
63736, 63993, 64250, 64507, 64764, 65021, 65278, 65535,
|
||||||
|
65535,
|
||||||
|
};
|
||||||
|
const prog_uint16_t lut_res_env_expo[] PROGMEM = {
|
||||||
|
0, 1035, 2054, 3057, 4045, 5018, 5975, 6918,
|
||||||
|
7846, 8760, 9659, 10545, 11416, 12275, 13120, 13952,
|
||||||
|
14771, 15577, 16371, 17152, 17921, 18679, 19425, 20159,
|
||||||
|
20881, 21593, 22294, 22983, 23662, 24331, 24989, 25637,
|
||||||
|
26274, 26902, 27520, 28129, 28728, 29318, 29899, 30471,
|
||||||
|
31034, 31588, 32133, 32670, 33199, 33720, 34232, 34737,
|
||||||
|
35233, 35722, 36204, 36678, 37145, 37604, 38056, 38502,
|
||||||
|
38940, 39371, 39796, 40215, 40626, 41032, 41431, 41824,
|
||||||
|
42211, 42592, 42967, 43336, 43699, 44057, 44409, 44756,
|
||||||
|
45097, 45434, 45764, 46090, 46411, 46727, 47037, 47344,
|
||||||
|
47645, 47941, 48233, 48521, 48804, 49083, 49357, 49627,
|
||||||
|
49893, 50155, 50412, 50666, 50916, 51162, 51404, 51642,
|
||||||
|
51877, 52108, 52335, 52559, 52780, 52997, 53210, 53421,
|
||||||
|
53628, 53831, 54032, 54230, 54424, 54616, 54804, 54990,
|
||||||
|
55173, 55353, 55530, 55704, 55876, 56045, 56211, 56375,
|
||||||
|
56536, 56695, 56851, 57005, 57157, 57306, 57453, 57597,
|
||||||
|
57740, 57880, 58018, 58153, 58287, 58419, 58548, 58676,
|
||||||
|
58801, 58925, 59047, 59167, 59285, 59401, 59515, 59628,
|
||||||
|
59739, 59848, 59955, 60061, 60165, 60267, 60368, 60468,
|
||||||
|
60566, 60662, 60757, 60850, 60942, 61032, 61121, 61209,
|
||||||
|
61295, 61380, 61464, 61546, 61628, 61707, 61786, 61863,
|
||||||
|
61939, 62014, 62088, 62161, 62233, 62303, 62372, 62441,
|
||||||
|
62508, 62574, 62639, 62703, 62767, 62829, 62890, 62950,
|
||||||
|
63010, 63068, 63125, 63182, 63238, 63293, 63347, 63400,
|
||||||
|
63452, 63504, 63554, 63604, 63654, 63702, 63750, 63797,
|
||||||
|
63843, 63888, 63933, 63977, 64021, 64063, 64105, 64147,
|
||||||
|
64188, 64228, 64267, 64306, 64344, 64382, 64419, 64456,
|
||||||
|
64492, 64527, 64562, 64596, 64630, 64664, 64696, 64729,
|
||||||
|
64760, 64792, 64822, 64853, 64883, 64912, 64941, 64969,
|
||||||
|
64997, 65025, 65052, 65079, 65105, 65131, 65157, 65182,
|
||||||
|
65206, 65231, 65255, 65278, 65302, 65324, 65347, 65369,
|
||||||
|
65391, 65412, 65434, 65454, 65475, 65495, 65515, 65535,
|
||||||
|
65535,
|
||||||
|
};
|
||||||
|
const prog_uint16_t lut_res_env_quartic[] PROGMEM = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 1, 1, 2, 3, 4, 5,
|
||||||
|
6, 8, 9, 11, 14, 16, 19, 22,
|
||||||
|
25, 29, 33, 37, 42, 48, 53, 59,
|
||||||
|
66, 73, 81, 89, 98, 107, 117, 128,
|
||||||
|
139, 151, 164, 177, 191, 206, 222, 238,
|
||||||
|
256, 274, 293, 313, 334, 355, 378, 402,
|
||||||
|
427, 453, 480, 508, 537, 567, 599, 631,
|
||||||
|
665, 700, 737, 775, 814, 854, 896, 939,
|
||||||
|
984, 1030, 1077, 1127, 1177, 1230, 1283, 1339,
|
||||||
|
1396, 1455, 1515, 1577, 1641, 1707, 1775, 1844,
|
||||||
|
1916, 1989, 2064, 2141, 2220, 2302, 2385, 2470,
|
||||||
|
2557, 2647, 2739, 2833, 2929, 3027, 3128, 3231,
|
||||||
|
3336, 3444, 3554, 3667, 3782, 3899, 4019, 4142,
|
||||||
|
4267, 4395, 4525, 4658, 4794, 4933, 5074, 5218,
|
||||||
|
5365, 5515, 5668, 5824, 5983, 6144, 6309, 6477,
|
||||||
|
6648, 6822, 6999, 7179, 7363, 7550, 7740, 7933,
|
||||||
|
8130, 8330, 8534, 8741, 8951, 9165, 9383, 9604,
|
||||||
|
9829, 10057, 10289, 10525, 10765, 11008, 11255, 11507,
|
||||||
|
11761, 12020, 12283, 12550, 12821, 13096, 13375, 13658,
|
||||||
|
13945, 14237, 14532, 14832, 15137, 15445, 15758, 16076,
|
||||||
|
16397, 16724, 17054, 17390, 17730, 18074, 18423, 18777,
|
||||||
|
19136, 19499, 19868, 20241, 20618, 21001, 21389, 21781,
|
||||||
|
22179, 22582, 22990, 23403, 23821, 24244, 24672, 25106,
|
||||||
|
25545, 25990, 26440, 26895, 27355, 27821, 28293, 28770,
|
||||||
|
29253, 29742, 30236, 30735, 31241, 31752, 32270, 32793,
|
||||||
|
33321, 33856, 34397, 34944, 35497, 36056, 36621, 37192,
|
||||||
|
37769, 38353, 38943, 39539, 40142, 40751, 41366, 41988,
|
||||||
|
42617, 43251, 43893, 44541, 45196, 45857, 46526, 47201,
|
||||||
|
47882, 48571, 49267, 49969, 50678, 51395, 52118, 52849,
|
||||||
|
53587, 54332, 55084, 55843, 56610, 57384, 58165, 58954,
|
||||||
|
59750, 60553, 61364, 62183, 63010, 63843, 64685, 65535,
|
||||||
|
65535,
|
||||||
|
};
|
||||||
|
const prog_uint16_t lut_res_raised_cosine[] PROGMEM = {
|
||||||
|
0, 2, 9, 22, 39, 61, 88, 120,
|
||||||
|
157, 199, 246, 298, 354, 416, 482, 553,
|
||||||
|
629, 710, 796, 886, 982, 1082, 1186, 1296,
|
||||||
|
1410, 1530, 1653, 1782, 1915, 2053, 2195, 2342,
|
||||||
|
2494, 2650, 2811, 2976, 3146, 3320, 3498, 3681,
|
||||||
|
3869, 4060, 4256, 4457, 4661, 4870, 5083, 5300,
|
||||||
|
5522, 5747, 5977, 6210, 6448, 6689, 6935, 7184,
|
||||||
|
7437, 7694, 7955, 8220, 8488, 8760, 9035, 9314,
|
||||||
|
9597, 9883, 10172, 10465, 10762, 11061, 11364, 11670,
|
||||||
|
11980, 12292, 12607, 12926, 13247, 13572, 13899, 14229,
|
||||||
|
14562, 14898, 15236, 15578, 15921, 16267, 16616, 16967,
|
||||||
|
17321, 17676, 18034, 18395, 18757, 19122, 19488, 19857,
|
||||||
|
20227, 20600, 20974, 21350, 21728, 22107, 22488, 22871,
|
||||||
|
23255, 23641, 24027, 24416, 24805, 25196, 25588, 25980,
|
||||||
|
26374, 26769, 27165, 27562, 27959, 28357, 28756, 29155,
|
||||||
|
29555, 29956, 30356, 30758, 31159, 31561, 31963, 32365,
|
||||||
|
32767, 33169, 33571, 33973, 34375, 34776, 35178, 35578,
|
||||||
|
35979, 36379, 36778, 37177, 37575, 37972, 38369, 38765,
|
||||||
|
39160, 39554, 39946, 40338, 40729, 41118, 41507, 41893,
|
||||||
|
42279, 42663, 43046, 43427, 43806, 44184, 44560, 44934,
|
||||||
|
45307, 45677, 46046, 46412, 46777, 47139, 47500, 47858,
|
||||||
|
48213, 48567, 48918, 49267, 49613, 49956, 50298, 50636,
|
||||||
|
50972, 51305, 51635, 51962, 52287, 52608, 52927, 53242,
|
||||||
|
53554, 53864, 54170, 54473, 54772, 55069, 55362, 55651,
|
||||||
|
55937, 56220, 56499, 56774, 57046, 57314, 57579, 57840,
|
||||||
|
58097, 58350, 58599, 58845, 59086, 59324, 59557, 59787,
|
||||||
|
60012, 60234, 60451, 60664, 60873, 61077, 61278, 61474,
|
||||||
|
61665, 61853, 62036, 62214, 62388, 62558, 62723, 62884,
|
||||||
|
63040, 63192, 63339, 63481, 63619, 63752, 63881, 64004,
|
||||||
|
64124, 64238, 64348, 64452, 64552, 64648, 64738, 64824,
|
||||||
|
64905, 64981, 65052, 65118, 65180, 65236, 65288, 65335,
|
||||||
|
65377, 65414, 65446, 65473, 65495, 65512, 65525, 65532,
|
||||||
|
65532,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const prog_uint16_t* const lookup_table_table[] = {
|
||||||
|
lut_res_env_linear,
|
||||||
|
lut_res_env_expo,
|
||||||
|
lut_res_env_quartic,
|
||||||
|
lut_res_raised_cosine,
|
||||||
|
};
|
||||||
|
|
||||||
|
const prog_uint32_t lut_res_env_increments[] PROGMEM = {
|
||||||
|
3504693313, 3176601606, 2884013866, 2622586312, 2388566072, 2178702957, 1990175547, 1820529079,
|
||||||
|
1667623120, 1529587348, 1404784101, 1291776569, 1189301718, 1096247183, 1011631504, 934587183,
|
||||||
|
864346126, 800227116, 741624993, 688001314, 638876255, 593821582, 552454550, 514432575,
|
||||||
|
479448594, 447227012, 417520144, 390105102, 364781062, 341366853, 319698837, 299629042,
|
||||||
|
281023504, 263760808, 247730789, 232833385, 218977613, 206080659, 194067073, 182868042,
|
||||||
|
172420748, 162667792, 153556675, 145039341, 137071757, 129613544, 122627643, 116080011,
|
||||||
|
109939351, 104176866, 98766043, 93682448, 88903546, 84408543, 80178232, 76194860,
|
||||||
|
72442009, 68904484, 65568210, 62420143, 59448188, 56641118, 53988510, 51480677,
|
||||||
|
49108615, 46863947, 44738874, 42726133, 40818955, 39011029, 37296465, 35669767,
|
||||||
|
34125801, 32659769, 31267185, 29943852, 28685844, 27489481, 26351320, 25268129,
|
||||||
|
24236882, 23254735, 22319022, 21427239, 20577032, 19766190, 18992633, 18254405,
|
||||||
|
17549664, 16876677, 16233811, 15619528, 15032376, 14470989, 13934075, 13420417,
|
||||||
|
12928865, 12458333, 12007794, 11576280, 11162871, 10766702, 10386951, 10022842,
|
||||||
|
9673638, 9338643, 9017196, 8708673, 8412479, 8128051, 7854857, 7592388,
|
||||||
|
7340165, 7097730, 6864649, 6640510, 6424922, 6217511, 6017923, 5825821,
|
||||||
|
5640885, 5462808, 5291300, 5126085, 4966898, 4813488, 4665615, 4523052,
|
||||||
|
4385580, 4252991, 4125088, 4001681, 3882588, 3767639, 3656668, 3549518,
|
||||||
|
3446038, 3346084, 3249520, 3156214, 3066041, 2978879, 2894614, 2813136,
|
||||||
|
2734340, 2658124, 2584393, 2513053, 2444015, 2377196, 2312513, 2249888,
|
||||||
|
2189246, 2130516, 2073628, 2018517, 1965119, 1913373, 1863220, 1814606,
|
||||||
|
1767475, 1721775, 1677458, 1634475, 1592781, 1552330, 1513082, 1474994,
|
||||||
|
1438028, 1402145, 1367310, 1333488, 1300644, 1268747, 1237765, 1207668,
|
||||||
|
1178428, 1150015, 1122405, 1095570, 1069485, 1044128, 1019474, 995501,
|
||||||
|
972187, 949513, 927457, 906001, 885126, 864814, 845047, 825809,
|
||||||
|
807084, 788855, 771109, 753829, 737003, 720616, 704656, 689110,
|
||||||
|
673965, 659209, 644832, 630822, 617168, 603860, 590888, 578242,
|
||||||
|
565913, 553892, 542169, 530738, 519588, 508712, 498103, 487753,
|
||||||
|
477655, 467801, 458186, 448802, 439643, 430702, 421975, 413455,
|
||||||
|
405136, 397013, 389081, 381334, 373768, 366378, 359159, 352106,
|
||||||
|
345216, 338483, 331904, 325475, 319192, 313051, 307048, 301180,
|
||||||
|
295443, 289834, 284350, 278988, 273744, 268615, 263599, 258693,
|
||||||
|
253893, 249198, 244605, 240110, 235713, 231409, 227198, 223077,
|
||||||
|
219043,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const prog_uint32_t* const lookup_table_32_table[] = {
|
||||||
|
lut_res_env_increments,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace pure_adsr
|
61
pure_adsr/resources.h
Normal file
61
pure_adsr/resources.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
// Copyright 2019 Jan-Henrik Bruhn.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This program 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, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Resources definitions.
|
||||||
|
//
|
||||||
|
// Automatically generated with:
|
||||||
|
// make resources
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef PURE_ADSR_RESOURCES_H_
|
||||||
|
#define PURE_ADSR_RESOURCES_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "avrlib/avrlib.h"
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace pure_adsr {
|
||||||
|
|
||||||
|
typedef uint8_t ResourceId;
|
||||||
|
|
||||||
|
extern const prog_char* const string_table[];
|
||||||
|
|
||||||
|
extern const prog_uint16_t* const lookup_table_table[];
|
||||||
|
|
||||||
|
extern const prog_uint32_t* const lookup_table_32_table[];
|
||||||
|
|
||||||
|
extern const prog_uint16_t lut_res_env_linear[] PROGMEM;
|
||||||
|
extern const prog_uint16_t lut_res_env_expo[] PROGMEM;
|
||||||
|
extern const prog_uint16_t lut_res_env_quartic[] PROGMEM;
|
||||||
|
extern const prog_uint16_t lut_res_raised_cosine[] PROGMEM;
|
||||||
|
extern const prog_uint32_t lut_res_env_increments[] PROGMEM;
|
||||||
|
#define STR_RES_DUMMY 0 // dummy
|
||||||
|
#define LUT_RES_ENV_LINEAR 0
|
||||||
|
#define LUT_RES_ENV_LINEAR_SIZE 257
|
||||||
|
#define LUT_RES_ENV_EXPO 1
|
||||||
|
#define LUT_RES_ENV_EXPO_SIZE 257
|
||||||
|
#define LUT_RES_ENV_QUARTIC 2
|
||||||
|
#define LUT_RES_ENV_QUARTIC_SIZE 257
|
||||||
|
#define LUT_RES_RAISED_COSINE 3
|
||||||
|
#define LUT_RES_RAISED_COSINE_SIZE 257
|
||||||
|
#define LUT_RES_ENV_INCREMENTS 0
|
||||||
|
#define LUT_RES_ENV_INCREMENTS_SIZE 257
|
||||||
|
|
||||||
|
} // namespace pure_adsr
|
||||||
|
|
||||||
|
#endif // PURE_ADSR_RESOURCES_H_
|
0
pure_adsr/resources/__init__.py
Normal file
0
pure_adsr/resources/__init__.py
Normal file
79
pure_adsr/resources/lookup_tables.py
Normal file
79
pure_adsr/resources/lookup_tables.py
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
#!/usr/bin/python2.5
|
||||||
|
#
|
||||||
|
# Copyright 2014 Emilie Gillet.
|
||||||
|
#
|
||||||
|
# Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
# THE SOFTWARE.
|
||||||
|
#
|
||||||
|
# See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
#
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Lookup table definitions.
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
|
||||||
|
SAMPLE_RATE = 20000000.0 / 510 / 16#/ 4 # hz
|
||||||
|
|
||||||
|
"""----------------------------------------------------------------------------
|
||||||
|
LFO and envelope increments.
|
||||||
|
----------------------------------------------------------------------------"""
|
||||||
|
|
||||||
|
lookup_tables = []
|
||||||
|
lookup_tables_32 = []
|
||||||
|
excursion = 1 << 32
|
||||||
|
sample_rate = SAMPLE_RATE
|
||||||
|
num_values = 257
|
||||||
|
min_frequency = 1.0 / 32.0 # Hertz
|
||||||
|
max_frequency = 160.0 # Hertz
|
||||||
|
min_increment = excursion * min_frequency / sample_rate
|
||||||
|
max_increment = excursion * max_frequency / sample_rate
|
||||||
|
|
||||||
|
# Create lookup table for envelope times (x^0.25).
|
||||||
|
max_time = 8.0 # seconds
|
||||||
|
min_time = 0.0005
|
||||||
|
gamma = 0.175
|
||||||
|
min_increment = excursion / (max_time * sample_rate)
|
||||||
|
max_increment = excursion / (min_time * sample_rate)
|
||||||
|
|
||||||
|
rates = numpy.linspace(numpy.power(max_increment, -gamma),
|
||||||
|
numpy.power(min_increment, -gamma), num_values)
|
||||||
|
|
||||||
|
values = numpy.power(rates, -1/gamma).astype(int)
|
||||||
|
lookup_tables_32.append(
|
||||||
|
('env_increments', values)
|
||||||
|
)
|
||||||
|
|
||||||
|
"""----------------------------------------------------------------------------
|
||||||
|
Envelope curves
|
||||||
|
-----------------------------------------------------------------------------"""
|
||||||
|
|
||||||
|
env_linear = numpy.arange(0, 257.0) / 256.0
|
||||||
|
env_linear[-1] = env_linear[-2]
|
||||||
|
env_quartic = env_linear ** 3.32
|
||||||
|
env_expo = 1.0 - numpy.exp(-4 * env_linear)
|
||||||
|
|
||||||
|
lookup_tables.append(('env_linear', env_linear / env_linear.max() * 65535.0))
|
||||||
|
lookup_tables.append(('env_expo', env_expo / env_expo.max() * 65535.0))
|
||||||
|
lookup_tables.append(
|
||||||
|
('env_quartic', env_quartic / env_quartic.max() * 65535.0))
|
||||||
|
|
||||||
|
raised_cosine = 0.5 - numpy.cos(env_linear * numpy.pi) / 2
|
||||||
|
lookup_tables.append(('raised_cosine', raised_cosine * 65535.0))
|
81
pure_adsr/resources/resources.bak
Normal file
81
pure_adsr/resources/resources.bak
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
#!/usr/bin/python2.5
|
||||||
|
#
|
||||||
|
# Copyright 2014 Emilie Gillet.
|
||||||
|
#
|
||||||
|
# Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
# THE SOFTWARE.
|
||||||
|
#
|
||||||
|
# See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
#
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Master resources file.
|
||||||
|
|
||||||
|
header = """// Copyright 2013 Emilie Gillet.
|
||||||
|
//
|
||||||
|
// Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
// See http://creativecommons.org/licenses/MIT/ for more information.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Resources definitions.
|
||||||
|
//
|
||||||
|
// Automatically generated with:
|
||||||
|
// make resources
|
||||||
|
"""
|
||||||
|
|
||||||
|
namespace = 'pure_adsr'
|
||||||
|
target = 'pure_adsr'
|
||||||
|
includes = """
|
||||||
|
#include "avrlib/avrlib.h"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import lookup_tables
|
||||||
|
|
||||||
|
types = ['uint8_t', 'uint16_t']
|
||||||
|
create_specialized_manager = True
|
||||||
|
|
||||||
|
resources = [
|
||||||
|
('dummy', 'string', 'STR', 'char', str, False),
|
||||||
|
(lookup_tables.lookup_tables,
|
||||||
|
'lookup_table', 'LUT', 'uint16_t', int, False),
|
||||||
|
(lookup_tables.lookup_tables_32,
|
||||||
|
'lookup_table_32', 'LUT', 'uint32_t', int, False)
|
||||||
|
]
|
||||||
|
|
64
pure_adsr/resources/resources.py
Normal file
64
pure_adsr/resources/resources.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#!/usr/bin/python2.5
|
||||||
|
#
|
||||||
|
# Copyright 2012 Emilie Gillet.
|
||||||
|
#
|
||||||
|
# Author: Emilie Gillet (emilie.o.gillet@gmail.com)
|
||||||
|
#
|
||||||
|
# This program 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, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Master resources file.
|
||||||
|
|
||||||
|
header = """// Copyright 2019 Jan-Henrik Bruhn.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This program 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, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Resources definitions.
|
||||||
|
//
|
||||||
|
// Automatically generated with:
|
||||||
|
// make resources
|
||||||
|
"""
|
||||||
|
|
||||||
|
namespace = 'pure_adsr'
|
||||||
|
target = 'pure_adsr'
|
||||||
|
modifier = 'PROGMEM'
|
||||||
|
types = ['uint8_t', 'uint16_t']
|
||||||
|
includes = """
|
||||||
|
#include "avrlib/avrlib.h"
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
"""
|
||||||
|
|
||||||
|
import lookup_tables
|
||||||
|
|
||||||
|
create_specialized_manager = False
|
||||||
|
|
||||||
|
resources = [
|
||||||
|
('dummy', 'string', 'STR_RES', 'prog_char', str, True),
|
||||||
|
(lookup_tables.lookup_tables,
|
||||||
|
'lookup_table', 'LUT_RES', 'prog_uint16_t', int, True),
|
||||||
|
(lookup_tables.lookup_tables_32,
|
||||||
|
'lookup_table_32', 'LUT_RES', 'prog_uint32_t', int, True)
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in a new issue