Skip to content

Commit

Permalink
OpenP5Machine: added sound
Browse files Browse the repository at this point in the history
  • Loading branch information
galsasson committed Dec 28, 2013
1 parent 6f2263d commit 0fad331
Show file tree
Hide file tree
Showing 5 changed files with 569 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ void CloudsVisualSystemOpenP5Machine::selfSetup(){
color2HSB.g = 130;
color2HSB.b = 90;

// sound
synth.setOutputGen(buildSynth());

ofAddListener(GetCloudsAudioEvents()->diageticAudioRequested, this, &CloudsVisualSystemOpenP5Machine::audioRequested);
}


Expand Down Expand Up @@ -224,4 +228,24 @@ void CloudsVisualSystemOpenP5Machine::selfMousePressed(int x, int y, int button)
void CloudsVisualSystemOpenP5Machine::selfMouseReleased(int x, int y, int button){
// cam.enableMouseInput();

}
}

Generator CloudsVisualSystemOpenP5Machine::buildSynth()
{
string strDir = GetCloudsDataPath()+"sound/textures/";
ofDirectory sdir(strDir);
string strAbsPath = sdir.getAbsolutePath() + "/Machine.aif";

SampleTable sample = loadAudioFile(strAbsPath);

Generator sampleGen = BufferPlayer().setBuffer(sample).trigger(1).loop(1);

return sampleGen;
}

void CloudsVisualSystemOpenP5Machine::audioRequested(ofAudioEventArgs& args)
{
synth.fillBufferOfFloats(args.buffer, args.bufferSize, args.nChannels);
}


Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

#pragma once

#include "CloudsGlobal.h"
#include "CloudsVisualSystem.h"
#include "ofxTonic.h"
#include "CloudsAudioEvents.h"

using namespace Tonic;

//TODO: rename this to your own visual system
class CloudsVisualSystemOpenP5Machine : public CloudsVisualSystem {
Expand Down Expand Up @@ -121,6 +126,9 @@ class CloudsVisualSystemOpenP5Machine : public CloudsVisualSystem {
float shiftY;
float shiftZ;


// Sound
ofxTonicSynth synth;
Generator buildSynth();
void audioRequested(ofAudioEventArgs& args);

};
Loading

0 comments on commit 0fad331

Please sign in to comment.