Compare commits

...

3 Commits

Author SHA1 Message Date
Mike Lynch 550e48402f Stripped-back fibomod 2024-02-11 14:56:11 +11:00
Mike Lynch 43b41bde8f bassline for Numerology 2024-02-11 14:55:58 +11:00
Mike Lynch 0bff8f0db0 Musically interesting fibo waveforms 2024-02-11 14:01:31 +11:00
3 changed files with 109 additions and 35 deletions

View File

@ -6,12 +6,17 @@
Adafruit_MCP4728 mcp;
#define nsamp 256
#define nsamp 1500
#define dacmax 256
unsigned int phase = 0;
unsigned int fibo = 20;
unsigned int fibo = 3;
unsigned int scale = 0;
unsigned int fibi = 0;
unsigned int pmax = nsamp;
unsigned int fibosort[] = { 4,3,11,8,29,7,21,19,38,76,5,55,199,6,9,12,16,18,24,36,48,72,144,13,22,31,44,62,124,47,141,17,34,68,136,152,15,33,41,123,165,205,58,116,211,89,139,14,23,28,32,42,46,56,63,69,84,92,96,112,126,138,161,168,184,207,224,252,101,151,233,39,87,59,10,20,40,61,88,110,122,155,220,244,248,71,27,51,54,57,102,107,108,114,153,171,204,214,216,228,37,113,79,158,35,77,105,231,26,52,104,232,43,129,181,209,64,94,188,192,25,53,106,109,212,218,121,49,91,147,203,229,30,45,60,66,80,82,90,93,99,120,132,164,176,180,183,186,198,240,246,131,178,67,201,65,143,145,119,133,189,238,73,149,202,111,235,78,83,117,156,166,174,208,234,249,118,236,179,85,95,170,187,190,191,128,97,75,103,142,81,159,162,74,148,226,177,239,70,115,140,154,160,210,217,230,241,253,251,221,247,127,86,172,137,195,213,219,50,100,200,237,157,163,242,98,167,182,196,173,135,255,169,185,193,197,175,134,130,215,146,223,222,227,125,245,194,150,225,206,243,254,250 };
byte waveform[nsamp];
@ -26,7 +31,7 @@ void setup() {
// set compare match register for 1hz increments
//OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
//OCR1A = 7812;// = (16*10^6) / (1*1024) - 1 (must be <65536)
OCR1A = 10000;
OCR1A = 2000;
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler
@ -37,6 +42,7 @@ void setup() {
sei();
Serial.begin(115200);
if (!mcp.begin(0x64)) {
@ -50,38 +56,46 @@ void setup() {
for( int i = 0; i < nsamp; i++ ) {
waveform[i] = 1;
}
fibo = fibosort[fibi];
setwave();
}
void setwave(){
waveform[0] = 0;
waveform[1] = 1;
fibo = fibosort[fibi];
Serial.println(fibo);
pmax = nsamp;
for (int i=2; i<nsamp; ++i){
waveform[i] = (waveform[i - 1] + waveform[i - 2]) % fibo;
if( waveform[i - 1] == 0 && waveform[i] == 1 ) {
pmax = i - 1;
break;
}
}
Serial.println(pmax);
float scale = 256 / fibo;
for( int i = 0; i < nsamp; ++i ) {
waveform[i] *= scale;
}
}
ISR(TIMER1_COMPA_vect){//timer1
unsigned int flog;
scale = 10;
fibo = 3 + analogRead(A0) >> 2;
flog = fibo;
while( flog ) {
flog = flog >> 1;
scale -= 1;
fibi++;
if( fibi == 128 ) {
fibi = 0;
}
Serial.println(fibo);
Serial.println(scale);
Serial.println(fibo << scale);
Serial.println("Setting wave");
setwave();
phase = 0;
}
void loop() {
int p0 = phase - 1;
int p1 = phase + 2;
if( p0 < 0 ) {
p0 += nsamp;
}
if( p1 < 0 ) {
p1 += nsamp;
}
waveform[phase] = (waveform[p1] + waveform[p0]) % fibo;
mcp.fastWrite(waveform[phase] << scale, 0, 0, 0);
mcp.fastWrite(waveform[phase] << 4, 0, 0, 0);
phase += 1;
if( phase >= nsamp ) {
if( phase == pmax ) {
phase = 0;
}
}

View File

@ -0,0 +1,63 @@
// can fibomod make an interesting noise?
#include <Adafruit_MCP4728.h>
#include <Wire.h>
Adafruit_MCP4728 mcp;
unsigned int fibo = 43;
unsigned int a = 0;
unsigned int b = 1;
void setup() {
cli();
//set timer1 interrupt at 1Hz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1hz increments
//OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
//OCR1A = 7812;// = (16*10^6) / (1*1024) - 1 (must be <65536)
OCR1A = 1000;
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();
Serial.begin(115200);
if (!mcp.begin(0x64)) {
while (1) {
delay(100);
}
}
mcp.setSpeed(800000L);
}
ISR(TIMER1_COMPA_vect){
fibo = analogRead(A0);
if( fibo < 3 )
Serial.println(fibo);
}
void loop() {
unsigned int c = (a + b) % fibo;
a = b;
b = c;
mcp.fastWrite(a << 2, 0, 0, 0);
}

View File

@ -15,10 +15,9 @@ unsigned int phase;
unsigned int length;
unsigned int repeats;
int note = 0;
//int freqs[] = { 256, 228, 205, 192, 171, 154, 137, 128, 114, 102, 96, 85, 77, 68, 64 };
//int freqs[] = { 128, 114, 102, 96, 85, 77, 68, 64, 56, 51, 48, 42, 38, 34, 32 };
int freqs[] = { 64, 56, 51, 48, 42, 38, 34, 32, 28, 25, 24, 21, 19, 17, 16 };
int tune[] = { 0, 4, 3, 5, -1, -1, -1, -1 };
int tune2[] = { 2, -1, -1, 2, -1, -1, 3, -1, 2, -1, -1, -1, 0, -1, -1, -1 };
//int tune2[] = { 2, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, 4, -1, -1, -1 };
byte waveform[nsamp];
@ -35,10 +34,10 @@ void setup() {
// set compare match register for 1hz increments
//OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
//OCR1A = 7812;// = (16*10^6) / (1*1024) - 1 (must be <65536)
OCR1A = 10000;
OCR1A = 2000;
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler
// Set CS10 and CS12 bits for 1024 escaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
@ -46,7 +45,6 @@ void setup() {
sei();
Serial.begin(115200);
if (!mcp.begin(0x64)) {
while (1) {
@ -62,18 +60,17 @@ void setup() {
}
ISR(TIMER1_COMPA_vect){//timer1
if( tune[note] > -1 ) {
length=freqs[tune[note]];
if( tune2[note] > -1 ) {
length=freqs[tune2[note]];
for (int i=0; i<nsamp; ++i){
waveform[i]=random(256);
}
}
note++;
if( note > 7 ) {
if( note > 15 ) {
note = 0;
}
pd = analogRead(A0) >> 4;
Serial.println(pd);
}