Exemplo n.º 1
0
	///----------------------------------------------------------------------------//
	///--------------------- ENTER SECTION ----------------------------------------//
	///----------------------------------------------------------------------------//
	void onPreEnter(Scene::Enum from) override {
        // Prepare game
        if (from == Scene::CountDown) {
            game->datas->faderHelper.start(Fading::In, 0.5);
        }

		ADSR(haveToAddLeavesInGrid)->attackTiming = game->datas->timing.haveToAddLeavesInGrid;
        ADSR(replaceGrid)->attackTiming = game->datas->timing.replaceGrid;

		fillTheBlank(newLeaves);

		//we need to create the whole grid (start game and level change)
		if ((int)newLeaves.size() == theHeriswapGridSystem.GridSize*theHeriswapGridSystem.GridSize) {
	     	LOGI("create '" << newLeaves.size() << "' cells");
			for(unsigned int i=0; i<newLeaves.size(); i++) {
	            if (newLeaves[i].entity == 0)
				    newLeaves[i].entity = createCell(newLeaves[i], true);
			}
	        ADSR(haveToAddLeavesInGrid)->active = true;
			removeEntitiesInCombination();
		} else {
		    ADSR(haveToAddLeavesInGrid)->active = false;
	    }
	    ADSR(haveToAddLeavesInGrid)->activationTime = 0;

		ADSR(replaceGrid)->activationTime = 0;
		ADSR(replaceGrid)->active = false;
	}
Exemplo n.º 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);
}
Exemplo n.º 3
0
int main(int argc, char** argv) {

  fftw_real out[N], in[N];
  rfftw_plan plan_backward;
  buffer_t buffer[N];

  int i, time = 0;

  song_t* head;
  song_t* next;

  print_prologoue(N, SR);

  next = head = read_song("song.txt");
  dump_song(head);
  plan_backward = rfftw_create_plan(N, FFTW_COMPLEX_TO_REAL, FFTW_ESTIMATE);

  while ( next ) {

	// clear out
	for ( i = 0; i < N; i++ )
		out[i] =  0.0f;

	i = 0;
	while (i < ACCORD_SIZE && next->accord[i] != 0)
	  play_note(next->accord[i++], ADSR(time, next->duration), out);

	rfftw_one(plan_backward, out, in);

	for ( i = 0; i < N; i++ )
	  buffer[i] = limit_output(in[i]);;

  	write(1, buffer, N* sizeof(buffer_t));

	time ++;
	if ( time == next->duration ) {
	  // play next note

	  next = next->next;
	  time = 0;

	  // loop:
	  if (next == NULL) next = head;
	}
  }

  rfftw_destroy_plan(plan_backward);
  free_song(head);
  print_epilogue();
  return 0;
}
Exemplo n.º 4
0
double Instrument::ADSR(double frequency, double time, double duration) const // time in seconds
{
	if (decayTime_ == 0 && sustainLevel_ == 0)
	{
		if (time > attackTime_)
			return getReleaseVolume(1.0, time - attackTime_);
		return getAttackVolume(time);
	}
	if (time > duration)
		return getReleaseVolume(ADSR(frequency, duration, duration), time - duration);
	if (time <= attackTime_)
		return getAttackVolume(time);
	if (time <= attackTime_ + decayTime_)
		return getDecayVolume(time - attackTime_);
	return sustainLevel_;
}
Exemplo n.º 5
0
double Instrument::getWaveValue(double frequency, // frequency contains 2pi/SAMPLE_RATE
				double phase,
				double volume,
				double time, // time in seconds/SAMPLE_RATE; 
				double duration) const  // duration in seconds
{
	double timeInSeconds = time / static_cast<double>(SAMPLE_RATE);
	double waveValue = 0;
	for (auto harmonic : harmonics_.harmonics)
	{
		if (harmonic.first * frequency * SAMPLE_RATE / TWO_PI <= MAX_FREQUENCY)
		waveValue += (harmonic.second * sin(
		     	      harmonic.first * frequency * time +
		     	      phase));
	}
	waveValue /= harmonics_.normalizeIndex;
	return ADSR(frequency, timeInSeconds, duration) * volume * waveValue;
}
Exemplo n.º 6
0
void test_waveshaper() {
	Sine vox;					// declare oscillator
	ADSR env = ADSR(5, 0.5, 0.5, 0.5, 0.5); 

#ifndef USE_STATIC_TABLE
	VWaveShaper vox2(vox, NULL, linearWaveShaperFxn);
#else
	VWaveShaper vox2(vox, NULL, linearWaveShaperFxn, 1000);  //Using static table
#endif
	vox.set_frequency(200);			// set the carrier's frequency
	vox.set_scale(env);					// set the carrier's envelop	

	logMsg("CSL playing waveshaper...");

	env.trigger();
    run_test(vox2);

	logMsg("CSL done.");
}
Exemplo n.º 7
0
	static Entity createCell(Feuille& f, bool assignGridPos) {
		Entity e = theEntityManager.CreateEntityFromTemplate("spawn/cell");
		ADD_COMPONENT(e, HeriswapGrid);
	    ADD_COMPONENT(e, Twitch);

		TRANSFORM(e)->position = HeriswapGame::GridCoordsToPosition(f.X, f.Y, theHeriswapGridSystem.GridSize);
		TRANSFORM(e)->z = DL_Cell + Random::Float(0.f, 1.f) * 0.001f;
		RenderingComponent* rc = RENDERING(e);
		rc->show = true;

		TRANSFORM(e)->size = glm::vec2(0.f);
		ADSR(e)->idleValue = HeriswapGame::CellSize(theHeriswapGridSystem.GridSize, f.type).x * HeriswapGame::CellContentScale();
		HERISWAPGRID(e)->type = f.type;
		if (assignGridPos) {
			HERISWAPGRID(e)->i = f.X;
			HERISWAPGRID(e)->j = f.Y;
		}
		rc->texture = theRenderingSystem.loadTextureFile(HeriswapGame::cellTypeToTextureNameAndRotation(f.type, &TRANSFORM(e)->rotation));
		return e;
	}
Exemplo n.º 8
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;
    
}
Exemplo n.º 9
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);
    
}
Exemplo n.º 10
0
void myFM::genFM(double fc)
{
	MONO_PCM pcm;
	int A, D, R, gate, duration;
	//    double *ac, fc, *am, ratio, gain, S;
	double S, ac, am, num, fm;

	pcm.fs = 44100; /* 標本化周波数 */
	pcm.bits = 16; /* 量子化精度 */
	pcm.length = OUTPUT_FRAMES; /* 音データの長さ */
	//pcm.s = (double*)calloc(pcm.length, sizeof(double)); /* 音データ */

	//ac = (double*)calloc(pcm.length, sizeof(double));
	//am = (double*)calloc(pcm.length, sizeof(double));

#if 0
	/* キャリア振幅 */
	gate = pcm.fs * 4;
	duration = pcm.fs * 4;
	A = 0;
	D = pcm.fs * 4;
	S = 0.0;
	R = pcm.fs * 4;
	ADSR(ac, A, D, S, R, gate, duration);

	fc = 440.0; /* キャリア周波数 */

	/* モジュレータ振幅 */
	gate = pcm.fs * 4;
	duration = pcm.fs * 4;
	A = 0;
	D = pcm.fs * 2;
	S = 0.0;
	R = pcm.fs * 2;
	ADSR(am, A, D, S, R, gate, duration);

	ratio = 3.5;
	fm = fc * ratio; /* モジュレータ周波数 */
#endif

	A = 0;
	D = pcm.fs * 4;
	S = 0.0;
	R = pcm.fs * 4;
	gate = pcm.fs * 4;
	duration = pcm.fs * 4;
	ac = ADSR(A, D, S, R, gate, duration);

	gate = pcm.fs * 4;
	duration = pcm.fs * 4;
	A = 0;
	D = pcm.fs * 8;
	S = 0.0;
	R = pcm.fs * 2;
	am = ADSR(A, D, S, R, gate, duration);

	fm = fc * 3.5;

	/* FM音源 */
	//    for (n = 0; n < pcm.length; n++)
	for (int n = 0; n < OUTPUT_FRAMES; n++)
	{
		num = ac * sin(2.0 * M_PI * fc * keyon / pcm.fs + am * sin(2.0 * M_PI * fm * keyon / pcm.fs));
		//num = sin(2.0 * M_PI * fc * keyon / pcm.fs * sin(2.0 * M_PI * fm * keyon / pcm.fs));
		//num = sin(2.0 * M_PI * fc * keyon / pcm.fs);
		outputBuffer[n] = num;

		//ログを出力
		//if (keyon % 1000 == 0) {
		//	LOGI("buf:%f", num);
		//  LOGI("keyon:%d", keyon);
		//}

		keyon++;
	}

	//LOGI("num: %f", num);

	if (num == 0.0) keyon = 0;

	//free(pcm.s);
	//free(ac);
	//free(am);
}