Skip to content

Commit

Permalink
Plaits: fixed initialization issue in chord table
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilie Gillet committed May 15, 2020
1 parent 20b02f8 commit 99432f2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion avr_audio_bootloader
2 changes: 1 addition & 1 deletion avrlib
39 changes: 35 additions & 4 deletions plaits/dsp/engine/chord_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ namespace plaits {
using namespace std;
using namespace stmlib;

#ifdef JON_CHORDS

// Alternative chord table by Jon Butler [email protected]
const float chords[kChordNumChords][kChordNumNotes] = {
// Fixed Intervals
{ 0.00f, 0.01f, 11.99f, 12.00f }, // Octave
{ 0.00f, 7.01f, 7.00f, 12.00f }, // Fifth
// Minor
{ 0.00f, 3.00f, 7.00f, 12.00f }, // Minor
{ 0.00f, 3.00f, 7.00f, 10.00f }, // Minor 7th
{ 0.00f, 3.00f, 10.00f, 14.00f }, // Minor 9th
{ 0.00f, 3.00f, 10.00f, 17.00f }, // Minor 11th
// Major
{ 0.00f, 4.00f, 7.00f, 12.00f }, // Major
{ 0.00f, 4.00f, 7.00f, 11.00f }, // Major 7th
{ 0.00f, 4.00f, 11.00f, 14.00f }, // Major 9th
// Colour Chords
{ 0.00f, 5.00f, 7.00f, 12.00f }, // Sus4
{ 0.00f, 2.00f, 9.00f, 16.00f }, // 69
{ 0.00f, 4.00f, 7.00f, 9.00f }, // 6th
{ 0.00f, 7.00f, 16.00f, 23.00f }, // 10th (Spread maj7)
{ 0.00f, 4.00f, 7.00f, 10.00f }, // Dominant 7th
{ 0.00f, 7.00f, 10.00f, 13.00f }, // Dominant 7th (b9)
{ 0.00f, 3.00f, 6.00f, 10.00f }, // Half Diminished
{ 0.00f, 3.00f, 6.00f, 9.00f }, // Fully Diminished
};

#else

const float chords[kChordNumChords][kChordNumNotes] = {
{ 0.00f, 0.01f, 11.99f, 12.00f }, // OCT
{ 0.00f, 7.01f, 7.00f, 12.00f }, // 5
Expand All @@ -51,6 +80,8 @@ const float chords[kChordNumChords][kChordNumNotes] = {
{ 0.00f, 4.00f, 7.00f, 12.00f }, // M
};

#endif // JON_CHORDS

void ChordEngine::Init(BufferAllocator* allocator) {
for (int i = 0; i < kChordNumVoices; ++i) {
divide_down_voice_[i].Init();
Expand All @@ -60,13 +91,13 @@ void ChordEngine::Init(BufferAllocator* allocator) {
morph_lp_ = 0.0f;
timbre_lp_ = 0.0f;

ratios_ = allocator->Allocate<float>(kChordNumChords * kChordNumVoices);
ratios_ = allocator->Allocate<float>(kChordNumChords * kChordNumNotes);
}

void ChordEngine::Reset() {
for (int i = 0; i < kChordNumChords; ++i) {
for (int j = 0; j < kChordNumVoices; ++j) {
ratios_[i * kChordNumVoices + j] = SemitonesToRatio(chords[i][j]);
for (int j = 0; j < kChordNumNotes; ++j) {
ratios_[i * kChordNumNotes + j] = SemitonesToRatio(chords[i][j]);
}
}
}
Expand Down Expand Up @@ -105,7 +136,7 @@ int ChordEngine::ComputeChordInversion(
float inversion,
float* ratios,
float* amplitudes) {
const float* base_ratio = &ratios_[chord_index * kChordNumVoices];
const float* base_ratio = &ratios_[chord_index * kChordNumNotes];
inversion = inversion * float(kChordNumNotes * 5);

MAKE_INTEGRAL_FRACTIONAL(inversion);
Expand Down
9 changes: 8 additions & 1 deletion plaits/dsp/engine/chord_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ namespace plaits {

const int kChordNumNotes = 4;
const int kChordNumVoices = 5;
const int kChordNumChords = 11;
const int kChordNumHarmonics = 3;

// #define JON_CHORDS

#ifdef JON_CHORDS
const int kChordNumChords = 17;
#else
const int kChordNumChords = 11;
#endif // JON_CHORDS

class ChordEngine : public Engine {
public:
ChordEngine() { }
Expand Down
2 changes: 1 addition & 1 deletion stmlib
Submodule stmlib updated 166 files

0 comments on commit 99432f2

Please sign in to comment.