diff --git a/projekte/soundz/karplus_strong_totally_borken/karplus_strong_totally_borken.pde b/projekte/soundz/karplus_strong_totally_borken/karplus_strong_totally_borken.pde index 9df36f3..a503021 100644 --- a/projekte/soundz/karplus_strong_totally_borken/karplus_strong_totally_borken.pde +++ b/projekte/soundz/karplus_strong_totally_borken/karplus_strong_totally_borken.pde @@ -23,54 +23,98 @@ void setup() { // Set initial pulse width to the first sample. OCR2A = 0; + + // DEBUG + Serial.begin(9600); } +// Frequencies (in Hz) of notes +#define FSH_4 370 +#define A_4 440 +#define B_4 494 +#define E_4 330 +#define CSH_5 554 +#define D_5 587 +#define FSH_5 740 +#define CSH_4 277 +#define GSH_4 415 + +#define REST 0 + int play (uint16_t f, uint8_t T) { - sendKarplusStrongSound(f, T); + #define MAGIC_TUNE_FAC 3 + if (f == REST) { + _delay_ms(T*1000/16*MAGIC_TUNE_FAC); + } else { + sendKarplusStrongSound(f, T*MAGIC_TUNE_FAC); + } } // http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1249193795 -int sendKarplusStrongSound(const uint16_t f /*Hz*/, const uint8_t T /*sec*/) { - const uint8_t N = 32; - const uint32_t sr = f * N; // sample rate: 800(25Hz)..47619(1488Hz) +int sendKarplusStrongSound(uint16_t f /*Hz*/, uint8_t T /* 1/16 sec*/) { + uint32_t sr = 11025; + uint8_t N = sr/f; + //uint8_t N=32; + //uint32_t sr = (uint32_t) N*f; + + Serial.print("N = "); + Serial.print(N, DEC); + Serial.println(); - int16_t buf[N]; + unsigned long millis_alt = millis(); + + int buf[N]; for (uint8_t i=0; i