Esempio n. 1
0
BOOL CSoundBufferFMod::ReadWavBuffer(const STRING &name)
{
	Release();

	char* lpAddress = NULL;
	DWORD dwSize = CGameProcedure::s_pResourceProvider->loadResource(name.c_str(), lpAddress, "General");
	if(dwSize > 0)
	{
		m_pFModSample = FSOUND_Sample_Load(FSOUND_FREE, 
				lpAddress, 
				FSOUND_HW3D | FSOUND_LOADMEMORY, 0, dwSize);
		CGameProcedure::s_pResourceProvider->unloadResource( lpAddress, dwSize );
	}
	
	if(!m_pFModSample) 
	{
		KLThrow("Invalid sound file:%s", name.c_str());
		return FALSE;
	}

	//缺省所有声音都是不循环的
    FSOUND_Sample_SetMode(m_pFModSample, FSOUND_LOOP_OFF);

	return TRUE;
}
void CAudioManager::PlaySoundClip(int id, unsigned int mode){
  if(m_bValidAudio == false)
    return;

  for(int i = 0; i < m_AudioClip.size(); i++){
    if(m_AudioClip[i].AudioID == id){
      if(mode == 0)
        FSOUND_Sample_SetMode(m_AudioClip[i].handle, FSOUND_LOOP_OFF);
      else
        FSOUND_Sample_SetMode(m_AudioClip[i].handle, FSOUND_LOOP_NORMAL);
        
      //m_AudioClip[i].channelPlaying = FSOUND_PlaySound(FSOUND_FREE, m_AudioClip[i].handle);
      m_AudioClip[i].channelPlaying = FSOUND_PlaySound(id, m_AudioClip[i].handle);
    }
  }
}
Esempio n. 3
0
//Copy rel chan
static INT32 relcopy(INT32 handle)
{
	FSOUND_SAMPLE *fmsample = NULL;
	INT32 chan = -1;
	float pos[3];
	float vel[3];

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

	fmsample = FSOUND_GetCurrentSample(handle);

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

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

	if (FSOUND_GetCurrentSample(chan))
	{

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

	return FSOUND_FREE;
}
void LLAudioBufferFMOD::set3DMode(bool use3d)
{
	U16 current_mode = FSOUND_Sample_GetMode(mSamplep);
	
	if (use3d)
	{
		if (!FSOUND_Sample_SetMode(mSamplep, (current_mode & (~FSOUND_2D))))
		{
			llwarns << "LLAudioBufferFMOD::set3DMode error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl;
		}
	}
	else
	{
		if (!FSOUND_Sample_SetMode(mSamplep, current_mode | FSOUND_2D))
		{
			llwarns << "LLAudioBufferFMOD::set3DMode error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl;
		}
	}
}
Esempio n. 5
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;
}
Esempio n. 6
0
int CFMOD::PlaySample(char *sname,int wchannel,int flags)
{
    int number_samples_playing=0;
    CSample *sample; if(!bfmod) return 0;
    sample=GetSample(sname); if(!sample) return 0;
    for(int i=0;i<FSOUND_GetMaxChannels();i++)
    {
        if(sample->data==FSOUND_GetCurrentSample(i))
        {
            number_samples_playing++;
        }
    }
    if(number_samples_playing>=sample->max_simultaneous) return 0;
    if(flags) FSOUND_Sample_SetMode(sample->data, flags);
    FSOUND_SetVolume(wchannel,sample->volume);
    return FSOUND_PlaySound(wchannel,sample->data);
}
Esempio n. 7
0
glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify)
{
    FILE *file;
    long pos, len;
    glui32 type;
    char *buf;
    int offset = 0;
    int i;

    if (!chan) {
	gli_strict_warning("schannel_play_ext: invalid id.");
	return 0;
    }

    /* stop previous noise */
    glk_schannel_stop(chan);

    if (repeats == 0)
	return 1;

    /* load sound resource into memory */

    if (!giblorb_is_resource_map())
    {
	char name[1024];

	sprintf(name, "%s/SND%ld", gli_workdir, snd); 

	file = fopen(name, "rb");
	if (!file)
	    return 0;

	fseek(file, 0, SEEK_END);
	len = ftell(file);

	buf = malloc(len);
	if (!buf) {
	    fclose(file);
	    return 0;
	}

	fseek(file, 0, 0);
	fread(buf, 1, len, file);
	fclose(file);

	/* identify by file magic the two types that fmod can do... */

	type = 0;	/* unidentified */

	/* AIFF */
	if (len > 4 && !memcmp(buf, "FORM", 4))		
	    type = giblorb_ID_FORM;

	/* WAVE */
	if (len > 4 && !memcmp(buf, "WAVE", 4))
	    type = giblorb_ID_WAVE;

	/* MIDI */
	if (len > 4 && !memcmp(buf, "MThd", 4))
	    type = giblorb_ID_MIDI;

	/* Ogg Vorbis */
	if (len > 4 && !memcmp(buf, "OggS", 4))
	    type = giblorb_ID_OGG;

	/* s3m */
	if (len > 0x30 && !memcmp(buf + 0x2c, "SCRM", 4))
	    type = giblorb_ID_MOD;

	/* XM */
	if (len > 20 && !memcmp(buf, "Extended Module: ", 17))
	    type = giblorb_ID_MOD;

	/* MOD */
	if (len > 1084)
	{
	    char resname[4];
	    memcpy(resname, buf + 1080, 4);
	    if (!strcmp(resname+1, "CHN") ||	/* 4CHN, 6CHN, 8CHN */
		    !strcmp(resname+2, "CN") ||	 /* 16CN, 32CN */
		    !strcmp(resname, "M.K.") || !strcmp(resname, "M!K!") ||
		    !strcmp(resname, "FLT4") || !strcmp(resname, "CD81") ||
		    !strcmp(resname, "OKTA") || !strcmp(resname, "    "))
		type = giblorb_ID_MOD;
	}

	if (!memcmp(buf, "\377\372", 2))	/* mp3 */
	    type = giblorb_ID_MP3;

	/* look for RIFF (future boy has broken resources...?) */
	if (len > 128 && type == 0)
	    for (i = 0; i < 124; i++)
		if (!memcmp(buf+i, "RIFF", 4))
		{
		    offset = i;
		    type = giblorb_ID_WAVE;
		    break;
		}

	if (type == 0)
	    type = giblorb_ID_MP3;
    }

    else
    {
	giblorb_get_resource(giblorb_ID_Snd, snd, &file, &pos, &len, &type);
	if (!file)
	    return 0;

	buf = malloc(len);
	if (!buf)
	    return 0;

	fseek(file, pos, 0);
	fread(buf, 1, len, file);
    }

    switch (type)
    {
    case giblorb_ID_FORM:
    case giblorb_ID_WAVE:
    case giblorb_ID_MP3:
	chan->sample = FSOUND_Sample_Load(FSOUND_UNMANAGED, buf + offset,
		FSOUND_NORMAL|FSOUND_LOADMEMORY, 0, len);
	if (!chan->sample) { free(buf); return 0; }
	if (repeats != 1)
	    FSOUND_Sample_SetMode(chan->sample, FSOUND_LOOP_NORMAL);
	else
	    FSOUND_Sample_SetMode(chan->sample, FSOUND_LOOP_OFF);
	chan->channel = FSOUND_PlaySound(FSOUND_FREE, chan->sample);
	FSOUND_SetVolume(chan->channel, chan->volume / 256);
	FSOUND_SetPaused(chan->channel, 0);
	break;

    case giblorb_ID_MOD:
    case giblorb_ID_MIDI:
	chan->module = FMUSIC_LoadSongEx(buf, 0, len, FSOUND_LOADMEMORY, 0, 0);
	if (!chan->module) { free(buf); return 0; }
	if (repeats != 1)
	    FMUSIC_SetLooping(chan->module, 1);
	else
	    FMUSIC_SetLooping(chan->module, 0);
	FMUSIC_SetMasterVolume(chan->module, chan->volume / 256);
	FMUSIC_PlaySong(chan->module);
	break;

    default:
	gli_strict_warning("schannel_play_ext: unknown resource type.");
    }

    free(buf);

    return 1;
}
Esempio n. 8
0
/*
[
    [DESCRIPTION]

    [PARAMETERS]
 
    [RETURN_VALUE]

    [REMARKS]

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

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

    /*
        LOAD SAMPLES
    */

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

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

    /*
        DISPLAY HELP
    */

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

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

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

    /*
        SET UP DSPS!
    */

    SetupReverb();

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

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

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

        FSOUND_SetPaused(FSOUND_SYSTEMCHANNEL, FALSE);
    }

    /*
        START PLAYING!
    */

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

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


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

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

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

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

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

                    FSOUND_SetPaused(fxchannel, FALSE);

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

    } while (key != 27);

    printf("\n");

    /*
        CLEANUP AND SHUTDOWN
    */

    FSOUND_DSP_Free(DrySFXUnit);    

    CloseReverb();

    FSOUND_Sample_Free(samp1);
    FSOUND_Sample_Free(samp2);

    FSOUND_Close();
   
    return 0;
}
Esempio n. 9
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

}
Esempio n. 10
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;
}
Esempio n. 11
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;
}
Esempio n. 12
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;
}