Esempio n. 1
0
FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int *outchannels) 
{
    FMOD_RESULT result;
    char name[256];
    unsigned int userdata;
    FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance; 

    /* 
        This redundant call just shows using the instance parameter of FMOD_DSP_STATE to 
        call a DSP information function. 
    */
    result = thisdsp->getInfo(name, 0, 0, 0, 0);
    ERRCHECK(result);

    result = thisdsp->getUserData((void **)&userdata);
    ERRCHECK(result);

	if (delayBuffer == NULL)
		delayBuffer = (float*)malloc(bufferSize * sizeof(float));

    /*
        This loop assumes inchannels = outchannels, which it will be if the DSP is created with '0' 
        as the number of channels in FMOD_DSP_DESCRIPTION.  
        Specifying an actual channel count will mean you have to take care of any number of channels coming in,
        but outputting the number of channels specified. Generally it is best to keep the channel 
        count at 0 for maximum compatibility.
    */
    for (unsigned int samp = 0; samp < length; samp++) 
    { 
        /*
            Feel free to unroll this.
        */
        for (int chan = 0; chan < *outchannels; chan++)
        {
            /* 
                This DSP filter just halves the volume! 
                Input is modified, and sent to output.
            */
            //outbuffer[(samp * *outchannels) + chan] = inbuffer[(samp * inchannels) + chan] * 0.2f;
			delayBuffer[((sampleCount * *outchannels) + chan) % bufferSize] = inbuffer[(samp * inchannels) + chan];
			int delayBufferPosition = (((sampleCount - delay) * inchannels) + chan) % bufferSize;
			if (delayBufferPosition >= 0)
			{
				outbuffer[(samp * *outchannels) + chan] = delayBuffer[delayBufferPosition];
			}
			else
			{
				outbuffer[(samp * *outchannels) + chan] = 0;
			}
		}

		sampleCount++;
    } 

    return FMOD_OK; 
} 
Esempio n. 2
0
	//----------------------------------------------------------------------
	FMOD_RESULT F_CALLBACK dspReset( FMOD_DSP_STATE* dsp_state )
	{
		CustomDSPImpl* customDSP = nullptr;

		FMOD::DSP* thisDSP = (FMOD::DSP*)dsp_state->instance;

		thisDSP->getUserData( (void**)&customDSP );		

		return customDSP->reset( dsp_state );
	}
Esempio n. 3
0
	//----------------------------------------------------------------------
	FMOD_RESULT F_CALLBACK dspRead( FMOD_DSP_STATE * dsp_state, float * inBuffer, float* outBuffer, unsigned int length, int inChannels, int outChannels )
	{
		CustomDSPImpl* customDSP = nullptr;
		
		FMOD::DSP* thisDSP = (FMOD::DSP*)dsp_state->instance;

		thisDSP->getUserData( (void**)&customDSP );
		

		return customDSP->read( dsp_state, inBuffer, outBuffer, length, inChannels, outChannels );
	}
Esempio n. 4
0
FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels) 
{ 
    unsigned int count, userdata;
    int count2;
    char name[256]; 
    FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance; 

    /* 
        This redundant call just shows using the instance parameter of FMOD_DSP_STATE and using it to 
        call a DSP information function. 
    */
    thisdsp->getInfo(name, 0, 0, 0, 0);

    thisdsp->getUserData((void **)&userdata);

    /*
        This loop assumes inchannels = outchannels, which it will be if the DSP is created with '0' 
        as the number of channels in FMOD_DSP_DESCRIPTION.  
        Specifying an actual channel count will mean you have to take care of any number of channels coming in,
        but outputting the number of channels specified.  Generally it is best to keep the channel 
        count at 0 for maximum compatibility.
    */
    for (count = 0; count < length; count++) 
    { 
        /*
            Feel free to unroll this.
        */
        for (count2 = 0; count2 < outchannels; count2++)
        {
            /* 
                This DSP filter just halves the volume! 
                Input is modified, and sent to output.
            */
            outbuffer[(count * outchannels) + count2] = inbuffer[(count * inchannels) + count2] * 0.2f;
        }
    } 

    return FMOD_OK; 
} 
Esempio n. 5
0
FMOD_RESULT F_CALLBACK DSPCallback(FMOD_DSP_STATE* dsp_state, 
	f32* inbuffer, f32* outbuffer, u32 length, 
	s32 inchannels, s32* outchannels){

	assert(*outchannels >= 2);

	FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance; 

	void* ud = nullptr;
	cfmod(thisdsp->getUserData(&ud));

	s32 samplerate = 0;
	cfmod(dsp_state->callbacks->getsamplerate(dsp_state, &samplerate));
	f64 inc = 1.0/samplerate;

	auto dud = static_cast<DSPUserdata*>(ud);
	auto& phase = dud->phase;

	for(u32 i = 0; i < length; i++){
		f32 out = 0.f;
		f32 outl = 0.f;
		f32 outr = 0.f;
		
		sched.PlayNotes([&](const NoteTimePair& n){
			constexpr f32 attack = 0.1;
			
			auto pos = (sched.time-n.begin)/n.length;
			f32 env;
			if(pos < attack){
				env = pos/attack;
			}else{
				env = (1.0-pos)/(1.0-attack);
			}

			f32 o = 0.0;
			// o += Wave::sin(n.freq*phase*0.5) * env * 0.2;
			// o += Wave::sin(n.freq*phase*2.0) * env;
			f32 mod = Wave::sin(phase*10.f) * .02f;
			f32 ph = n.freq*phase + mod;
			f32 a = std::min(1.f, std::max(env*env*env * .5f, 0.f)); //Wave::sin(phase*1.f)*.5f + .5f;

			env *= n.volume;
			o += (Wave::sin(ph) * (1-a) + Wave::sqr(ph*2.f) * a) * env;
			// o += Wave::sin((n.freq + Wave::tri(phase*6.f) * .01f)*phase) * env;
			// o += Wave::sin((n.freq + 0.5)*phase) * env;
			out += o/3.0;
		});

		chords.PlayNotes([&](const NoteTimePair& n){
			constexpr f32 attack = 0.005;
			
			auto pos = (chords.time-n.begin)/n.length;
			f32 env;
			if(pos < attack){
				env = pos/attack;
			}else{
				env = (1.0-pos)/(1.0-attack);
			}

			f32 mod = Wave::sin(phase*10.f) * .02f;
			f32 ph = n.freq*phase + mod;
			f32 a = env*env * .3f + .3f + Wave::sin(phase*6.f) * 0.2f;
			a = std::min(1.f, std::max(a, 0.f));

			f32 phaseShift = 0.2f + Wave::sin(phase*3.f) * .2f + .5f; //phase / 6.f;

			outl += (Wave::sin(ph) * (1-a) + Wave::tri(ph) * a) * env * n.volume;
			outr += (Wave::sin(ph + phaseShift) * (1-a) + Wave::tri(ph * 1.01) * a) * env * n.volume;
		});

		perc.PlayNotes([&](const NoteTimePair& n){
			constexpr f32 attack = 0.1;

			auto pos = (perc.time-n.begin)/n.length;
			f32 env = 0;
			if(pos < attack){
				env = pos/attack;
			}else{
				env = (1.0-pos)/(1.0-attack);
			}

			env *= n.volume;

			f32 o = 0;
			o += Wave::sin(n.freq*phase) * env;
			o += Wave::tri(n.freq*phase) * env;
			out += o;
		});

		outbuffer[i**outchannels+0] = out + outl/3.f;
		outbuffer[i**outchannels+1] = out + outr/3.f;

		phase += inc;
		chords.Update(inc/60.0* tempo);
		sched.Update(inc/60.0* tempo);
		perc.Update(inc/60.0* tempo);
	}

	return FMOD_OK;
}