示例#1
0
文件: s_fmod.c 项目: HipsterLion/SRB2
//Copy rel chan
static INT32 relcopy(INT32 handle)
{
	FSOUND_SAMPLE *fmsample = NULL;
	INT32 chan = -1;
	float pos[3];
	float vel[3];

	if (!FSOUND_3D_GetAttributes(handle,&pos[0],&vel[0]))
		if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_3D_GetAttributes, Channel # %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError()));

	fmsample = FSOUND_GetCurrentSample(handle);

	if (fmsample)
	{
#ifdef REL2D
		if (!FSOUND_Sample_SetMode(fmsample, FSOUND_2D))
			DBG_Printf("FMOD(relcopy, FSOUND_Sample_SetMode, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError()));
#endif
		chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true);

		if (chan == -1)
		{
			if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_PlaySoundEx, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError()));
			return FSOUND_FREE;
		}
#ifdef MORESTUFF
		else
			DBG_Printf("FMOD(relcopy, Main): Copy Handle#%i to channel#%i\n",handle,chan);
#endif
	}
	else
	{
		if (FSOUND_GetError() != FMOD_ERR_NONE)
			DBG_Printf("FMOD(relcopy, FSOUND_GetCurrentSample, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError()));
		chan = FSOUND_PlaySoundEx(FSOUND_FREE,blankfmsample,NULL,true);
		//return FSOUND_FREE;
	}

	if (FSOUND_GetCurrentSample(chan))
	{

		if (!FSOUND_SetCurrentPosition(chan, 0))
			DBG_Printf("FMOD(relcopy, FSOUND_SetCurrentPosition, handle#%i, channel# %i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError()));
#ifndef REL2D
		if (!FSOUND_3D_SetAttributes(chan,pos,vel))
			DBG_Printf("FMOD(relcopy, FSOUND_3D_SetAttributes, handle#%i, channel#%i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError()));
#endif
/*
		if (!FSOUND_SetReserved(chan, TURE))
			DBG_Printf("FMOD(relcopy, FSOUND_SetReserved, handle#%i, channel# %i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError()));
*/
		return chan;
	}

	return FSOUND_FREE;
}
示例#2
0
VOID CSoundSourceFMod::Play(VOID)
{
	//停止
	Stop();

	//播放
	if(_Sample)
	{
		CSoundBufferFMod* bufFMod= static_cast<CSoundBufferFMod*>(_Sample);

		_State= source_playing;
		//以暂停模式开始播放声音
		if(bufFMod->m_pFModSample)
			_FModChannel= FSOUND_PlaySoundEx(FSOUND_FREE, bufFMod->m_pFModSample, NULL, true);

		//在Channel播放
		if(_FModChannel!=-1)
		{
			FSOUND_SetLoopMode(_FModChannel, _Loop?FSOUND_LOOP_NORMAL:FSOUND_LOOP_OFF);
			//音量
			UpdateVolume();
			//开始播放
			FSOUND_SetPaused(_FModChannel, false);
		}
	}
}
示例#3
0
文件: sound.c 项目: wosigh/duke3d
void wsay(char *dafilename, long dafreq, long volume1, long volume2)
{
	unsigned char ch1, ch2;
	long i, j, bad, free=-1, oldest=0;
	unsigned int oldestpos=0;
	int chan;

	if (fmod_inited == 0) return;

	i = numwaves-1;
	do
	{
		bad = 0;

		j = 0;
		while ((dafilename[j] > 0) && (j < 16))
		{
			ch1 = dafilename[j]; if ((ch1 >= 97) && (ch1 <= 123)) ch1 -= 32;
			ch2 = instname[i][j]; if ((ch2 >= 97) && (ch2 <= 123)) ch2 -= 32;
			if (ch1 != ch2) {bad = 1; break;}
			j++;
		}
		if (bad == 0)
		{
#if 0
			for (j=0; j<NUMCHANNELS; j++) {
				if (!FSOUND_IsPlaying(channels[j])) {
					free = j;
					break;
				}
				if (j==0) continue;
			
				if (FSOUND_GetCurrentPosition(channels[j]) > oldestpos) {
					oldest = j;
					oldestpos = FSOUND_GetCurrentPosition(channels[j]);
				}
			}

			if (free < 0) {
				FSOUND_StopSound(channels[oldest]);
				free = oldest;
			}

			chan = FSOUND_PlaySoundEx(FSOUND_FREE, samples[i], NULL, 1);
			if (chan == -1) return;
			FSOUND_SetFrequency(chan, dafreq*11025/4096);
			FSOUND_SetVolume(chan, (volume1*volume2)>>1);
			// set pan
			FSOUND_SetPaused(chan, 0);
#endif

			channels[free] = chan;
			
			return;
		}

		i--;
	} while (i >= 0);
}
/**
 * @return Der erzeugte Channel
 * @author JoSch
 * @date 08-08-2005
 */
int Fmod3SoundSample::createChannel() throw (RuntimeException)
{
    mChannel = FSOUND_PlaySoundEx(FSOUND_FREE, getSample(), 0, true);

    if( mChannel == -1 )
    {
        int err = FSOUND_GetError();
        Throw( RuntimeException, "Fmod Error:" + Ogre::StringConverter::toString(err) + " while playing " + getName() );
    }   
	return mChannel; 
}
示例#5
0
文件: soundfx.cpp 项目: boredzo/CCX
void PlayStereoFrequency( short player, short which, short freq )
{
	if( soundOn )
	{
		#ifdef UseSDLMixer
		Mix_PlayChannel(-1, sound[which], 0);
//		Mix_SetPanning(chanHandle, 0, 0);
		#else
		// FMod
		int chanHandle = FSOUND_PlaySoundEx( FSOUND_FREE, sound[which], NULL, true );
		FSOUND_SetPan( chanHandle, player? 255: 0 );
		FSOUND_SetFrequency( chanHandle, (FSOUND_GetFrequency(chanHandle) * (16 + freq)) / 16 );
	    FSOUND_SetPaused( chanHandle, false );
		#endif
	}
}
示例#6
0
文件: s_fmod.c 项目: HipsterLion/SRB2
/******************************************************************************
 *
 * Creates 2D (stereo) source
 *
 ******************************************************************************/
EXPORT INT32 HWRAPI (Add2DSource) (sfx_data_t *sfx)
{
	FSOUND_SAMPLE *fmsample = NULL;
	INT32 chan = -1;

	if (!sfx)
		return chan;

	fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH);

	if (fmsample)
	{
		if (!FSOUND_Sample_SetDefaults(fmsample,
		 (INT32)((float)(*((UINT16 *)sfx->data+1)) * recalc_pitch(sfx->pitch)),
		 sfx->volume == -1 ? 255 : sfx->volume,
		 sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep,
		 sfx->priority))
			DBG_Printf("FMOD(Add2DSource, FSOUND_Sample_SetDefaults, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError()));

		if (!FSOUND_Sample_SetMode(fmsample,FSOUND_2D))
			DBG_Printf("FMOD(Add2DSource, FSOUND_Sample_SetMode, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError()));

		chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true);

		if (chan == -1)
		{
			DBG_Printf("FMOD(Add2DSource, FSOUND_PlaySoundEx, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError()));
			return chan;
		}
#ifdef MORESTUFF
		else DBG_Printf("FMOD(Add2DSource, FSOUND_PlaySoundEx): sfxid# %i is playing on channel %i\n", sfx->id,chan);
#endif
	}
	else
	{
		DBG_Printf("FMOD(Add2DSource,FSOUND_Sample_Load, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError()));
		return chan;
	}

	if (FSOUND_GetCurrentSample(chan))
	{
		if (!FSOUND_SetCurrentPosition(chan, 0))
			DBG_Printf("FMOD(Add2DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx->id,FMOD_ErrorString(FSOUND_GetError()));
	}

	return chan;
}
bool LLAudioChannelFMOD::updateBuffer()
{
	if (LLAudioChannel::updateBuffer())
	{
		// Base class update returned true, which means that we need to actually
		// set up the channel for a different buffer.

		LLAudioBufferFMOD *bufferp = (LLAudioBufferFMOD *)mCurrentSourcep->getCurrentBuffer();

		// Grab the FMOD sample associated with the buffer
		FSOUND_SAMPLE *samplep = bufferp->getSample();
		if (!samplep)
		{
			// This is bad, there should ALWAYS be a sample associated with a legit
			// buffer.
			llerrs << "No FMOD sample!" << llendl;
			return false;
		}


		// Actually play the sound.  Start it off paused so we can do all the necessary
		// setup.
		mChannelID = FSOUND_PlaySoundEx(FSOUND_FREE, samplep, FSOUND_DSP_GetSFXUnit(), true);

		//llinfos << "Setting up channel " << std::hex << mChannelID << std::dec << llendl;
	}

	// If we have a source for the channel, we need to update its gain.
	if (mCurrentSourcep)
	{
		// SJB: warnings can spam and hurt framerate, disabling
		if (!FSOUND_SetVolume(mChannelID, llround(getSecondaryGain() * mCurrentSourcep->getGain() * 255.0f)))
		{
// 			llwarns << "LLAudioChannelFMOD::updateBuffer error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl;
		}
		
		if (!FSOUND_SetLoopMode(mChannelID, mCurrentSourcep->isLoop() ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF))
		{
// 			llwarns << "Channel " << mChannelID << "Source ID: " << mCurrentSourcep->getID()
// 					<< " at " << mCurrentSourcep->getPositionGlobal() << llendl;
// 			llwarns << "LLAudioChannelFMOD::updateBuffer error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl;
		}
	}

	return true;
}
示例#8
0
/*
[
    [DESCRIPTION]

    [PARAMETERS]
 
    [RETURN_VALUE]

    [REMARKS]

    [SEE_ALSO]
]
*/
int main()
{
    FSOUND_SAMPLE *samp1 = 0, *samp2 = 0;
    int key;
    int eqid1,eqid2;
   
    if (FSOUND_GetVersion() < FMOD_VERSION)
    {
        printf("Error : You are using the wrong DLL version!  You should be using FMOD %.02f\n", FMOD_VERSION);
        return 1;
    }

     /*
        INITIALIZE
    */
    FSOUND_SetBufferSize(100);  /* This is nescessary to get FX to work on output buffer */
    if (!FSOUND_Init(44100, 32, FSOUND_INIT_ENABLESYSTEMCHANNELFX))
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }

    /*
        LOAD SAMPLES
    */

    /* PCM,44,100 Hz, 8 Bit, Mono */
    samp1 = FSOUND_Sample_Load(FSOUND_FREE, "../../media/drumloop.wav", FSOUND_2D, 0, 0);
    if (!samp1)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }
    FSOUND_Sample_SetMode(samp1, FSOUND_LOOP_OFF);

    /* PCM,44,100 Hz, 16 Bit, Stereo */
    samp2 = FSOUND_Sample_Load(FSOUND_FREE, "../../media/jules.mp3", FSOUND_HW2D | FSOUND_ENABLEFX, 0, 0);
    if (!samp2)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }

    /*
        DISPLAY HELP
    */

    printf("FSOUND Output Method : ");
    switch (FSOUND_GetOutput())
    {
        case FSOUND_OUTPUT_NOSOUND:  printf("FSOUND_OUTPUT_NOSOUND\n"); break;
        case FSOUND_OUTPUT_WINMM:    printf("FSOUND_OUTPUT_WINMM\n"); break;
        case FSOUND_OUTPUT_DSOUND:   printf("FSOUND_OUTPUT_DSOUND\n"); break;
        case FSOUND_OUTPUT_ASIO:     printf("FSOUND_OUTPUT_ASIO\n"); break;
        case FSOUND_OUTPUT_OSS:      printf("FSOUND_OUTPUT_OSS\n"); break;
        case FSOUND_OUTPUT_ALSA:     printf("FSOUND_OUTPUT_ALSA\n"); break;
        case FSOUND_OUTPUT_ESD:      printf("FSOUND_OUTPUT_ESD\n"); break;
    };

    printf("FSOUND Mixer         : ");
    switch (FSOUND_GetMixer())
    {
        case FSOUND_MIXER_QUALITY_FPU:    printf("FSOUND_MIXER_QUALITY_FPU\n"); break;
        case FSOUND_MIXER_QUALITY_MMXP5:  printf("FSOUND_MIXER_QUALITY_MMXP5\n"); break;
        case FSOUND_MIXER_QUALITY_MMXP6:  printf("FSOUND_MIXER_QUALITY_MMXP6\n"); break;
    };
    printf("FSOUND Driver        : %s\n", FSOUND_GetDriverName(FSOUND_GetDriver()));

    printf("=========================================================================\n");
    printf("Press 1       Play SOFTWARE sound affected by following reverb dsp unit (wet)\n");
    printf("      2       Play SOFTWARE sound unaffected by following reverb dsp unit (dry)\n");
    if (FSOUND_GetOutput() == FSOUND_OUTPUT_DSOUND)
    {
        printf("      3       Play HARDWARE FX enabled sound using Direct X 8 (echo+flange)\n");
        printf("      4       Set EQ on global software output to be affect by DX8 FX\n");
        printf("              Press 1 or 2 to hear the effect (3 is unaffected)\n");
        printf("      5       Turn off EQ on global software output\n");
    }
    printf("      ESC     Quit\n");
    printf("=========================================================================\n");

    /*
        SET UP DSPS!
    */

    SetupReverb();

    /*
        Note if we are using a dsp unit for playing sounds, callback and parameter are ignored!
    */
    DrySFXUnit = FSOUND_DSP_Create(NULL, FSOUND_DSP_DEFAULTPRIORITY_USER+100, 0);
    FSOUND_DSP_SetActive(DrySFXUnit, TRUE);

    /*
        You must pause the software output before getting the FX handle on it.
    */
    if (FSOUND_GetOutput() == FSOUND_OUTPUT_DSOUND)
    {
        FSOUND_SetPaused(FSOUND_SYSTEMCHANNEL, TRUE);

        eqid1 = FSOUND_FX_Enable(FSOUND_SYSTEMCHANNEL, FSOUND_FX_PARAMEQ);
        eqid2 = FSOUND_FX_Enable(FSOUND_SYSTEMCHANNEL, FSOUND_FX_PARAMEQ);

        FSOUND_SetPaused(FSOUND_SYSTEMCHANNEL, FALSE);
    }

    /*
        START PLAYING!
    */

    do
    {
        key = 0;
        printf("channels playing = %d cpu usage = %.02f%%\r", FSOUND_GetChannelsPlaying(), FSOUND_GetCPUUsage());

        if (kbhit())
        {
            key = getch();


            if (key == '1') 
            {
                int channel = FSOUND_PlaySound(FSOUND_FREE, samp1);
            }
            if (key == '2') 
            {
                FSOUND_PlaySoundEx(FSOUND_FREE, samp1, DrySFXUnit, FALSE);
            }
            if (FSOUND_GetOutput() == FSOUND_OUTPUT_DSOUND)
            {       
                if (key == '3') 
                {
                    static int  fxchannel = FSOUND_FREE;
                    static int  echoid = -1, echoid2 = -1,flangeid = -1, firsttime;

                    if (fxchannel == FSOUND_FREE)
                    {
                        firsttime = TRUE;
                    }
                    else
                    {
                        firsttime = FALSE;
                    }

                    fxchannel = FSOUND_PlaySoundEx(fxchannel, samp2, DrySFXUnit, TRUE);     

                    /* 
                       NOTE! Even though it is for hardware FX, set it to a DrySFXUnit just 
                       in case a non hardware output mode has been selected (such as 
                       WINMM/Linux etc) and it actually drops back to 100% software 
                     */

                    FSOUND_SetVolume(fxchannel, 120); /* turn it down a bit! */
                
                    if (firsttime)
                    {
                        echoid   = FSOUND_FX_Enable(fxchannel, FSOUND_FX_ECHO);
                        echoid2  = FSOUND_FX_Enable(fxchannel, FSOUND_FX_ECHO);
                        flangeid = FSOUND_FX_Enable(fxchannel, FSOUND_FX_FLANGER);
                    }

                    FSOUND_SetPaused(fxchannel, FALSE);

                    FSOUND_FX_SetEcho(echoid,  80.0f, 70.0f, 100.0f, 100.0f, TRUE);
                    FSOUND_FX_SetEcho(echoid2,  100, 70.0f, 10, 10, FALSE);
                }
                if (key == '4')
                {
                    FSOUND_FX_SetParamEQ(eqid1, 8000, 36, -15);
                    FSOUND_FX_SetParamEQ(eqid2, 16000, 36, -15);
                }
                if (key == '5')
                {
                    FSOUND_FX_SetParamEQ(eqid1, 8000, 15, 0);
                    FSOUND_FX_SetParamEQ(eqid2, 8000, 15, 0);
                }
            }
        }
        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        CLEANUP AND SHUTDOWN
    */

    FSOUND_DSP_Free(DrySFXUnit);    

    CloseReverb();

    FSOUND_Sample_Free(samp1);
    FSOUND_Sample_Free(samp2);

    FSOUND_Close();
   
    return 0;
}
示例#9
0
文件: sound.c 项目: wosigh/duke3d
void wsayfollow(char *dafilename, long dafreq, long davol, long *daxplc, long *dayplc, char followstat)
{
/*
	dafilename:
		filename

	dafreq:
		4096 = Middle C
		8192 = +1 8ve

	davol:
		0-256 = volume

	daxplc:
	dayplc:
		followstat: 0 = sound emination origin (fixed)
		followstat: 1 = pointer to sprite coordinates (dynamic)

	followstat:
		0 = position is fixed in space
		1 = position follows an object
*/
	unsigned char ch1, ch2;
	long i, wavnum, bad, oldest=0, free=-1, ox, oy, x, y, vo;
	unsigned int oldestpos=0;
	int chan;

	if (fmod_inited == 0) return;

	for (wavnum=numwaves-1;wavnum>=0;wavnum--) {
		bad = 0;

		i = 0;
		while ((dafilename[i] > 0) && (i < 16))
		{
			ch1 = dafilename[i]; if ((ch1 >= 97) && (ch1 <= 123)) ch1 -= 32;
			ch2 = instname[wavnum][i]; if ((ch2 >= 97) && (ch2 <= 123)) ch2 -= 32;
			if (ch1 != ch2) {bad = 1; break;}
			i++;
		}
		if (bad != 0) continue;

#if 0
		for (i=0; i<NUMCHANNELS; i++) {
			if (!FSOUND_IsPlaying(channels[i])) {
				free = i;
				break;
			}
			if (i==0) continue;
			
			if (FSOUND_GetCurrentPosition(channels[i]) > oldestpos) {
				oldest = i;
				oldestpos = FSOUND_GetCurrentPosition(channels[i]);
			}
		}

		if (free < 0) {
			FSOUND_StopSound(channels[oldest]);
			free = oldest;
		}

		chan = FSOUND_PlaySoundEx(FSOUND_FREE, samples[wavnum], NULL, 1);
		if (chan == -1) return;
		FSOUND_SetFrequency(chan, dafreq*11025/4096);
		FSOUND_SetVolume(chan, davol);
		
		FSOUND_SetPaused(chan, 0);
#endif
		channels[free] = chan;
		return;
	}
}
示例#10
0
文件: main.c 项目: Dangr8/Cities3D
/*
[
	[DESCRIPTION]

	[PARAMETERS]
 
	[RETURN_VALUE]

	[REMARKS]

	[SEE_ALSO]
]
*/
int main()
{
	FSOUND_SAMPLE *samp1 = 0, *samp2 = 0;
	int key;
   
	if (FSOUND_GetVersion() < FMOD_VERSION)
	{
		printf("Error : You are using the wrong DLL version!  You should be using FMOD %.02f\n", FMOD_VERSION);
		return 1;
	}

 	/*
	    INITIALIZE
	*/
	if (!FSOUND_Init(44100, 32, 0))
	{
		printf("Error!\n");
		printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
		return 1;
	}

	/*
	    LOAD SAMPLES
	*/

	/* PCM,44,100 Hz, 8 Bit, Mono */
#if defined(__MACH__) || defined(WIN32)
	samp1 = FSOUND_Sample_Load(FSOUND_FREE, "../../media/drumloop.wav", FSOUND_2D, 0, 0);
#else
	samp1 = FSOUND_Sample_Load(FSOUND_FREE, ":::media:drumloop.wav", FSOUND_2D, 0, 0);
#endif
	if (!samp1)
	{
		printf("Error!\n");
		printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
		return 1;
	}
	FSOUND_Sample_SetMode(samp1, FSOUND_LOOP_OFF);

	/* PCM,44,100 Hz, 16 Bit, Stereo */
#if defined(__MACH__) || defined(WIN32)
	samp2 = FSOUND_Sample_Load(FSOUND_FREE, "../../media/jules.mp3", FSOUND_HW2D | FSOUND_ENABLEFX, 0, 0);
#else
	samp2 = FSOUND_Sample_Load(FSOUND_FREE, ":::media:jules.mp3", FSOUND_HW2D | FSOUND_ENABLEFX, 0, 0);
#endif
	if (!samp2)
	{
		printf("Error!\n");
		printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
		return 1;
	}

	/*
	    DISPLAY HELP
	*/

	printf("FSOUND Output Method : ");
	switch (FSOUND_GetOutput())
	{
		case FSOUND_OUTPUT_NOSOUND:	printf("FSOUND_OUTPUT_NOSOUND\n"); break;
		case FSOUND_OUTPUT_WINMM:	printf("FSOUND_OUTPUT_WINMM\n"); break;
		case FSOUND_OUTPUT_DSOUND:	printf("FSOUND_OUTPUT_DSOUND\n"); break;
		case FSOUND_OUTPUT_ASIO:	printf("FSOUND_OUTPUT_ASIO\n"); break;
		case FSOUND_OUTPUT_OSS:		printf("FSOUND_OUTPUT_OSS\n"); break;
		case FSOUND_OUTPUT_ALSA:	printf("FSOUND_OUTPUT_ALSA\n"); break;
		case FSOUND_OUTPUT_ESD:		printf("FSOUND_OUTPUT_ESD\n"); break;
		case FSOUND_OUTPUT_MAC:		printf("FSOUND_OUTPUT_MAC\n"); break;
	};
	printf("FSOUND Driver        : %s\n", FSOUND_GetDriverName(FSOUND_GetDriver()));

	printf("=========================================================================\n");
	printf("Press 1       Play SOFTWARE sound affected by following reverb dsp unit (wet)\n");
	printf("      2       Play SOFTWARE sound unaffected by following reverb dsp unit (dry)\n");
	printf("      ESC     Quit\n");
	printf("=========================================================================\n");

	/*
	    SET UP DSPS!
	*/

	SetupReverb();

	/*
        Note if we are using a dsp unit for playing sounds, callback and parameter are ignored!
    */
	DrySFXUnit = FSOUND_DSP_Create(NULL, FSOUND_DSP_DEFAULTPRIORITY_USER+100, 0);
	FSOUND_DSP_SetActive(DrySFXUnit, TRUE);


	/*
	    START PLAYING!
	*/

	do
	{
		key = 0;
		printf("channels playing = %d cpu usage = %.02f%%\r", FSOUND_GetChannelsPlaying(), FSOUND_GetCPUUsage());

//		if (kbhit())
		{
			key = getch();


			if (key == '1') 
            {
				int channel = FSOUND_PlaySound(FSOUND_FREE, samp1);
            }
			if (key == '2') 
			{
				FSOUND_PlaySoundEx(FSOUND_FREE, samp1, DrySFXUnit, FALSE);
			}
		}
		Sleep(10);

	} while (key != 27);

	printf("\n");

	/*
	    CLEANUP AND SHUTDOWN
	*/

	FSOUND_DSP_Free(DrySFXUnit);	

	CloseReverb();

	FSOUND_Sample_Free(samp1);
	FSOUND_Sample_Free(samp2);

	FSOUND_Close();
   
    return 0;
}
示例#11
0
文件: s_fmod.c 项目: HipsterLion/SRB2
EXPORT INT32 HWRAPI (Add3DSource) (source3D_data_t *src, sfx_data_t *sfx)
{
	FSOUND_SAMPLE *fmsample = NULL;
	INT32 chan = -1;
	float pos[3];
	float vel[3];
#ifdef MORESTUFF
	src->min_distance = MIN_DISTANCE;
	src->max_distance = MAX_DISTANCE;
#endif

	pos[0] = src->pos.x;
	pos[1] = src->pos.z;
	pos[2] = src->pos.y;
	vel[0] = src->pos.momx;
	vel[1] = src->pos.momz;
	vel[2] = src->pos.momy;
	if (sfx)
		fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH);
	else
		fmsample = blankfmsample;

	if (fmsample)
	{
		if (sfx && !FSOUND_Sample_SetDefaults(fmsample,
				(INT32)((*((UINT16 *)sfx->data+1))*recalc_pitch(sfx->pitch)),
				(sfx->volume == -1 ? 255 : sfx->volume),
				(sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep),
				(sfx->priority)
				)
			)
			DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_SetDefaults, SFX's ID# %i): %s\n",  sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError()));
#if 0
		if (!FSOUND_Sample_SetMinMaxDistance(fmsample, src->min_distance, src->max_distance))
			DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_SetMinMaxDistance, SFX's ID# %i): %s\n", sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError()));
#endif
		chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true);

		if (chan == -1)
		{
			DBG_Printf("FMOD(Add3DSource, FSOUND_PlaySoundEx, SFX's ID# %i): %s\n",sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError()));
			return chan;
		}
		else
		{
			if (!sfx)
				DBG_Printf("FMOD(Add3DSource, Main): Added blank-sound added to channel %i\n",chan);
#ifdef MORESTUFF
			else DBG_Printf("FMOD(Add3DSource, Main): Added sfxid# %i added to channel %i\n",sfx->id,chan);
#endif
		}
	}
	else
	{
		if (sfx)
			DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_Load, sfxid# %i): %s\n",sfx->id,FMOD_ErrorString(FSOUND_GetError()));
		else
			DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_Alloc): %s\n", FMOD_ErrorString(FSOUND_GetError()));

		return chan;
	}

	if (FSOUND_GetCurrentSample(chan))
	{
		if (!FSOUND_SetCurrentPosition(chan, 0))
			DBG_Printf("FMOD(Add3DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError()));

		if (!FSOUND_3D_SetAttributes(chan,pos,vel))
			DBG_Printf("FMOD(Add3DSource, FSOUND_3D_SetAttributes, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError()));

		if (!FSOUND_SetReserved(chan, (signed char)src->permanent))
			DBG_Printf("FMOD(Add3DSource, FSOUND_SetReserved, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError()));

		if (src->head_relative) reladd(chan);
	}

	return chan;
}