当前位置: 首页>>代码示例>>C++>>正文


C++ Sine类代码示例

本文整理汇总了C++中Sine的典型用法代码示例。如果您正苦于以下问题:C++ Sine类的具体用法?C++ Sine怎么用?C++ Sine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Sine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

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;
}
开发者ID:eriser,项目名称:CSL,代码行数:31,代码来源:Test_RTP_Server.cpp

示例2: test_waveshaper2

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.");
}
开发者ID:eriser,项目名称:CSL,代码行数:26,代码来源:Test_all.cpp

示例3: main

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);
}
开发者ID:juanmeleiro,项目名称:btpd,代码行数:57,代码来源:motor.cpp

示例4: test_frequency_envelope

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.");
}
开发者ID:eriser,项目名称:CSL,代码行数:9,代码来源:Test_all.cpp

示例5: test_gliss_sin

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.");
}
开发者ID:eriser,项目名称:CSL,代码行数:10,代码来源:Test_all.cpp

示例6: evaluate_tree

// 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;
    }
}
开发者ID:p-patil,项目名称:Domain-Coloring,代码行数:58,代码来源:parser.cpp

示例7: test_notch

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.");
}
开发者ID:eriser,项目名称:CSL,代码行数:13,代码来源:Test_all.cpp

示例8: test_envelopes

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.");
}
开发者ID:eriser,项目名称:CSL,代码行数:14,代码来源:Test_all.cpp

示例9: test_filter_sweep

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.");
}
开发者ID:eriser,项目名称:CSL,代码行数:16,代码来源:Test_all.cpp

示例10: test_formant

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.");
}
开发者ID:eriser,项目名称:CSL,代码行数:18,代码来源:Test_all.cpp

示例11: test_waveshaper

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.");
}
开发者ID:eriser,项目名称:CSL,代码行数:19,代码来源:Test_all.cpp

示例12: strcat

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;
}
开发者ID:MusashiNakajima,项目名称:System_cpp_Mac,代码行数:43,代码来源:ModuleController.cpp

示例13: play

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;
}
开发者ID:ryo-okabayashi,项目名称:pa,代码行数:44,代码来源:pa.cpp

示例14: audioCB

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);
	}
}
开发者ID:AlloSphere-Research-Group,项目名称:Gamma,代码行数:11,代码来源:modFreqFeedback.cpp

示例15: audioCB

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;
	}
}
开发者ID:AlloSphere-Research-Group,项目名称:Gamma,代码行数:11,代码来源:modAmp.cpp


注:本文中的Sine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。