From 1aec9b6cb7e6a9485d3ddb4782741b602e9e68be Mon Sep 17 00:00:00 2001 From: Joachim Fenkes Date: Sat, 4 Aug 2012 22:49:40 +0200 Subject: [PATCH] rhythm for arpeggio, lol --- win/binary.h | 38 +++++++++++++++++++++++++++++++++++ win/main.cpp | 12 +++++++---- win/noiseplug.vcxproj | 3 +++ win/noiseplug.vcxproj.filters | 5 +++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 win/binary.h diff --git a/win/binary.h b/win/binary.h new file mode 100644 index 0000000..c81b5f2 --- /dev/null +++ b/win/binary.h @@ -0,0 +1,38 @@ +/* Binary constant generator macro +By Tom Torfs - donated to the public domain +*/ + +/* All macro's evaluate to compile-time constants */ + +/* *** helper macros *** / + +/* turn a numeric literal into a hex constant +(avoids problems with leading zeroes) +8-bit constants max value 0x11111111, always fits in unsigned long +*/ +#define HEX__(n) 0x##n##LU + +/* 8-bit conversion function */ +#define B8__(x) ((x&0x0000000FLU)?1:0) \ ++((x&0x000000F0LU)?2:0) \ ++((x&0x00000F00LU)?4:0) \ ++((x&0x0000F000LU)?8:0) \ ++((x&0x000F0000LU)?16:0) \ ++((x&0x00F00000LU)?32:0) \ ++((x&0x0F000000LU)?64:0) \ ++((x&0xF0000000LU)?128:0) + +/* *** user macros *** / + +/* for upto 8-bit binary constants */ +#define B8(d) ((unsigned char)B8__(HEX__(d))) + +/* for upto 16-bit binary constants, MSB first */ +#define B16(dmsb,dlsb) (((unsigned short)B8(dmsb)<<8) \ ++ B8(dlsb)) + +/* for upto 32-bit binary constants, MSB first */ +#define B32(dmsb,db2,db3,dlsb) (((unsigned long)B8(dmsb)<<24) \ ++ ((unsigned long)B8(db2)<<16) \ ++ ((unsigned long)B8(db3)<<8) \ ++ B8(dlsb)) diff --git a/win/main.cpp b/win/main.cpp index 46838d9..8ca7b96 100644 --- a/win/main.cpp +++ b/win/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include "binary.h" int notes[25] = { 134, 142, 150, 159, 169, 179, 189, 201, 213, 225, 239, 253, 268, 284, 301, 319, 338, 358, 379, 401, 425, 451, 477, 506, 536 }; @@ -15,6 +16,8 @@ int arpeggio[][4] = { { 1, 3, 5, 10 }, }; int arpseq[16] = { 0, 0, 1, 1, 2, 2, 4, 3, 0, 0, 1, 1, 2, 3, 4, 4 }; +//int arptiming[32] = { 4, 2, 4, 2, 4, 2, 4, 5, 1, 2, 2 } +const uint32_t arptiming = B32(00001100,00110000,11000011,11101100); int bassbeat[8] = { 0, 0, 1, 0, 0, 1, 0, 1 }; int bassline[16] = { 12, 12, 15, 10, 12, 12, 17, 10, 12, 12, 15, 7, 8, 8, 3, 7 }; @@ -43,8 +46,8 @@ static inline unsigned char voice_lead(unsigned long i) uint8_t melody = leadmelody[leadptr]; int note = notes[melody == 1 ? 0 : melody]; // TODO remove this hack by using note table lead_osc += note; - lead_flange += note + 1;//(i & 1); - return (!melody) ? 0 : (((lead_osc >> 6) & 0x7F) + ((lead_flange >> 6) & 0x3F)); // xor also sounds cool + lead_flange += note + (i & 1); + return (!melody) ? 0 : (((lead_osc >> 6) & 0x7F) + ((lead_osc >> 6) & 0x3F) + ((lead_flange >> 6) & 0x3F)); // xor also sounds cool } static inline unsigned char voice_arp(unsigned long i) @@ -52,7 +55,8 @@ static inline unsigned char voice_arp(unsigned long i) static uint16_t arp_osc = 0; int note = notes[12 + arpeggio[arpseq[(i >> 13) & 15]][(i >> 7) & 3]]; arp_osc += note; - return ((arp_osc >> 5) & 128) - 1; + return ((arptiming & (1 << (31 - (i >> 9)))) && (arp_osc & (1 << 12))) ? 0 : 140; + //return ((arp_osc >> 5) & 128) - 1; } static inline unsigned char voice_bass(unsigned long i) @@ -73,7 +77,7 @@ void fill(char *data) for (int j = 0; j < 4096; j++) { - unsigned char sample = (voice_lead(i) >> 1) + (voice_bass(i) >> 1);// + (voice_arp(i) >> 1); + unsigned char sample = /*(voice_lead(i) >> 1) + */(voice_bass(i) >> 2) + (voice_arp(i) >> 2); data[j] = sample; i++; } diff --git a/win/noiseplug.vcxproj b/win/noiseplug.vcxproj index 7da8b1a..5abdf3a 100644 --- a/win/noiseplug.vcxproj +++ b/win/noiseplug.vcxproj @@ -77,6 +77,9 @@ + + + diff --git a/win/noiseplug.vcxproj.filters b/win/noiseplug.vcxproj.filters index 6e05b87..04fa324 100644 --- a/win/noiseplug.vcxproj.filters +++ b/win/noiseplug.vcxproj.filters @@ -19,4 +19,9 @@ Quelldateien + + + Headerdateien + + \ No newline at end of file