Beispiel #1
0
//--------------------------------------------------------------
void ofApp::setup(){
	//makes audio go out of openframeworks
	ofSoundStreamSetup(2,0,this,44100,256,4);

	//these will be the nods and we name them.
	ControlGenerator midiNote= 
		synth.addParameter("midiNumber");
	//convert a midi note to a frequincy
	ControlGenerator noteFreq = ControlMidiToFreq().input(midiNote);
	
	Generator tone = SawtoothWave().freq(noteFreq);
	//create a tone
	tone= LPF12().input(tone).Q(2).cutoff((noteFreq*2) +SineWave().freq(3) *0.5* noteFreq);

	//trigger
	ControlGenerator envelopeTrigger = synth.addParameter("trigger");
	Generator toneWithEnvelope =  tone * ADSR().attack(0.01).decay(1.5).sustain(0).release(0).trigger(envelopeTrigger).legato(true);

	Generator toneWithDelay= StereoDelay(0.5,.7).input(toneWithEnvelope).wetLevel(0.1).feedback(0.2);
	synth.setOutputGen(toneWithDelay);

//	arduino bit
	ard.connect("COM4", 57600);
	ofAddListener(ard.EInitialized, this, &ofApp::setupArd);
	
}
Beispiel #2
0
void lineOsc::setup(int _gridResolutionX, int _gridResolutionY, int _size, ofPoint _center) {
    gridResolutionX = _gridResolutionX;
    gridResolutionY = _gridResolutionY;
    size = _size;
    center = _center;
    
    vector<ofColor> palette;
    palette.push_back(ofColor(156, 205, 201));
    palette.push_back(ofColor(248, 177, 113));
    palette.push_back(ofColor(233, 158, 137));
    palette.push_back(ofColor(214, 115, 109));
    palette.push_back(ofColor(243, 220, 189));
    palette.push_back(ofColor(192, 49, 55));
    
    int xSpacing = size / gridResolutionX;
    int ySpacing = size / gridResolutionY;
    
    for(int x = 0; x <= gridResolutionX; x++) {
        lineObj lo;
        
        lo.start.set(center.x - size / 2, x * xSpacing + (center.x - size / 2));
        lo.end.set(center.x + size / 2, x * xSpacing + (center.x - size / 2));
        lo.position = lo.start;
        
        lo.fillColor.set(palette[(int) ofRandom(palette.size())]);
        lo.frequency = ofRandom(MIN_FREQUENCY, MAX_FREQUENCY) + ofRandom(200);
        lo.playing = false;
        lo.playCounter = PLAY_DURATION;
        
        lineObjs.push_back(lo);
    }
    for(int y = 0; y <= gridResolutionY; y++) {
        lineObj lo;
        
        lo.start.set(y * ySpacing + (center.y - size / 2) + 0.5, center.y - size / 2);
        lo.end.set(y * ySpacing + (center.y - size / 2) + 0.5, center.y + size / 2);
        lo.position = lo.start;
        
        lo.fillColor.set(palette[(int) ofRandom(palette.size())]);
        lo.frequency = ofRandom(MIN_FREQUENCY, MAX_FREQUENCY);
        lo.playing = false;
        lo.playCounter = PLAY_DURATION;
        
        lineObjs.push_back(lo);
    }
    
    ControlGenerator midiNote = synth.addParameter("midiNumber");
    ControlGenerator noteFreq =  ControlMidiToFreq().input(midiNote);
    Generator tone = SawtoothWave().freq( noteFreq );
    tone = LPF12().input(tone).Q(10).cutoff(noteFreq * 2);
    ControlGenerator envelopeTrigger = synth.addParameter("trigger");
    Generator toneWithEnvelope = 0.05 * tone * ADSR().attack(0.02).decay(0.2).sustain(0).release(0).trigger(envelopeTrigger);//.legato(true);
    
    synth.setOutputGen( toneWithEnvelope );
    
    stringColor.set(150, 150, 150);
}
//--------------------------------------------------------------
void AudioTonic::setup()
{
    volume	= 0.0f;
//	volume	= 0.79f;

    //TONIC AUDIO STUFF
    ControlParameter volume = synth.addParameter("volume", -58.f).displayName("Volume (dbFS)").min(-60.f).max(0.f);
    ControlParameter carrierPitch = synth.addParameter("carrierPitch", 20.f).displayName("Carrier Pitch").min(20.f).max(32.f);
    ControlParameter carrierOffset = synth.addParameter("carrierOffset", 1.f).displayName("Carrier Offset").min(0.f).max(8.f);
    ControlParameter modIndex = synth.addParameter("modIndex", 0.25f).displayName("FM Amount").min(0.f).max(10.0f);
    ControlParameter modLfoAmt = synth.addParameter("modLfoAmt", 0.5f).displayName("Mod LFO Amount").min(0.f).max(4.f);
    ControlParameter modLfoSpeed = synth.addParameter("modLfoSpeed", 10.0f).displayName("Mod LFO Speed").min(0.f).max(20.f);
    ControlParameter ampLfoAmt = synth.addParameter("ampLfoAmt", 0.75f).displayName("Amp LFO Amount").min(0.f).max(1.f);
    ControlParameter ampLfoSpeed = synth.addParameter("ampLfoSpeed", 0.15f).displayName("Amp LFO Speed").min(0.f).max(20.f);

    Generator rCarrierFreq = ControlMidiToFreq().input(carrierPitch).smoothed();
    Generator rModFreq     = rCarrierFreq * 4.0f;

    float smoothTime = 0.1;

    osc1 = SineWave()
           .freq( rCarrierFreq
                  + (
                      SineWave().freq( rModFreq ) *
                      rModFreq *
                      (modIndex.smoothed(smoothTime) * (1.0f + SineWave().freq(modLfoSpeed.smoothed(smoothTime)) * modLfoAmt.smoothed(smoothTime) * 0.5f))
                  )
                ) * (1.0f + SineWave().freq(ampLfoSpeed.smoothed(smoothTime)) * ampLfoAmt.smoothed(smoothTime) + 0.25) * ControlDbToLinear().input(volume).smoothed(smoothTime);

    osc2 = SineWave()
           .freq( rCarrierFreq + carrierOffset.smoothed(smoothTime)
                  + (
                      SineWave().freq( rModFreq ) *
                      rModFreq *
                      (modIndex.smoothed(smoothTime) * (1.0f + SineWave().freq(modLfoSpeed.smoothed(smoothTime)) * modLfoAmt.smoothed(smoothTime) * 0.5f))
                  )
                ) * (1.0f + SineWave().freq(ampLfoSpeed.smoothed(smoothTime)) * ampLfoAmt.smoothed(smoothTime) + 0.25) * ControlDbToLinear().input(volume).smoothed(smoothTime);

    synth.setOutputGen(osc1 * osc2);

//   synth.getOutputGen();

//   synth.getParameters();
}
Beispiel #4
0
//--------------------------------------------------------------
void ofApp::setup(){
//    ofSetDataPathRoot("../Resources/");
    
    ofSetFrameRate(60);
    ofBackground(ofColor::fromHsb(0,0,10,255));

    ofEnableSmoothing();
    ofEnableAlphaBlending();
    
    //    myFont.loadFont("Inconsolata.otf", 12);
    // Gui Setting
    vector<string> hnames;
    hnames.push_back("Upper");
    hnames.push_back("Bottom");
    hnames.push_back("Front");
    hnames.push_back("Side");
    
    drawPadding = true;
    float dim = 22;
    ofColor backGuiColor = ofColor(110,100);
    
    // Tempo Control ---------------------------------
    bellTempoChange = 65;
    synthTempoChange = 75;
    bassTempoChange = 85;
    padTempoChange = 95;
    
    // GL Setting ---------------------------------
    // glEnable(GL_DEPTH_TEST);
    yRotate = 0;
    xRotate = 0;
    mouseXmoving = 0;
    mouseYmoving = 0;
    PmouseXmoving = 0;
    PmouseYmoving = 0;
    
    // Class  ---------------------------------
    float first_x1 = 0;
    float second_x1 = 0;
    float third_x1 = 0;
    float fourth_x1 = 0;
    float fifth_x1 = 0;
    float sixth_x1 = 0;
    int xPosition = 0;
    
    bellLinedance = new LineFigure();
    synthLinedance = new LineFigure();
    bassLinedance = new LineFigure();
    padLinedance = new LineFigure();
    
    redrawBell = false;
    redrawSynth = false;
    redrawPad = false;
    redrawBass = false;
    
    sizeIncreaseBell = 20;
    sizeIncreaseSynth = 20;
    sizeIncreasePad = 20;
    sizeIncreaseBass = 20;
    
    alphaTBellcircle = 80;
    alphaTSynthcircle = 80;
    alphaTPadcircle = 80;
    alphaTBasscircle = 80;
    
    xRatio = 4;
    
    tableViewOnOff = false;
    
    cam.setFov( 50 );
    cam.setNearClip( 0.1f );
    cam.setFarClip( 10000.0f );
    cam.setPosition ( ofVec3f( ofGetWidth()/2.0, -ofGetHeight()/2.0, 0 ) );
    
    
    ofSoundStreamSetup(2, 0, this, 44100, 256, 4);
    
    float _volumeSet = 0.5;
    ControlParameter carrierPitch1 = synth1.addParameter("carrierPitch1");
    float amountMod1 = 4;
    ControlGenerator rCarrierFreq1 = ControlMidiToFreq().input(carrierPitch1);
    ControlGenerator rModFreq1 = rCarrierFreq1 * 3.489;
    Generator modulationTone1 = SineWave().freq( rModFreq1 ) * rModFreq1 * amountMod1;
    Generator tone1 = SineWave().freq(rCarrierFreq1 + modulationTone1);
    ControlGenerator envelopTrigger1 = synth1.addParameter("trigger1");
    Generator env1 = ADSR().attack(0.001).decay(0.3).sustain(0).release(0).trigger(envelopTrigger1).legato(true);
    synth1.setOutputGen( tone1 * env1 * _volumeSet );
    
    ControlParameter carrierPitch2 = synth2.addParameter("carrierPitch2");
    float amountMod2 = 1;
    ControlGenerator rCarrierFreq2 = ControlMidiToFreq().input(carrierPitch2);
    ControlGenerator rModFreq2 = rCarrierFreq2 * 3.489;
    Generator modulationTone2 = SineWave().freq( rModFreq2 ) * rModFreq2 * amountMod2;
    Generator tone2 = SineWave().freq(rCarrierFreq2 + modulationTone2);
    ControlGenerator envelopTrigger2 = synth2.addParameter("trigger2");
    Generator env2 = ADSR().attack(0.001).decay(0.1).sustain(0).release(0).trigger(envelopTrigger2).legato(false);
    synth2.setOutputGen( tone2 * env2 * _volumeSet );
    
    ControlParameter carrierPitch3 = synth3.addParameter("carrierPitch3");
    float amountMod3 = 6;
    ControlGenerator rCarrierFreq3 = ControlMidiToFreq().input(carrierPitch3);
    ControlGenerator rModFreq3 = rCarrierFreq3 * 3.489;
    Generator modulationTone3 = SineWave().freq( rModFreq3 ) * rModFreq3 * amountMod3;
    Generator tone3 = SineWave().freq(rCarrierFreq3 + modulationTone3);
    ControlGenerator envelopTrigger3 = synth3.addParameter("trigger3");
    Generator env3 = ADSR().attack(0.1).decay(0.2).sustain(0).release(0).trigger(envelopTrigger3).legato(false);
    synth3.setOutputGen( tone3 * env3 * _volumeSet );

    ControlParameter carrierPitch4 = synth4.addParameter("carrierPitch4");
    float amountMod4 = 3;
    ControlGenerator rCarrierFreq4 = ControlMidiToFreq().input(carrierPitch4);
    ControlGenerator rModFreq4 = rCarrierFreq4 * 3.489;
    Generator modulationTone4 = SineWave().freq( rModFreq4 ) * rModFreq4 * amountMod4;
    Generator tone4 = SineWave().freq(rCarrierFreq4 + modulationTone4);
    ControlGenerator envelopTrigger4 = synth4.addParameter("trigger4");
    Generator env4 = ADSR().attack(0.01).decay(0.1).sustain(0).release(0).trigger(envelopTrigger4).legato(false);
    synth4.setOutputGen( tone4 * env4 * _volumeSet );

//    Reverb reverb = Reverb();
//    ControlValue dry = -4.0;
//    ControlValue wet = -12.0;
//    
//    reverb = Reverb()
//    .preDelayTime(0.01)
//    .inputLPFCutoff(18000)
//    .inputHPFCutoff(20)
//    .decayTime(1.0)
//    .decayLPFCutoff(16000)
//    .decayHPFCutoff(20)
//    .stereoWidth(0.75)
//    .density(0.7)
//    .roomShape(0.7)
//    .roomSize(0.7)
//    .dryLevel(ControlDbToLinear().input(dry))
//    .wetLevel(ControlDbToLinear().input(wet));
    
    synthMain.setOutputGen( ((synth1 + synth2 + synth3 + synth4)) * 1.0 );
    
    fullScreen = false;
    
}
Beispiel #5
0
//--------------------------------------------------------------
void ofApp::setup(){
    
    sliderArea = ofRectangle(0, 0, ofGetWindowWidth() / 2, ofGetWindowHeight());
    
    ///////////////////////////////
    //      Audio Stuff
    ///////////////////////////////
    
    const int NUM_STEPS = 8;
    
    // synth paramters are like instance variables -- they're values you can set later, by
    // cally synth.setParameter()
    ControlGenerator bpm = synth.addParameter("tempo",100).min(50).max(300);
    ControlGenerator transpose = synth.addParameter("transpose", 0).min(-6).max(6);
    
    // ControlMetro generates a "trigger" message at a given bpm. We multiply it by four because we
    // want four 16th notes for every beat
    ControlGenerator metro = ControlMetro().bpm(4 * bpm);
    
    // ControlStepper increments a value every time it's triggered, and then starts at the beginning again
    // Here, we're using it to move forward in the sequence
    ControlGenerator step = ControlStepper().end(NUM_STEPS).trigger(metro);
    
    // ControlSwitcher holds a list of ControlGenerators, and routes whichever one the inputIndex is pointing
    // to to its output.
    ControlSwitcher pitches = ControlSwitcher().inputIndex(step);
    ControlSwitcher cutoffs = ControlSwitcher().inputIndex(step);
    ControlSwitcher glides = ControlSwitcher().inputIndex(step);
    
    // stick a bunch of random values into the pitch and cutoff lists
    for(int i = 0; i < NUM_STEPS; i++){
        ControlGenerator pitchForThisStep = synth.addParameter("step" + to_string(i) + "Pitch", randomFloat(10, 80)).min(10).max(80);
        pitches.addInput(pitchForThisStep);
        
        ControlGenerator cutoff = synth.addParameter("step" + to_string(i) + "Cutoff", 500).min(30).max(1500);
        cutoffs.addInput(cutoff);
        
        ControlGenerator glide = synth.addParameter("step" + to_string(i) + "Glide", 0).min(0).max(0.1);
        glides.addInput(glide);
        
    }
    
    // Define a scale according to steps in a 12-note octave. This is a pentatonic scale. Like using
    // just the black keys on a piano
    vector<float> scale;
    scale.push_back(0);
    scale.push_back(2);
    scale.push_back(3);
    scale.push_back(5);
    scale.push_back(7);
    scale.push_back(10);
    
    // ControlSnapToScale snaps a float value to the nearest scale value, no matter what octave its in
    ControlGenerator midiNote = transpose + ControlSnapToScale().setScale(scale).input(pitches);
    
    ControlGenerator frequencyInHertz = ControlMidiToFreq().input(midiNote);
    
    // now that we've done all that, we have a frequency signal that's changing 4x per beat
    Generator tone = RectWave().freq( frequencyInHertz.smoothed().length(glides) );
    
    // create an amplitude signal with an ADSR envelope, and scale it down a little so it's not scary loud
    Generator amplitude = ADSR(0.01, 0.1, 0,0).trigger(metro) * 0.3;
    
    // create a filter, and feed the cutoff sequence in to it
    LPF24 filter =  LPF24().cutoff(cutoffs).Q(0.1);
    filter.input(tone * amplitude);
    
    // rout the output of the filter to the synth's main output
    synth.setOutputGen( filter );
    
    // build a slider for each parameter
    vector<ControlParameter> synthParameters = synth.getParameters();
    for(int i = 0; i < synthParameters.size(); i++){
        sliders.push_back(ParameterSlider(synthParameters.at(i)));
    }
    
    
    auto _devices = soundStream.getDeviceList();
    ofSoundStreamSettings _settings;
    if (!_devices.empty()) {
        _settings.setOutDevice(_devices[1]);
    }
    _settings.setOutListener(this);
    _settings.bufferSize = 512;
    _settings.sampleRate = 44100;
    _settings.numInputChannels = 0;
    _settings.numOutputChannels = 2;
    soundStream.setup(_settings);
    
}