Ejemplo n.º 1
0
int main (int argc, const char * argv[]) {
	READ_CSL_OPTS;					// read the standard CSL options

	logMsg("Running CSL4 RTP Server test");
	
	Sine sineOsc (660.0, 0.2);			// create 2 sine oscillators
	Sine sineOsc2(440.0, 0.2);
	sineOsc.setOffset(sineOsc2);		// add 'em
	
	PAIO * theIO = new PAIO;			// PortAudio IO object

	RtpSender rtpSend;

	theIO->open();
	theIO->start();

	rtpSend.setInput(sineOsc);		// Plug in the rtpSender below the adder object
	rtpSend.addRtpDestination("127.0.0.1", 46000);
	
	theIO->setRoot(rtpSend);			// plug in the whole graph
	
	sleepSec(30);					// sleep a bit

	rtpSend.BYEDestroy(RTPTime(10,0),"Test server stopped normally",0);

	theIO->stop();
	theIO->close();
	
	logMsg("done!");
	return 0;
}
Ejemplo n.º 2
0
void test_waveshaper2() {
	Sine vox;					// declare oscillator
	ADSR env = ADSR(5, 0.5, 0.5, 0.5, 0.5); 
	int chebyHarmonics[NUMHARMONICS] = {1, 2, 4,  MAXHARMONIC};		 //What harmonic content we want
	sample chebyWeights[NUMHARMONICS] = {1, 0.3, 0.17, 1/10};   //Weight of each harmonic
	sample chebyCoefficients[MAXHARMONIC + 1];	         //Array to store cheby coefficients
	Polynomial f = {MAXHARMONIC, chebyCoefficients};     //Descriptor for cheby coefficients

	EvaluateCheby(chebyCoefficients, chebyHarmonics, chebyWeights, NUMHARMONICS, 
		MAXHARMONIC);  //Produce the summation of Cheby polynomials corresponding to harmonics

#ifndef USE_STATIC_WAVETABLE
	VWaveShaper vox2(vox, (void *)&f, simpleWaveShaperFxn);
#else
	VWaveShaper vox2(vox, (void *)&f, simpleWaveShaperFxn, 1000); //use static table
#endif
	vox.set_frequency(200);					// set the carrier's frequency
	vox.set_scale(env);					// set the carrier's frequency	

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

	env.trigger();

    run_test(vox2);
	logMsg("CSL done.");
}
Ejemplo n.º 3
0
int main()
{
    Sine s;
    Triangle t;
    Square sq;

    vector<double> buf(44100*5);
    
    s.generate(0, 440.0, &buf);
    // t.generate(0, 440.0, &buf);
    // sq.generate(0, 440.0, &buf);

    //   printf("Generated Sine\n");
    //    for (int i = 0; i < 100; i++) printf("%f\n", buf[i]);

    vector<short> bufShort(44100*5);

    transform(buf.begin(), buf.end(), bufShort.begin(), [](double x){
        return static_cast<short>(x * 30000);
    });

//    for (int i = 0; i <= 100; i++) printf("%d\n", bufShort[3000+i]);	

    //    printf("Ready to initialize\n");
    initialize();
    checkError();
    
    ALuint buffer;
    alGenBuffers(1, &buffer);

    alBufferData(buffer, AL_FORMAT_MONO16, bufShort.data(), bufShort.size(), 44100);
    checkError();

    ALuint source;
    alGenSources(1, &source);
    checkError();

    alSourcei(source, AL_BUFFER, buffer);
    checkError();

    //    printf("Before play\n");

    alSourcePlay(source);
    checkError();
    
     //   printf("After play\n");

     //   printf("Before wait\n");

    std::this_thread::sleep_for(std::chrono::milliseconds(3000));

     //   printf("After wait\n");

    checkError();
    exit();
    return(EXIT_SUCCESS);
}
Ejemplo n.º 4
0
void test_frequency_envelope() {
	Sine vox;
	Envelope env(3, 0, 220, 0.7, 280, 1.3, 180, 2.0, 200, 3, 1000);
	vox.set_frequency(env);
	logMsg("playing sin envelope on frequency");
	env.trigger();	
	run_test(vox);
	logMsg("sin envelope on frequency done.");
}
Ejemplo n.º 5
0
void test_gliss_sin() {
	Sine vox;
	LineSegment line(3, 100, 800);
	vox.set_frequency(line);
	StaticVariable vol(0.1);
	MulOp mul(vox, vol);
	logMsg("playing gliss sin...");
	run_test(mul);
	logMsg("gliss sin done.");
}
Ejemplo n.º 6
0
// TODO: Expand to allow for more functions.
// TODO: When parsing e^(f(z)), use Exponential class instead of Power class.
// Evaluates the given expression tree on the given variable value.
ComplexNumber evaluate_tree(const ExpressionTreeNode *root, const ComplexNumber z) {
    if (root->is_op_node()) {
        ExpressionTreeBinaryOp *temp = (ExpressionTreeBinaryOp *) root;
        ComplexNumber left = evaluate_tree(temp->get_left(), z);
        ComplexNumber right = evaluate_tree(temp->get_right(), z);

        // Find the appropriate operator, apply, then return.
        if (temp->get_operator() == PLUS) {
            return left + right;
        } else if (temp->get_operator() == MINUS) {
            return left - right;
        } else if (temp->get_operator() == TIMES) {
            return left * right;
        } else if (temp->get_operator() == DIVIDE) {
            return left / right;
        } else { // temp->get_operator() == EXP
            Power p (right);
            return p.eval(left);
        }
    } else if (root->is_func_node()) {
        ExpressionTreeFunction *temp = (ExpressionTreeFunction *) root;
        ComplexNumber arg = evaluate_tree(temp->get_argument(), z);

        // Find the appropriate function, evaluate, then return.
        if (temp->get_function() == LOG) {
            Logarithm l (1, 0);
            return l.eval(arg);
        } else if (temp->get_function() == SIN) {
            Sine s (1, 1, 0);
            return s.eval(arg);
        } else if (temp->get_function() == COS) {
            Cosine c (1, 1, 0);
            return c.eval(arg);
        } else { // temp->get_function() == TAN
            Tangent t (1, 1, 0);
            return t.eval(arg);
        }
    } else if (root->is_leaf_node()) {
        ExpressionTreeLeaf *temp = (ExpressionTreeLeaf *) root;
        return temp->get_val(); // Return the value itself
    } else if (root->is_const_node()) {
        ExpressionTreeConstant *temp = (ExpressionTreeConstant *) root;

        // Return the corresponding mathematical constant
        if (temp->get_constant() == e) {
            return E;
        } else if (temp->get_constant() == pi) {
            return PI;
        } else { // temp->get_constant() == phi
            return PHI;
        }
    } else { // root->is_var_node()
        return z;
    }
}
Ejemplo n.º 7
0
void test_notch() {
// 	WhiteNoise osc;
	Sine osc(600);
//	LineSegment cutoffSweep(3, 2000.0, 200.0);
	Sine sweep;
	sweep.set_frequency(1);
	sweep.set_scale(550);
	sweep.set_offset(600);
	Notch lpfilter(osc, osc.sample_rate(), sweep, 0.99995F );
	logMsg("playing band-reject (notch) filter...");
	run_test(lpfilter);
	logMsg("notch test done.");
}
Ejemplo n.º 8
0
void test_envelopes() {
	Sine vox;
	LineSegment line(3, 600, 100);
	vox.set_frequency(line);
//	ADSR env(3, 0.1, 0.1, 0.25, 1.5);			// sharp ADSR
//	AR env(3, 1, 1.5);					// gentle AR
	Triangle env(3, 1); 					// 3-sec triangle
	env.dump();
	vox.set_scale(env);
	logMsg("playing gliss sin with envelope...");
	env.trigger();
	run_test(vox);
	logMsg("gliss sin done.");
}
Ejemplo n.º 9
0
void test_filter_sweep() {		
	WhiteNoise wnoise;
	Sine centerSin;
	centerSin.set_frequency(0.5);
	MulOp centerMod(centerSin, 500.0);
	StaticVariable centerOffset(1000);
	AddOp centerSweep(centerMod, 1000.0);
	Sine BWSin;
	BWSin.set_frequency(5);
	MulOp BWMod(BWSin, 50.0);
	AddOp BWSweep(BWMod, 100.0);
	Butter lpfilter(wnoise, wnoise.sample_rate(), Butter::BW_BAND_PASS, centerSweep, BWSweep);
	logMsg("playing filter_sweep...");
	run_test(lpfilter);
	logMsg("filter_sweep done.");
}
Ejemplo n.º 10
0
void test_formant() {
//	WhiteNoise osc;
	Sawtooth osc;
	osc.set_frequency(400);
	Sine sweep;
	sweep.set_frequency(1);
	sweep.set_scale(200);
	sweep.set_offset(600);
//	LineSegment cutoffSweep(3, 2000.0, 200.0);
//	StaticVariable cutoffSweep(2000);
	Formant lpfilter(osc, osc.sample_rate(), sweep, 0.995F );
//	Formant lpfilter(osc, osc.sample_rate(), 600, 0.995F );
//	lpfilter.set_normalize(false);
//	Filter lpfilter(osc);
	logMsg("playing Formant...");
	run_test(lpfilter, 10);
	logMsg("Formant done.");
}
Ejemplo n.º 11
0
void play(double &left, double &right) {
	if (count%(int)(SAMPLE_RATE*1.6)==0) {
		kick_freq.reset();
		env_kick.reset();
	}
	if (count%(int)(SAMPLE_RATE*6.4)==0) {
		env_bass.reset();
		bass_freq.reset();
		bass2_freq.reset();
	}
	left += kick.freq(kick_freq.val()).val() * env_kick.val() * 0.3;
	left += fil_bass.io( bass.freq(bass_freq.val()).val() + bass2.freq(bass2_freq.val()).val() ) * env_bass.val() * 0.3;

	if (count%(int)(SAMPLE_RATE*25.6)==0) {
		for (int i = 0; i < 8; i++) {
			s0_freq[i] = rand()%5000+500;
		}
	}
	if (count%(int)(SAMPLE_RATE*3.2)==0) {
		s0_fade.reset();
	}
	if (count%(int)(SAMPLE_RATE*0.1)==0) {
		if (s0_i > 7) s0_i = 0;
		s0.freq(s0_freq[s0_i++]);
		env_s0.reset();

		if (rand()%4==0) {
			env_s1.reset();
		}
	}
	left += s0.val() * env_s0.val() * s0_fade.val() * 0.1;
	left += s1.val() * env_s1.val() * 0.05;

	for (int n = 0; n < num; n++) {
		if (ars[n].done()) {
			sines[n].freq(rand()%1000+100);
			ars[n].set(0, 1, rand()%1000*0.01, 0, rand()%1000*0.01);
		}
	}
	for (int n = 0; n < num; n++) {
		left += sines[n].val() * ars[n].val() * 0.02;
	}
	right = left;
}
Ejemplo n.º 12
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.");
}
int ModuleController::sine(const char   *path, 
                           const char   *types, 
                           lo_arg       **argv, 
                           int          argc,
                           void         *data, 
                           void         *user_data)
{
    ModuleController *mc = (ModuleController *)user_data;
    
    char p[64] = "/ModuleManager/GN/Sine/Tile";
    strcat(p, &argv[1]->s);

    if (argv[0]->i) {//argv[0] = 1:モジュール生成 0:モジュール解放
        for (std::list<Sine*>::iterator iter = mc->sineList.begin(); iter != mc->sineList.end(); iter++) {
            Sine* sine = (*iter);
            if (strcmp(p,sine->OSCAddr)==0) {
                if (sine->tID == atoi(&argv[1]->s)) {
                    printf("err: Creating Sine\n");
                    return 0;
                }
            }
        }
        
        Sine *sine = new Sine(mc->st, p);
        sine->setTID(atoi(&argv[1]->s));
        sine->mColor = 3;
        sine->sendSetMdtkn();
        mc->sineList.push_back(sine);
        printf("create Sine\n");

    }else {
        for (std::list<Sine*>::iterator iter = mc->sineList.begin(); iter != mc->sineList.end(); iter++) {
            Sine* sine = (*iter);

            if (strcmp(p,sine->OSCAddr)==0) {
                delete sine;
                mc->sineList.remove(sine);
                printf("delete Sine\n");
            }
        }
    }
    return 0;
}
void audioCB(AudioIOData& io){

	while(io()){

		float s = osc();
		io.out(0) = io.out(1) = s * 0.2f;
		
		osc.phaseAdd(s*0.01*mod.hann());
		//osc.freq((s*0.5+0.5)*mod.hann()*800 + 400);
	}
}
Ejemplo n.º 15
0
void audioCB(AudioIOData& io){

	while(io()){

		oscM.freq(modFreq.hann() * 110 + 1);	// change modulator frequency

		float s = oscC() * (oscM() * 0.5 + 0.5) * 0.2;
		
		io.out(0) = io.out(1) = s;
	}
}
void audioCB(AudioIOData& io){

	while(io()){

		oscM.freq(modFreq.hann() * 110 + 1);	// change modulator frequency
		oscC.freq(ff + oscM()*100);				// modulate frequency of carrier

		float s = oscC() * 0.2;
		
		io.out(0) = io.out(1) = s;
	}
}
Ejemplo n.º 17
0
void audioCB(AudioIOData& io){

	while(io()){
	
		if(tmr()){
			env = fund*2 + rnd::uni(10.0);	// set new target value of envelope
		}
		
		osc2.freq(env());					// modulate frequency of 2nd harmonic
		float s = (osc1() + osc2()) * 0.1;

		io.out(0) = io.out(1) = s;
	}
}
void audioCB(AudioIOData& io){

	while(io()){
		
		if(tmr()){
			freq = pow(2, rnd::uniS(1.))*440;
		}
		
		src.freq(freq());
		
		float s = src();
			
		io.out(0) = io.out(1) = s * 0.2f;
	}
}
Ejemplo n.º 19
0
	void onAudio(AudioIOData& io){

		tmr.period(0.25);

		// Set time taken to reach new frequency value
		freq.lag(0.1);

		while(io()){

			if(tmr()){
				// Set new target frequency of one-pole
				freq = pow(2, rnd::uniS(1.))*440;
			}

			// Use smoothed output of one-pole for oscillator frequency
			src.freq(freq());
			
			float s = src();
				
			io.out(0) = io.out(1) = s * 0.2f;
		}
	}
Ejemplo n.º 20
0
	void onAudio(AudioIOData& io){
		while(io()){
			src.freq(220);
			float s = src();

			// Input next sample for analysis
			// When this returns true, then we have a new spectral frame
			if(stft(s)){
			
				// Loop through all the bins
				for(unsigned k=0; k<stft.numBins(); ++k){
					// Here we simply scale the complex sample
					stft.bin(k) *= 0.2;
				}
			}
		
			// Get next resynthesized sample
			s = stft();
		
			io.out(0) = s;
			io.out(1) = s;
		}
	}
Ejemplo n.º 21
0
ComplexNumber Tangent::eval(const ComplexNumber z) const {
    Sine sine (a, b, c);
    Cosine cosine (a, b, c);

    return sine.eval(z) / cosine.eval(z);
}