Skip to content

Commit

Permalink
bug fixes that I should have done last year
Browse files Browse the repository at this point in the history
arg
  • Loading branch information
micknoise committed Oct 15, 2014
1 parent a38ec23 commit bbe04a0
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 65 deletions.
70 changes: 21 additions & 49 deletions main.cpp
@@ -1,61 +1,33 @@
#include "maximilian.h"

//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.

maxiOsc sound,bass,timer,mod,lead,lead2,leadmod;//here are the synth bits
maxiEnv envelope, leadenvelope;//some envelopes
maxiFilter filter, filter2;//some filters
maxiDelayline delay;//a delay
convert mtof;//a method for converting midi notes to frequency
double bassout,leadout, delayout;//some variables to hold the data and pass it around
int trigger, trigger2, newnote;//some control variables
int currentCount,lastCount,playHead=0, currentChord=0;//some other control variables
int pitch[8]={57,57,59,60};//the bassline for the arpeggio
int chord[8]={0,0,7,2,5,5,0,0};//the root chords for the arpeggio
float currentPitch,leadPitch;//the final pitch variables

//here's the lead line trigger array, followed by the pitches
int leadLineTrigger[256]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int leadLinePitch[15]={69,67,65,64,67,66,64,62,65,64,62,57,55,60,57};


maxiOsc myCounter,mySwitchableOsc;//
int CurrentCount;//
double myOscOutput,myFilteredOutput;//
double myEnvelopeData[6] = {500,0,1000,500,0,500};//this data will be used to make an envelope. Value and time to value in ms.
maxiEnvelope myEnvelope;
maxiFilter myFilter;

void setup() {//some inits

myEnvelope.amplitude=myEnvelopeData[0]; //initialise the envelope
}

void play(double *output) {//this is where the magic happens. Very slow magic.

currentCount=(int)timer.phasor(9);//this sets up a metronome that ticks every so often
void play(double *output) {

if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
trigger=1;//play the arpeggiator line
trigger2=leadLineTrigger[playHead%256];//play the lead line
if (trigger2==1) {//if we are going to play a note
leadPitch=mtof.mtof(leadLinePitch[newnote]);//get the next pitch val
newnote++;//and iterate
if (newnote>14) {
newnote=0;//make sure we don't go over the edge of the array
}
}
currentPitch=mtof.mtof(pitch[(playHead%4)]+chord[currentChord%8]);//write the frequency val into currentPitch
playHead++;//iterate the playhead
if (playHead%32==0) {//wrap every 4 bars
currentChord++;//change the chord
}
//cout << "tick\n";//the clock ticks
lastCount=0;//set lastCount to 0
}
CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.

bassout=filter2.lores(envelope.adsr(bass.saw(currentPitch*0.5)+sound.pulse(currentPitch*0.5,mod.phasor(1)),1,0.9995, 0.25, 0.9995, 1, trigger),9250,2);//new, simple ADSR.
leadout=filter.lores(leadenvelope.ar(lead2.saw(leadPitch*4)+lead.pulse(leadPitch+(leadmod.sinebuf(1.9)*1.5), 0.6), 0.00005, 0.999975, 50000, trigger2),5900,10);//leadline
if (CurrentCount<5)//simple if statement

myOscOutput=mySwitchableOsc.square(CurrentCount*100);

delayout=(leadout+(delay.dl(leadout, 14000, 0.8)*0.5))/2;//add some delay
else if (CurrentCount>=5)//and the 'else' bit.

myOscOutput=mySwitchableOsc.saw(CurrentCount*50);//one osc object can produce whichever waveform you want.

if(trigger!=0)trigger=0;//set the trigger to off if you want it to trigger immediately next time.
if (CurrentCount==1)

myEnvelope.trigger(0,myEnvelopeData[0]); //trigger the envelope

myFilteredOutput=myFilter.lores(myOscOutput,(myEnvelope.line(6, myEnvelopeData)),10);//lores takes an audio input, a frequency and a resonance factor (1-100)

output[0]=(bassout+delayout)/2;//sum output
output[1]=(bassout+delayout)/2;

}
*output=myFilteredOutput;//point me at your speakers and fire.
}
12 changes: 6 additions & 6 deletions maximilian.cpp
Expand Up @@ -368,7 +368,7 @@ double maxiEnvelope::line(int numberofsegments,double segments[1000]) {
//This is a basic multi-segment ramp generator that you can use for more or less anything.
//However, it's not that intuitive.
if (isPlaying==1) {//only make a sound once you've been triggered
period=2./(segments[valindex+1]*0.004);
period=4./(segments[valindex+1]*0.0044);
nextval=segments[valindex+2];
currentval=segments[valindex];
if (currentval-amplitude > 0.0000001 && valindex < numberofsegments) {
Expand Down Expand Up @@ -440,9 +440,9 @@ double maxiFilter::hipass(double input, double cutoff) {
}
//awesome. cuttof is freq in hz. res is between 1 and whatever. Watch out!
double maxiFilter::lores(double input,double cutoff1, double resonance) {
cutoff=cutoff1*0.5;
cutoff=cutoff1;
if (cutoff<10) cutoff=10;
if (cutoff>(maxiSettings::sampleRate*0.5)) cutoff=(maxiSettings::sampleRate*0.5);
if (cutoff>(maxiSettings::sampleRate)) cutoff=(maxiSettings::sampleRate);
if (resonance<1.) resonance = 1.;
z=cos(TWOPI*cutoff/maxiSettings::sampleRate);
c=2-2*z;
Expand All @@ -456,9 +456,9 @@ double maxiFilter::lores(double input,double cutoff1, double resonance) {

//working hires filter
double maxiFilter::hires(double input,double cutoff1, double resonance) {
cutoff=cutoff1*0.5;
cutoff=cutoff1;
if (cutoff<10) cutoff=10;
if (cutoff>(maxiSettings::sampleRate*0.5)) cutoff=(maxiSettings::sampleRate*0.5);
if (cutoff>(maxiSettings::sampleRate)) cutoff=(maxiSettings::sampleRate);
if (resonance<1.) resonance = 1.;
z=cos(TWOPI*cutoff/maxiSettings::sampleRate);
c=2-2*z;
Expand Down Expand Up @@ -1202,7 +1202,7 @@ double maxiEnv::ar(double input, double attack, double release, long holdtime, i
return output;
}

/* and here's a new adsr. It's not bad, very simple to use*/
/* adsr. It's not bad, very simple to use*/

double maxiEnv::adsr(double input, double attack, double decay, double sustain, double release, long holdtime, int trigger) {

Expand Down
6 changes: 6 additions & 0 deletions maximilianTest.xcodeproj/project.pbxproj
Expand Up @@ -149,6 +149,8 @@
/* Begin PBXProject section */
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
};
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "maximilianTest" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
Expand Down Expand Up @@ -188,6 +190,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD)";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
Expand All @@ -204,13 +207,15 @@
"\"$(SRCROOT)\"",
);
PRODUCT_NAME = rtaudiotest;
SDKROOT = macosx;
};
name = Debug;
};
1DEB923308733DC60010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
INSTALL_PATH = /usr/local/bin;
Expand All @@ -220,6 +225,7 @@
"\"$(SRCROOT)\"",
);
PRODUCT_NAME = rtaudiotest;
SDKROOT = macosx;
};
name = Release;
};
Expand Down
Expand Up @@ -10,29 +10,29 @@
<string>maximilianTest</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>FEC4E512-E134-4CF0-895B-9FCE9B4F273E</key>
<key>9EA75D55FA54A28D61D05E99737654AEBBBF0FB9</key>
<string>ssh://github.com/micknoise/Maximilian.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>maximilianTest.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>FEC4E512-E134-4CF0-895B-9FCE9B4F273E</key>
<key>9EA75D55FA54A28D61D05E99737654AEBBBF0FB9</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/micknoise/Maximilian.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>FEC4E512-E134-4CF0-895B-9FCE9B4F273E</string>
<string>9EA75D55FA54A28D61D05E99737654AEBBBF0FB9</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>FEC4E512-E134-4CF0-895B-9FCE9B4F273E</string>
<string>9EA75D55FA54A28D61D05E99737654AEBBBF0FB9</string>
<key>IDESourceControlWCCName</key>
<string>Maximilian</string>
</dict>
Expand Down
Binary file not shown.
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0600"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8DD76F620486A84900D96B5E"
BuildableName = "rtaudiotest"
BlueprintName = "maximilianTest"
ReferencedContainer = "container:maximilianTest.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8DD76F620486A84900D96B5E"
BuildableName = "rtaudiotest"
BlueprintName = "maximilianTest"
ReferencedContainer = "container:maximilianTest.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8DD76F620486A84900D96B5E"
BuildableName = "rtaudiotest"
BlueprintName = "maximilianTest"
ReferencedContainer = "container:maximilianTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8DD76F620486A84900D96B5E"
BuildableName = "rtaudiotest"
BlueprintName = "maximilianTest"
ReferencedContainer = "container:maximilianTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>maximilianTest.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>8DD76F620486A84900D96B5E</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Expand Up @@ -10,29 +10,29 @@
<string>maximilianTest_10.8</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>FEC4E512-E134-4CF0-895B-9FCE9B4F273E</key>
<key>9EA75D55FA54A28D61D05E99737654AEBBBF0FB9</key>
<string>ssh://github.com/micknoise/Maximilian.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>maximilianTest_10.8.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>FEC4E512-E134-4CF0-895B-9FCE9B4F273E</key>
<key>9EA75D55FA54A28D61D05E99737654AEBBBF0FB9</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/micknoise/Maximilian.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>FEC4E512-E134-4CF0-895B-9FCE9B4F273E</string>
<string>9EA75D55FA54A28D61D05E99737654AEBBBF0FB9</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>FEC4E512-E134-4CF0-895B-9FCE9B4F273E</string>
<string>9EA75D55FA54A28D61D05E99737654AEBBBF0FB9</string>
<key>IDESourceControlWCCName</key>
<string>Maximilian</string>
</dict>
Expand Down
Binary file not shown.

0 comments on commit bbe04a0

Please sign in to comment.