rhythm for arpeggio, lol

This commit is contained in:
Joachim Fenkes 2012-08-04 22:49:40 +02:00
parent f9b166825c
commit 1aec9b6cb7
4 changed files with 54 additions and 4 deletions

38
win/binary.h Normal file
View file

@ -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))

View file

@ -4,6 +4,7 @@
#include <malloc.h> #include <malloc.h>
#include <Windows.h> #include <Windows.h>
#include <MMSystem.h> #include <MMSystem.h>
#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 }; 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 }, { 1, 3, 5, 10 },
}; };
int arpseq[16] = { 0, 0, 1, 1, 2, 2, 4, 3, 0, 0, 1, 1, 2, 3, 4, 4 }; 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 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 }; 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]; uint8_t melody = leadmelody[leadptr];
int note = notes[melody == 1 ? 0 : melody]; // TODO remove this hack by using note table int note = notes[melody == 1 ? 0 : melody]; // TODO remove this hack by using note table
lead_osc += note; lead_osc += note;
lead_flange += note + 1;//(i & 1); lead_flange += note + (i & 1);
return (!melody) ? 0 : (((lead_osc >> 6) & 0x7F) + ((lead_flange >> 6) & 0x3F)); // xor also sounds cool 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) 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; static uint16_t arp_osc = 0;
int note = notes[12 + arpeggio[arpseq[(i >> 13) & 15]][(i >> 7) & 3]]; int note = notes[12 + arpeggio[arpseq[(i >> 13) & 15]][(i >> 7) & 3]];
arp_osc += note; 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) static inline unsigned char voice_bass(unsigned long i)
@ -73,7 +77,7 @@ void fill(char *data)
for (int j = 0; j < 4096; j++) 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; data[j] = sample;
i++; i++;
} }

View file

@ -77,6 +77,9 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClInclude Include="binary.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View file

@ -19,4 +19,9 @@
<Filter>Quelldateien</Filter> <Filter>Quelldateien</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClInclude Include="binary.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
</Project> </Project>