Skip to content

Commit

Permalink
limit voices by default, add some drums
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhumbert committed Dec 21, 2016
1 parent 53ea854 commit 438a5d6
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 25 deletions.
2 changes: 2 additions & 0 deletions keyboards/planck/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_COL_PINS { F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 }
#define UNUSED_PINS

#define AUDIO_VOICES

#define BACKLIGHT_PIN B7

/* COL2ROW or ROW2COL */
Expand Down
2 changes: 2 additions & 0 deletions keyboards/preonic/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_COL_PINS { F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 }
#define UNUSED_PINS

#define AUDIO_VOICES

#define BACKLIGHT_PIN B7

/* COL2ROW or ROW2COL */
Expand Down
105 changes: 80 additions & 25 deletions quantum/audio/voices.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ float voice_envelope(float frequency) {
polyphony_rate = 0;
break;

#ifdef AUDIO_VOICES

case something:
glissando = false;
polyphony_rate = 0;
Expand All @@ -58,36 +60,87 @@ float voice_envelope(float frequency) {
case drums:
glissando = false;
polyphony_rate = 0;
note_timbre = 0;
// switch (compensated_index) {
// case 0 ... 10:
// note_timbre = 0.5;
// break;
// case 11 ... 20:
// note_timbre = 0.5 * (21 - compensated_index) / 10;
// break;
// default:
// note_timbre = 0;
// break;
// }
// frequency = (rand() % (int)(frequency * 1.2 - frequency)) + (frequency * 0.8);

if (frequency < 80.0) {

} else if (frequency < 160.0) {

// Bass drum: 60 - 100 Hz
frequency = (rand() % (int)(40)) + 60;
switch (envelope_index) {
case 0 ... 10:
note_timbre = 0.5;
break;
case 11 ... 20:
note_timbre = 0.5 * (21 - envelope_index) / 10;
break;
default:
note_timbre = 0;
break;
}

} else if (frequency < 320.0) {


// Snare drum: 1 - 2 KHz
frequency = (rand() % (int)(1000)) + 1000;
switch (envelope_index) {
case 0 ... 5:
note_timbre = 0.5;
break;
case 6 ... 20:
note_timbre = 0.5 * (21 - envelope_index) / 15;
break;
default:
note_timbre = 0;
break;
}

} else if (frequency < 640.0) {

// Closed Hi-hat: 3 - 5 KHz
frequency = (rand() % (int)(2000)) + 3000;
switch (envelope_index) {
case 0 ... 20:
case 0 ... 15:
note_timbre = 0.5;
break;
case 16 ... 20:
note_timbre = 0.5 * (21 - envelope_index) / 5;
break;
default:
frequency = (rand() % (int)(frequency * 1.2 - frequency)) + (frequency * 0.8);
note_timbre = 0;
break;
}
// if (frequency < 80.0) {
// switch (envelope_index % 4) {
// case 0:
// frequency = 348.0;
// case 1:
// frequency = 53.0;
// case 2:
// frequency = 128.0;
// case 3:
// frequency = 934.0;
// default:
// break;
// }
// } else if (frequency < 160.0) {

// } else if (frequency < 320.0) {

// } else if (frequency < 640.0) {

// } else if (frequency < 1280.0) {

// }

} else if (frequency < 1280.0) {

// Open Hi-hat: 3 - 5 KHz
frequency = (rand() % (int)(2000)) + 3000;
switch (envelope_index) {
case 0 ... 35:
note_timbre = 0.5;
break;
case 36 ... 50:
note_timbre = 0.5 * (51 - envelope_index) / 15;
break;
default:
note_timbre = 0;
break;
}

}
break;
case butts_fader:
glissando = true;
Expand Down Expand Up @@ -217,6 +270,8 @@ float voice_envelope(float frequency) {
// note_timbre = 0.25;
// break;

#endif

default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions quantum/audio/voices.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ float voice_envelope(float frequency);

typedef enum {
default_voice,
#ifdef AUDIO_VOICES
something,
drums,
butts_fader,
Expand All @@ -23,6 +24,7 @@ typedef enum {
// duty_fourth_down,
// duty_third_down,
// duty_fifth_third_down,
#endif
number_of_voices // important that this is last
} voice_type;

Expand Down

0 comments on commit 438a5d6

Please sign in to comment.