Beispiel #1
0
void QSPCallBacks::Init(QSPFrame *frame)
{
	m_frame = frame;
	m_volumeCoeff = 1.0;

	FMOD_System_Create(&m_sys);
	wxString soundPath(QSPTools::GetAppPath() + QSP_SOUNDPLUGINS);
	FMOD_System_SetPluginPath(m_sys, wxConvFile.cWX2MB(soundPath.c_str()));
	#ifdef __WXMSW__
		FMOD_System_SetOutput(m_sys, FMOD_OUTPUTTYPE_DSOUND);
	#elif __WXOSX__
		FMOD_System_SetOutput(m_sys, FMOD_OUTPUTTYPE_COREAUDIO);
	#else
		FMOD_System_SetOutput(m_sys, FMOD_OUTPUTTYPE_ALSA);
	#endif
	FMOD_System_Init(m_sys, 32, FMOD_INIT_NORMAL, 0);

	QSPSetCallBack(QSP_CALL_SETTIMER, (QSP_CALLBACK)&SetTimer);
	QSPSetCallBack(QSP_CALL_REFRESHINT, (QSP_CALLBACK)&RefreshInt);
	QSPSetCallBack(QSP_CALL_SETINPUTSTRTEXT, (QSP_CALLBACK)&SetInputStrText);
	QSPSetCallBack(QSP_CALL_ISPLAYINGFILE, (QSP_CALLBACK)&IsPlay);
	QSPSetCallBack(QSP_CALL_PLAYFILE, (QSP_CALLBACK)&PlayFile);
	QSPSetCallBack(QSP_CALL_CLOSEFILE, (QSP_CALLBACK)&CloseFile);
	QSPSetCallBack(QSP_CALL_SHOWMSGSTR, (QSP_CALLBACK)&Msg);
	QSPSetCallBack(QSP_CALL_SLEEP, (QSP_CALLBACK)&Sleep);
	QSPSetCallBack(QSP_CALL_GETMSCOUNT, (QSP_CALLBACK)&GetMSCount);
	QSPSetCallBack(QSP_CALL_SHOWMENU, (QSP_CALLBACK)&ShowMenu);
	QSPSetCallBack(QSP_CALL_INPUTBOX, (QSP_CALLBACK)&Input);
	QSPSetCallBack(QSP_CALL_SHOWIMAGE, (QSP_CALLBACK)&ShowImage);
	QSPSetCallBack(QSP_CALL_SHOWWINDOW, (QSP_CALLBACK)&ShowPane);
	QSPSetCallBack(QSP_CALL_OPENGAME, (QSP_CALLBACK)&OpenGame);
	QSPSetCallBack(QSP_CALL_OPENGAMESTATUS, (QSP_CALLBACK)&OpenGameStatus);
	QSPSetCallBack(QSP_CALL_SAVEGAMESTATUS, (QSP_CALLBACK)&SaveGameStatus);
}
Beispiel #2
0
FMOD_SYSTEM *Sound::fmodSetup() {
    FMOD_SYSTEM *system;
    FMOD_RESULT result;
    unsigned int version;
    int numDrivers;
    FMOD_SPEAKERMODE speakerMode;
    FMOD_CAPS caps;
    char name[256];

    result = FMOD_System_Create(&system);
    FMODErrorCheck(result);

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

    result = FMOD_System_GetNumDrivers(system, &numDrivers);
    FMODErrorCheck(result);

    if (numDrivers == 0) {
        result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_NOSOUND);
        FMODErrorCheck(result);
    }
    else {
        result = FMOD_System_GetDriverCaps(system, 0, &caps, 0, &speakerMode);
        FMODErrorCheck(result);

        result = FMOD_System_SetSpeakerMode(system, speakerMode);
        FMODErrorCheck(result);

        if (caps & FMOD_CAPS_HARDWARE_EMULATED) {
            result = FMOD_System_SetDSPBufferSize(system, 1024, 10);
            FMODErrorCheck(result);
        }
        result = FMOD_System_GetDriverInfo(system, 0, name, 256, 0);
        FMODErrorCheck(result);

        if (strstr(name, "SigmaTel")) {
            result = FMOD_System_SetSoftwareFormat(system, 48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0, 0,
                                                   FMOD_DSP_RESAMPLER_LINEAR);
            FMODErrorCheck(result);
        }
    }

    result = FMOD_System_Init(system, 100, FMOD_INIT_NORMAL, 0);

    if (result == FMOD_ERR_OUTPUT_CREATEBUFFER) {
        result = FMOD_System_SetSpeakerMode(system, FMOD_SPEAKERMODE_STEREO);
        FMODErrorCheck(result);
        result = FMOD_System_Init(system, 100, FMOD_INIT_NORMAL, 0);
    }

    FMODErrorCheck(result);

    return system;
}
Beispiel #3
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;
	}
}
// ----------------------------------------------------------------------------
// 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;
	}
}
//---------------------------------------
// 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 #6
0
void Game::initMusic() {
	FMOD_System_Create (&system);
	FMOD_System_Init (system, 100, FMOD_INIT_NORMAL, 0);
	FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_NOSOUND);
	songMusic = NULL;
	soundMusic = NULL;
	curchan = NULL;
	//cursong = NULL;
	
	/*	unsigned int version;
	int numDrivers = 0;

	FMOD_System_GetVersion(system, &version);
 
	FMOD_System_GetNumDrivers (system, &numDrivers);
	if (numDrivers == 0)
	{
		FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_NOSOUND);
	}
	*/
}
Beispiel #7
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM          *system  = 0;
    FMOD_SOUND           *sound   = 0;
    FMOD_RESULT            result;
    FMOD_CREATESOUNDEXINFO exinfo;
    int                    key, recorddriver, numdrivers, count;
    unsigned int           version;    
    FILE                  *fp;
    unsigned int           datalength = 0, soundlength;

    /*
        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;
    }

    /* 
        System initialization
    */
    printf("---------------------------------------------------------\n");    
    printf("Select OUTPUT type\n");    
    printf("---------------------------------------------------------\n");    
    printf("1 :  DirectSound\n");
    printf("2 :  Windows Multimedia WaveOut\n");
    printf("3 :  ASIO\n");
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = _getch();
    } while (key != 27 && key < '1' && key > '5');
    
    switch (key)
    {
        case '1' :  result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_DSOUND);
                    break;
        case '2' :  result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_WINMM);
                    break;
        case '3' :  result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ASIO);
                    break;
        default  :  return 1; 
    }  
    ERRCHECK(result);
    
    /*
        Enumerate record devices
    */

    result = FMOD_System_GetRecordNumDrivers(system, &numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a RECORD driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = FMOD_System_GetRecordDriverInfo(system, count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    recorddriver = 0;
    do
    {
        key = _getch();
        if (key == 27)
        {
            return 0;
        }
        recorddriver = key - '1';
    } while (recorddriver < 0 || recorddriver >= numdrivers);

    printf("\n");
  
    result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 2;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = 44100;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 2;
    
    result = FMOD_System_CreateSound(system, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    printf("========================================================================\n");
    printf("Record to disk example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("========================================================================\n");
    printf("\n");
    printf("Press a key to start recording to record.wav\n");
    printf("\n");

    _getch();

    result = FMOD_System_RecordStart(system, recorddriver, sound, TRUE);
    ERRCHECK(result);

    printf("Press 'Esc' to quit\n");
    printf("\n");

    fp = fopen("record.wav", "wb");
    if (!fp)
    {
        printf("ERROR : could not open record.wav for writing.\n");
        return 1;
    }

    /*
        Write out the wav header.  As we don't know the length yet it will be 0.
    */
    WriteWavHeader(fp, sound, datalength);

    result = FMOD_Sound_GetLength(sound, &soundlength, FMOD_TIMEUNIT_PCM);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        static unsigned int lastrecordpos = 0;
        unsigned int recordpos = 0;

        if (_kbhit())
        {
            key = _getch();
        }

        FMOD_System_GetRecordPosition(system, recorddriver, &recordpos);
        ERRCHECK(result);

        if (recordpos != lastrecordpos)        
        {
            void *ptr1, *ptr2;
            int blocklength;
            unsigned int len1, len2;
            
            blocklength = (int)recordpos - (int)lastrecordpos;
            if (blocklength < 0)
            {
                blocklength += soundlength;
            }

            /*
                Lock the sound to get access to the raw data.
            */
            FMOD_Sound_Lock(sound, lastrecordpos * exinfo.numchannels * 2, blocklength * exinfo.numchannels * 2, &ptr1, &ptr2, &len1, &len2);   /* * exinfo.numchannels * 2 = stereo 16bit.  1 sample = 4 bytes. */

            /*
                Write it to disk.
            */
            if (ptr1 && len1)
            {
                datalength += fwrite(ptr1, 1, len1, fp);
            }
            if (ptr2 && len2)
            {
                datalength += fwrite(ptr2, 1, len2, fp);
            }

            /*
                Unlock the sound to allow FMOD to use it again.
            */
            FMOD_Sound_Unlock(sound, ptr1, ptr2, len1, len2);
        }

        lastrecordpos = recordpos;

        printf("%-23s. Record buffer pos = %6d : Record time = %02d:%02d\r", (timeGetTime() / 500) & 1 ? "Recording to record.wav" : "", recordpos, datalength / exinfo.defaultfrequency / exinfo.numchannels / 2 / 60, (datalength / exinfo.defaultfrequency / exinfo.numchannels / 2) % 60);

        FMOD_System_Update(system);

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Write back the wav header now that we know its length.
    */
    WriteWavHeader(fp, sound, datalength);

    fclose(fp);

    /*
        Shut down
    */
    result = FMOD_Sound_Release(sound);
    ERRCHECK(result);

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

    return 0;
}
Beispiel #8
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM           *system  = 0;
    FMOD_SOUND            *sound   = 0;
    FMOD_CHANNEL          *channel = 0;
    FMOD_RESULT            result;
    FMOD_CREATESOUNDEXINFO exinfo;
    int                    key, driver, recorddriver, numdrivers, 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;
    }

    /*
        System initialization
    */
    printf("---------------------------------------------------------\n");
    printf("Select OUTPUT type\n");
    printf("---------------------------------------------------------\n");
    printf("1 :  OSS  - Open Sound System\n");
    printf("2 :  ALSA - Advanced Linux Sound Architecture\n");
    printf("3 :  ESD  - Enlightenment Sound Daemon\n");
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = getch();
    } while (key != 27 && key < '1' && key > '5');

    switch (key)
    {
    case '1' :
        result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_OSS);
        break;
    case '2' :
        result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ALSA);
        break;
    case '3' :
        result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ESD);
        break;
    default  :
        return 1;
    }
    ERRCHECK(result);

    /*
        Enumerate playback devices
    */

    result = FMOD_System_GetNumDrivers(system, &numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");
    printf("Choose a PLAYBACK driver\n");
    printf("---------------------------------------------------------\n");
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = FMOD_System_GetDriverInfo(system, count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    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 >= numdrivers);

    result = FMOD_System_SetDriver(system, driver);
    ERRCHECK(result);

    /*
        Enumerate record devices
    */

    result = FMOD_System_GetRecordNumDrivers(system, &numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");
    printf("Choose a RECORD driver\n");
    printf("---------------------------------------------------------\n");
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = FMOD_System_GetRecordDriverInfo(system, count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

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

    printf("\n");

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

    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 1;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = 44100;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;

    result = FMOD_System_CreateSound(system, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    printf("===================================================================\n");
    printf("Recording example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===================================================================\n");
    printf("\n");
    printf("Press 'r' to record a 5 second segment of audio and write it to a wav file.\n");
    printf("Press 'p' to play the 5 second segment of audio.\n");
    printf("Press 'l' to turn looping on/off.\n");
    printf("Press 's' to stop recording and playback.\n");
    printf("Press 'w' to save the 5 second segment to a wav file.\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Main loop.
    */
    do
    {
        static FMOD_CHANNEL *channel = 0;
        static int   looping   = 0;
        int          recording = 0;
        int          playing   = 0;
        unsigned int recordpos = 0;
        unsigned int playpos   = 0;
        unsigned int length;

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

            switch (key)
            {
            case 'r' :
            case 'R' :
            {
                result = FMOD_System_RecordStart(system, recorddriver, sound, looping);
                ERRCHECK(result);
                break;
            }
            case 'p' :
            case 'P' :
            {
                if (looping)
                {
                    FMOD_Sound_SetMode(sound, FMOD_LOOP_NORMAL);
                }
                else
                {
                    FMOD_Sound_SetMode(sound, FMOD_LOOP_OFF);
                }
                ERRCHECK(result);

                result = FMOD_System_PlaySound(system, FMOD_CHANNEL_REUSE, sound, 0, &channel);
                ERRCHECK(result);
                break;
            }
            case 'l' :
            case 'L' :
            {
                looping = !looping;
                break;
            }
            case 's' :
            case 'S' :
            {
                result = FMOD_System_RecordStop(system, recorddriver);
                if (channel)
                {
                    FMOD_Channel_Stop(channel);
                    channel = 0;
                }
                break;
            }
            case 'w' :
            case 'W' :
            {
                printf("Writing to record.wav ...                                                     \r");

                SaveToWav(sound);
                Sleep(500);

                break;
            }
            }
        }

        FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCM);
        ERRCHECK(result);

        FMOD_System_IsRecording(system, recorddriver, &recording);
        ERRCHECK(result);

        FMOD_System_GetRecordPosition(system, recorddriver, &recordpos);
        ERRCHECK(result);

        if (channel)
        {
            FMOD_Channel_IsPlaying(channel, &playing);
            ERRCHECK(result);

            FMOD_Channel_GetPosition(channel, &playpos, FMOD_TIMEUNIT_PCM);
            ERRCHECK(result);
        }

        printf("State: %-19s. Record pos = %6d : Play pos = %6d : Loop %-3s\r", recording ? playing ? "Recording / playing" : "Recording" : playing ? "Playing" : "Idle", recordpos, playpos, looping ? "On" : "Off");
        fflush(stdout);

        FMOD_System_Update(system);

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(sound);
    ERRCHECK(result);

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

    return 0;
}
Beispiel #9
0
/*
=======================================
    生成 FMODEx 系统对象
=======================================
*/
CR_API bool_t
fmodex_init (void_t)
{
    uint_t              vers;
    sint_t              ndrv;
    FMOD_CAPS           caps;
    FMOD_RESULT         result;
    FMOD_SYSTEM*        system;
    FMOD_SPEAKERMODE    spkmode;
    ansi_t              name[256];

    /* 已经生成过了 */
    if (s_fmodex != NULL)
        return (TRUE);

    /* FMODEx 推荐的初始化过程 */
    result = FMOD_System_Create(&system);
    if (result != FMOD_OK)
        return (FALSE);
    result = FMOD_System_GetVersion(system, &vers);
    if (result != FMOD_OK)
        goto _failure;
    if (vers < FMOD_VERSION)
        goto _failure;
    result = FMOD_System_GetNumDrivers(system, &ndrv);
    if (result != FMOD_OK)
        goto _failure;
    if (ndrv == 0) {
        result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_NOSOUND);
        if (result != FMOD_OK)
            goto _failure;
    }
    else {
        result = FMOD_System_GetDriverCaps(system, 0, &caps, 0, &spkmode);
        if (result != FMOD_OK)
            goto _failure;
        result = FMOD_System_SetSpeakerMode(system, spkmode);
        if (result != FMOD_OK)
            goto _failure;
        if (caps & FMOD_CAPS_HARDWARE_EMULATED) {
            result = FMOD_System_SetDSPBufferSize(system, 1024, 10);
            if (result != FMOD_OK)
                goto _failure;
        }
        result = FMOD_System_GetDriverInfo(system, 0, name, sizeof(name), 0);
        if (result != FMOD_OK)
            goto _failure;
        if (str_strA(name, "SigmaTel")) {
            result = FMOD_System_SetSoftwareFormat(system,
                            48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0, 0,
                                FMOD_DSP_RESAMPLER_LINEAR);
            if (result != FMOD_OK)
                goto _failure;
        }
    }
    result = FMOD_System_Init(system, 100, FMOD_INIT_NORMAL, 0);
    if (result == FMOD_ERR_OUTPUT_CREATEBUFFER) {
        result = FMOD_System_SetSpeakerMode(system, FMOD_SPEAKERMODE_STEREO);
        if (result != FMOD_OK)
            goto _failure;
        result = FMOD_System_Init(system, 100, FMOD_INIT_NORMAL, 0);
    }
    if (result != FMOD_OK)
        goto _failure;

    /* 设置全局对象 */
    s_fmodex = system;
    return (TRUE);

_failure:
    FMOD_System_Release(system);
    return (FALSE);
}
Beispiel #10
0
void Sound::Initialize()
{
    FMOD_RESULT result = FMOD_OK;

	result = FMOD_System_Create(&fmodSystem);
	check_error(result);

	unsigned int version;
	result = FMOD_System_GetVersion(fmodSystem, &version);
	check_error(result);
	if(version < FMOD_VERSION)
	{
		LOG_ISSUE("AUDIO ERROR: fmodex.dll is an older version than needed. "
			"FMOD version should be at least %u.", FMOD_VERSION);
	}

	int numDrivers;
	result = FMOD_System_GetNumDrivers(fmodSystem, &numDrivers);
	check_error(result);

	if(numDrivers == 0)
	{
		result = FMOD_System_SetOutput(fmodSystem, FMOD_OUTPUTTYPE_NOSOUND);
		check_error(result);
	}
	else
	{
		FMOD_CAPS capabilities;
		FMOD_SPEAKERMODE speakerMode;
		result = FMOD_System_GetDriverCaps(fmodSystem, 0, &capabilities, nullptr, &speakerMode);
		check_error(result);

		result = FMOD_System_SetSpeakerMode(fmodSystem, speakerMode);
		check_error(result);

		// if hardware acceleration is not available,
		// extend the buffer size to make sure there is enough room
		if(capabilities & FMOD_CAPS_HARDWARE_EMULATED)
		{
			result = FMOD_System_SetDSPBufferSize(fmodSystem, 1024, 10);
			check_error(result);
		}

		char name[256];
		result = FMOD_System_GetDriverInfo(fmodSystem, 0, name, 256, nullptr);
		check_error(result);

		// SigmaTel sound devices crackle when the sound format is PCM 16-bit
		// PCM Floating-Point seems to fix it
		if(strstr(name, "SigmaTel"))
		{
			result = FMOD_System_SetSoftwareFormat(fmodSystem, 48000, FMOD_SOUND_FORMAT_PCMFLOAT,
				0, 0, FMOD_DSP_RESAMPLER_LINEAR);
			check_error(result);
		}
	}

	result = FMOD_System_Init(fmodSystem, MAX_CHANNELS, FMOD_INIT_NORMAL, 0);
	check_error(result);

	result = FMOD_System_CreateSoundGroup(fmodSystem, "Music", &musicGroup);
	check_error(result);
	result = FMOD_System_CreateSoundGroup(fmodSystem, "Sound Effects", &noiseGroup);
	check_error(result);

	numSounds = 0;
	for(int i = 0; i < MAX_SOUNDS; i++)
		sounds[i] = nullptr;
}
Beispiel #11
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM           *system  = 0;
    FMOD_SOUND            *sound   = 0;
    FMOD_CHANNEL          *channel = 0;
    FMOD_DSP              *dsp     = 0;
    FMOD_RESULT            result;
    FMOD_CREATESOUNDEXINFO exinfo;
    FMOD_SPEAKERMODE       speakermode;
    FMOD_CAPS              caps;
    int                    key, numdrivers;
    unsigned int           version;    
    unsigned int           datalength = 0, soundlength;
    char                   name[256];
    unsigned int           adjustedlatency;

    /*
        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;
    }

    /* 
        System initialization (recommended startup sequence)
    */
    result = FMOD_System_GetNumDrivers(system, &numdrivers);
    ERRCHECK(result);

    if (numdrivers == 0)
    {
        result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_NOSOUND);
        ERRCHECK(result);
    }
    else
    {
        result = FMOD_System_GetDriverCaps(system, 0, &caps, 0, &speakermode);
        ERRCHECK(result);

        result = FMOD_System_SetSpeakerMode(system, speakermode);       /* Set the user selected speaker mode. */
        ERRCHECK(result);

        if (caps & FMOD_CAPS_HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
        {                                                   /* You might want to warn the user about this. */
            result = FMOD_System_SetDSPBufferSize(system, 1024, 10);
            ERRCHECK(result);
        }
#ifdef LOWLATENCY
        else
        {
            result = FMOD_System_SetDSPBufferSize(system, 256, 4);
        }
#endif
        result = FMOD_System_GetDriverInfo(system, 0, name, 256, 0);
        ERRCHECK(result);

        if (strstr(name, "SigmaTel"))   /* Sigmatel sound devices crackle for some reason if the format is PCM 16bit.  PCM floating point output seems to solve it. */
        {
            result = FMOD_System_SetSoftwareFormat(system, 48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR);
            ERRCHECK(result);
        }
    }

    result = FMOD_System_Init(system, 100, FMOD_INIT_NORMAL, 0);
    if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)         /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
    {
        result = FMOD_System_SetSpeakerMode(system, FMOD_SPEAKERMODE_STEREO);
        ERRCHECK(result);
            
        result = FMOD_System_Init(system, 100, FMOD_INIT_NORMAL, 0);/* ... and re-init. */
        ERRCHECK(result);
    }
    /* 
        System initialization complete (recommended startup sequence)
    */
 

    /*
        Create user sound to record into.  Set it to loop for playback.
    */
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 1;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = RECORDRATE;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5; /* 5 second buffer, doesnt really matter how big this is, but not too small of course. */
    
    result = FMOD_System_CreateSound(system, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    printf("========================================================================\n");
    printf("Record with realtime playback example.\n");
    printf("Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("\n");
    printf("Try #define LOWLATENCY to reduce latency for more modern machines!\n");
    printf("========================================================================\n");
    printf("\n");
    printf("Press a key to start recording.  Playback will start %d samples (%d ms) later.\n", LATENCY, LATENCY * 1000 / RECORDRATE);
    printf("\n");

    _getch();

    printf("Press 'E' to toggle an effect on/off.\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    result = FMOD_System_RecordStart(system, 0, sound, TRUE);
    ERRCHECK(result);

    result = FMOD_Sound_GetLength(sound, &soundlength, FMOD_TIMEUNIT_PCM);
    ERRCHECK(result);

    /*
        Create a DSP effect to play with.
    */
    result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_FLANGE, &dsp);
    ERRCHECK(result);
    result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_FLANGE_RATE, 4.0f);
    ERRCHECK(result);
    result = FMOD_DSP_SetBypass(dsp, TRUE);   
    ERRCHECK(result);
    
    adjustedlatency = LATENCY;  /* This might change depending on record block size. */
    
    /*
        Main loop.
    */
    do
    {
        static unsigned int lastrecordpos = 0, samplesrecorded = 0;
        unsigned int recordpos = 0, recorddelta;
        
        key = 0;
        if (_kbhit())
        {
            key = _getch();
        }

        if (key == 'e' || key == 'E')
        {
            int bypass;
            FMOD_DSP_GetBypass(dsp, &bypass);
            FMOD_DSP_SetBypass(dsp, !bypass);
            if (bypass)
            {
                FMOD_REVERB_PROPERTIES prop = FMOD_PRESET_CONCERTHALL;
                FMOD_System_SetReverbProperties(system, &prop);
            }
            else
            {
                FMOD_REVERB_PROPERTIES prop = FMOD_PRESET_OFF;
                FMOD_System_SetReverbProperties(system, &prop);
            }
            printf("\n\n *** TURN DSP EFFECT %s ** \n\n", bypass ? "ON" : "OFF");
        }
        
        FMOD_System_GetRecordPosition(system, 0, &recordpos);
        ERRCHECK(result);

        recorddelta = recordpos >= lastrecordpos ? recordpos - lastrecordpos : recordpos + soundlength - lastrecordpos;
        samplesrecorded += recorddelta;

		if (samplesrecorded >= adjustedlatency && !channel)
		{
		    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
            ERRCHECK(result);
            
            result = FMOD_Channel_AddDSP(channel, dsp, 0);
            ERRCHECK(result);
		}
				
        if (channel && recorddelta)
        {
            unsigned int playrecorddelta;
            unsigned int playpos = 0;
            int adjusting = 0;
            float smootheddelta;
            float dampratio = 0.97f;
            static unsigned int minrecorddelta = (unsigned int)-1;
            
            /*
                If the record driver steps the position of the record cursor in larger increments than the user defined latency value, then we should
                increase our latency value to match.
            */
            if (recorddelta < minrecorddelta)
            {
                minrecorddelta = recorddelta;
                if (adjustedlatency < recorddelta)
                {
                    adjustedlatency = recorddelta;
                }
            }

            FMOD_Channel_GetPosition(channel, &playpos, FMOD_TIMEUNIT_PCM);

            playrecorddelta = recordpos >= playpos ? recordpos - playpos : recordpos + soundlength - playpos;
            
	        /*
                Smooth total
            */
            {
                static float total = 0;
                
                total = total * dampratio;
	            total += playrecorddelta;
	            smootheddelta = total * (1.0f - dampratio);
            }
           
            if (smootheddelta < adjustedlatency - DRIFTTHRESHOLD || smootheddelta > soundlength / 2)   /* if play cursor is catching up to record (or passed it), slow playback down */
            {
                FMOD_Channel_SetFrequency(channel, RECORDRATE - (RECORDRATE / 50)); /* Decrease speed by 2% */
                adjusting = 1;
            }
            else if (smootheddelta > adjustedlatency + DRIFTTHRESHOLD)   /* if play cursor is falling too far behind record, speed playback up */
            {
                FMOD_Channel_SetFrequency(channel, RECORDRATE + (RECORDRATE / 50)); /* Increase speed by 2% */
                adjusting = 2;
            }
            else
            {
                FMOD_Channel_SetFrequency(channel, RECORDRATE);          /* Otherwise set to normal rate */
                adjusting = 0;
            }
            
            printf("REC %5d (REC delta %5d) : PLAY %5d, PLAY/REC diff %5d %s\r", recordpos, recorddelta, playpos, (int)smootheddelta, adjusting == 1 ? "DECREASE SPEED" : adjusting == 2 ? "INCREASE SPEED" : "              ");
        }
        
        lastrecordpos = recordpos;
        
        FMOD_System_Update(system);

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(sound);
    ERRCHECK(result);

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

    return 0;
}
Beispiel #12
0
//FMOD Thread
void getSpectrum(void *fm) {
	FMOD_SYSTEM *fmod = (FMOD_SYSTEM*)fm;
	FMOD_CHANNEL *channel = 0;
	FMOD_SOUND *sound = 0;
	FMOD_CREATESOUNDEXINFO exinfo;
	int numdrivers, selected=-1;//for stereo mix
	int count;//stereo mix
	char name[256]; //stereo mix
	float t[SPECTRUMSIZE/8];
	int j = 0;
	int i = 0;
	float max=0;

	FMOD_RESULT result;
	static float spectrum[SPECTRUMSIZE];

	result = FMOD_System_SetOutput(fmod, FMOD_OUTPUTTYPE_DSOUND); //output=directsound

	//get stereo mix
	result = FMOD_System_GetRecordNumDrivers(fmod, &numdrivers);

	for (count=0; count < numdrivers; count++)
    {
        result = FMOD_System_GetRecordDriverInfo(fmod, count, name, 256, 0);
        
		if(strncmp(name, "Stereo Mix", strlen("Stereo Mix"))==0) {
			selected=count;
		}
    }

	if(selected == -1) {
		printf("Couldn't find Stereo Mix!\n");
		exit(-1);
	}

	//create a sound
	result = FMOD_System_SetSoftwareFormat(fmod, OUTPUTRATE, FMOD_SOUND_FORMAT_PCM16, 1, 0, FMOD_DSP_RESAMPLER_LINEAR);
    
	result = FMOD_System_Init(fmod, 100, FMOD_INIT_NORMAL, 0);

	memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 1;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = OUTPUTRATE;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
    
    result = FMOD_System_CreateSound(fmod, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);

	result = FMOD_System_RecordStart(fmod, selected, sound, TRUE);
	Sleep(200);
	result = FMOD_System_PlaySound(fmod, FMOD_CHANNEL_REUSE, sound, FALSE, &channel);
	result = FMOD_Channel_SetVolume(channel, 0);

	do {
		result = FMOD_Channel_GetSpectrum(channel, spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE);

		
		for(i = 0;i<8000;i++) {
			t[j]+=(10.0f * (float)log10(spectrum[i]) * 2.0f);

			if(i<=1600) j=0;
			if(i>1600)j=1;
			if(i>3200)j=2;
			if(i>4800)j=3;
			if(i>6400)j=4;
			
		}

		max=0;

		WaitForSingleObject(spectrumMutex, INFINITE);
		for(i =0;i<5;i++) {
			t[i]=t[i]/1600+150;
			

			analyzedSpectrum[i] = t[i];

			if(t[i] >max) {max=t[i];}
		}
		ReleaseMutex(spectrumMutex);
		

		FMOD_System_Update(fmod);
		Sleep(10);

		WaitForSingleObject(stopAppMutex, INFINITE);
		if(_stopApp==TRUE) {break;}
		ReleaseMutex(stopAppMutex);
	}while(1);

	_endthread();
}
Beispiel #13
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM           *system  = 0;
    FMOD_SOUND            *sound   = 0;
    FMOD_CHANNEL          *channel = 0;
    FMOD_RESULT            result;
    FMOD_CREATESOUNDEXINFO exinfo;
    int                    key, driver, recorddriver, numdrivers, count, bin;
    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;
    }

    /* 
        System initialization
    */
    printf("---------------------------------------------------------\n");    
    printf("Select OUTPUT type\n");    
    printf("---------------------------------------------------------\n");    
    printf("1 :  DirectSound\n");
    printf("2 :  Windows Multimedia WaveOut\n");
    printf("3 :  ASIO\n");
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = _getch();
    } while (key != 27 && key < '1' && key > '5');
    
    switch (key)
    {
        case '1' :  result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_DSOUND);
                    break;
        case '2' :  result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_WINMM);
                    break;
        case '3' :  result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ASIO);
                    break;
        default  :  return 1; 
    }  
    ERRCHECK(result);
    
    /*
        Enumerate playback devices
    */

    result = FMOD_System_GetNumDrivers(system, &numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a PLAYBACK driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = FMOD_System_GetDriverInfo(system, count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    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 >= numdrivers);

    result = FMOD_System_SetDriver(system, driver);
    ERRCHECK(result);

    /*
        Enumerate record devices
    */

    result = FMOD_System_GetRecordNumDrivers(system, &numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a RECORD driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = FMOD_System_GetRecordDriverInfo(system, count, name, 256, 0);
        ERRCHECK(result);

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    recorddriver = 0;
    do
    {
        key = _getch();
        if (key == 27)
        {
            return 0;
        }
        recorddriver = key - '1';
    } while (recorddriver < 0 || recorddriver >= numdrivers);

    printf("\n");
 
    result = FMOD_System_SetSoftwareFormat(system, OUTPUTRATE, FMOD_SOUND_FORMAT_PCM16, 1, 0, FMOD_DSP_RESAMPLER_LINEAR);
    ERRCHECK(result);

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

    /*
        Create a sound to record to.
    */
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 1;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = OUTPUTRATE;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
    
    result = FMOD_System_CreateSound(system, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    /*
        Start the interface
    */
    printf("=========================================================================\n");
    printf("Pitch detection example.  Copyright (c) Firelight Technologies 2004-2015.\n");
    printf("=========================================================================\n");
    printf("\n");
    printf("Record something through the selected recording device and FMOD will\n");
    printf("Determine the pitch.  Sustain the tone for at least a second to get an\n");
    printf("accurate reading.\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    result = FMOD_System_RecordStart(system, recorddriver, sound, TRUE);
    ERRCHECK(result);
    
    Sleep(200);                         /* Give it some time to record something */
    
    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_REUSE, sound, FALSE, &channel);
    ERRCHECK(result);

    /* Dont hear what is being recorded otherwise it will feedback.  Spectrum analysis is done before volume scaling in the DSP chain */
    result = FMOD_Channel_SetVolume(channel, 0);
    ERRCHECK(result);

    bin = 0;

    /*
        Main loop.
    */
    do
    {
        static float spectrum[SPECTRUMSIZE];
        float        dominanthz = 0;
        float        max;
        int          dominantnote = 0;
        float        binsize = BINSIZE;

        if (_kbhit())
        {
            key = _getch();
        }

        result = FMOD_Channel_GetSpectrum(channel, spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE); 
        ERRCHECK(result);

        max = 0;

        for (count = 0; count < SPECTRUMSIZE; count++)
        {
            if (spectrum[count] > 0.01f && spectrum[count] > max)
            {
                max = spectrum[count];
                bin = count;
            }
        }        

        dominanthz  = (float)bin * BINSIZE;       /* dominant frequency min */

        dominantnote = 0;
        for (count = 0; count < 120; count++)
        {
             if (dominanthz >= notefreq[count] && dominanthz < notefreq[count + 1])
             {
                /* which is it closer to.  This note or the next note */
                if (fabs(dominanthz - notefreq[count]) < fabs(dominanthz - notefreq[count+1]))
                {
                    dominantnote = count;
                }
                else
                {
                    dominantnote = count + 1;
                }
                break;
             }
        }

        printf("Detected rate : %7.1f -> %7.1f hz.  Detected musical note. %-3s (%7.1f hz)\r", dominanthz, ((float)bin + 0.99f) * BINSIZE, note[dominantnote], notefreq[dominantnote]);

        FMOD_System_Update(system);

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(sound);
    ERRCHECK(result);

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

    return 0;
}
Beispiel #14
0
int main(int argc, char *argv[])
{
    FMOD_CHANNEL    *channel[2] = { 0,0 };
    FMOD_RESULT       result;
    int               key, outputrate, slot = 0, count, numdrivers;
    unsigned int      version;
    
    printf("=============================================================================\n");
    printf("Granular Synthesis SetDelay example.\n");
    printf("Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("=============================================================================\n");
    printf("\n");
    printf("TOGGLE #define USE_STREAMS ON/OFF TO SWITCH BETWEEN STREAMS/STATIC SAMPLES.\n");
    printf("Press space to pause, Esc to quit\n");
    printf("\n");
    
    /*
        ===============================================================================================================
        RECOMMENDED STARTUP SEQUENCE BEGIN
        ===============================================================================================================
    */

    result = FMOD_System_Create(&gSystem);
    ERRCHECK(result);
    
    result = FMOD_System_GetVersion(gSystem, &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_GetNumDrivers(gSystem, &numdrivers);
    ERRCHECK(result);

    if (numdrivers == 0)
    {
        result = FMOD_System_SetOutput(gSystem, FMOD_OUTPUTTYPE_NOSOUND);
        ERRCHECK(result);
    }
    else
    {
        FMOD_CAPS caps;
        FMOD_SPEAKERMODE speakermode;
        char name[256];
        
        result = FMOD_System_GetDriverCaps(gSystem, 0, &caps, 0, &speakermode);
        ERRCHECK(result);

        result = FMOD_System_SetSpeakerMode(gSystem, speakermode);       /* Set the user selected speaker mode. */
        ERRCHECK(result);

        if (caps & FMOD_CAPS_HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
        {                                                   /* You might want to warn the user about this. */
            result = FMOD_System_SetDSPBufferSize(gSystem, 1024, 10);
            ERRCHECK(result);
        }

        result = FMOD_System_GetDriverInfo(gSystem, 0, name, 256, 0);
        ERRCHECK(result);

        if (strstr(name, "SigmaTel"))   /* Sigmatel sound devices crackle for some reason if the format is PCM 16bit.  PCM floating point output seems to solve it. */
        {
            result = FMOD_System_SetSoftwareFormat(gSystem, 48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR);
            ERRCHECK(result);
        }
    }

    result = FMOD_System_Init(gSystem, 100, FMOD_INIT_NORMAL, 0);
    if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)         /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
    {
        result = FMOD_System_SetSpeakerMode(gSystem, FMOD_SPEAKERMODE_STEREO);
        ERRCHECK(result);
            
        result = FMOD_System_Init(gSystem, 100, FMOD_INIT_NORMAL, 0);/* ... and re-init. */
        ERRCHECK(result);
    }
    
    /*
        ===============================================================================================================
        RECOMMENDED STARTUP SEQUENCE END
        ===============================================================================================================
    */
        
    result = FMOD_System_GetSoftwareFormat(gSystem, &outputrate, 0,0,0,0,0);
    ERRCHECK(result);   
   
#if !defined(USE_STREAMS)
    for (count = 0; count < NUMSOUNDS; count++)
    {
        result = FMOD_System_CreateSound(gSystem, soundname[count], FMOD_IGNORETAGS, 0, &sound[count]);
        ERRCHECK(result);
    }
#endif

    /*
        Kick off the first 2 sounds.  First one is immediate, second one will be triggered to start after the first one.
    */
    channel[slot] = queue_next_sound(outputrate, channel[1-slot], rand()%NUMSOUNDS, slot);
    slot = 1-slot;  /* flip */
    channel[slot] = queue_next_sound(outputrate, channel[1-slot], rand()%NUMSOUNDS, slot);
    slot = 1-slot;  /* flip */

    /*
        Main loop.
    */
    do
    {
        int isplaying;
        static int paused = 0;

        if (_kbhit())
        {
            key = _getch();

            switch (key)
            {
                case ' ' :
                {
                    set_paused(channel, paused);
                    paused = !paused;
                    break;
                }
            }
        }

        FMOD_System_Update(gSystem);

        /*
            Replace the sound that just finished with a new sound, to create endless seamless stitching!
        */
        result = FMOD_Channel_IsPlaying(channel[slot], &isplaying);
        if (!isplaying && !paused)
        {
            printf("sound %d finished, start a new one\n", slot);
            #ifdef USE_STREAMS
            /* 
                Release the sound that isn't playing any more. 
            */
            result = FMOD_Sound_Release(sound[slot]);       
            ERRCHECK(result);
            sound[slot] = 0;
            #endif
   
            /*
                Replace sound that just ended with a new sound, queued up to trigger exactly after the other sound ends.
            */
            channel[slot] = queue_next_sound(outputrate, channel[1-slot], rand()%NUMSOUNDS, slot);
            slot = 1-slot;  /* flip */
        }
        
        Sleep(10);  /* If you wait too long, ie longer than the length of the shortest sound, you will get gaps. */

    } while (key != 27);

    printf("\n");

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

    return 0;
}
Beispiel #15
0
void FMOD_Startup (void)
{
	FMOD_CAPS			caps;
	FMOD_SPEAKERMODE	speakermode;
	FMOD_OUTPUTTYPE		fmod_output;
	unsigned int		version;
	int numdrivers;
	char name[256];

	result = FMOD_System_Create(&fmod_system);
    FMOD_ERROR(result, true, false);

    result = FMOD_System_GetVersion(fmod_system, &version);
    FMOD_ERROR(result, true, false);

    if (version < FMOD_VERSION)
    {
		Con_Printf("\nFMOD version incorrect, found v%1.2f, requires v%1.2f or newer\n", version, FMOD_VERSION);
        return;
    }

	result = FMOD_System_GetNumDrivers(fmod_system, &numdrivers);
	FMOD_ERROR(result, true, false);

	if (numdrivers == 0)
	{
		result = FMOD_System_SetOutput(fmod_system, FMOD_OUTPUTTYPE_NOSOUND);
		FMOD_ERROR(result, true, false);
	}
	else
	{
		result = FMOD_System_SetOutput(fmod_system, FMOD_OUTPUTTYPE_AUTODETECT);
		FMOD_ERROR(result, true, false);

		result = FMOD_System_GetDriverCaps(fmod_system, 0, &caps, NULL, &speakermode);
		FMOD_ERROR(result, true, false);

		// set the user selected speaker mode
		result = FMOD_System_SetSpeakerMode(fmod_system, FMOD_SPEAKERMODE_STEREO /*speakermode*/);
		FMOD_ERROR(result, true, false);

		if (caps & FMOD_CAPS_HARDWARE_EMULATED)
		{
			// the user has the 'Acceleration' slider set to off. this is really bad for latency!
			result = FMOD_System_SetDSPBufferSize(fmod_system, 1024, 10);
			FMOD_ERROR(result, true, false);

			Con_Printf("\nHardware Acceleration is turned off!\n");
		}

		result = FMOD_System_GetDriverInfo(fmod_system, 0, name, 256, NULL);
		FMOD_ERROR(result, true, false);
		
		if (strstr(name, "SigmaTel"))
		{
			// Sigmatel sound devices crackle for some reason if the format is PCM 16bit.
			// PCM floating point output seems to solve it.
			result = FMOD_System_SetSoftwareFormat(fmod_system, 48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0, 0, FMOD_DSP_RESAMPLER_LINEAR);
			FMOD_ERROR(result, true, false);
		}
	}

	result = FMOD_System_GetSoftwareChannels(fmod_system, &SND_SoftwareChannels);
	FMOD_ERROR(result, true, false);

	result = FMOD_System_GetSoftwareFormat(fmod_system, &SND_Rate, NULL, NULL, NULL, NULL, &SND_Bits);
	FMOD_ERROR(result, true, false);

	result = FMOD_System_Init(fmod_system, MAX_CHANNELS, FMOD_INIT_NORMAL, NULL);
    FMOD_ERROR(result, true, false);

	if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)
	{
		// the speaker mode selected isn't supported by this soundcard. Switch it back to stereo...
		result = FMOD_System_SetSpeakerMode(fmod_system, FMOD_SPEAKERMODE_STEREO);
		FMOD_ERROR(result, true, false);

		// ... and re-init.
		result = FMOD_System_Init(fmod_system, MAX_CHANNELS, FMOD_INIT_NORMAL, NULL);
		FMOD_ERROR(result, true, false);
	}

	result = FMOD_System_GetSpeakerMode(fmod_system, &speakermode);
	FMOD_ERROR(result, true, false);

	result = FMOD_System_GetOutput(fmod_system, &fmod_output);
	FMOD_ERROR(result, true, false);

	result = FMOD_System_GetHardwareChannels(fmod_system, &SND_HardwareChannels);
	FMOD_ERROR(result, true, false);


	// print all the sound information to the console

	Con_Printf("\nFMOD version %01x.%02x.%02x\n", (FMOD_VERSION >> 16) & 0xff, (FMOD_VERSION >> 8) & 0xff, FMOD_VERSION & 0xff);

	switch(fmod_output)
	{
		case FMOD_OUTPUTTYPE_NOSOUND:
			Con_Printf("using No Sound\n");
			break;

		case FMOD_OUTPUTTYPE_DSOUND:
			Con_Printf("using Microsoft DirectSound\n");
			break;

		case FMOD_OUTPUTTYPE_WINMM:
			Con_Printf("using Windows Multimedia\n");
			break;

		case FMOD_OUTPUTTYPE_WASAPI:
			Con_Printf("using Windows Audio Session API\n");
			break;

		case FMOD_OUTPUTTYPE_ASIO:
			Con_Printf("using Low latency ASIO\n");
			break;
	}
	
	Con_Printf("   software channels: %i\n", SND_SoftwareChannels);
	Con_Printf("   hardware channels: %i\n", SND_HardwareChannels);
	Con_Printf("   %i bits/sample\n", SND_Bits);
	Con_Printf("   %i bytes/sec\n", SND_Rate);

	switch(speakermode)
	{
		case FMOD_SPEAKERMODE_RAW:
			Con_Printf("Speaker Output: Raw\n");
			break;

		case FMOD_SPEAKERMODE_MONO:
			Con_Printf("Speaker Output: Mono\n");
			break;

		case FMOD_SPEAKERMODE_STEREO:
			Con_Printf("Speaker Output: Stereo\n");
			break;

		case FMOD_SPEAKERMODE_QUAD:
			Con_Printf("Speaker Output: Quad\n");
			break;

		case FMOD_SPEAKERMODE_SURROUND:
			Con_Printf("Speaker Output: Surround\n");
			break;

		case FMOD_SPEAKERMODE_5POINT1:
			Con_Printf("Speaker Output: 5.1\n");
			break;

		case FMOD_SPEAKERMODE_7POINT1:
			Con_Printf("Speaker Output: 7.1\n");
			break;

		case FMOD_SPEAKERMODE_SRS5_1_MATRIX:
			Con_Printf("Speaker Output: Stereo compatible\n");
			break;

		case FMOD_SPEAKERMODE_MYEARS:
			Con_Printf("Speaker Output: Headphones\n");
			break;

		default:
			Con_Printf("Speaker Output: Unknown\n");
	}

	if(SND_File.data)
		free(SND_File.data);
	SND_File.data = NULL;
	SND_File.length = 0;
	strcpy(SND_File.filename, "\0");


	CDA_Startup(true);


	SND_Initialised = true;
}