Ejemplo n.º 1
0
//Chamada do main
int main(void)
{
//Inicia o som

    FSOUND_SAMPLE *samp1 = 0; //cria um ponteiro para armazenar o som em memória
    if (FSOUND_GetVersion() < FMOD_VERSION) // verificação da versão do fmod caso a versão do FSOUND for menor que a do FMOD retorna uma menssagem de erro
    {
        printf("Error : You are using the wrong DLL version!  You should be using FMOD %.02f\n", FMOD_VERSION);
        return 1;
    }
    //    Seleciona a saída de audio
    FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);

    //    Seleção do driver
   FSOUND_GetOutput(); // indentifica o tipo de saida
   FSOUND_GetMixer(); // indentifica o mixer
   FSOUND_SetDriver(0); // seta o driver de som que vai ser usado

    //    Inicializando o FMOD
    if (!FSOUND_Init(44100, 32, FSOUND_INIT_GLOBALFOCUS)) // se o valor do FSOUND_Init for 0 execute o tratamento de erro
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }

    // Carrengando o Sample
    // PCM,44,100 Hz, 32 Bit, Mono ou uma mp3 ou outros formatos suportados pelo fmod
    samp1 = FSOUND_Sample_Load(FSOUND_UNMANAGED, "topgear.ogg", FSOUND_NORMAL | FSOUND_HW2D, 0, 0); 
    if (!samp1)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }

   // Aqui fala qual maneira o sample ira tocar caso falhe excute o tratamento de erro
    if(!FSOUND_Sample_SetMode(samp1, FSOUND_LOOP_NORMAL))// o loop normal toca a musica continuamente ate o programa fechar
   {
   printf("Error!\n");   
    printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
   }
   // Aqui sera tocado o sample ,caso falhe, execute o tratamento de erro
   if(!FSOUND_PlaySound(FSOUND_FREE, samp1))
   {
   printf("Error!\n");   
   printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
   }
    //Fim do codigo do som \\o  \o/   o//\o/
    //Sleep(10000);  // executa o som durante 10 segundos     (Essa funcao esta desativada no Street Frog)
    printf ("Jogo desenvolvido como Projeto Final para a Disciplina de Computacao Grafica");
    printf ("\nUFRN - CT - DCA");
    printf ("\nPor Claudio Henrique | Paulo Bruno | Thaisa Ramos");
    //printf ("\n");


    //E por fim a chamada para o OpenGL
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB); //Modo para nao exibir rastros na tela
    glutInitWindowSize (890, 550); //Tamanho da janela
    glutInitWindowPosition (50, 50);  //Localizacao inicial da janela
	glutCreateWindow("Ajude o menino a chegar em casa"); //Nome da janela
    glutKeyboardFunc(Teclado); //Chama as funcoes do teclado
    glutSpecialFunc(Mover);  //Chama as funcoes especias do teclado (setas de movimento)
	Inicializa(); 
	iniciaText();
	glutDisplayFunc(Desenha); //Chama o desenho
	glutReshapeFunc(AlteraTamanhoJanela); //Correcao de largura e altura para a janela
    glutTimerFunc(10,movimentar,1);       //Chamada de movimento do carro
    glutTimerFunc(10,movimentacarro,1);   //Chamada de movimento do carro
    glutTimerFunc(10,movimentacarro2,1);  //Chamada de movimento do carro
    glutTimerFunc(10,movermad,1);         //Chamada de movimento da madeira
    glutTimerFunc(10,movermad1,1);        //Chamada de movimento da madeira
    glutTimerFunc(10,movermad2,1);        //Chamada de movimento da madeira
    glutMouseFunc(GerenciaMouse);         //Ativa o botao direito
	glutMainLoop();
	//Final das funcoes do OpenGL
	
    //    limpando a memoria e fechando o fmod (Som)
    FSOUND_Sample_Free(samp1); // limpa a memoria ultilizada pelo ponteiro do sample
    FSOUND_Close();  // encerra a API FMOD

}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
/*
[
    [DESCRIPTION]
    main entry point into streamer example.

    [PARAMETERS]
    'argc'    Number of command line parameters.
    'argv'    Parameter list
 
    [RETURN_VALUE]
    void

    [REMARKS]

    [SEE_ALSO]
]
*/
int main(int argc, char *argv[])
{
    FSOUND_STREAM *stream;
    FSOUND_SAMPLE *sptr;
    char           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;
    }

    if (argc < 2)
    {
        printf("-------------------------------------------------------------\n");
        printf("FMOD Streamer example.\n");
        printf("Copyright (c) Firelight Technologies Pty, Ltd, 1999-2004.\n");
        printf("-------------------------------------------------------------\n");
        printf("Syntax: stream infile.[mp2 mp3 wav ogg wma asf]\n\n");
        return 1;
    }

#if defined(WIN32) || defined(_WIN64) || defined(__CYGWIN32__) || defined(__WATCOMC__)
    FSOUND_SetOutput(FSOUND_OUTPUT_WINMM);
#elif defined(__linux__)
    FSOUND_SetOutput(FSOUND_OUTPUT_OSS);
#endif

    // Set custom file callbacks?  This doesnt have to be done, its just here as an example.
    FSOUND_File_SetCallbacks(myopen, myclose, myread, myseek, mytell);

    // ==========================================================================================
    // SELECT DRIVER
    // ==========================================================================================
    {
        long i,driver=0;
        char key;

        // 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_A3D:        printf("A3D"); break;
            case FSOUND_OUTPUT_OSS:        printf("Open Sound System"); break;
            case FSOUND_OUTPUT_ESD:        printf("Enlightenment 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) exit(0);

            driver = key - '1';
        } while (driver < 0 || driver >= FSOUND_GetNumDrivers());

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

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

    FSOUND_Stream_SetBufferSize(1000);

    // ==========================================================================================
    // OPEN STREAM (use #if 1 for streaming from memory)
    // ==========================================================================================
#if 0
    {
        FILE      *fp;
        int        length;
        char      *data;

        fp = fopen(argv[1], "rb");
        if (!fp)
        {
            printf("Error!\n");
            printf("File Not Found\n");
            FSOUND_Close();
            return 1;
        }
        fseek(fp, 0, SEEK_END);
        length = ftell(fp);
        fseek(fp, 0, SEEK_SET);

        data = (char *)malloc(length);
        fread(data, length, 1, fp);
        fclose(fp);

        stream = FSOUND_Stream_Open(data, FSOUND_NORMAL | FSOUND_MPEGACCURATE | FSOUND_LOADMEMORY, 0, length);

        // The memory pointer MUST remain valid while streaming!
    }
#else

    if (!strnicmp(argv[1], "http:", 5))
    {
        printf("Connecting to %s, please wait (this may take some time)....\n", argv[1]);
    }
    stream = FSOUND_Stream_Open(argv[1], FSOUND_NORMAL | FSOUND_MPEGACCURATE, 0, 0);
    if (!stream)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        FSOUND_Close();

        return 1;
    }

#endif

    // ==========================================================================================
    // SET AN END OF STREAM CALLBACK AND RIFF SYNCH POINTS CALLBACK
    // ==========================================================================================
    FSOUND_Stream_SetEndCallback(stream, endcallback, 0);
    FSOUND_Stream_SetSyncCallback(stream, endcallback, 0);
   

    printf("=========================================================================\n");
    printf("Press SPACE to pause/unpause\n");
    printf("Press 'f'   to fast forward 2 seconds\n");
    printf("Press ESC   to quit\n");
    printf("=========================================================================\n");
    printf("Playing stream...\n\n");
  
    sptr = FSOUND_Stream_GetSample(stream);
    if (sptr)
    {
        int freq;
        FSOUND_Sample_GetDefaults(sptr, &freq, NULL, NULL, NULL);
        printf("Name      : %s\n", FSOUND_Sample_GetName(sptr));
        printf("Frequency : %d\n\n", freq);
    }

    key = 0;
    do
    {
        if (channel < 0)
        {
            // ==========================================================================================
            // PLAY STREAM
            // ==========================================================================================
            channel = FSOUND_Stream_PlayEx(FSOUND_FREE, stream, NULL, TRUE);
            FSOUND_SetPaused(channel, FALSE);
        }

        if (kbhit())
        {
            key = getch();
            if (key == ' ')
            {
                FSOUND_SetPaused(channel, !FSOUND_GetPaused(channel));
            }
            if (key == 'f')
            {
                FSOUND_Stream_SetTime(stream, FSOUND_Stream_GetTime(stream) + 2000);
            }
        }

        printf("pos %6d/%6d time %02d:%02d/%02d:%02d cpu %5.02f%%   \r", FSOUND_Stream_GetPosition(stream), 
                                                                         FSOUND_Stream_GetLength(stream), 
                                                                         FSOUND_Stream_GetTime(stream) / 1000 / 60, 
                                                                         FSOUND_Stream_GetTime(stream) / 1000 % 60, 
                                                                         FSOUND_Stream_GetLengthMs(stream) / 1000 / 60, 
                                                                         FSOUND_Stream_GetLengthMs(stream) / 1000 % 60, 
                                                                         FSOUND_GetCPUUsage());

        Sleep(10);
    
    } while (key != 27);

    printf("\n");

    FSOUND_Stream_Close(stream);

    FSOUND_Close();

    return 0;
}
Ejemplo n.º 4
0
/*
[
    [DESCRIPTION]

    [PARAMETERS]
 
    [RETURN_VALUE]

    [REMARKS]

    [SEE_ALSO]
]
*/
int main(int argc, char *argv[])
{
    FSOUND_STREAM *stream;
    int read_percent = 0, i, driver = 0, channel = -1, status = 0, openstate, bitrate;
    unsigned int flags;
    char s[256] = "";
    char 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;
    }

    if ((argc < 2) || (strnicmp(argv[1], "http:", 5)))
    {
        printf("-------------------------------------------------------------\n");
        printf("FMOD netstream example.\n");
        printf("Copyright (c) Firelight Technologies Pty, Ltd, 1999-2003.\n");
        printf("-------------------------------------------------------------\n");
        printf("Syntax:  netstream <url>\n");
        printf("Example: netstream http://www.fmod.org/stream.mp3\n\n");
        return 1;
    }

#if defined(WIN32) || defined(__CYGWIN32__) || defined(__WATCOMC__)
    FSOUND_SetOutput(FSOUND_OUTPUT_WINMM);
#elif defined(__linux__)
    FSOUND_SetOutput(FSOUND_OUTPUT_OSS);
#endif

    // ==========================================================================================
    // SELECT DRIVER
    // ==========================================================================================
    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_A3D:        printf("A3D");                        break;
        case FSOUND_OUTPUT_OSS:        printf("Open Sound System");          break;
        case FSOUND_OUTPUT_ESD:        printf("Enlightenment 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));
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = getch();
        if (key == 27) exit(0);

        driver = key - '1';
    } while (driver < 0 || driver >= FSOUND_GetNumDrivers());

    FSOUND_SetDriver(driver);

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

    /*
        Internet streams can work with a much smaller stream buffer than normal streams because they
        use another level of buffering on top of the stream buffer.
    */
    FSOUND_Stream_SetBufferSize(100);

    /*
        Here's where we set the size of the network buffer and some buffering parameters.
        In this case we want a network buffer of 64k, we want it to prebuffer 60% of that when we first
        connect, and we want it to rebuffer 80% of that whenever we encounter a buffer underrun.
    */
    FSOUND_Stream_Net_SetBufferProperties(64000, 60, 80);

    /*
        Open the stream using FSOUND_NONBLOCKING because the connect/buffer process might take a long time
    */
    stream = FSOUND_Stream_Open(argv[1], FSOUND_NORMAL | FSOUND_NONBLOCKING, 0, 0);
    if (!stream)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        FSOUND_Close();
        return 1;
    }

    printf("\nPress ESC to quit...\n\n");
  
    key = 0;
    do
    {
        if (kbhit())
        {
            key = getch();
        }

        /*
            Play the stream if it's not already playing
        */
        if (channel < 0)
        {
            channel = FSOUND_Stream_PlayEx(FSOUND_FREE, stream, NULL, TRUE);
            FSOUND_SetPaused(channel, FALSE);

            if (channel != -1)
            {
                FSOUND_Stream_Net_SetMetadataCallback(stream, metacallback, 0);
            }
        }

        openstate = FSOUND_Stream_GetOpenState(stream);
        if ((openstate == -1) || (openstate == -3))
        {
            printf("\nERROR: failed to open stream!\n");
            printf("SERVER: %s\n", FSOUND_Stream_Net_GetLastServerStatus());
            break;
        }

        FSOUND_Stream_Net_GetStatus(stream, &status, &read_percent, &bitrate, &flags);

        /*
            Show how much of the net buffer is used and what the status is
        */
        if (metanum)
        {
            printf("%s - %s\n", artist, title);
            metanum = 0;
        }
        s[0] = 0;
        strncat(s, bar, (read_percent >> 1) + (read_percent & 1));
        strncat(s, nobar, (100 - read_percent) >> 1);
        printf("|%s| %d%%  %s\r", s, read_percent, status_str[status]);

        Sleep(16);
    
    } while (key != 27);

    printf("\n");

    FSOUND_Stream_Close(stream);
    FSOUND_Close();

    return 0;
}
Ejemplo n.º 5
0
/*
[
	[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;
}
Ejemplo n.º 6
0
void LLAudioChannelFMOD::update3DPosition()
{
    if (!mChannelID)
    {
        // We're not actually a live channel (i.e., we're not playing back anything)
        return;
    }

    LLAudioBufferFMOD *bufferp = (LLAudioBufferFMOD *)mCurrentBufferp;
    if (!bufferp)
    {
        // We don't have a buffer associated with us (should really have been picked up
        // by the above if.
        return;
    }

    if (mCurrentSourcep->isAmbient())
    {
        // Ambient sound, don't need to do any positional updates.
        bufferp->set3DMode(false);
    }
    else
    {
        // Localized sound.  Update the position and velocity of the sound.
        bufferp->set3DMode(true);

        LLVector3 float_pos;
        float_pos.setVec(mCurrentSourcep->getPositionGlobal());
        if (!FSOUND_3D_SetAttributes(mChannelID, float_pos.mV, mCurrentSourcep->getVelocity().mV))
        {
            LL_DEBUGS("FMOD") << "LLAudioChannelFMOD::update3DPosition error: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL;
        }
    }
}
Ejemplo n.º 7
0
bool LLAudioEngine_FMOD::init(const S32 num_channels, void* userdata)
{
    LLAudioEngine::init(num_channels, userdata);

    // Reserve one extra channel for the http stream.
    if (!FSOUND_SetMinHardwareChannels(num_channels + 1))
    {
        LL_WARNS("AppInit") << "FMOD::init[0](), error: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL;
    }

    LL_DEBUGS("AppInit") << "LLAudioEngine_FMOD::init() initializing FMOD" << LL_ENDL;

    F32 version = FSOUND_GetVersion();
    if (version < FMOD_VERSION)
    {
        LL_WARNS("AppInit") << "Error : You are using the wrong FMOD version (" << version
                            << ")!  You should be using FMOD " << FMOD_VERSION << LL_ENDL;
        //return false;
    }

    U32 fmod_flags = 0x0;

#if LL_WINDOWS
    // Windows needs to know which window is frontmost.
    // This must be called before FSOUND_Init() per the FMOD docs.
    // This could be used to let FMOD handle muting when we lose focus,
    // but we don't actually want to do that because we want to distinguish
    // between minimized and not-focused states.
    if (!FSOUND_SetHWND(userdata))
    {
        LL_WARNS("AppInit") << "Error setting FMOD window: "
                            << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL;
        return false;
    }
    // Play audio when we don't have focus.
    // (For example, IM client on top of us.)
    // This means we also try to play audio when minimized,
    // so we manually handle muting in that case. JC
    fmod_flags |= FSOUND_INIT_GLOBALFOCUS;
#endif

#if LL_LINUX
    // initialize the FMOD engine

    // This is a hack to use only FMOD's basic FPU mixer
    // when the LL_VALGRIND environmental variable is set,
    // otherwise valgrind will fall over on FMOD's MMX detection
    if (getenv("LL_VALGRIND"))		/*Flawfinder: ignore*/
    {
        LL_INFOS("AppInit") << "Pacifying valgrind in FMOD init." << LL_ENDL;
        FSOUND_SetMixer(FSOUND_MIXER_QUALITY_FPU);
    }

    // If we don't set an output method, Linux FMOD always
    // decides on OSS and fails otherwise.  So we'll manually
    // try ESD, then OSS, then ALSA.
    // Why this order?  See SL-13250, but in short, OSS emulated
    // on top of ALSA is ironically more reliable than raw ALSA.
    // Ack, and ESD has more reliable failure modes - but has worse
    // latency - than all of them, so wins for now.
    bool audio_ok = false;

    if (!audio_ok)
    {
        if (NULL == getenv("LL_BAD_FMOD_ESD")) /*Flawfinder: ignore*/
        {
            LL_DEBUGS("AppInit") << "Trying ESD audio output..." << LL_ENDL;
            if(FSOUND_SetOutput(FSOUND_OUTPUT_ESD) &&
                    FSOUND_Init(44100, num_channels, fmod_flags))
            {
                LL_DEBUGS("AppInit") << "ESD audio output initialized OKAY"
                                     << LL_ENDL;
                audio_ok = true;
            } else {
                LL_WARNS("AppInit") << "ESD audio output FAILED to initialize: "
                                    << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL;
            }
        } else {
            LL_DEBUGS("AppInit") << "ESD audio output SKIPPED" << LL_ENDL;
        }
    }
    if (!audio_ok)
    {
        if (NULL == getenv("LL_BAD_FMOD_OSS")) 	 /*Flawfinder: ignore*/
        {
            LL_DEBUGS("AppInit") << "Trying OSS audio output..."	<< LL_ENDL;
            if(FSOUND_SetOutput(FSOUND_OUTPUT_OSS) &&
                    FSOUND_Init(44100, num_channels, fmod_flags))
            {
                LL_DEBUGS("AppInit") << "OSS audio output initialized OKAY" << LL_ENDL;
                audio_ok = true;
            } else {
                LL_WARNS("AppInit") << "OSS audio output FAILED to initialize: "
                                    << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL;
            }
        } else {
            LL_DEBUGS("AppInit") << "OSS audio output SKIPPED" << LL_ENDL;
        }
    }
    if (!audio_ok)
    {
        if (NULL == getenv("LL_BAD_FMOD_ALSA"))		/*Flawfinder: ignore*/
        {
            LL_DEBUGS("AppInit") << "Trying ALSA audio output..." << LL_ENDL;
            if(FSOUND_SetOutput(FSOUND_OUTPUT_ALSA) &&
                    FSOUND_Init(44100, num_channels, fmod_flags))
            {
                LL_DEBUGS("AppInit") << "ALSA audio output initialized OKAY" << LL_ENDL;
                audio_ok = true;
            } else {
                LL_WARNS("AppInit") << "ALSA audio output FAILED to initialize: "
                                    << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL;
            }
        } else {
            LL_DEBUGS("AppInit") << "OSS audio output SKIPPED" << LL_ENDL;
        }
    }
    if (!audio_ok)
    {
        LL_WARNS("AppInit") << "Overall audio init failure." << LL_ENDL;
        return false;
    }

    // On Linux, FMOD causes a SIGPIPE for some netstream error
    // conditions (an FMOD bug); ignore SIGPIPE so it doesn't crash us.
    // NOW FIXED in FMOD 3.x since 2006-10-01.
    //signal(SIGPIPE, SIG_IGN);

    // We're interested in logging which output method we
    // ended up with, for QA purposes.
    switch (FSOUND_GetOutput())
    {
    case FSOUND_OUTPUT_NOSOUND:
        LL_DEBUGS("AppInit") << "Audio output: NoSound" << LL_ENDL;
        break;
    case FSOUND_OUTPUT_OSS:
        LL_DEBUGS("AppInit") << "Audio output: OSS" << LL_ENDL;
        break;
    case FSOUND_OUTPUT_ESD:
        LL_DEBUGS("AppInit") << "Audio output: ESD" << LL_ENDL;
        break;
    case FSOUND_OUTPUT_ALSA:
        LL_DEBUGS("AppInit") << "Audio output: ALSA" << LL_ENDL;
        break;
    default:
        LL_INFOS("AppInit") << "Audio output: Unknown!" << LL_ENDL;
        break;
    };

#else // LL_LINUX

    // initialize the FMOD engine
    if (!FSOUND_Init(44100, num_channels, fmod_flags))
    {
        LL_WARNS("AppInit") << "Error initializing FMOD: "
                            << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL;
        return false;
    }

#endif

    // set up our favourite FMOD-native streaming audio implementation if none has already been added
    if (!getStreamingAudioImpl()) // no existing implementation added
        setStreamingAudioImpl(new LLStreamingAudio_FMOD());

    LL_DEBUGS("AppInit") << "LLAudioEngine_FMOD::init() FMOD initialized correctly" << LL_ENDL;

    mInited = true;

    return true;
}
Ejemplo n.º 8
0
EXPORT INT32 HWRAPI (StartSource) (INT32 chan)
{
	FSOUND_SAMPLE *fmsample;
	if (chan < 0)
		return -1;

	fmsample = FSOUND_GetCurrentSample(chan);

	if (!fmsample)
		return -1;

#ifdef MORESTUFF
	if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D)
	{
		DBG_Printf("FMOD(StartSource,Main): Starting 2D channel %i?\n",chan);
		//return -1;
	}
	else
	{
		DBG_Printf("FMOD(StartSource,Main): Starting 3D Channel %i?\n",chan);
		//return -1;
	}
#endif

	if (FSOUND_GetPaused(relcheckup(chan)))
	{
		if (!FSOUND_SetPaused(relcheckup(chan), false))
			DBG_Printf("FMOD(StartSource,FSOUND_SetPaused, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError()));
		else if (relstack(chan) != -1)
			relarray[relstack(chan)].pos.active = false;
	}
	else
		DBG_Printf("FMOD(StartSource,FSOUND_GetPaused): Channel %i is playing already",chan);

	return chan;
}
Ejemplo n.º 9
0
EXPORT void HWRAPI (StopSource) (INT32 chan)
{
	FSOUND_SAMPLE *fmsample;

	if (chan < 0)
		return;

	fmsample = FSOUND_GetCurrentSample(chan);

	if (!fmsample)
		return;

	if (!FSOUND_GetPaused(relcheckup(chan)))
	{
		if (!FSOUND_SetPaused(relcheckup(chan),true))
		{
			DBG_Printf("FMOD(StopSource,FSOUND_SetPaused, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError()));
		}
		else if (relstack(chan) != -1)
		{
			relarray[relstack(chan)].pos.active = false;
		}
	}
#ifdef MORESTUFF
	else
		DBG_Printf("FMOD(StopSource,FSOUND_GetPaused): Channel %i is stopped already\n",chan);
#endif
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
/******************************************************************************
 *
 * 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;
}
Ejemplo n.º 12
0
/******************************************************************************
 *
 * Initialise driver and listener
 *
 *****************************************************************************/
EXPORT INT32 HWRAPI(Startup) (I_Error_t FatalErrorFunction, snddev_t *snd_dev)
{
	boolean inited = false;
	INT32 i = 0;

	I_ErrorFMOD = FatalErrorFunction;

	if (FSOUND_GetVersion() < FMOD_VERSION)
	{
		DBG_Printf("Error : You are using the wrong DLL version!\nYou should be using FMOD %.02f\n", FMOD_VERSION);
		return inited;
	}
	else
		DBG_Printf("S_FMOD Init(): FMOD_SOUND driver for SRB2 %s\n",VERSIONSTRING);

	if (!FSOUND_SetMinHardwareChannels(STATIC_SOURCES_NUM*4))
		DBG_Printf("FMOD(Startup,FSOUND_SetMinHardwareChannels,# of Channels Min: %i): %s\n",STATIC_SOURCES_NUM*4, FMOD_ErrorString(FSOUND_GetError()));

	if (!FSOUND_SetMaxHardwareChannels(0))
		DBG_Printf("FMOD(Startup,FSOUND_SetMaxHardwareChannels,# of Channels Min: %i): %s\n",0, FMOD_ErrorString(FSOUND_GetError()));

	for (i = 0; i < FSOUND_GetNumDrivers(); i++)
	{
		UINT32 caps = 0;
		DBG_Printf("Driver Caps, if any\n");

		if (FSOUND_GetDriverCaps(i, &caps))
		{
			DBG_Printf("FMOD: Driver# %d - %s\n", i+1, FSOUND_GetDriverName(i));    // print driver names
			if (caps & FSOUND_CAPS_HARDWARE)
				DBG_Printf("This sound hardware supports hardware accelerated 3d sound.\n");

			if (caps & FSOUND_CAPS_EAX2)
				DBG_Printf("This sound hardware supports hardware accelerated 3d sound with EAX 2 reverb.\n");

			if (caps & FSOUND_CAPS_EAX3)
				DBG_Printf("This sound hardware supports hardware accelerated 3d sound with EAX 3 reverb.\n");
		}
		else
			DBG_Printf("FMOD(Startup,FSOUND_GetDriverCaps,%s): %s\n",FSOUND_GetDriverName(i), FMOD_ErrorString(FSOUND_GetError()));
	}
#if defined (_WIN32) || defined (_WIN64)
	if (!FSOUND_SetHWND(snd_dev->hWnd))
	{
		DBG_Printf("FMOD(Startup,FSOUND_SetHWND): %s\n", FMOD_ErrorString(FSOUND_GetError()));
		return inited;
	}
	else
#endif
	{
		DBG_Printf("Initialising FMOD %.02f\n",FMOD_VERSION);
		inited = FSOUND_Init(snd_dev->sample_rate,MAXCHANNEL,0);
	}

	if (!inited)
	{
		DBG_Printf("FMOD(Startup,Main): %s\n", FMOD_ErrorString(FSOUND_GetError()));
	}
	else
	{
#ifdef OLDFMOD
		DBG_Printf("   Maximum hardware mixing buffers %d\n", FSOUND_GetNumHardwareChannels());
#else
		INT32 num2DC, num3DC, numDC;

		if (FSOUND_GetNumHWChannels(&num2DC,&num3DC,&numDC))
		{
			DBG_Printf("   Maximum hardware 2D buffers %d\n", num2DC);
			DBG_Printf("   Maximum hardware 3D buffers %d\n", num3DC);
			DBG_Printf("   Maximum hardware mixing buffers %d\n", numDC);
		}
		else
			DBG_Printf("FMOD(Startup,FSOUND_GetNumHWChannels): %s\n", FMOD_ErrorString(FSOUND_GetError()));
#endif

		DBG_Printf("FMOD is up and running at %i KHZ\n",FSOUND_GetOutputRate());
		DBG_Printf("Sound hardware capabilities:\n");

		if (FSOUND_GetDriverName(FSOUND_GetDriver()))
			DBG_Printf("   Driver is %s\n",FSOUND_GetDriverName(FSOUND_GetDriver()));
		else
			DBG_Printf("FMOD(Startup,FSOUND_GetDriverName): %s\n", FMOD_ErrorString(FSOUND_GetError()));

		FSOUND_3D_SetDistanceFactor(1.0f/72.0f);
		FSOUND_3D_SetRolloffFactor(0);
		FSOUND_3D_SetRolloffFactor(1.6f);
#ifdef MORESTUFF
		FSOUND_3D_SetDopplerFactor(0);
#endif

		switch (FSOUND_GetOutput())
		{
			case FSOUND_OUTPUT_NOSOUND:
				DBG_Printf("FMOD driver: NoSound driver, all calls to this succeed but do nothing.\n");
				break;
			case FSOUND_OUTPUT_WINMM:
				DBG_Printf("FMOD driver: Windows Multimedia driver.\n");
				break;
			case FSOUND_OUTPUT_DSOUND:
				DBG_Printf("FMOD driver: DirectSound driver. You need this to get EAX2 or EAX3 support, or FX api support.\n");
				break;
			case FSOUND_OUTPUT_A3D:
				DBG_Printf("FMOD driver: A3D driver.\n");
				break;
			case FSOUND_OUTPUT_XBOX:
				DBG_Printf("FMOD driver: Xbox driver\n");
				break;
			case FSOUND_OUTPUT_OSS:
				DBG_Printf("FMOD driver: Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers.\n");
				break;
			case FSOUND_OUTPUT_ESD:
				DBG_Printf("FMOD driver: Linux/Unix ESD (Enlightment Sound Daemon) driver.\n");
				break;
			case FSOUND_OUTPUT_ALSA:
				DBG_Printf("FMOD driver: Linux Alsa driver.\n");
				break;
			case FSOUND_OUTPUT_MAC:
				DBG_Printf("FMOD driver: Mac SoundManager driver\n");
				break;
			case FSOUND_OUTPUT_PS2:
				DBG_Printf("FMOD driver: PlayStation 2 driver\n");
				break;
			case FSOUND_OUTPUT_GC:
				DBG_Printf("FMOD driver: Gamecube driver\n");
				break;
			case FSOUND_OUTPUT_NOSOUND_NONREALTIME:
				DBG_Printf("FMOD driver: This is the same as nosound, but the sound generation is driven by FSOUND_Update\n");
				break;
			case FSOUND_OUTPUT_ASIO:
				DBG_Printf("FMOD driver: Low latency ASIO driver\n");
				break;
			default:
				DBG_Printf("FMOD driver: Unknown Sound Driver\n");
				break;
		}

		relsetup();

		blankfmsample = FSOUND_Sample_Alloc(FSOUND_UNMANAGED,1,FSOUND_UNORMAL,11025,127,FSOUND_STEREOPAN,127);

		if (!blankfmsample)
			DBG_Printf("FMOD(Startup,FSOUND_Sample_Alloc): %s\n", FMOD_ErrorString(FSOUND_GetError()));
		else if (!FSOUND_Sample_SetMaxPlaybacks(blankfmsample,STATIC_SOURCES_NUM*2))
			DBG_Printf("FMOD(Startup,FSOUND_Sample_SetMaxPlaybacks): %s\n", FMOD_ErrorString(FSOUND_GetError()));
	}
	return inited;
}
Ejemplo n.º 13
0
//update the rel chans
static void relupdate(INT32 handle)
{
	if (handle == FSOUND_FREE)
	{
		INT32 stack;

		for (stack = 0; stack <= STATIC_SOURCES_NUM;stack++)
		{
			//if (FSOUND_GetCurrentSample(relarray[stack].handle))
			//	relarray[stack].chan = relcopy(relarray[stack].handle);

			if (relarray[stack].chan != FSOUND_FREE)
			{
				relarray[stack].pos.active = false;
				relupdate(relarray[stack].chan);
			}
			else
				relarray[stack].pos.active = false;
		}
	}
	else if (handle == relcheckup(handle))
		return;
#ifndef REL2D
	else
	{
		float pos[3], vel[3];
		INT32 stack = relstack(handle);
		INT32 chan = relcheckup(handle);
		INT32 which = relarray[stack].listener;

		pos[0] = relarray[stack].pos.pos[0] + rellistener[which].pos[0];
		pos[1] = relarray[stack].pos.pos[1] + rellistener[which].pos[1];
		pos[2] = relarray[stack].pos.pos[2] + rellistener[which].pos[2];
		vel[0] = relarray[stack].pos.vel[0] + rellistener[which].vel[0];
		vel[1] = relarray[stack].pos.vel[1] + rellistener[which].vel[1];
		vel[2] = relarray[stack].pos.vel[2] + rellistener[which].vel[2];

		if (!FSOUND_3D_SetAttributes(chan,pos,vel))
			DBG_Printf("FMOD(relupdate, FSOUND_3D_SetAttributes, Handle #%i,Channel #%i): %s\n",handle, chan,FMOD_ErrorString(FSOUND_GetError()));
	}
#endif
}
Ejemplo n.º 14
0
		DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPan, channel %i to sep %i): %s\n", chan,sep,FMOD_ErrorString(FSOUND_GetError()));

	if (!FSOUND_SetPaused(chan, false))
		DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Resume, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError()));
}

// --------------------------------------------------------------------------
// Set the global volume for sound effects
// --------------------------------------------------------------------------
EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 vol)
{
	INT32 realvol = (vol<<3)+(vol>>2);

	FSOUND_SetSFXMasterVolume(realvol);
#ifdef MORESTUFF
	DBG_Printf("FMOD(SetGlobalSfxVolume, Main, the volume is set to %i): %s\n", realvol,FMOD_ErrorString(FSOUND_GetError()));
#endif
}

//Alam_GBC: Not Used?
EXPORT INT32 HWRAPI (SetCone) (INT32 chan, cone_def_t *cone_def)
{
	FSOUND_SAMPLE *fmsample;

	if (chan < 0)
		return -1;

	fmsample = FSOUND_GetCurrentSample(chan);

	if (fmsample)
	{
Ejemplo n.º 15
0
/*
[
    [DESCRIPTION]

    [PARAMETERS]
 
    [RETURN_VALUE]

    [REMARKS]

    [SEE_ALSO]
]
*/
int main()
{
    FSOUND_STREAM  *stream;
    FSOUND_DSPUNIT *dsp1,*dsp2;
    char 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;
    }

    printf("-------------------------------------------------------------\n");
    printf("FSOUND Streamer example.\n");
    printf("Copyright (c) Firelight Technologies Pty, Ltd, 2001-2004.\n");
    printf("-------------------------------------------------------------\n");


    printf("---------------------------------------------------------\n");    
    printf("Output Type\n");    
    printf("---------------------------------------------------------\n");    
#if defined(WIN32) || defined(_WIN64) || defined(__CYGWIN32__) || defined(__WATCOMC__)
    printf("1 - Direct Sound\n");
    printf("2 - Windows Multimedia Waveout\n");
    printf("3 - ASIO\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("4 - NoSound\n");
    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(_WIN64) || 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_ASIO);
                    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       
        case '4' :  FSOUND_SetOutput(FSOUND_OUTPUT_NOSOUND);
                    break;
        default :   exit(0);
    }

    // ==========================================================================================
    // SELECT DRIVER
    // ==========================================================================================
    {
        int i,driver=0;
        char key;

        // 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_ASIO:      printf("ASIO"); 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) exit(0);
            driver = key - '1';
        } while (driver < 0 || driver >= FSOUND_GetNumDrivers());

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

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

    // ==========================================================================================
    // CREATE USER STREAM
    // ==========================================================================================
    stream = FSOUND_Stream_Create(streamcallback, 6*2048, FSOUND_NORMAL | FSOUND_16BITS | FSOUND_STEREO, 44100, (void *)12345);
    if (!stream)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }

    FSOUND_Stream_SetEndCallback(stream, endcallback, 0);

    dsp1 = FSOUND_Stream_CreateDSP(stream, dspcallback, 0, 0);    // priority 0 = it comes first in dsp chain.
    dsp2 = FSOUND_Stream_CreateDSP(stream, dspcallback, 1, 0);    // priority 1 = it comes last

    printf("Press any key to quit\n");
    printf("=========================================================================\n");
    printf("Playing stream...\n");

    // ==========================================================================================
    // PLAY STREAM
    // ==========================================================================================
    if (FSOUND_Stream_Play(FSOUND_FREE, stream) == -1)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;

    }

    printf("******* Hit a key to active stream DSP unit #1 to halve the stream volume.\n");
    getch();

    FSOUND_DSP_SetActive(dsp1, 1);
    printf("******* Now hit a key to active stream DSP unit #2 to quarter the stream volume.\n");
    getch();
    FSOUND_DSP_SetActive(dsp2, 1);
    printf("******* How hit a key to finish.\n");

    getch();

    printf("\n");

    FSOUND_DSP_Free(dsp1);
    FSOUND_DSP_Free(dsp2);

    FSOUND_Stream_Close(stream);

    FSOUND_Close();
   
    return 0;
}
Ejemplo n.º 16
0
EXPORT void HWRAPI (UpdateSourceVolume) (INT32 chan, INT32 vol)
{
	if (chan < 0)
		return;

	if (!FSOUND_GetCurrentSample(chan))
		return;

	if (!FSOUND_SetVolume(chan,vol))
		DBG_Printf("FMOD(UpdateSourceVolume, FSOUND_SetVolume, channel %i to volume %i): %s\n", chan,vol,FMOD_ErrorString(FSOUND_GetError()));
	else
	{
#ifdef MORESTUFF
		DBG_Printf("FMOD(UpdateSourceVolume, Main): channel %i is set to the volume of %i", chan,vol);
#endif
		relvol(chan);
	}
}
Ejemplo n.º 17
0
void initsb(char dadigistat, char damusistat, long dasamplerate, char danumspeakers, char dabytespersample, char daintspersec, char daquality)
{
	char *s;
	int i,j;
	
	if (fmod_inited) return;
	fmod_inited = 0;

	if (dasamplerate < 6000) dasamplerate = 6000;
	else if (dasamplerate > 48000) dasamplerate = 48000;

	musicstat = damusistat;
	
	printOSD("Initialising FMOD...\n");

	/* We're going to be requesting certain things from our audio
	   device, so we set them up beforehand */
	int audio_rate = 22050;
	Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
	int audio_channels = 2;
	int audio_buffers = 4096;

	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
		initprintf("Unable to open audio!\n");
		return;
	}

	/* If we actually care about what we got, we can ask here.  In this
	   program we don't, but I'm showing the function call here anyway
	   in case we'd want to know later. */
	Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
	
	fmod_inited = 1;

#if 0
	printOSD("  Linked version: %.02f\n", FMOD_VERSION);
	printOSD("  DLL version: %.02f\n", FSOUND_GetVersion());

	if (FSOUND_GetVersion() < FMOD_VERSION) {
		printOSD("  ... Failure: FMOD DLL too old! Sound disabled.\n");
		return;
	}
	
	printOSD("  Samplerate: %d hz\n", dasamplerate);

	//FSOUND_SetOutput(FSOUND_OUTPUT_ASIO);

	if (FSOUND_Init(dasamplerate, NUMCHANNELS, 0)) {
		printOSD("  ... Success\n");
		fmod_inited = 1;
	} else {
		printOSD("  ... Failure: %s\n", FMOD_ErrorString(FSOUND_GetError()));
	}

	switch (FSOUND_GetOutput()) {
		case FSOUND_OUTPUT_NOSOUND: s = "No Sound"; break;
		case FSOUND_OUTPUT_WINMM: s = "WINMM"; break;
		case FSOUND_OUTPUT_DSOUND: s = "DirectSound"; break;
		case FSOUND_OUTPUT_OSS: s = "OSS"; break;
		case FSOUND_OUTPUT_ESD: s = "ESound"; break;
		case FSOUND_OUTPUT_ALSA: s = "ALSA"; break;
		case FSOUND_OUTPUT_ASIO: s = "ASIO"; break;
		default: s = "Other"; break;
	}
	printOSD("Using FMOD \"%s\" output driver\n", s);

	FSOUND_File_SetCallbacks(
			(FSOUND_OPENCALLBACK)f_open,
			(FSOUND_CLOSECALLBACK)f_close,
			(FSOUND_READCALLBACK)f_read,
			(FSOUND_SEEKCALLBACK)f_seek,
			(FSOUND_TELLCALLBACK)f_tell);
	//FSOUND_SetMemorySystem(fmod_cache, fmod_cachelen, NULL, NULL, NULL);
#endif
	loadwaves();

	for (i=0; i<NUMCHANNELS; i++) channels[i] = -1;
}
Ejemplo n.º 18
0
/******************************************************************************
 *
 * Update volume and separation (panning) of 2D source
 *
 *****************************************************************************/
EXPORT void HWRAPI (Update2DSoundParms) (INT32 chan, INT32 vol, INT32 sep)
{
	FSOUND_SAMPLE *fmsample;

	if (chan < 0)
		return;

	fmsample = FSOUND_GetCurrentSample(chan);

	if (fmsample)
	{
		if (!FSOUND_Sample_GetMode(fmsample) & FSOUND_2D)
		{
			DBG_Printf("FMOD(Update2DSoundParms,Main): 2D Vol/Pan on 3D channel %i?\n",chan);
			//return;
		}
	}
	else
		return;

	if (!FSOUND_SetPaused(chan, true))
		DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Pause, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError()));

	if (!FSOUND_SetVolume(chan,vol))
		DBG_Printf("FMOD(Update2DSoundParms, , channel %i to volume %i): %s\n", chan,vol,FMOD_ErrorString(FSOUND_GetError()));

	if (!FSOUND_SetPan(chan, sep == NORMAL_SEP ? FSOUND_STEREOPAN : sep))
		DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPan, channel %i to sep %i): %s\n", chan,sep,FMOD_ErrorString(FSOUND_GetError()));

	if (!FSOUND_SetPaused(chan, false))
		DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Resume, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError()));
}
Ejemplo n.º 19
0
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;
}
int main( int argc, char **argv )
{
    Music music;
    int   audio_rate, audio_channels,
    //set this to any of 512,1024,2048,4096
    //the higher it is, the more FPS shown and CPU needed
          audio_buffers = 4096;
#ifdef HAVE_SDL
    Uint16 audio_format;
    //initialize SDL for audio and video
    if (SDL_Init( SDL_INIT_AUDIO ) < 0)
        cleanExit( "SDL_Init\n" );
    Mix_HookMusicFinished( &music_finished );
#else
#ifdef __APPLE__
    if ( !FSOUND_Init( 44100, 64, FSOUND_INIT_GLOBALFOCUS ) ) {
        printf( "SOUND Error %d\n", FSOUND_GetError() );
        exit( 1 );
    }
#endif
#endif
    INET_startup();
    GetMaxVolume();
    //initialize sdl mixer, open up the audio device
#ifdef HAVE_SDL
    if (Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, audio_buffers ) < 0)
        cleanExit( "Mix_OpenAudio\n" );
    //print out some info on the audio device and stream
    Mix_QuerySpec( &audio_rate, &audio_format, &audio_channels );
    bits = audio_format&0xFF;
#endif
    printf( "Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate,
            bits, audio_channels > 1 ? "stereo" : "mono", audio_buffers );
    //load the song
    for (int i = 0; i < 10 && mysocket == -1; i++)
        mysocket = INET_AcceptFrom( 4364, "localhost" );
    if (mysocket == -1)
        return 1;
    printf( "\n[CONNECTED]\n" );
    char ministr[2] = {'\0', '\0'};
    while (!done) {
//if ((Mix_PlayingMusic() || Mix_PausedMusic())&&(!done)) {
        char arg;
        std::string str;
        arg = INET_fgetc( mysocket );
        printf( "%c", arg );
        switch (arg)
        {
        case 'p':
        case 'P':
            arg = INET_fgetc( mysocket );
            while (arg != '\0' && arg != '\n') {
                if (arg != '\r') {
                    ministr[0] = arg;
                    str += ministr;
                }
                arg = INET_fgetc( mysocket );
            }
            printf( "%s", str.c_str() );
            if ( (str != curmus || invalid_string)
#ifdef HAVE_SDL
                || ( !Mix_PlayingMusic() )
#endif
                 ) {
                music = PlayMusic( str.c_str(), music );
                if (music.m) {
                    printf( "\n[PLAYING %s WITH %d FADEIN AND %d FADEOUT]\n", str.c_str(), fadein, fadeout );
                    curmus = str;
                    invalid_string = false;
                } else {
                    printf( "\n[UNABLE TO PLAY %s WITH %d FADEIN AND %d FADEOUT]\n", str.c_str(), fadein, fadeout );
                    music_finished();
                }
            } else {
                printf( "\n[%s WITH %d FADEIN AND %d FADEOUT IS ALREADY PLAYING]\n", str.c_str(), fadein, fadeout );
            }
            break;
        case 'i':
        case 'I':
            arg = INET_fgetc( mysocket );
            while (arg != '\0' && arg != '\n') {
                if (arg != '\r') {
                    ministr[0] = arg;
                    str += ministr;
                }
                arg = INET_fgetc( mysocket );
            }
            printf( "%s", str.c_str() );
            fadein = atoi( str.c_str() );
            printf( "\n[SETTING FADEIN TO %d]\n", fadein );
            break;
        case 'o':
        case 'O':
            arg = INET_fgetc( mysocket );
            while (arg != '\0' && arg != '\n') {
                if (arg != '\r') {
                    ministr[0] = arg;
                    str += ministr;
                }
                arg = INET_fgetc( mysocket );
            }
            printf( "%s", str.c_str() );
            fadeout = atoi( str.c_str() );
            printf( "\n[SETTING FADEOUT TO %d]\n", fadeout );
            break;
        case 'v':
        case 'V':
            arg = INET_fgetc( mysocket );
            while (arg != '\0' && arg != '\n') {
                if (arg != '\r') {
                    ministr[0] = arg;
                    str += ministr;
                }
                arg = INET_fgetc( mysocket );
            }
            printf( "%s", str.c_str() );
            volume = atof( str.c_str() );
            printf( "\n[SETTING VOLUME TO %f]\n", volume );
            music.SetVolume( volume );
            break;
        case 't':
        case 'T':
        case '\0':
            INET_close( mysocket );
            done = true;
            printf( "\n[TERMINATING MUSIC SERVER]\n" );
            break;
        }
    }
    //free & close
    INET_cleanup();
#ifdef HAVE_SDL
    Mix_CloseAudio();
    SDL_Quit();
#endif

    return 0;
}
Ejemplo n.º 21
0
bool LLAudioBufferFMOD::loadWAV(const std::string& filename)
{
    // Try to open a wav file from disk.  This will eventually go away, as we don't
    // really want to block doing this.
    if (filename.empty())
    {
        // invalid filename, abort.
        return false;
    }

    if (!LLAPRFile::isExist(filename, NULL, LL_APR_RPB))
    {
        // File not found, abort.
        return false;
    }

    if (mSamplep)
    {
        // If there's already something loaded in this buffer, clean it up.
        FSOUND_Sample_Free(mSamplep);
        mSamplep = NULL;
    }

    // Load up the wav file into an fmod sample
#if LL_WINDOWS
    // MikeS. - Loading the sound file manually and then handing it over to FMOD,
    //	since FMOD uses posix IO internally,
    // which doesn't work with unicode file paths.
    LLFILE* sound_file = LLFile::fopen(filename,"rb");	/* Flawfinder: ignore */
    if (sound_file)
    {
        fseek(sound_file,0,SEEK_END);
        U32	file_length = ftell(sound_file);	//Find the length of the file by seeking to the end and getting the offset
        size_t	read_count;
        fseek(sound_file,0,SEEK_SET);	//Seek back to the beginning
        char*	buffer = new char[file_length];
        llassert(buffer);
        read_count = fread((void*)buffer,file_length,1,sound_file);//Load it..
        if(ferror(sound_file)==0 && (read_count == 1)) { //No read error, and we got 1 chunk of our size...
            unsigned int mode_flags = FSOUND_LOOP_NORMAL | FSOUND_LOADMEMORY;
            //FSOUND_16BITS | FSOUND_MONO | FSOUND_LOADMEMORY | FSOUND_LOOP_NORMAL;
            mSamplep = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, mode_flags , 0, file_length);
        }
        delete[] buffer;
        fclose(sound_file);
    }
#else
    mSamplep = FSOUND_Sample_Load(FSOUND_UNMANAGED, filename.c_str(), FSOUND_LOOP_NORMAL, 0, 0);
#endif

    if (!mSamplep)
    {
        // We failed to load the file for some reason.
        llwarns << "Could not load data '" << filename << "': "
                << FMOD_ErrorString(FSOUND_GetError()) << llendl;

        //
        // If we EVER want to load wav files provided by end users, we need
        // to rethink this!
        //
        // file is probably corrupt - remove it.
        LLFile::remove(filename);
        return false;
    }

    // Everything went well, return true
    return true;
}
Ejemplo n.º 22
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;
}