Beispiel #1
0
//---------------------------------------------------------------------------
// Name: sound_volume 
// Desc: Sets sound volume.
//---------------------------------------------------------------------------
static int csl_sound_volume(void)
{
    int argc = csl_argc()+1;
	    
	    
	if(argc!=2)
	{
		csl_textout(1, "syntax: sound_volume [0 - 255]");
		csl_textoutf(1, "Current sound_volume is \"%d\".",fiend_sound_volume);
	}
	else
	{
		fiend_sound_volume = atoi(csl_argv(1));
		
		if(sound_is_on) {
			//FSOUND_SetSFXMasterVolume(fiend_sound_volume);
			FMOD_CHANNELGROUP *cgroup = NULL;
			FMOD_System_GetMasterChannelGroup(fmod_system, &cgroup);
			FMOD_ChannelGroup_SetVolume(cgroup, ((float)fiend_sound_volume)/256);
		}

		csl_textoutf(1, "Sound_volume is set to \"%d\".", fiend_sound_volume);
	}

		
	return CSLMSG_O_K;
    
}
Beispiel #2
0
// this should only be called once per device
void ofMultiDeviceSoundPlayer::initializeFmodWithTargetDevice(int deviceIndex)
{
	if(!sys_Array_init[deviceIndex]){
		FMOD_System_Create(&sys_Array[deviceIndex]);
		
		int driverNum;
		FMOD_System_GetNumDrivers(sys_Array[deviceIndex], &driverNum);
		
		cout << "NUM DRIVERS : " << driverNum << endl;
		/*
		
		for(int i=0; i<driverNum; i++)
		{
			char name[256];
			FMOD_GUID *guid = new FMOD_GUID();
			FMOD_System_GetDriverInfo(sys_Array[deviceIndex], i, name, 256, guid);
		
			//printf("%d : %s\n", i, name);
		}*/
		
		FMOD_System_SetDriver(sys_Array[deviceIndex], deviceIndex);
		FMOD_System_Init(sys_Array[deviceIndex], 2000, FMOD_INIT_NORMAL, NULL);  //do we want just 32 channels?
		
		FMOD_System_GetMasterChannelGroup(sys_Array[deviceIndex], &channel_Array[deviceIndex]);
		
		sys_Array_init[deviceIndex] = true;
	}
}
Beispiel #3
0
// this should only be called once per device
void ofMultiDeviceSoundPlayer::initializeFmodWithTargetDevice(int deviceIndex)
{
	if(!sys_Array_init[deviceIndex]){
		FMOD_System_Create(&sys_Array[deviceIndex]);
		
		int driverNum;
		FMOD_System_GetNumDrivers(sys_Array[deviceIndex], &driverNum);
		
		
		for(int i=0; i<driverNum; i++)
		{
			char name[256];
			FMOD_System_GetDriverName(sys_Array[deviceIndex], i, name, 256);
			
			printf("%d : %s\n", i, name);
		}
		
		FMOD_System_SetDriver(sys_Array[deviceIndex], deviceIndex);
		FMOD_System_Init(sys_Array[deviceIndex], 2000, FMOD_INIT_NORMAL, NULL);  //do we want just 32 channels?
		
		FMOD_System_GetMasterChannelGroup(sys_Array[deviceIndex], &channel_Array[deviceIndex]);
		
		sys_Array_init[deviceIndex] = true;
	}
}
//---------------------------------------
// this should only be called once
void ofSoundPlayer::initializeFmod(){
	if(!bFmodInitialized){
		FMOD_System_Create(&sys);
		FMOD_System_Init(sys, 32, FMOD_INIT_NORMAL, NULL);  //do we want just 32 channels?
		FMOD_System_GetMasterChannelGroup(sys, &channelgroup);
		bFmodInitialized = true;
	}
}
Beispiel #5
0
//const int& maxChannelsNumber
bool
CFModExDriver::init(const SAudioParameters&)
{

    const int maxChannelsNumber = 4;
    FMOD_RESULT result;

    result = FMOD_System_Create(&_audioSystem);

    if(result != FMOD_OK){

        //fus::ILogger::Log(fus::EWarning)
        _LOG_WARNING << "Impossible to initialize FmodEx : " << FMOD_ErrorString(result);
        return false;
    }


    unsigned int version = 0;
    getFMODExVersion(version);

    // check version is correct
    if (version < FMOD_VERSION) {
        _LOG_WARNING << "Error!  You are using an old version of FMOD " << version << ".  This program requires " << FMOD_VERSION;
        return false;
    }

    result = FMOD_System_Init(_audioSystem, maxChannelsNumber, FMOD_INIT_NORMAL, NULL);

    if(result != FMOD_OK){

        //fus::ILogger::Log(fus::EWarning)
        _LOG_WARNING << "Impossible to init audio system : " << FMOD_ErrorString(result);
        return false;
    }
    //Specify user callbacks for FMOD's internal file manipulation functions.
//        result = _audioSystem->setFileSystem(&fmodFileOpenCallback, &fmodFileCloseCallback, &fmodFileReadCallback, &fmodFileSeekCallback, 2048);
//        if (result != FMOD_OK){
//
//        }


    // update var static
    //CSound::_audioSystem = _audioSystem;

    // TODO Parametrer le volume

    FMOD_System_GetMasterChannelGroup( _audioSystem, &_masterGroup);


    // TODO
    //FMOD_System_createChannelGroup()

    //fus::ILogger::Log(fus::ENotice)
    _INFO  << "Sound System ok";
    return true;

}
Beispiel #6
0
//---------------------------------------
// this should only be called once
void ofFmodSoundPlayer::initializeFmod(){
	if(!bFmodInitialized_){
		FMOD_System_Create(&sys);
		#ifdef TARGET_LINUX
			FMOD_System_SetOutput(sys,FMOD_OUTPUTTYPE_ALSA);
		#endif
		FMOD_System_Init(sys, 32, FMOD_INIT_NORMAL, NULL);  //do we want just 32 channels?
		FMOD_System_GetMasterChannelGroup(sys, &channelgroup);
		bFmodInitialized_ = true;
	}
}
Beispiel #7
0
FMOD_CHANNELGROUP * bmx_FMOD_System_GetMasterChannelGroup(FMOD_SYSTEM *system) {
	FMOD_CHANNELGROUP * group;
	
	FMOD_RESULT res = FMOD_System_GetMasterChannelGroup(system, &group);
	
	if (res) {
		return 0;
	}
	
	return group;	
}
// ----------------------------------------------------------------------------
// these are global functions, that affect every sound / channel:
// ----------------------------------------------------------------------------
void ofxSoundInitialize() // this should only be called once
{
	if(!bFmodInitialized)
	{
		FMOD_System_Create(&sys);
    #ifdef TARGET_LINUX
		FMOD_System_SetOutput(sys,FMOD_OUTPUTTYPE_ALSA);
    #endif
		FMOD_System_Init(sys, 32, FMOD_INIT_NORMAL, NULL);  //do we want just 32 channels?
		FMOD_System_GetMasterChannelGroup(sys, &channelgroup);
		bFmodInitialized = true;
	}
}
Beispiel #9
0
void    music_pause(t_music *m)
{
  FMOD_CHANNELGROUP *channel;
  FMOD_BOOL state;

  if (m->DUCK_isPlaying == 1)
    {
      FMOD_System_GetMasterChannelGroup(m->system, &channel);
      FMOD_ChannelGroup_GetPaused(channel, &state);
      if (state)
        FMOD_ChannelGroup_SetPaused(channel, 0);
      else
        FMOD_ChannelGroup_SetPaused(channel, 1);
    }
}
Beispiel #10
0
void AudioManager::Allocate( const int32_t MaxChannels, const FMOD_INITFLAGS InitFlags, void* ExDriverData )
{
	// Create local variables.

		size_t GroupIndex = 1;

	// Initialize audio system.

		if( !Initialized )
		{
			if( FMOD_System_Create( &SystemInstance ) != FMOD_OK )
				throw exception();

			if( FMOD_System_Init( SystemInstance, MaxChannels, InitFlags, ExDriverData ) != FMOD_OK )
				throw exception();

			for( size_t Index = 0; Index < MaxAudioTypes; Index += 2 )
			{
				AudioMaps[ Index ].Group = AudioMaps[ ( Index + 1 ) ].Group = GroupIndex;
				GroupIndex++;
			}

			if( FMOD_System_GetMasterChannelGroup( SystemInstance, &ChannelGroups[ MasterGroup ].Instance ) != FMOD_OK )
				throw exception();

			ChannelGroups[ MasterGroup ].Volume = AUDIOMANAGER_DEF_VOLUME;

			if( FMOD_ChannelGroup_SetVolume( ChannelGroups[ MasterGroup ].Instance, AUDIOMANAGER_DEF_VOLUME ) != FMOD_OK )
				throw exception();

			for( size_t Index = 1; Index < MaxChannelGroups; Index++ )
			{
				if( FMOD_System_CreateChannelGroup( SystemInstance, nullptr, &ChannelGroups[ Index ].Instance ) != FMOD_OK )
					throw exception();

				ChannelGroups[ Index ].Volume = AUDIOMANAGER_DEF_VOLUME;

				if( FMOD_ChannelGroup_SetVolume( ChannelGroups[ Index ].Instance, AUDIOMANAGER_DEF_VOLUME ) != FMOD_OK )
					throw exception();

				if( FMOD_ChannelGroup_AddGroup( ChannelGroups[ MasterGroup ].Instance, ChannelGroups[ Index ].Instance ) != FMOD_OK )
					throw exception();
			}

			Initialized = true;
		}
}
//---------------------------------------
// this should only be called once
void ofFmodSoundPlayer::initializeFmod(){
	if(!bFmodInitialized_){
		
		FMOD_System_Create(&sys);
		
		// set buffersize, keep number of buffers
		unsigned int bsTmp;
		int nbTmp;
		FMOD_System_GetDSPBufferSize(sys, &bsTmp, &nbTmp);
		FMOD_System_SetDSPBufferSize(sys, buffersize, nbTmp);

		#ifdef TARGET_LINUX
			FMOD_System_SetOutput(sys,FMOD_OUTPUTTYPE_ALSA);
		#endif
		FMOD_System_Init(sys, 32, FMOD_INIT_NORMAL, nullptr);  //do we want just 32 channels?
		FMOD_System_GetMasterChannelGroup(sys, &channelgroup);
		bFmodInitialized_ = true;
	}
}
Beispiel #12
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM       *system;
    FMOD_SOUND        *sound[6];
    FMOD_CHANNEL      *channel[6];
    FMOD_CHANNELGROUP *groupA, *groupB, *masterGroup;
    FMOD_RESULT        result;
    int                key, count;
    unsigned int       version;

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

    result = FMOD_System_GetVersion(system, &version);
    ERRCHECK(result);

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

    result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_LOOP_NORMAL, 0, &sound[0]);
    ERRCHECK(result);
    result = FMOD_System_CreateSound(system, "../media/jaguar.wav", FMOD_LOOP_NORMAL, 0, &sound[1]);
    ERRCHECK(result);
    result = FMOD_System_CreateSound(system, "../media/swish.wav", FMOD_LOOP_NORMAL, 0, &sound[2]);
    ERRCHECK(result);
    result = FMOD_System_CreateSound(system, "../media/c.ogg", FMOD_LOOP_NORMAL, 0, &sound[3]);
    ERRCHECK(result);
    result = FMOD_System_CreateSound(system, "../media/d.ogg", FMOD_LOOP_NORMAL, 0, &sound[4]);
    ERRCHECK(result);
    result = FMOD_System_CreateSound(system, "../media/e.ogg", FMOD_LOOP_NORMAL, 0, &sound[5]);
    ERRCHECK(result);

    result = FMOD_System_CreateChannelGroup(system, "Group A", &groupA);
    ERRCHECK(result);

    result = FMOD_System_CreateChannelGroup(system, "Group B", &groupB);
    ERRCHECK(result);

    result = FMOD_System_GetMasterChannelGroup(system, &masterGroup);
    ERRCHECK(result);

    printf("=======================================================================\n");
    printf("ChannelGroups Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("=======================================================================\n");
    printf("\n");
    printf("Group A : drumloop.wav, jaguar.wav, swish.wav\n");
    printf("Group B : c.ogg, d.ogg, e.ogg\n");
    printf("\n");
    printf("Press 'A' to mute/unmute group A\n");
    printf("Press 'B' to mute/unmute group B\n");
    printf("Press 'C' to mute/unmute group A and B (master group)\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Instead of being independent, set the group A and B to be children of the master group.
    */
    result = FMOD_ChannelGroup_AddGroup(masterGroup, groupA);
    ERRCHECK(result);

    result = FMOD_ChannelGroup_AddGroup(masterGroup, groupB);
    ERRCHECK(result);

    /*
        Start all the sounds!
    */
    for (count = 0; count < 6; count++)
    {
        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound[count], TRUE, &channel[count]);
        ERRCHECK(result);
        if (count < 3)
        {
            result = FMOD_Channel_SetChannelGroup(channel[count], groupA);
        }
        else
        {
            result = FMOD_Channel_SetChannelGroup(channel[count], groupB);
        }
        ERRCHECK(result);
        result = FMOD_Channel_SetPaused(channel[count], FALSE);
        ERRCHECK(result);
    }

    /*
        Change the volume of each group, just because we can!  (And makes it less of a loud noise).
    */
    result = FMOD_ChannelGroup_SetVolume(groupA, 0.5f);
    ERRCHECK(result);
    result = FMOD_ChannelGroup_SetVolume(groupB, 0.5f);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        if (_kbhit())
        {
            key = _getch();

            switch (key)
            {
                case 'a' : 
                case 'A' : 
                {
                    static int mute = TRUE;

                    FMOD_ChannelGroup_SetMute(groupA, mute);

                    mute = !mute;
                    break;
                }
                case 'b' : 
                case 'B' : 
                {
                    static int mute = TRUE;

                    FMOD_ChannelGroup_SetMute(groupB, mute);

                    mute = !mute;
                    break;
                }
                case 'c' : 
                case 'C' : 
                {
                    static int mute = TRUE;

                    FMOD_ChannelGroup_SetMute(masterGroup, mute);

                    mute = !mute;
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        {
            int  channelsplaying = 0;

            FMOD_System_GetChannelsPlaying(system, &channelsplaying);

            printf("Channels Playing %2d\r", channelsplaying);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        A little fade out. (over 2 seconds)
    */
    printf("Goodbye!\n");
    {
        float pitch = 1.0f;
        float vol = 1.0f;

        for (count = 0; count < 200; count++)
        {
            FMOD_ChannelGroup_SetPitch(masterGroup, pitch);
            FMOD_ChannelGroup_SetVolume(masterGroup, vol);

            vol   -= (1.0f / 200.0f);
            pitch -= (0.5f / 200.0f);

            Sleep(10);
        }
    }

    /*
        Shut down
    */
    for (count = 0; count < 6; count++)
    {
        result = FMOD_Sound_Release(sound[count]);
        ERRCHECK(result);
    }

    result = FMOD_ChannelGroup_Release(groupA);
    ERRCHECK(result);
    result = FMOD_ChannelGroup_Release(groupB);
    ERRCHECK(result);

    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    return 0;
}
Beispiel #13
0
int main(int argc, char *argv[])
{
	int continuer = 1;
	float volume = 1.0;
	Touche tab[NB_TOUCHES];
	SDL_Surface *ecran = NULL, *fde = NULL;
	SDL_Event event;
	SDL_Rect positionFond;
	FMOD_SYSTEM *system;
	FMOD_CHANNELGROUP* channel = null;
	
	positionFond.x = 0;
	positionFond.y = 0;
	
	/*SONS*/
	/* Création et initialisation d'un objet système pour le FMOD*/
	FMOD_System_Create(&system);
	FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL);
	
	/* Chargement des sons */
	if(init_touches(system, tab))
		return EXIT_FAILURE;
	
	/*SDL*/
	/* Initialisation de la SDL */
	SDL_Init(SDL_INIT_VIDEO);
	
	ecran = SDL_SetVideoMode(283, 200, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
	SDL_WM_SetCaption("Launchpad de la TIPS", NULL);
	
	fde = IMG_Load("../files/fde.png");
	SDL_WM_SetIcon(fde, NULL);
	SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
	SDL_BlitSurface(fde, NULL, ecran, &positionFond);
	SDL_Flip(ecran);
	
	while (continuer)
	{
		SDL_WaitEvent(&event);
		switch(event.type)
		{
			case SDL_QUIT:
				continuer = 0;
				break;
			case SDL_MOUSEBUTTONDOWN: /* Si clique de la souris */
				/* Non utile pour le moment*/
				break;
			case SDL_KEYDOWN: /* Si appuie sur une touche */
				
				/* Esc pour quitter */
				if(event.key.keysym.sym == SDLK_ESCAPE)
					continuer = 0;
				/* UP pour monter le son */
				else if(event.key.keysym.sym == SDLK_UP)
				{
					FMOD_System_GetMasterChannelGroup(system, &channel);
					volume += 0.1;
					FMOD_ChannelGroup_SetVolume(channel, volume);
				}
				/* DOWN pour baisser le son */
				else if(event.key.keysym.sym == SDLK_DOWN)
				{
					FMOD_System_GetMasterChannelGroup(system, &channel);
					volume -= 0.1;
					FMOD_ChannelGroup_SetVolume(channel, volume);
				}
				/* LEFT ou RIGHT pour stopper la musique */
				else if((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_RIGHT))
				{
					FMOD_System_GetMasterChannelGroup(system, &channel);
					FMOD_ChannelGroup_Stop(channel);
				}
				else if(tab[event.key.keysym.sym].son != NULL)
				{
					FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, tab[event.key.keysym.sym].son, 0, NULL);
				}
				break;
		}
	}

	/* On ferme la SDL */
	SDL_FreeSurface(fde);
	SDL_Quit();

	/* On libère le son et on ferme et libère l'objet système */
	libere_touches(tab);
	FMOD_System_Close(system);
	FMOD_System_Release(system);
	
	return EXIT_SUCCESS;
}
Beispiel #14
0
int main(int argc, const char *argv[]){
    
    SDL_Surface *ecran = NULL, *viseur = NULL;
    SDL_Event event;
    SDL_Rect position;
    int continuer = 1;
    
    FMOD_SYSTEM *system;
    FMOD_SOUND *tir;
    FMOD_SOUND *musique;
    
    FMOD_CHANNEL *musicChannel, *effectChannel;
    
    FMOD_CHANNELGROUP *musicChannelGroup, *effectChannelGroup;
    
    FMOD_RESULT resultat;
    
    FMOD_RESULT resultatMusic;
    
    /* Création et initialisation d'un objet système */
    FMOD_System_Create(&system);
    FMOD_System_Init(system, 2, FMOD_INIT_NORMAL, NULL);
    
    FMOD_System_CreateChannelGroup(system, "music", &musicChannelGroup);
    FMOD_System_CreateChannelGroup(system, "effect", &effectChannelGroup);
    
    /* Chargement du son et vérification du chargement */
    resultat = FMOD_System_CreateSound(system, "pan.wav", FMOD_CREATESAMPLE, 0, &tir);
    
    resultatMusic = FMOD_System_CreateSound(system, "hype_home.mp3", FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    
    if (resultat != FMOD_OK)
    {
        fprintf(stderr, "Impossible de lire pan.wav\n");
        exit(EXIT_FAILURE);
    }
    
    FMOD_Sound_SetLoopCount(musique, -1);
    
    FMOD_System_PlaySound(system, musique, musicChannelGroup, 0, &musicChannel);
    
    /* Initialisation de la SDL */
    SDL_Init(SDL_INIT_VIDEO);
    
    SDL_ShowCursor(SDL_DISABLE);
    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("Gestion du son avec FMOD", NULL);
    
    viseur = IMG_Load("viseur.png");
    
    while (continuer)
    {
        SDL_WaitEvent(&event);
        
        switch(event.type)
        {
            case SDL_QUIT:
                continuer = 0;
                break;
            case SDL_MOUSEBUTTONDOWN:
                /* Lorqu'on clique, on joue le son */
                FMOD_System_PlaySound(system, tir, effectChannelGroup, 0, &effectChannel);
                break;
            case SDL_MOUSEMOTION:
                /* Lorsqu'on déplace la souris, on place le centre du viseur à la position de la souris
                 ... D'où notamment le "viseur->w / 2" pour réussir à faire cela */
                position.x = event.motion.x - (viseur->w / 2);
                position.y = event.motion.y - (viseur->h / 2);
                break;
            case SDL_KEYDOWN:
                if (event.key.keysym.sym == SDLK_p) //Si on appuie sur P
                {
                    FMOD_CHANNELGROUP *canal;
                    FMOD_BOOL etat;
                    FMOD_System_GetMasterChannelGroup(system, &canal);
                    FMOD_ChannelGroup_GetPaused(canal, &etat);
                    
                    if (etat) // Si la chanson est en pause
                        FMOD_ChannelGroup_SetPaused(canal, 0); // On enlève la pause
                    else // Sinon, elle est en cours de lecture
                        FMOD_ChannelGroup_SetPaused(canal, 1); // On active la pause
                }
                break;
        }
        
        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
        SDL_BlitSurface(viseur, NULL, ecran, &position);
        SDL_Flip(ecran);
    }
    
    /* On ferme la SDL */
    SDL_FreeSurface(viseur);
    SDL_Quit();
    
    /* On libère le son et on ferme et libère l'objet système */
    FMOD_Sound_Release(tir);
    FMOD_System_Close(system);
    FMOD_System_Release(system);
    
    return EXIT_SUCCESS;
}
FMOD_CHANNELGROUP *SoundEngine::getChannelGroup()
{
    FMOD_CHANNELGROUP *channel;
    FMOD_System_GetMasterChannelGroup(system, &channel);
    return channel;
}