• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ fmod::DSP类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: myDSPCallback

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; 
} 
开发者ID:addrum,项目名称:DSPCoursework,代码行数:56,代码来源:dsp_custom.cpp


示例2: dspReset

	//----------------------------------------------------------------------
	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 );
	}
开发者ID:hulcyp,项目名称:GuildhallProjects,代码行数:11,代码来源:CustomDSPImpl.cpp


示例3: dspRead

	//----------------------------------------------------------------------
	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 );
	}
开发者ID:hulcyp,项目名称:GuildhallProjects,代码行数:12,代码来源:CustomDSPImpl.cpp


示例4: FMODGMS_Effect_Get_Parameter

GMexport double FMODGMS_Effect_Get_Parameter(double e, double p)
{
	int effectIndex = (int)round(e);
	if ((effectIndex < 0) || (effectIndex >= (int)effectList.size()))
	{
		errorMessage = "Invalid effect index";
		return GMS_error;
	}
	FMOD::DSP* effect = effectList[effectIndex];

	int param = (int)round(p);
	FMOD_DSP_PARAMETER_DESC* desc = NULL;
	if (effect->getParameterInfo(param, &desc) != FMOD_OK)
	{
		errorMessage = "Could not get effect parameter info, probably invalid param index";
		return GMS_error;
	}

	if (desc->type == FMOD_DSP_PARAMETER_TYPE_FLOAT)
	{
		float value;
		if (effect->getParameterFloat(param, &value, NULL, 0) == FMOD_OK)
			return (double)value;
	}
	else if (desc->type == FMOD_DSP_PARAMETER_TYPE_INT)
	{
		int value;
		if (effect->getParameterInt(param, &value, NULL, 0) == FMOD_OK)
			return (double)value;
	}
	else if (desc->type == FMOD_DSP_PARAMETER_TYPE_BOOL)
	{
		bool value;
		if (effect->getParameterBool(param, &value, NULL, 0) == FMOD_OK)
			return (double)value;
	}
	else
	{
		errorMessage = "Unsupported effect parameter type";
		return GMS_error;
	}

	errorMessage = "Could not get effect parameter";
	return GMS_error;
}
开发者ID:mstop4,项目名称:FMODGMS,代码行数:45,代码来源:fmodgms.cpp


示例5: addEffect

void FMOD_Sound::addEffect(int module_id, int type, float value)
{
	float normalized_value = value / 100.0f;

	switch(type)
	{
		case Reverb:
			FMOD::DSP * reverb;
			system->createDSPByType(FMOD_DSP_TYPE_REVERB, &reverb);
			channelMap[module_id]->addDSP(reverb, 0);
			reverb->setParameter(FMOD_DSP_REVERB_ROOMSIZE, normalized_value);
			reverbMap[module_id] = reverb;
			break;
		case Pitch:
			FMOD::DSP * pitch;
			system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &pitch);
			channelMap[module_id]->addDSP(pitch, 0);
			pitch->setParameter(0, normalized_value);
			pitchMap[module_id] = pitch;
			break;
		case Distortion:
			FMOD::DSP * distortion;
			system->createDSPByType(FMOD_DSP_TYPE_DISTORTION, &distortion);
			channelMap[module_id]->addDSP(distortion, 0);
			distortion->setParameter(0, normalized_value);
			distortionMap[module_id] = distortion;
			break;
		case Echo:
			FMOD::DSP * echo;
			system->createDSPByType(FMOD_DSP_TYPE_ECHO, &echo);
			channelMap[module_id]->addDSP(echo, 0);
			echo->setParameter(0, normalized_value);
			echoMap[module_id] = echo;
			break;
		case Flange:
			FMOD::DSP * flange;
			system->createDSPByType(FMOD_DSP_TYPE_FLANGE, &flange);
			channelMap[module_id]->addDSP(flange, 0);
			flange->setParameter(0, normalized_value);
			flangeMap[module_id] = flange;
			break;
		default:
			break;
	}
}
开发者ID:willstepp,项目名称:resonance-v1,代码行数:45,代码来源:FMOD_Sound.cpp


示例6: FMODGMS_Effect_Remove

//Frees an effect from the memory
GMexport double FMODGMS_Effect_Remove(double e)
{
	int effectIndex = (int)round(e);
	if ((effectIndex < 0) || (effectIndex >= (int)effectList.size()))
	{
		errorMessage = "Invalid effect index";
		return GMS_error;
	}
	FMOD::DSP* effect = effectList[effectIndex];
	if (effect->release() == FMOD_OK)
	{
		effectList[effectIndex] = NULL;
		return FMODGMS_Util_ErrorChecker();
	}

	errorMessage = "Could not remove effect, is it still attached to some audio?";
	return GMS_error;
}
开发者ID:mstop4,项目名称:FMODGMS,代码行数:19,代码来源:fmodgms.cpp


示例7: FMODGMS_Effect_Set_Parameter

//Sets a parameter a of effect e to value v. For parameters of different effects, see fmod_dsp_effects.h
GMexport double FMODGMS_Effect_Set_Parameter(double e, double p, double v)
{
	int effectIndex = (int)round(e);
	if ((effectIndex < 0) || (effectIndex >= (int)effectList.size()))
	{
		errorMessage = "Invalid effect index";
		return GMS_error;
	}
	FMOD::DSP* effect = effectList[effectIndex];

	int param = (int)round(p);
	int value = (int)round(v);
	FMOD_DSP_PARAMETER_DESC* desc = NULL;
	if (effect->getParameterInfo(param, &desc) != FMOD_OK)
	{
		errorMessage = "Could not get effect parameter info, probably invalid param index";
		return GMS_error;
	}

	if (desc->type == FMOD_DSP_PARAMETER_TYPE_FLOAT)
	{
		if (effect->setParameterFloat(param, (float)value) == FMOD_OK)
			return FMODGMS_Util_ErrorChecker();
	}
	else if (desc->type == FMOD_DSP_PARAMETER_TYPE_INT)
	{
		if (effect->setParameterInt(param, (int)round(value)) == FMOD_OK)
			return FMODGMS_Util_ErrorChecker();
	}
	else if (desc->type == FMOD_DSP_PARAMETER_TYPE_BOOL)
	{
		if (effect->setParameterBool(param, (bool)(value > 0.5)) == FMOD_OK)
			return FMODGMS_Util_ErrorChecker();
	}
	else
	{
		errorMessage = "Unsupported effect parameter type";
		return GMS_error;
	}
	
	errorMessage = "Could not set effect parameter";
	return GMS_error;
}
开发者ID:mstop4,项目名称:FMODGMS,代码行数:44,代码来源:fmodgms.cpp


示例8: myDSPCallback

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; 
} 
开发者ID:EEmmanuel7,项目名称:leapmotion-irrlicht,代码行数:39,代码来源:main.cpp


示例9: FMODGMS_Chan_Get_Level

//Get current level/loudness of audio (RMS value)
GMexport double FMODGMS_Chan_Get_Level(double channel)
{
	int c = (int)round(channel);
	int chanListSize = channelList.size();

	if (chanListSize > c && c >= 0)
	{
		FMOD::DSP* headDSP;
		channelList[c]->getDSP(FMOD_CHANNELCONTROL_DSP_TAIL, &headDSP);

		//enable channel metering if it isn't already
		bool meteringEnabled = 0;
		if (headDSP->getMeteringEnabled(NULL, &meteringEnabled) != FMOD_OK)
			return FMODGMS_Util_ErrorChecker();
		if (!meteringEnabled)
			headDSP->setMeteringEnabled(true, false);

		//get level using metering on head dsp
		FMOD_DSP_METERING_INFO meteringInfo;
		if (headDSP->getMeteringInfo(&meteringInfo, NULL) != FMOD_OK)
			return FMODGMS_Util_ErrorChecker();
		double level = 0;
		short numChannels = meteringInfo.numchannels;
		for (int i = 0; i < numChannels; i++)
			level += (double)meteringInfo.rmslevel[i];
		level /= numChannels;

		if (FMODGMS_Util_ErrorChecker() == GMS_true)
			return level;
		else
			return GMS_error;
	}
	else
	{
		errorMessage = "Index out of bounds.";
		return GMS_error;
	}
}
开发者ID:mstop4,项目名称:FMODGMS,代码行数:39,代码来源:fmodgms.cpp


示例10: main

int main(int argc, char *argv[])
{
	int numSounds = 1;
    FMOD::System        *system;
    FMOD::Sound         *sound[numSounds];
	FMOD::Sound         *applause;
    FMOD::Channel       *channel[numSounds];
	FMOD::Channel       *applauseChannel;
    FMOD::DSP           *dsppitch;
	FMOD::DSP        *dsplowpass    = 0;
    FMOD::DSP        *dsphighpass   = 0;
    FMOD::DSP        *dspecho       = 0;
    FMOD::DSP        *dspflange     = 0;
    FMOD::DSP        *dspdistortion = 0;
    FMOD::DSP        *dspchorus     = 0;
    FMOD::DSP        *dspparameq    = 0;
    FMOD_RESULT          result;
    int                  key;
    unsigned int         version;
    float                pan = 0;
	float                volume;
	float                frequency;
	int					tempFrequency = 0;
	int					tempPitch = 0;
	int					frequencyCount = 0;
	int					pitchCount = 0;
	int					tempoChange = 0;
	float                speed;
	float				pitch = 1;
	float				originalFrequency;
	string				line;
	int					lineCount = 0;
	int inc = 0;
	int count;
	
	float frequencyArray[numSounds];
	float frequencyCountArray[numSounds];
	float pitchfArray[numSounds];
	float volumeArray[numSounds];
	float panArray[numSounds];
	
	float pitchf = 1.0f;
	
    /*
	 Create a System object and initialize.
	 */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);
	
    result = system->getVersion(&version);
    ERRCHECK(result);
	
    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }
	
    result = system->init(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);
	
	result = system->createSound("../Config/Seven Nation Army Drum.mp3", FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound[0]);
    ERRCHECK(result);
		
    printf("===============================================================================\n");
    printf("									Maestro									   \n");
    printf("===============================================================================\n");
	printf("Press '1' to play left speaker only\n");
    printf("Press '2' to play right speaker only\n");
	printf("Press '3' to play from both speakers\n");
    printf("Press '[' to pan sound left\n");
    printf("Press ']' to pan sound right\n");
	printf("Press 'v/V' to increase volume\n");
	printf("Press 'd/D' to decrease volume\n");
	printf("Press '6' pitch octave down\n");
	printf("Press '7' pitch semitone down\n");
	printf("Press '8' pitch semitone up\n");
	printf("Press '9' pitch octave up\n");
    printf("Press 'Esc' to quit\n");
	printf("Press 'n' pitch scale down\n");
    printf("Press 'm' pitch scale up\n");
    printf("\n");
	
	for (count = 0; count < numSounds; count++)
    {
		result = system->playSound(FMOD_CHANNEL_FREE, sound[count], false, &channel[count]);
		ERRCHECK(result);
		
		bool paused;
		
		channel[0]->getPaused(&paused);
		ERRCHECK(result);
		
		paused = !paused;
		
		result = channel[0]->setPaused(paused);
		ERRCHECK(result);
	}

	
//.........这里部分代码省略.........
开发者ID:avinashb-sd,项目名称:MaestroRepo,代码行数:101,代码来源:GroupB.cpp


示例11: FMOD_Main

int FMOD_Main()
{
    FMOD::System       *system;
    FMOD::Sound        *sound;
    FMOD::Channel      *channel;
    FMOD::DSP          *mydsp;
    FMOD::ChannelGroup *mastergroup;
    FMOD_RESULT         result;
    unsigned int        version;
    void               *extradriverdata = 0;

    Common_Init(&extradriverdata);

    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        Common_Fatal("FMOD lib version %08x doesn't match header version %08x", version, FMOD_VERSION);
    }

    result = system->init(32, FMOD_INIT_NORMAL, extradriverdata);
    ERRCHECK(result);

    result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound);
    ERRCHECK(result);

    result = system->playSound(sound, 0, false, &channel);
    ERRCHECK(result);

    /*
        Create the DSP effect.
    */  
    { 
        FMOD_DSP_DESCRIPTION dspdesc; 
        memset(&dspdesc, 0, sizeof(dspdesc));
        
        strncpy(dspdesc.name, "My first DSP unit", sizeof(dspdesc.name));
        dspdesc.version = 0x00010000;
        dspdesc.numinputbuffers = 1;
        dspdesc.numoutputbuffers = 1;
        dspdesc.read = myDSPCallback; 
        dspdesc.userdata = (void *)0x12345678; 

        result = system->createDSP(&dspdesc, &mydsp); 
        ERRCHECK(result); 
    } 

    /*
        Attach the DSP, inactive by default.
    */
    result = mydsp->setBypass(true);
    ERRCHECK(result);

    result = system->getMasterChannelGroup(&mastergroup);
    ERRCHECK(result);

    result = mastergroup->addDSP(0, mydsp, 0);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        bool bypass;

        Common_Update();

        result = mydsp->getBypass(&bypass);
        ERRCHECK(result);

        if (Common_BtnPress(BTN_ACTION1))
        {
            bypass = !bypass;
            
            result = mydsp->setBypass(bypass);
            ERRCHECK(result);
        }

        result = system->update();
        ERRCHECK(result);

        Common_Draw("==================================================");
        Common_Draw("Custom DSP Example.");
        Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
        Common_Draw("==================================================");
        Common_Draw("");
        Common_Draw("Press %s to toggle filter bypass", Common_BtnStr(BTN_ACTION1));
        Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
        Common_Draw("");
        Common_Draw("Filter is %s", bypass ? "inactive" : "active");

        Common_Sleep(50);
//.........这里部分代码省略.........
开发者ID:Silentpope,项目名称:transistor-breach,代码行数:101,代码来源:dsp_custom.cpp


示例12: DSPCallback

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;
}
开发者ID:manpat,项目名称:ProcSynthJamThing,代码行数:100,代码来源:main.cpp


示例13: InitFmod

void InitFmod(){
	cfmod(FMOD::System_Create(&fmodSystem));

	u32 version = 0;
	cfmod(fmodSystem->getVersion(&version));
	if(version < FMOD_VERSION){
		std::cerr 
			<< "FMOD version of at least " << FMOD_VERSION 
			<< " required. Version used " << version 
			<< std::endl;
		throw "FMOD Error";
	}

	cfmod(fmodSystem->init(100, FMOD_INIT_NORMAL, nullptr));

	FMOD::DSP* dsp;
	FMOD::DSP* compressor;

	{	FMOD_DSP_DESCRIPTION desc;
		memset(&desc, 0, sizeof(desc));

		// strncpy(desc.name, "Fuckyou", sizeof(desc.name));
		desc.numinputbuffers = 0;
		desc.numoutputbuffers = 1;
		desc.read = DSPCallback;
		desc.userdata = new DSPUserdata{/*sched, */0.0};

		cfmod(fmodSystem->createDSP(&desc, &dsp));
		cfmod(dsp->setChannelFormat(FMOD_CHANNELMASK_STEREO,2,FMOD_SPEAKERMODE_STEREO));
	}

	cfmod(fmodSystem->createDSPByType(FMOD_DSP_TYPE_COMPRESSOR, &compressor));

	cfmod(compressor->setParameterFloat(FMOD_DSP_COMPRESSOR_THRESHOLD, -13));
	cfmod(compressor->setParameterFloat(FMOD_DSP_COMPRESSOR_ATTACK, 1));
	cfmod(compressor->setBypass(false));
	cfmod(dsp->setBypass(false));

	FMOD::ChannelGroup* mastergroup;
	cfmod(fmodSystem->getMasterChannelGroup(&mastergroup));
	cfmod(mastergroup->addDSP(0, compressor));
	cfmod(fmodSystem->playDSP(dsp, mastergroup, false, &channel));
	cfmod(channel->setMode(FMOD_2D));
	cfmod(channel->setVolume(0.7f));

	FMOD::Reverb3D* reverb;
	cfmod(fmodSystem->createReverb3D(&reverb));

	// http://www.fmod.org/docs/content/generated/FMOD_REVERB_PROPERTIES.html

	FMOD_REVERB_PROPERTIES rprops = {
		.DecayTime			= 8000.0, //1500.0, /* Reverberation decay time in ms */
		.EarlyDelay			= 7.0, //7.0, /* Initial reflection delay time */
		.LateDelay			= 11.0, //11.0, /* Late reverberation delay time relative to initial reflection */
		.HFReference		= 5000.0, /* Reference high frequency (hz) */
		.HFDecayRatio		= 50.0, /* High-frequency to mid-frequency decay time ratio */
		.Diffusion			= 60.0, /* Value that controls the echo density in the late reverberation decay. */
		.Density			= 100.0, //100.0, /* Value that controls the modal density in the late reverberation decay */
		.LowShelfFrequency	= 250.0, /* Reference low frequency (hz) */
		.LowShelfGain		= 0.0, /* Relative room effect level at low frequencies */
		.HighCut			= 10000.0, /* Relative room effect level at high frequencies */
		.EarlyLateMix		= 50.0, /* Early reflections level relative to room effect */
		.WetLevel			= -12.0, //-6.0, /* Room effect level (at mid frequencies) */
	};

	cfmod(reverb->setProperties(&rprops));
}
开发者ID:manpat,项目名称:ProcSynthJamThing,代码行数:67,代码来源:main.cpp


示例14: main

int main(int argc, char *argv[])
{
    FMOD::System     *system        = 0;
    FMOD::Sound      *sound         = 0;
    FMOD::Channel    *channel       = 0;
    FMOD::DSP        *dsplowpass    = 0;
    FMOD::DSP        *dsphighpass   = 0;
    FMOD::DSP        *dspecho       = 0;
    FMOD::DSP        *dspflange     = 0;
    FMOD::DSP        *dspdistortion = 0;
    FMOD::DSP        *dspchorus     = 0;
    FMOD::DSP        *dspparameq    = 0;
    FMOD_RESULT       result;
    int               key;
    unsigned int      version;

    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }

    result = system->init(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound);
    ERRCHECK(result);

    printf("=================================================================\n");
    printf("Effects Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("=================================================================\n");
    printf("\n");
    printf("Press SPACE to paused/unpause sound.\n");
    printf("Press 1 to toggle dsplowpass effect.\n");
    printf("Press 2 to toggle dsphighpass effect.\n");
    printf("Press 3 to toggle dspecho effect.\n");
    printf("Press 4 to toggle dspflange effect.\n");
    printf("Press 5 to toggle dspdistortion effect.\n");
    printf("Press 6 to toggle dspchorus effect.\n");
    printf("Press 7 to toggle dspparameq effect.\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
    ERRCHECK(result);

    /*
        Create some effects to play with.
    */
    result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_HIGHPASS, &dsphighpass);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_ECHO, &dspecho);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_FLANGE, &dspflange);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_DISTORTION, &dspdistortion);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_CHORUS, &dspchorus);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_PARAMEQ, &dspparameq);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case ' ' :
                {
                    bool paused;

                    channel->getPaused(&paused);
                    ERRCHECK(result);

                    paused = !paused;

                    result = channel->setPaused(paused);
                    ERRCHECK(result);
                    break;
                }
                case '1' :
                {
                    bool active;
//.........这里部分代码省略.........
开发者ID:YanisBreton,项目名称:wolf3d,代码行数:101,代码来源:main.cpp


示例15: FMOD_Main

int FMOD_Main()
{
    FMOD::System       *system        = 0;
    FMOD::Sound        *sound         = 0;
    FMOD::Channel      *channel       = 0;
    FMOD::ChannelGroup *mastergroup   = 0; 
    FMOD::DSP          *dsplowpass    = 0;
    FMOD::DSP          *dsphighpass   = 0;
    FMOD::DSP          *dspecho       = 0;
    FMOD::DSP          *dspflange     = 0;
    FMOD_RESULT         result;
    unsigned int        version;
    void               *extradriverdata = 0;

    Common_Init(&extradriverdata);

    /*
        Create a System object and initialize
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        Common_Fatal("FMOD lib version %08x doesn't match header version %08x", version, FMOD_VERSION);
    }

    result = system->init(32, FMOD_INIT_NORMAL, extradriverdata);
    ERRCHECK(result);

    result = system->getMasterChannelGroup(&mastergroup);
    ERRCHECK(result);

    result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_DEFAULT, 0, &sound);
    ERRCHECK(result);

    result = system->playSound(sound, 0, false, &channel);
    ERRCHECK(result);

    /*
        Create some effects to play with
    */
    result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_HIGHPASS, &dsphighpass);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_ECHO, &dspecho);
    ERRCHECK(result);
    result = system->createDSPByType(FMOD_DSP_TYPE_FLANGE, &dspflange);
    ERRCHECK(result);

    /*
        Add them to the master channel group.  Each time an effect is added (to position 0) it pushes the others down the list.
    */
    result = mastergroup->addDSP(0, dsplowpass);
    ERRCHECK(result);
    result = mastergroup->addDSP(0, dsphighpass);
    ERRCHECK(result);
    result = mastergroup->addDSP(0, dspecho);
    ERRCHECK(result);
    result = mastergroup->addDSP(0, dspflange);
    ERRCHECK(result);

    /*
        By default, bypass all effects.  This means let the original signal go through without processing.
        It will sound 'dry' until effects are enabled by the user.
    */
    result = dsplowpass->setBypass(true);
    ERRCHECK(result);
    result = dsphighpass->setBypass(true);
    ERRCHECK(result);
    result = dspecho->setBypass(true);
    ERRCHECK(result);
    result = dspflange->setBypass(true);
    ERRCHECK(result);

    /*
        Main loop
    */
    do
    {
        Common_Update();

        if (Common_BtnPress(BTN_MORE))
        {
            bool paused;

            result = channel->getPaused(&paused);
            ERRCHECK(result);

            paused = !paused;

            result = channel->setPaused(paused);
            ERRCHECK(result);
        }

        if (Common_BtnPress(BTN_ACTION1))
//.........这里部分代码省略.........
开发者ID:Athlos,项目名称:Circuit-Collector,代码行数:101,代码来源:effects.cpp


示例16: main

int main(int argc, char *argv[])
{
    FMOD::System          *system  = 0;
    FMOD::Sound           *sound   = 0;
    FMOD::Channel         *channel = 0;
    FMOD::DSP             *dsp     = 0;
    FMOD_RESULT            result;
    FMOD_CREATESOUNDEXINFO exinfo;
    FMOD_SPEAKERMODE       speakermode;
    FMOD_CAPS              caps;
    int                    key, numdrivers;
    unsigned int           version;    
    unsigned int           datalength = 0, soundlength;
    char                   name[256];
    unsigned int           adjustedlatency;

    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }

    /* 
        System initialization (recommended startup sequence)
    */
    result = system->getNumDrivers(&numdrivers);
    ERRCHECK(result);

    if (numdrivers == 0)
    {
        result = system->setOutput(FMOD_OUTPUTTYPE_NOSOUND);
        ERRCHECK(result);
    }
    else
    {
        result = system->getDriverCaps(0, &caps, 0, &speakermode);
        ERRCHECK(result);

        result = system->setSpeakerMode(speakermode);       /* Set the user selected speaker mode. */
        ERRCHECK(result);

        if (caps & FMOD_CAPS_HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
        {                                                   /* You might want to warn the user about this. */
            result = system->setDSPBufferSize(1024, 10);
            ERRCHECK(result);
        }
#ifdef LOWLATENCY
        else
        {
            result = system->setDSPBufferSize(256, 4);
        }
#endif
        result = system->getDriverInfo(0, name, 256, 0);
        ERRCHECK(result);

        if (strstr(name, "SigmaTel"))   /* Sigmatel sound devices crackle for some reason if the format is PCM 16bit.  PCM floating point output seems to solve it. */
        {
            result = system->setSoftwareFormat(48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR);
            ERRCHECK(result);
        }
    }

    result = system->init(100, FMOD_INIT_NORMAL, 0);
    if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)         /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
    {
        result = system->setSpeakerMode(FMOD_SPEAKERMODE_STEREO);
        ERRCHECK(result);
            
        result = system->init(100, FMOD_INIT_NORMAL, 0);/* ... and re-init. */
        ERRCHECK(result);
    }
    /* 
        System initialization complete (recommended startup sequence)
    */
 

    /*
        Create user sound to record into.  Set it to loop for playback.
    */
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 1;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = RECORDRATE;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5; /* 5 second buffer, doesnt really matter how big this is, but not too small of course. */
    
    result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    printf("========================================================================\n");
    printf("Record with realtime playback example.\n");
//.........这里部分代码省略.........
开发者ID:chandonnet,项目名称:FTB2015,代码行数:101,代码来源:main.cpp


示例17: getSpectrum

void AnalyzerToolUtils::getSpectrum(SoundAnalyzer* soundAnalyzer)
{
	//FMod variable
	boost::thread_group threadpool;

	FMOD::DSP* dspSpectrum;
	FMOD::ChannelGroup* masterChannel;
	FMOD::Channel* chan;
	FMOD_RESULT res;

	//Variable
	int sampleRate, musicSpectrumSize;
	unsigned int soundTime;
	float niquistRate, i = 0;


	//sound time in MS
	soundAnalyzer->Sound->getLength(&soundTime, FMOD_TIMEUNIT_MS);

	//DSP / FFT / Window
	soundAnalyzer->sys->createDSPByType(FMOD_DSP_TYPE_FFT, &dspSpectrum);
	dspSpectrum->setParameterInt(FMOD_DSP_FFT_WINDOWSIZE, soundAnalyzer->GetWindowSize());
	dspSpectrum->getParameterInt(FMOD_DSP_FFT_WINDOWSIZE, &musicSpectrumSize, 0, 0);
	dspSpectrum->setParameterInt(FMOD_DSP_FFT_WINDOWTYPE, FMOD_DSP_FFT_WINDOW_TRIANGLE);

	//Master Channel -> Add Dsp
	soundAnalyzer->sys->getMasterChannelGroup(&masterChannel);
	masterChannel->addDSP(0, dspSpectrum);
	soundAnalyzer->sys->setOutput(FMOD_OUTPUTTYPE_NOSOUND_NRT); //FMOD_OUTPUTTYPE_NOSOUND_NRT
	soundAnalyzer->sys->playSound(soundAnalyzer->Sound, masterChannel, false, &chan);

	soundAnalyzer->sys->setDSPBufferSize(SPECTRUM_BUFFER_SIZE, 0);

	soundAnalyzer->sys->update();

	//Get Samplerate
	soundAnalyzer->sys->getSoftwareFormat(&sampleRate, 0, 0);
	niquistRate = sampleRate / 2.0f;

	soundAnalyzer->data.SpectrumData.resize(static_cast<int>(soundTime / (((double)SPECTRUM_BUFFER_SIZE / (double)sampleRate) * 1000)) + 1);

	soundAnalyzer->SetFrequencyStep(musicSpectrumSize / niquistRate);

	int index = 0;
	//double val;
	do{
		FMOD_DSP_PARAMETER_FFT *dataSpectrum;
		dspSpectrum->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)&dataSpectrum, 0, 0, 0);
		
		SpectrumSegment segment(musicSpectrumSize / 2, musicSpectrumSize / niquistRate);
		threadpool.create_thread(boost::bind(&AnalyzerToolUtils::ExtractSpectrum, soundAnalyzer, boost::ref(dataSpectrum), musicSpectrumSize/2, musicSpectrumSize / niquistRate, index));
		/*for (int bin = 0; bin < dataSpectrum->length/2; bin++)
		{
			val = 0;
			for (int channel = 0; channel < MAX_CHANNELS; channel++)
			{
				val += dataSpectrum->spectrum[channel][bin];
			}
			segment.AddSegment(val);
		}

		soundAnalyzer->data.AddData(segment);*/
		soundAnalyzer->sys->update();
		index++;
		i += ((double)SPECTRUM_BUFFER_SIZE / (double)sampleRate) * 1000;
	} while (i < (soundTime));

	threadpool.join_all();
}
开发者ID:LecomteEmerick,项目名称:SoundAnalyzer,代码行数:69,代码来源:AnalyzerToolUtils.cpp


示例18: UpdateInteriorVolumes

// Taken mostly from ActiveSound.cpp
void UFMODAudioComponent::UpdateInteriorVolumes()
{
	// Result of the ambient calculations to apply to the instance
	float AmbientVolumeMultiplier = 1.0f;
	float AmbientHighFrequencyGain = 1.0f;

	FInteriorSettings Ambient;
	const FVector& Location = GetOwner()->GetTransform().GetTranslation();
	AAudioVolume* AudioVolume = GetWorld()->GetAudioSettings(Location, NULL, &Ambient);

	const FFMODListener& Listener = IFMODStudioModule::Get().GetNearestListener(Location);
	if( InteriorLastUpdateTime < Listener.InteriorStartTime )
	{
		SourceInteriorVolume = CurrentInteriorVolume;
		SourceInteriorLPF = CurrentInteriorLPF;
		InteriorLastUpdateTime = FApp::GetCurrentTime();
	}


	bool bAllowSpatialization = true;
	if( Listener.Volume == AudioVolume || !bAllowSpatialization )
	{
		// Ambient and listener in same ambient zone
		CurrentInteriorVolume = ( SourceInteriorVolume * ( 1.0f - Listener.InteriorVolumeInterp ) ) + Listener.InteriorVolumeInterp;
		AmbientVolumeMultiplier *= CurrentInteriorVolume;

		CurrentInteriorLPF = ( SourceInteriorLPF * ( 1.0f - Listener.InteriorLPFInterp ) ) + Listener.InteriorLPFInterp;
		AmbientHighFrequencyGain *= CurrentInteriorLPF;

		//UE_LOG(LogFMOD, Verbose, TEXT( "Ambient in same volume. Volume *= %g LPF *= %g" ), CurrentInteriorVolume, CurrentInteriorLPF);
	}
	else
	{
		// Ambient and listener in different ambient zone
		if( Ambient.bIsWorldSettings )
		{
			// The ambient sound is 'outside' - use the listener's exterior volume
			CurrentInteriorVolume = ( SourceInteriorVolume * ( 1.0f - Listener.ExteriorVolumeInterp ) ) + ( Listener.InteriorSettings.ExteriorVolume * Listener.ExteriorVolumeInterp );
			AmbientVolumeMultiplier *= CurrentInteriorVolume;

			CurrentInteriorLPF = ( SourceInteriorLPF * ( 1.0f - Listener.ExteriorLPFInterp ) ) + ( Listener.InteriorSettings.ExteriorLPF * Listener.ExteriorLPFInterp );
			AmbientHighFrequencyGain *= CurrentInteriorLPF;

			//UE_LOG(LogFMOD, Verbose, TEXT( "Ambient in diff volume, ambient outside. Volume *= %g LPF *= %g" ), CurrentInteriorVolume, CurrentInteriorLPF);
		}
		else
		{
			// The ambient sound is 'inside' - use the ambient sound's interior volume multiplied with the listeners exterior volume
			CurrentInteriorVolume = (( SourceInteriorVolume * ( 1.0f - Listener.InteriorVolumeInterp ) ) + ( Ambient.InteriorVolume * Listener.InteriorVolumeInterp ))
										* (( SourceInteriorVolume * ( 1.0f - Listener.ExteriorVolumeInterp ) ) + ( Listener.InteriorSettings.ExteriorVolume * Listener.ExteriorVolumeInterp ));
			AmbientVolumeMultiplier *= CurrentInteriorVolume;

			CurrentInteriorLPF = (( SourceInteriorLPF * ( 1.0f - Listener.InteriorLPFInterp ) ) + ( Ambient.InteriorLPF * Listener.InteriorLPFInterp ))
										* (( SourceInteriorLPF * ( 1.0f - Listener.ExteriorLPFInterp ) ) + ( Listener.InteriorSettings.ExteriorLPF * Listener.ExteriorLPFInterp ));
			AmbientHighFrequencyGain *= CurrentInteriorLPF;

			//UE_LOG(LogFMOD, Verbose, TEXT( "Ambient in diff volume, ambient inside. Volume *= %g LPF *= %g" ), CurrentInteriorVolume, CurrentInteriorLPF);
		}
	}

	StudioInstance->setVolume(AmbientVolumeMultiplier);

	FMOD::ChannelGroup* ChanGroup = nullptr;
	StudioInstance->getChannelGroup(&ChanGroup);
	if (ChanGroup)
	{
		int NumDSP = 0;
		ChanGroup->getNumDSPs(&NumDSP);
		for (int Index=0; Index<NumDSP; ++Index)
		{
			FMOD::DSP* ChanDSP = nullptr;
			ChanGroup->getDSP(Index, &ChanDSP);
			if (ChanDSP)
			{
				FMOD_DSP_TYPE DSPType = FMOD_DSP_TYPE_UNKNOWN;
				ChanDSP->getType(&DSPType);
				if (DSPType == FMOD_DSP_TYPE_LOWPASS || DSPType == FMOD_DSP_TYPE_LOWPASS_SIMPLE)
				{
					static float MAX_FREQUENCY = 8000.0f;
					float Frequency = MAX_FREQUENCY * AmbientHighFrequencyGain;
					ChanDSP->setParameterFloat(FMOD_DSP_LOWPASS_CUTOFF, MAX_FREQUENCY * AmbientHighFrequencyGain);
					break;
				}
			}
		}
	}
}
开发者ID:azarus,项目名称:ue4integration,代码行数:88,代码来源:FMODAudioComponent.cpp


示例19: main

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ fmod::Sound类代码示例发布时间:2022-05-31
下一篇:
C++ fmod::Channel类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap