Пример #1
0
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);
}
void SoundManager2::stopMusic( void ){
    FSOUND_StopSound(musicChannel);
    if(isDebug()){
        printf("Music stopped on Channel: %i\n", musicChannel);
    }
    //TODO if we have multiple music channels, stop all of them
    //TODO another function allowing you to stop just 1 music channel
}
Пример #3
0
void CSample::Play(int channel)
{
    if(data)
    {
        FSOUND_StopSound(channel);
        FSOUND_SetVolume(channel,volume);
        FSOUND_PlaySound(channel,data);
    }
}
Пример #4
0
//---------------------------------------------------------------------------
// Func: CShip::~unload()
//---------------------------------------------------------------------------
void CShip::unload()
{ 
  FSOUND_StopSound( channel );
  closeFile();
  model.unload();
  texture.unload();
  model.releaseTexPointer();
  detachFromScene(); // sets scene = NULL; trackPtr = NULL;
  initialized = 0;
}
Пример #5
0
void CSoundSourceFMod::Stop()
{
	_State= source_stoped;

	// Stop the FMod channel
	if(_FModChannel!=-1)
	{
		FSOUND_StopSound(_FModChannel);
		_FModChannel= -1;
	}
}
Пример #6
0
void CAudioManager::StopSoundClip(int id){
  if(FSOUND_IsPlaying(id)==true)
    FSOUND_StopSound(id);
  return;

  if(m_bValidAudio == false)
    return;
  FSOUND_SAMPLE *handle;
  for(int i = 0; i < m_AudioClip.size(); i++){
    if(m_AudioClip[i].AudioID == id){
      for(int j=0; j < GetMaxChannels(); j++){
        handle = FSOUND_Sample_Get(j);
        
        if(handle == m_AudioClip[i].handle){
          if(j > -1)
            FSOUND_StopSound(j - 1);
        }
      }//for
    }//if
  }
}
Пример #7
0
bool CSoundManager::StopWave(int Nr)
{
	if (its_Sounds[Nr] == NULL)
		return false;

	if (its_Sounds[Nr]->isPlaying == false)
		return false;

	FSOUND_StopSound(its_Sounds[Nr]->Channel);

	its_Sounds[Nr]->isPlaying = false;
	its_Sounds[Nr]->Channel	 = -1;

	return true;
}
void LLAudioChannelFMOD::cleanup()
{
	if (!mChannelID)
	{
		//llinfos << "Aborting cleanup with no channelID." << llendl;
		return;
	}

	//llinfos << "Cleaning up channel: " << mChannelID << llendl;
	if (!FSOUND_StopSound(mChannelID))
	{
		LL_DEBUGS("FMOD") << "LLAudioChannelFMOD::cleanup error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl;
	}

	mCurrentBufferp = NULL;
	mChannelID = 0;
}
Пример #9
0
void glk_schannel_stop(schanid_t chan)
{
    if (!chan) {
	gli_strict_warning("schannel_stop: invalid id.");
	return;
    }

    if (chan->module)
    {
	FMUSIC_StopSong(chan->module);
	FMUSIC_FreeSong(chan->module);
	chan->module = NULL;
    }

    if (chan->sample)
    {
	FSOUND_StopSound(chan->channel);
	FSOUND_Sample_Free(chan->sample);
	chan->sample = NULL;
    }
}
Пример #10
0
void CFMOD::StopSound(void)
{
    if(!bfmod) return;
    FSOUND_StopSound(FSOUND_ALL);
}
Пример #11
0
bool CSoundManager::LoadWave(char *Filename, int Nr, bool looped)
{
	if (false == InitSuccessfull)
		return false;

	if(GameRunning == false) 
		return false;

	bool			fromrar;	
	char			*pData; 
	char			Temp[256];
	unsigned long	Size; 
	char Buffer[100];	

	fromrar = false;

	int Nummer = Nr;
	if (its_Sounds[Nummer] != NULL)
	{
		delete(its_Sounds[Nummer]);
		its_Sounds[Nummer] = NULL;
	}

	// Zuerst checken, ob sich der Sound in einem MOD-Ordner befindet
	if (CommandLineParams.RunOwnLevelList == true)
	{
		sprintf_s(Temp, "levels/%s/%s", CommandLineParams.OwnLevelList, Filename);
		if (FileExists(Temp))
			goto loadfile;
	}

	// Dann checken, ob sich das File im Standard Ordner befindet
	sprintf_s(Temp, "data/%s", Filename);
	if (FileExists(Temp))
		goto loadfile;

	// Auch nicht? Dann ist es hoffentlich im RAR file
	if (urarlib_get(&pData, &Size, Filename, RARFILENAME, convertText(RARFILEPASSWORD)) == false)
	{		
		sprintf_s(Temp, "\n-> Error loading %s from Archive !\n", Filename);
		Protokoll.WriteText(Temp, true);
		return false;
	}
	else
		fromrar = true;

loadfile:	

	its_Sounds[Nummer] = new CWave();

	// von Platte laden
	if (fromrar == false)
	{
		if (looped == false)
			its_Sounds[Nummer]->SoundData = FSOUND_Sample_Load(Nr, Temp, FSOUND_LOOP_OFF, 0, Size);
		else // mit Loop laden
			its_Sounds[Nummer]->SoundData = FSOUND_Sample_Load(Nr, Temp, FSOUND_LOOP_NORMAL, 0, Size);
	}
	// aus Rarfile laden
	else
	{
		if (looped == false)
			its_Sounds[Nummer]->SoundData = FSOUND_Sample_Load(Nr, pData, FSOUND_LOADMEMORY | FSOUND_LOOP_OFF, 0, Size);
		else // mit Loop laden
			its_Sounds[Nummer]->SoundData = FSOUND_Sample_Load(Nr, pData, FSOUND_LOADMEMORY | FSOUND_LOOP_NORMAL, 0, Size);

		free(pData);
	}

	// Temp Datei wieder löschen und Speicher freigeben
	//DeleteFile("temp.dat");
	//free(pData);

	// Und bei bedarf den loop ausschalten
	//if (looped == false)
	//	FSOUND_Sample_SetLoopMode(its_Sounds[Nummer]->SoundData, FSOUND_LOOP_OFF);

	// Fehler beim Laden ?
	//
	if (its_Sounds[Nummer]->SoundData == NULL)
	{
		// TODO FIX
/*
		strcpy_s(Buffer, "\n-> Error loading ");
		strcat_s(Buffer, Filename);
		strcat_s(Buffer, "\n");
		Protokoll.WriteText(Buffer, true);
*/

	//	return (-1);
		return false;
	}

	its_Sounds[Nummer]->isLooped = looped;

	its_LoadedSounds++;

	//its_Sounds[Nummer].Name = Filename;

	// kurz anspielen und wieder stoppen
	int Channel = FSOUND_PlaySound   (FSOUND_FREE, its_Sounds[Nr]->SoundData);
	FSOUND_SetVolume(Channel, 0);
	FSOUND_StopSound(Channel);

	// TODO FIX
/*
		strcpy_s(Buffer, TextArray [TEXT_LADE_WAVE]);
		strcat_s(Buffer, Filename);
		strcat_s(Buffer, TextArray [TEXT_LADEN_ERFOLGREICH]);
		strcat_s(Buffer, " \n");
		Protokoll.WriteText(Buffer, false);*/
	

	DisplayLoadInfo(Buffer);

	//return Nummer;
	return true;
} // LoadWave
Пример #12
0
int main()
{
    FSOUND_SAMPLE *samp1;
    int channel, originalfreq;

    if (FSOUND_GetVersion() < FMOD_VERSION)
    {
        printf("Error : You are using the wrong DLL version!  You should be using FMOD %.02f\n", FMOD_VERSION);
        return 0;
    }
		
    /*
        INITIALIZE
    */
    if (!FSOUND_Init(44100, 16, FSOUND_INIT_ACCURATEVULEVELS))
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 0;
    }

    /*
        RECORD INTO A STATIC SAMPLE
    */

    /*
        Create a sample to record into
    */
    samp1 = FSOUND_Sample_Alloc(FSOUND_UNMANAGED, RECORDLEN, FSOUND_STEREO | FSOUND_16BITS , 44100, 255, 128, 255);

    printf("\n=========================================================================\n");
    printf("Press a key to start recording 5 seconds worth of 44khz 16bit data\n");
    printf("=========================================================================\n");

    getch();

    if (!FSOUND_Record_StartSample(samp1, FALSE))	/* it will record into this sample for 5 seconds then stop */
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));

        FSOUND_Close();
        return 0;
    }

    do
    {
        printf("\rRecording position = %d", FSOUND_Record_GetPosition());
        fflush(stdout);
        Sleep(50);
    } while (FSOUND_Record_GetPosition() < RECORDLEN && !kbhit());
	
    FSOUND_Record_Stop();	/* it already stopped anyway */

    printf("\n=========================================================================\n");
    printf("Press a key to play back recorded data\n");
    printf("=========================================================================\n");

    getch();

    channel = FSOUND_PlaySound(FSOUND_FREE, samp1);

    printf("Playing back sound...\n");

    do
    {
        printf("\rPlayback position = %d", FSOUND_GetCurrentPosition(channel));
        fflush(stdout);
        Sleep(50);
    } while (FSOUND_IsPlaying(channel) && !kbhit());

    /*
        REALTIME FULL DUPLEX RECORD / PLAYBACK!
    */

    printf("\n=========================================================================\n");
    printf("Press a key to do some full duplex realtime recording!\n");
    printf("=========================================================================\n");

    getch();

    FSOUND_Sample_SetMode(samp1, FSOUND_LOOP_NORMAL);	/* make it a looping sample */

    if (!FSOUND_Record_StartSample(samp1, TRUE))	/* start recording and make it loop also */
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));

        FSOUND_Close();
        return 0;
    }

    /*
        Increase this value if the sound sounds corrupted or the time between recording
        and hearing the result is longer than it should be..
    */
    #define RECORD_DELAY_MS			25
    #define RECORD_DELAY_SAMPLES	(44100 * RECORD_DELAY_MS / 1000)

    /*
        Let the record cursor move forward a little bit first before we try to play it
	    (the position jumps in blocks, so any non 0 value will mean 1 block has been recorded)
    */
    while (!FSOUND_Record_GetPosition()) 
    {
        Sleep(1);
    }

#ifdef ENABLEREVERB
    SetupReverb();
#endif

    channel = FSOUND_PlaySound(FSOUND_FREE, samp1);	/* play the sound */

    originalfreq = FSOUND_GetFrequency(channel);
		
/*	printf("initial delay = %d\n", FSOUND_GetCurrentPosition(channel) - FSOUND_Record_GetPosition()); */

    do
    {
        int playpos, recordpos, diff;
        static int oldrecordpos = 0, oldplaypos = 0;

        playpos = FSOUND_GetCurrentPosition(channel);
        recordpos = FSOUND_Record_GetPosition();

        /* 
            NOTE : As the recording and playback frequencies arent guarranteed to be exactly in 
		    sync, we have to adjust the playback frequency to keep the 2 cursors just enough 
		    apart not to overlap. (and sound corrupted)
		    This code tries to keep it inside a reasonable size window just behind the record
		    cursor. ie [........|play window|<-delay->|<-Record cursor.............] 
        */

        /*
            Dont do this code if either of the cursors just wrapped
        */
        if (playpos > oldplaypos && recordpos > oldrecordpos)	
        {
            diff = playpos - recordpos;

            if (diff > -RECORD_DELAY_SAMPLES)
            {
                FSOUND_SetFrequency(channel, originalfreq - 1000);	/* slow it down */
            }
            else if (diff < -(RECORD_DELAY_SAMPLES * 2))
            {
                FSOUND_SetFrequency(channel, originalfreq + 1000);	/* speed it up */
            }
            else
            {
                FSOUND_SetFrequency(channel, originalfreq);	
            }
        }

        oldplaypos = playpos;
        oldrecordpos = recordpos;

        /*
            Print some info and a VU meter (vu is smoothed)
        */
        {
            char vu[19];
            float vuval, l, r;
            static float smoothedvu = 0;

            FSOUND_GetCurrentLevels(channel, &l, &r);
            vuval = (l+r) * 0.5f;
            vuval *= 18.0f;

            #define VUSPEED 0.2f

            if (vuval > smoothedvu)
            {
                smoothedvu = vuval;
            }

            smoothedvu -= VUSPEED;
            if (smoothedvu < 0)
            {
                smoothedvu = 0;
            }

		    memset(vu, 0, 19);
		    memset(vu, '=', (int)(smoothedvu));

            printf("\rPlay=%6d Rec=%6d (gap=%6d, freqchange=%6d hz) VU:%-15s", playpos, recordpos,  diff, FSOUND_GetFrequency(channel) - originalfreq, vu);
	        fflush(stdout);
        }

        Sleep(10);
    } while (!kbhit());

    FSOUND_StopSound(channel);
    FSOUND_Record_Stop();

#ifdef ENABLEREVERB		
    CloseReverb();
#endif

    /*
        CLEANUP AND SHUTDOWN
    */

    FSOUND_Close();

    return 0;
}
Пример #13
0
void CSound::StopWav(int Index)
{
	//-3 is FSOUND_ALL, stops all sounds
		FSOUND_StopSound(Index);  
}
Пример #14
0
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;
	}
}
Пример #15
0
int CSound::Stopsound(int channum)
{

	FSOUND_StopSound(channum);
	return 0;
}
Пример #16
0
bool CWave::Update()
{
	if (FSOUND_IsPlaying(Channel) == false)
	{
		isPlaying = false;
		FadeMode = FADEMODE_NON;		
	}

	float vol = (float)FSOUND_GetVolume(Channel);

	// fading?
	//
	switch (FadeMode)
	{
		// momentan nicht faden
		//
		case FADEMODE_NON:
		break;

		// einfaden
		//
		case FADEMODE_IN:
		{
			// Volume erhöhen
			//
			vol += 30.0f SYNC;

			// maximum? Dann fading anhalten
			//
			if (vol > pSoundManager->its_GlobalSoundVolume * 2.55f)
			{
				vol = pSoundManager->its_GlobalSoundVolume * 2.55f;
				FadeMode = FADEMODE_FULL;
			}

			// Lautstärke setzen
			//
			FSOUND_SetVolume(Channel, (int)vol);
		}
		break;

		// ausfaden
		//
		case FADEMODE_OUT:
		{
			// Volume verringern
			//
			vol -= 30.0f SYNC;

			// < 0 ? Dann anhalten
			//
			if (vol < 0.0f)
			{				
				FSOUND_StopSound(Channel);
				isPlaying = false;
				Channel = -1;
				FadeMode = FADEMODE_NON;
			}
			else
				FSOUND_SetVolume(Channel, (int)vol);
		}
		break;

		default:
			break;
	}

	return true;
} // Update
Пример #17
0
int main(int argc, char *argv[])
{
	FSOUND_SAMPLE *samp1;
	signed char key;
	int driver, i, channel, originalfreq;

	if (FSOUND_GetVersion() < FMOD_VERSION)
	{
		printf("Error : You are using the wrong DLL version!  You should be using FMOD %.02f\n", FMOD_VERSION);
		return 0;
	}

	/*
	    SELECT OUTPUT METHOD
	*/
	
    printf("---------------------------------------------------------\n");	
    printf("Output Type\n");	
    printf("---------------------------------------------------------\n");	
#if defined(WIN32) || defined(__CYGWIN32__) || defined(__WATCOMC__)
    printf("1 - Direct Sound\n");
    printf("2 - Windows Multimedia Waveout\n");
    printf("3 - NoSound\n");
#elif defined(__linux__)
    printf("1 - OSS - Open Sound System\n");
    printf("2 - ESD - Elightment Sound Daemon\n");
    printf("3 - ALSA 0.9 - Advanced Linux Sound Architecture\n");   
#endif
	printf("---------------------------------------------------------\n");	/* print driver names */
	printf("Press a corresponding number or ESC to quit\n");

	do
	{
		key = getch();
	} while (key != 27 && key < '1' && key > '4');
	
	switch (key)
	{
#if defined(WIN32) || defined(__CYGWIN32__) || defined(__WATCOMC__)
		case '1' :	FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
					break;
		case '2' :	FSOUND_SetOutput(FSOUND_OUTPUT_WINMM);
					break;
		case '3' :	FSOUND_SetOutput(FSOUND_OUTPUT_NOSOUND);
					break;
#elif defined(__linux__)
		case '1' :	FSOUND_SetOutput(FSOUND_OUTPUT_OSS);
					break;
		case '2' :	FSOUND_SetOutput(FSOUND_OUTPUT_ESD);
					break;
		case '3' :	FSOUND_SetOutput(FSOUND_OUTPUT_ALSA);
					break;
#endif
		default :	return 0;
	}
	
	/*
	    SELECT OUTPUT DRIVER
	*/

	/* The following list are the drivers for the output method selected above. */
    printf("---------------------------------------------------------\n");	
    switch (FSOUND_GetOutput())
    {
        case FSOUND_OUTPUT_NOSOUND:    printf("NoSound"); break;
        case FSOUND_OUTPUT_WINMM:      printf("Windows Multimedia Waveout"); break;
        case FSOUND_OUTPUT_DSOUND:     printf("Direct Sound"); break;
        case FSOUND_OUTPUT_OSS:        printf("Open Sound System"); break;
        case FSOUND_OUTPUT_ESD:        printf("Enlightment Sound Daemon"); break;
        case FSOUND_OUTPUT_ALSA:       printf("ALSA"); break;       
    };
	printf(" Driver list\n");	
	printf("---------------------------------------------------------\n");	

	for (i=0; i < FSOUND_GetNumDrivers(); i++) 
	{
		printf("%d - %s\n", i+1, FSOUND_GetDriverName(i));	/* print driver names */
	}
	printf("---------------------------------------------------------\n");	/* print driver names */
	printf("Press a corresponding number or ESC to quit\n");

	do
	{
		key = getch();
		if (key == 27) 
		{
			FSOUND_Close();
			return 0;
		}
		driver = key - '1';
	} while (driver < 0 || driver >= FSOUND_GetNumDrivers());

	FSOUND_SetDriver(driver);					/* Select sound card (0 = default) */

	/*
	    SELECT MIXER
	*/

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


	/*
	    SELECT INPUT DRIVER (can be done before or after init)
	*/

	/* The following list are the drivers for the output method selected above. */
	printf("---------------------------------------------------------\n");	
	switch (FSOUND_GetOutput())
	{
        case FSOUND_OUTPUT_NOSOUND:    printf("NoSound"); break;
        case FSOUND_OUTPUT_WINMM:      printf("Windows Multimedia Waveout"); break;
        case FSOUND_OUTPUT_DSOUND:     printf("Direct Sound"); break;
        case FSOUND_OUTPUT_OSS:        printf("Open Sound System"); break;
        case FSOUND_OUTPUT_ESD:        printf("Enlightment Sound Daemon"); break;
        case FSOUND_OUTPUT_ALSA:       printf("ALSA"); break;       
	};
	printf(" Recording device driver list\n");	
	printf("---------------------------------------------------------\n");	

	for (i=0; i < FSOUND_Record_GetNumDrivers(); i++) 
	{
		printf("%d - %s\n", i+1, FSOUND_Record_GetDriverName(i));	/* print driver names */
	}
	printf("---------------------------------------------------------\n");	/* print driver names */
	printf("Press a corresponding number or ESC to quit\n");

	do
	{
		key = getch();
		if (key == 27) 
			return 0;
		driver = key - '1';
	} while (driver < 0 || driver >= FSOUND_Record_GetNumDrivers());

	if (!FSOUND_Record_SetDriver(driver))	/* Select input sound card (0 = default) */
	{
		printf("Error!\n");
		printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
		FSOUND_Close();
		return 0;
	}
	
	/*
	    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_OSS:        printf("FSOUND_OUTPUT_OSS\n"); break;
        case FSOUND_OUTPUT_ESD:        printf("FSOUND_OUTPUT_ESD\n"); break;
        case FSOUND_OUTPUT_ALSA:       printf("FSOUND_OUTPUT_ALSA\n"); break;       
	};

	printf("FSOUND Mixer         : ");
	switch (FSOUND_GetMixer())
	{
		case FSOUND_MIXER_BLENDMODE:	printf("FSOUND_MIXER_BLENDMODE\n"); break;
		case FSOUND_MIXER_MMXP5:		printf("FSOUND_MIXER_MMXP5\n"); break;
		case FSOUND_MIXER_MMXP6:		printf("FSOUND_MIXER_MMXP6\n"); break;
		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("FSOUND Record Driver : %s\n", FSOUND_Record_GetDriverName(FSOUND_Record_GetDriver()));

	/*
	    RECORD INTO A STATIC SAMPLE
	*/

	/*
        Create a sample to record into
    */
    samp1 = FSOUND_Sample_Alloc(FSOUND_UNMANAGED, RECORDLEN, FSOUND_STEREO | FSOUND_16BITS , RECORDRATE, 255, 128, 255);
    if (!samp1)
    {
        printf("Error!\n");
		printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        FSOUND_Close();
        return 0;
    }

	printf("\n");
	printf("=========================================================================\n");
	printf("Press a key to start recording 5 seconds worth of data\n");
	printf("=========================================================================\n");

	getch();

	if (!FSOUND_Record_StartSample(samp1, FALSE))	/* it will record into this sample for 5 seconds then stop */
	{
		printf("Error!\n");
		printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));

		FSOUND_Close();
		return 0;
	}

	do
	{
		printf("Recording position = %d\r", FSOUND_Record_GetPosition());
		Sleep(50);
	} while (FSOUND_Record_GetPosition() < RECORDLEN && !kbhit());

	FSOUND_Record_Stop();	/* it already stopped anyway */

	printf("\n=========================================================================\n");
	printf("Press a key to play back recorded data\n");
	printf("=========================================================================\n");

	getch();

	channel = FSOUND_PlaySound(FSOUND_FREE, samp1);

	printf("Playing back sound...\n");

	do
	{
		printf("Playback position = %d\r", FSOUND_GetCurrentPosition(channel));
		Sleep(50);
	} while (FSOUND_IsPlaying(channel) && !kbhit());

    if (FSOUND_GetOutput() == FSOUND_OUTPUT_OSS)
    {
        FSOUND_Sample_Free(samp1);
        FSOUND_Close();
        return 0;
    }

	/*
	    REALTIME FULL DUPLEX RECORD / PLAYBACK!
	*/

	printf("\n=========================================================================\n");
	printf("Press a key to do some full duplex realtime recording!\n");
	printf("(with reverb for mmx users)\n");
	printf("=========================================================================\n");

	getch();

	FSOUND_Sample_SetMode(samp1, FSOUND_LOOP_NORMAL);	/* make it a looping sample */

	if (!FSOUND_Record_StartSample(samp1, TRUE))	/* start recording and make it loop also */
	{
		printf("Error!\n");
		printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));

		FSOUND_Close();
		return 0;
	}

    /*
        Increase this value if the sound sounds corrupted or the time between recording
        and hearing the result is longer than it should be..
    */
    #define RECORD_DELAY_MS       25
    #define RECORD_DELAY_SAMPLES  (RECORDRATE * RECORD_DELAY_MS / 1000)

    /*
        Let the record cursor move forward a little bit first before we try to play it
        (the position jumps in blocks, so any non 0 value will mean 1 block has been recorded)
    */
    while (!FSOUND_Record_GetPosition()) 
    {
        Sleep(1);
    }

#ifdef ENABLEREVERB
	SetupReverb();
#endif

	channel = FSOUND_PlaySound(FSOUND_FREE, samp1);	/* play the sound */

	originalfreq = FSOUND_GetFrequency(channel);
		
/*	printf("initial delay = %d\n", FSOUND_GetCurrentPosition(channel) - FSOUND_Record_GetPosition()); */

	do
	{
		int playpos, recordpos, diff;
		static int oldrecordpos = 0, oldplaypos = 0;

		playpos = FSOUND_GetCurrentPosition(channel);
		recordpos = FSOUND_Record_GetPosition();

		/* 
            NOTE : As the recording and playback frequencies arent guarranteed to be exactly in 
		    sync, we have to adjust the playback frequency to keep the 2 cursors just enough 
		    apart not to overlap. (and sound corrupted)
		    This code tries to keep it inside a reasonable size window just behind the record
		    cursor. ie [........|play window|<-delay->|<-Record cursor.............] 
        */

		/*
            Dont do this code if either of the cursors just wrapped
        */
		if (playpos > oldplaypos && recordpos > oldrecordpos)	
		{
			diff = playpos - recordpos;

			if (diff > -RECORD_DELAY_SAMPLES)
            {
				FSOUND_SetFrequency(channel, originalfreq - 1000);	/* slow it down */
            }
			else if (diff < -(RECORD_DELAY_SAMPLES * 2))
            {
				FSOUND_SetFrequency(channel, originalfreq + 1000);	/* speed it up */
            }
			else
            {
				FSOUND_SetFrequency(channel, originalfreq);	
            }
		}

		oldplaypos = playpos;
		oldrecordpos = recordpos;

		/*
            Print some info and a VU meter (vu is smoothed)
        */
		{
			char vu[19];
			float vuval, l, r;
			static float smoothedvu = 0;

			FSOUND_GetCurrentLevels(channel, &l, &r);
            vuval = (l+r) * 0.5f;
            vuval *= 18.0f;

			#define VUSPEED 0.2f

			if (vuval > smoothedvu)
            {
				smoothedvu = vuval;
            }

			smoothedvu -= VUSPEED;
			if (smoothedvu < 0)
            {
				smoothedvu = 0;
            }

			memset(vu, 0, 19);
			memset(vu, '=', (int)(smoothedvu));

			printf("Play=%6d Rec=%6d (gap=%6d, freqchange=%6d hz) VU:%-15s\r", playpos, recordpos,  diff, FSOUND_GetFrequency(channel) - originalfreq, vu);
		}

		Sleep(10);
	} while (!kbhit());

    getch();

	FSOUND_StopSound(channel);
	FSOUND_Record_Stop();

#ifdef ENABLEREVERB		
	CloseReverb();
#endif

	/*
	    CLEANUP AND SHUTDOWN
	*/

    FSOUND_Sample_Free(samp1);
    FSOUND_Close();
    return 0;
}