Skip to content

Commit

Permalink
rhythm for arpeggio, lol
Browse files Browse the repository at this point in the history
  • Loading branch information
dojoe committed Aug 4, 2012
1 parent f9b1668 commit 1aec9b6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
38 changes: 38 additions & 0 deletions 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))
12 changes: 8 additions & 4 deletions win/main.cpp
Expand Up @@ -4,6 +4,7 @@
#include <malloc.h>
#include <Windows.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 };

Expand All @@ -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 };
Expand Down Expand Up @@ -43,16 +46,17 @@ 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)
{
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)
Expand All @@ -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++;
}
Expand Down
3 changes: 3 additions & 0 deletions win/noiseplug.vcxproj
Expand Up @@ -77,6 +77,9 @@
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="binary.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
5 changes: 5 additions & 0 deletions win/noiseplug.vcxproj.filters
Expand Up @@ -19,4 +19,9 @@
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="binary.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 1aec9b6

Please sign in to comment.