Skip to content

Commit

Permalink
Wave and plugins using it now has faster arrays...
Browse files Browse the repository at this point in the history
  • Loading branch information
olekristensen committed Mar 18, 2011
1 parent d77414a commit d8cebda
Show file tree
Hide file tree
Showing 10 changed files with 1,259 additions and 213 deletions.
4 changes: 2 additions & 2 deletions Plugins/Beach/Beach.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ -(void) update:(NSDictionary *)drawingInformation{

[voices replaceObjectAtIndex:iVoice withObject:newVoice];

NSMutableArray * newWave = [newVoice objectForKey:@"waveLine"];
WaveArray * newWave = [newVoice objectForKey:@"waveLine"];

if ([newWave count] > 0) {
waveForm[iVoice]->clear();
for (int i=0; i < [newWave count]; i++) {
waveForm[iVoice]->push_back([[newWave objectAtIndex:i] floatValue]);
waveForm[iVoice]->push_back([newWave getFloatAtIndex:i]);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Box/Box.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ -(void) draw:(NSDictionary *)drawingInformation{
}

-(float) aspect{
return [[[GetPlugin(Keystoner) getSurface:@"Wall" viewNumber:0 projectorNumber:0] aspect] floatValue];
return [[[GetPlugin(Keystoner) getSurface:@"Wall" viewNumber:0 projectorNumber:1] aspect] floatValue];
}


Expand Down
11 changes: 7 additions & 4 deletions Plugins/Ocean/Ocean.mm
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ -(void) update:(NSDictionary *)drawingInformation{
}

for (int i=0; i<springs.size(); i++) {

// springs[i]->

springs[i]->setStrength(PropF(@"stiffness"));
}

Expand Down Expand Up @@ -280,17 +283,17 @@ -(void) update:(NSDictionary *)drawingInformation{

if (PropB(waveOnStr)) {

NSMutableArray * newWave = [[voices objectAtIndex:iVoice] objectForKey:@"waveLine"];
WaveArray * newWave = [[voices objectAtIndex:iVoice] objectForKey:@"waveLine"];

int echoWaveIndex = (int)fmax( 0, ([echoVoices count]-1)-roundf((PropF(@"echoDelay")*kEchoLength*iVoice/NUM_VOICES)));
NSMutableArray * echoWave = [[echoVoices objectAtIndex:echoWaveIndex] objectForKey:@"waveLine"];
WaveArray * echoWave = [[echoVoices objectAtIndex:echoWaveIndex] objectForKey:@"waveLine"];

if ([newWave count] > 0) {
waveForm[iVoice]->clear();
for (int i=0; i < [newWave count]; i++) {
waveForm[iVoice]->push_back(
[[newWave objectAtIndex:i] floatValue] * (1.0-PropF(@"echo")) +
[[echoWave objectAtIndex:i] floatValue] * PropF(@"echo")
[newWave getFloatAtIndex:i] * (1.0-PropF(@"echo")) +
[echoWave getFloatAtIndex:i] * PropF(@"echo")
);
}

Expand Down
4 changes: 1 addition & 3 deletions Plugins/Umbilical/Umbilical.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
MSA::Interpolator1D * distortion[NUM_VOICES+1];
MSA::Interpolator1D * waveForm[NUM_VOICES+1];



vector<float> offsets[NUM_VOICES +1];

NSMutableArray * wave;
WaveArray * wave;

NSMutableArray * voices;
NSMutableArray * waveForms;
Expand Down
23 changes: 11 additions & 12 deletions Plugins/Umbilical/Umbilical.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ -(void) initPlugin{

for(int iBand=0;iBand<NUM_BANDS;iBand++){

NSMutableArray * aBand = [NSMutableArray arrayWithCapacity:MAX_RESOLUTION];
WaveArray * aBand = [[WaveArray alloc]init];

for (int iAmplitude=0; iAmplitude<MAX_RESOLUTION; iAmplitude++) {
[aBand addObject:[NSNumber numberWithDouble:0.0]];
[aBand addFloat:0.0];
}

[waveForms addObject:aBand];
Expand Down Expand Up @@ -113,7 +113,6 @@ -(void) setup{

endPos = ofxPoint2f([self aspect]*0.5,0.01);


physics = new ofxPhysics2d(ofPoint(0,0.0005));
physics->checkBounds(NO);
physics->enableCollisions(true);
Expand Down Expand Up @@ -348,7 +347,7 @@ -(void) update:(NSDictionary *)drawingInformation{

for(int iBand=0;iBand<NUM_BANDS;iBand++){

NSMutableArray * aBand = [NSMutableArray arrayWithCapacity:voiceLength];
WaveArray * aBand = [[WaveArray alloc]init];

for (int iAmplitude=0; iAmplitude<voiceLength; iAmplitude++) {

Expand All @@ -361,12 +360,12 @@ -(void) update:(NSDictionary *)drawingInformation{
double postDriftBalance = 1.0-powf((1.0-sqrt(fabs(postDrift))), 2.0);

if([[newWaveForms objectAtIndex:iBand] count] == [[oldWaveForms objectAtIndex:iBand] count]){
[aBand addObject:[NSNumber numberWithFloat:
((1.0-postDriftBalance)*[[[newWaveForms objectAtIndex:iBand] objectAtIndex:iAmplitude] floatValue])+
((postDriftBalance)*[[[oldWaveForms objectAtIndex:iBand] objectAtIndex:iFrom] floatValue])
]];
[aBand addFloat:
((1.0-postDriftBalance)*[[newWaveForms objectAtIndex:iBand] getFloatAtIndex:iAmplitude])+
((postDriftBalance)*[[oldWaveForms objectAtIndex:iBand] getFloatAtIndex:iFrom])
];
} else {
[aBand addObject:[NSNumber numberWithFloat:[[[newWaveForms objectAtIndex:iBand] objectAtIndex:iAmplitude] floatValue]]];
[aBand addFloat:[[newWaveForms objectAtIndex:iBand] getFloatAtIndex:iAmplitude]];
}


Expand Down Expand Up @@ -395,11 +394,11 @@ -(void) update:(NSDictionary *)drawingInformation{

if ([wave count] > 0) {
if(fabs(direction) > 0) {
distortion[iVoice]->push_back([[wave objectAtIndex:0] floatValue]);
distortion[iVoice]->push_back([wave getFloatAtIndex:0]);
}
waveForm[iVoice]->clear();
for (int i=0; i < [wave count]; i++) {
waveForm[iVoice]->push_back([[wave objectAtIndex:i] floatValue]);
waveForm[iVoice]->push_back([wave getFloatAtIndex:i]);
}
}

Expand Down Expand Up @@ -548,7 +547,7 @@ -(void) drawWave:(int)iVoice from:(ofxPoint2f)begin to:(ofxPoint2f)end{
float x = 1.0/(endSegment-startSegment)*(i-startSegment);
if (i < segments) {
float f = [self falloff:(float)x/PropF(@"falloffStart")] * [self falloff:(1-x)/PropF(@"falloffEnd")];
float val = [[[waveForms objectAtIndex:band] objectAtIndex:i] floatValue]*amplitude*f;
float val = [[waveForms objectAtIndex:band] getFloatAtIndex:i]*amplitude*f;

// ofxPoint2f p = ofxPoint2f(offsets[iVoice][i]+((distortion[iVoice]->getData()[i]*weighLiveOrBuffer)+(waveForm[iVoice]->sampleAt(x*length)*(1.0-weighLiveOrBuffer)))*amplitude*f, 0);
ofxPoint2f p = ofxPoint2f(val, 0);
Expand Down
18 changes: 9 additions & 9 deletions Plugins/Voice/Voice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ -(void) setup{

for(int iBand=0;iBand<NUM_BANDS;iBand++){

NSMutableArray * aBand = [NSMutableArray arrayWithCapacity:MAX_RESOLUTION];
WaveArray * aBand = [[WaveArray alloc]init];

for (int iAmplitude=0; iAmplitude<MAX_RESOLUTION; iAmplitude++) {
[aBand addObject:[NSNumber numberWithDouble:0.0]];
[aBand addFloat:0.0];
}

[waveForms addObject:aBand];
Expand Down Expand Up @@ -101,7 +101,7 @@ -(void) update:(NSDictionary *)drawingInformation{

for(int iBand=0;iBand<NUM_BANDS;iBand++){

NSMutableArray * aBand = [NSMutableArray arrayWithCapacity:voiceLength];
WaveArray * aBand = [[WaveArray alloc]init];

for (int iAmplitude=0; iAmplitude<voiceLength; iAmplitude++) {

Expand All @@ -114,12 +114,12 @@ -(void) update:(NSDictionary *)drawingInformation{
double postDriftBalance = 1.0-powf((1.0-sqrt(fabs(postDrift))), 2.0);

if([[newWaveForms objectAtIndex:iBand] count] == [[oldWaveForms objectAtIndex:iBand] count]){
[aBand addObject:[NSNumber numberWithFloat:
((1.0-postDriftBalance)*[[[newWaveForms objectAtIndex:iBand] objectAtIndex:iAmplitude] floatValue])+
((postDriftBalance)*[[[oldWaveForms objectAtIndex:iBand] objectAtIndex:iFrom] floatValue])
]];
[aBand addFloat:
((1.0-postDriftBalance)*[[newWaveForms objectAtIndex:iBand] getFloatAtIndex:iAmplitude])+
((postDriftBalance)*[[oldWaveForms objectAtIndex:iBand] getFloatAtIndex:iFrom])
];
} else {
[aBand addObject:[NSNumber numberWithFloat:[[[newWaveForms objectAtIndex:iBand] objectAtIndex:iAmplitude] floatValue]]];
[aBand addFloat:[[newWaveForms objectAtIndex:iBand] getFloatAtIndex:iAmplitude]];
}


Expand Down Expand Up @@ -159,7 +159,7 @@ -(void) draw:(NSDictionary *)drawingInformation{

float x = ([self aspect]*i)/resolution;
// float f = [self falloff:(float)x/PropF(@"falloffStart")] * [self falloff:(1-x)/PropF(@"falloffEnd")];
ofxPoint2f p = ofxPoint2f(x, [[[waveForms objectAtIndex:iBand] objectAtIndex:i] floatValue]*amplitude);
ofxPoint2f p = ofxPoint2f(x, [[waveForms objectAtIndex:iBand] getFloatAtIndex:i]*amplitude);
p.y *= 1*(1-PropF(@"falloffStrength")) + PropF(@"falloffStrength")*[self falloff:x*1.0/PropF(@"falloff")]*[self falloff:([self aspect]-x)*1.0/PropF(@"falloff")];
ofxVec2f v = p - lastPoint;
ofxVec2f h = ofxVec2f(-v.y,v.x);
Expand Down
14 changes: 14 additions & 0 deletions Plugins/Wave/Wave.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,17 @@


@end

@interface WaveArray : NSObject {

float array[MAX_RESOLUTION];
int count;
}

-(int) count;
-(void) addFloat:(float)floatValue;
-(float) getFloatAtIndex:(int)index;
-(void) setFloat:(float)floatValue atIndex:(int)index;
-(void) clear;

@end
Loading

0 comments on commit d8cebda

Please sign in to comment.