Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM             *system;
    FMOD_SOUND              *sound;
    FMOD_CHANNEL            *channel = 0;
    FMOD_RESULT             result;
    int                     key;
    FMOD_CREATESOUNDEXINFO  createsoundexinfo;
    unsigned int            version, decodesound_lengthbytes = 0;
    int                     decodesound_channels;
    float                   decodesound_rate;

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

    InitializeCriticalSection(&decodecrit);

    /*
        First create the 'decoder sound'.  Note it is a stream that does not initially read any data, because FMOD_OPENONLY has been specified.
        We could use createSound instead of createStream but that would allocate memory for the whole sound which is a waste.
    */
    result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_OPENONLY | FMOD_LOOP_NORMAL | FMOD_LOWMEM | FMOD_CREATESTREAM, 0, &decodesound); 
    ERRCHECK(result);

    result = FMOD_Sound_GetLength(decodesound, &decodesound_lengthbytes, FMOD_TIMEUNIT_PCMBYTES);
    ERRCHECK(result);

    result = FMOD_Sound_GetFormat(decodesound, 0, 0, &decodesound_channels, 0);
    ERRCHECK(result);

    result = FMOD_Sound_GetDefaults(decodesound, &decodesound_rate, 0, 0, 0);
    ERRCHECK(result);
        
    /*
        Now create a user created PCM stream that we will feed data into, and play.
    */
    memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    createsoundexinfo.cbsize            = sizeof(FMOD_CREATESOUNDEXINFO);              /* required. */
    createsoundexinfo.decodebuffersize  = 44100;                                       /* Chunk size of stream update in samples.  This will be the amount of data passed to the user callback. */
    createsoundexinfo.numchannels       = decodesound_channels;                        /* Number of channels in the sound. */
    createsoundexinfo.length            = decodesound_lengthbytes;                     /* Length of PCM data in bytes of whole song.  -1 = infinite. */
    createsoundexinfo.defaultfrequency  = (int)decodesound_rate;                       /* Default playback rate of sound. */
    createsoundexinfo.format            = FMOD_SOUND_FORMAT_PCM16;                     /* Data format of sound. */
    createsoundexinfo.pcmreadcallback   = pcmreadcallback;                             /* User callback for reading. */
    createsoundexinfo.pcmsetposcallback = pcmsetposcallback;                           /* User callback for seeking. */

    result = FMOD_System_CreateStream(system, 0, FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL, &createsoundexinfo, &sound);
    ERRCHECK(result);

    printf("============================================================================\n");
    printf("Manual Decode example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("============================================================================\n");
    printf("Sound played here decoded in realtime by the user with a 'decoder sound'    \n");
    printf("The mp3 is created as a stream opened with FMOD_OPENONLY. This is the       \n");
    printf("'decoder sound'.  The playback sound is a 16bit PCM FMOD_OPENUSER created   \n");
    printf("sound with a pcm read callback.  When the callback happens, we call readData\n");
    printf("on the decoder sound and use the pcmreadcallback data pointer as the parameter.\n");
    printf("============================================================================\n");
    printf("\n");
    printf("Press space to pause, Esc to quit\n");
    printf("Press '<' to rewind 1 second.\n");
    printf("Press '>' to fast forward 1 second.\n");
    printf("\n");

    /*
        Play the sound.
    */

    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
    ERRCHECK(result);

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

            switch (key)
            {
                case ' ' :
                {
                    int paused;
                    FMOD_Channel_GetPaused(channel, &paused);
                    FMOD_Channel_SetPaused(channel, !paused);
                    break;
                }
                case '<' :
                {
                    unsigned int position;

                    FMOD_Channel_GetPosition(channel, &position, FMOD_TIMEUNIT_MS);
                    if (position >= 1000)
                    {
                        position -= 1000;
                    }
                    FMOD_Channel_SetPosition(channel, position, FMOD_TIMEUNIT_MS);
                    break;
                }
                case '>' :
                {
                    unsigned int position;

                    FMOD_Channel_GetPosition(channel, &position, FMOD_TIMEUNIT_MS);
                    position += 1000;
                    FMOD_Channel_SetPosition(channel, position, FMOD_TIMEUNIT_MS);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        if (channel)
        {
            unsigned int ms;
            unsigned int lenms;
            int          playing;
            int          paused;

            FMOD_Channel_IsPlaying(channel, &playing);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Channel_GetPaused(channel, &paused);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
        }

        Sleep(20);

    } while (key != 27);

    printf("\n");

    EnterCriticalSection(&decodecrit);
    {
        /*
            Remove the sound - wait! it might be still in use!
            Instead of releasing the decode sound first we could release it last, but this protection is here to make the issue obvious.
        */
        result = FMOD_Sound_Release(decodesound);
        ERRCHECK(result);
        decodesound = 0;    /* This will make the read callback fail from now on. */
    }
    LeaveCriticalSection(&decodecrit);

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

    DeleteCriticalSection(&decodecrit);

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM      *system;
    FMOD_SOUND       *sound;
    FMOD_SOUND       *subsound[2];
    FMOD_CREATESOUNDEXINFO exinfo;
    FMOD_CHANNEL     *channel = 0;
    FMOD_RESULT       result;
    int               key;
    unsigned int      subsoundid, sentenceid;
    unsigned int      version;
    const char       *soundname[NUMSOUNDS] = 
    {
        "../media/e.ogg",   /* Ma-    */
        "../media/d.ogg",   /* ry     */
        "../media/c.ogg",   /* had    */
        "../media/d.ogg",   /* a      */
        "../media/e.ogg",   /* lit-   */
        "../media/e.ogg",   /* tle    */
        "../media/e.ogg",   /* lamb,  */
        "../media/e.ogg",   /* .....  */
        "../media/d.ogg",   /* lit-   */
        "../media/d.ogg",   /* tle    */
        "../media/d.ogg",   /* lamb,  */
        "../media/d.ogg",   /* .....  */
        "../media/e.ogg",   /* lit-   */
        "../media/e.ogg",   /* tle    */
        "../media/e.ogg",   /* lamb,  */
        "../media/e.ogg",   /* .....  */

        "../media/e.ogg",   /* Ma-    */
        "../media/d.ogg",   /* ry     */
        "../media/c.ogg",   /* had    */
        "../media/d.ogg",   /* a      */
        "../media/e.ogg",   /* lit-   */
        "../media/e.ogg",   /* tle    */
        "../media/e.ogg",   /* lamb,  */
        "../media/e.ogg",   /* its    */
        "../media/d.ogg",   /* fleece */
        "../media/d.ogg",   /* was    */
        "../media/e.ogg",   /* white  */
        "../media/d.ogg",   /* as     */
        "../media/c.ogg",   /* snow.  */
        "../media/c.ogg",   /* .....  */
        "../media/c.ogg",   /* .....  */
        "../media/c.ogg",   /* .....  */
    };

    /*
        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, 1, FMOD_INIT_NORMAL, NULL);
    ERRCHECK(result);

    /*
        Set up the FMOD_CREATESOUNDEXINFO structure for the user stream with room for 2 subsounds. (our subsound double buffer)
    */
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.defaultfrequency = 44100;
    exinfo.numsubsounds = 2;
    exinfo.numchannels = 1;
    exinfo.format = FMOD_SOUND_FORMAT_PCM16;

    /*
        Create the 'parent' stream that contains the substreams.  Set it to loop so that it loops between subsound 0 and 1.
    */
    result = FMOD_System_CreateStream(system, 0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    /*
        Add 2 of our streams as children of the parent.  They should be the same format (ie mono/stereo and bitdepth) as the parent sound.
        When subsound 0 has finished and it is playing subsound 1, we will swap subsound 0 with a new sound, and the same for when subsound 1 has finished,
        causing a continual double buffered flip, which means continuous sound.
    */
    result = FMOD_System_CreateStream(system, soundname[0], FMOD_DEFAULT, 0, &subsound[0]);
    ERRCHECK(result);

    result = FMOD_System_CreateStream(system, soundname[1], FMOD_DEFAULT, 0, &subsound[1]);
    ERRCHECK(result);

    result = FMOD_Sound_SetSubSound(sound, 0, subsound[0]);
    ERRCHECK(result);

    result = FMOD_Sound_SetSubSound(sound, 1, subsound[1]);
    ERRCHECK(result);

    /*
        Set up the gapless sentence to contain these first 2 streams.
    */
    {
        int soundlist[2] = { 0, 1 };
     
        result = FMOD_Sound_SetSubSoundSentence(sound, soundlist, 2);
        ERRCHECK(result);
    }

    subsoundid = 0;     
    sentenceid = 2;     /* The next sound to be appeneded to the stream. */

    printf("=============================================================================\n");
    printf("Real-time stitching example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("=============================================================================\n");
    printf("\n");
    printf("Press space to pause, Esc to quit\n");
    printf("\n");

    printf("Inserted subsound %d / 2 with sound %d / %d\n", 0, 0, NUMSOUNDS);
    printf("Inserted subsound %d / 2 with sound %d / %d\n", 1, 1, NUMSOUNDS);

    /*
        Play the sound.
    */

    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        unsigned int currentsubsoundid;

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

            switch (key)
            {
                case ' ' :
                {
                    int paused;
                    FMOD_Channel_GetPaused(channel, &paused);
                    FMOD_Channel_SetPaused(channel, !paused);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        /*
            Replace the subsound that just finished with a new subsound, to create endless seamless stitching!

            Note that this polls the currently playing subsound using the FMOD_TIMEUNIT_BUFFERED flag.  
            Remember streams are decoded / buffered ahead in advance! 
            Don't use the 'audible time' which is FMOD_TIMEUNIT_SENTENCE_SUBSOUND by itself.  When streaming, sound is 
            processed ahead of time, and things like stream buffer / sentence manipulation (as done below) is required 
            to be in 'buffered time', or else there will be synchronization problems and you might end up releasing a
            sub-sound that is still playing!
        */
        result = FMOD_Channel_GetPosition(channel, &currentsubsoundid, (FMOD_TIMEUNIT)(FMOD_TIMEUNIT_SENTENCE_SUBSOUND | FMOD_TIMEUNIT_BUFFERED));
        ERRCHECK(result);

        if (currentsubsoundid != subsoundid)
        {
            /* 
                Release the sound that isn't playing any more. 
            */
            result = FMOD_Sound_Release(subsound[subsoundid]);       
            ERRCHECK(result);
   
            /* 
                Replace it with a new sound in our list.
            */
            result = FMOD_System_CreateStream(system, soundname[sentenceid], FMOD_DEFAULT, 0, &subsound[subsoundid]);
            ERRCHECK(result);

            result = FMOD_Sound_SetSubSound(sound, subsoundid, subsound[subsoundid]);
            ERRCHECK(result);

            printf("Replacing subsound %d / 2 with sound %d / %d\n", subsoundid, sentenceid, NUMSOUNDS);

            sentenceid++;
            if (sentenceid >= NUMSOUNDS)
            {
                sentenceid = 0;
            }

            subsoundid = currentsubsoundid;
        }
        
        Sleep(50);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(sound);     /* Freeing a parent subsound also frees its children. */
    ERRCHECK(result);
    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    return 0;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM     *system;
    FMOD_SOUND      *sound;
    FMOD_RESULT       result;
    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, 1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
    ERRCHECK(result);

    printf("===============================================================================\n");
    printf("Offline Decoding Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("===============================================================================\n");
    printf("\n");
    printf("This program will open wave.mp3 and decode it into wave.raw using the\n");
    printf("FMOD_Sound_ReadData function.\n");
    printf("\n");

    /*
        Decode the sound and write it to a .raw file.
    */
    {
        void *data;
        unsigned int length = 0, read;
        unsigned int bytesread;
        FILE *outfp;

#define CHUNKSIZE 4096

        result = FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCMBYTES);
        ERRCHECK(result);

        outfp = fopen("output.raw", "wb");
        if (!outfp)
        {
            printf("Error!  Could not open output.raw output file.\n");
            return 0;
        }

        data = malloc(CHUNKSIZE);
        if (!data)
        {
            printf("Error!  Failed to allocate %d bytes.\n", CHUNKSIZE);
            return 0;
        }

        bytesread = 0;
        do
        {
            result = FMOD_Sound_ReadData(sound, (char *)data, CHUNKSIZE, &read);

            fwrite((char *)data, read, 1, outfp);

            bytesread += read;

            printf("writing %d bytes of %d to output.raw\r", bytesread, length);
        }
        while (result == FMOD_OK && read == CHUNKSIZE);

        /*
            Loop terminates when either
            1. the read function returns an error.  (ie FMOD_ERR_FILE_EOF etc).
            2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi).

            If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size,
            but this will not usually happen if FMOD_ACCURATETIME is used.  (this will give the correct length for VBR formats)
        */

        printf("\n");

        if (outfp)
        {
            fclose(outfp);
        }
    }


    printf("\n");

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

    return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM    *system;
    FMOD_SOUND     *fsb;
    FMOD_CHANNEL   *channel = 0;
    FMOD_RESULT     result;
    int             key, count, numsubsounds;
    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/example.fsb", FMOD_DEFAULT, 0, &fsb);
    ERRCHECK(result);

    printf("===================================================================\n");
    printf("FSB Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("===================================================================\n");
    printf("\n");

    result = FMOD_Sound_GetNumSubSounds(fsb, &numsubsounds);
    ERRCHECK(result);

    for (count = 0; count < numsubsounds; count++)
    {
        FMOD_SOUND *subsound;
        char name[256];

        result = FMOD_Sound_GetSubSound(fsb, count, &subsound);
        ERRCHECK(result);

        result = FMOD_Sound_GetName(subsound, name, 256);
        ERRCHECK(result);

        printf("Press '%c' to play \"%s\"\n", '1' + count, name);
    }
    printf("Press 'Esc' to quit\n");
    printf("\n");

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

            if (key >= '1' && key < '1' + numsubsounds)
            {
                FMOD_SOUND *subsound;
                int index = key - '1';

                FMOD_Sound_GetSubSound(fsb, index, &subsound);
               
                result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, subsound, FALSE, &channel);
                ERRCHECK(result);
            }
        }

        FMOD_System_Update(system);

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            int          playing = 0;
            int          paused = 0;
            int          channelsplaying = 0;

            if (channel)
            {
                FMOD_SOUND *currentsound = 0;

                result = FMOD_Channel_IsPlaying(channel, &playing);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPaused(channel, &paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }
               
                FMOD_Channel_GetCurrentSound(channel, &currentsound);
                if (currentsound)
                {
                    result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }
            }

            FMOD_System_GetChannelsPlaying(system, &channelsplaying);

            printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(fsb);
    ERRCHECK(result);
    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    return 0;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM    *system;
    FMOD_CHANNEL   *channel = 0;
    FMOD_DSP       *dsp = 0;
    FMOD_RESULT     result;
    int             key;
    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, NULL);
    ERRCHECK(result);

    /*
        Create an oscillator DSP unit for the tone.
    */
    result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_OSCILLATOR, &dsp);
    ERRCHECK(result);
    result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_RATE, 440.0f);       /* musical note 'A' */
    ERRCHECK(result);

    
    printf("======================================================================\n");
    printf("GenerateTone Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("======================================================================\n\n");
    printf("\n");
    printf("Press '1' to play a sine wave\n");
    printf("Press '2' to play a square wave\n");
    printf("Press '3' to play a saw wave\n");
    printf("Press '4' to play a triangle wave\n");
    printf("Press '5' to play a white noise\n");
    printf("Press 's' to stop channel\n");
    printf("\n");
    printf("Press 'v'/'V' to change channel volume\n");
    printf("Press 'f'/'F' to change channel frequency\n");
    printf("Press '['/']' to change channel pan\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

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

            switch (key)
            {
                case '1' :
                {
                    result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
                    FMOD_Channel_SetVolume(channel, 0.5f);
                    result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 0);
                    ERRCHECK(result);
                    FMOD_Channel_SetPaused(channel, FALSE);
                    break;
                }
                case '2' :
                {
                    result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
                    FMOD_Channel_SetVolume(channel, 0.125f);
                    result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 1);
                    ERRCHECK(result);
                    FMOD_Channel_SetPaused(channel, FALSE);
                    break;
                }
                case '3' :
                {
                    result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
                    FMOD_Channel_SetVolume(channel, 0.125f);
                    result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 2);
                    ERRCHECK(result);
                    FMOD_Channel_SetPaused(channel, FALSE);
                    break;
                }
                case '4' :
                {
                    result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
                    FMOD_Channel_SetVolume(channel, 0.5f);
                    result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 4);
                    ERRCHECK(result);
                    FMOD_Channel_SetPaused(channel, FALSE);
                    break;
                }
                case '5' :
                {
                    result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
                    FMOD_Channel_SetVolume(channel, 0.25f);
                    result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 5);
                    ERRCHECK(result);
                    FMOD_Channel_SetPaused(channel, FALSE);
                    break;
                }
                case 's' :
                {
                    FMOD_Channel_Stop(channel);
                    break;
                }
                case 'v' :
                {
                    float volume;

                    FMOD_Channel_GetVolume(channel, &volume);
                    volume -= 0.1f;
                    FMOD_Channel_SetVolume(channel, volume);
                    break;
                }
                case 'V' :
                {
                    float volume;

                    FMOD_Channel_GetVolume(channel, &volume);
                    volume += 0.1f;
                    FMOD_Channel_SetVolume(channel, volume);
                    break;
                }
                case 'f' :
                {
                    float frequency;

                    FMOD_Channel_GetFrequency(channel, &frequency);
                    frequency -= 500;
                    FMOD_Channel_SetFrequency(channel, frequency);
                    break;
                }
                case 'F' :
                {
                    float frequency;

                    FMOD_Channel_GetFrequency(channel, &frequency);
                    frequency += 500.0f;
                    FMOD_Channel_SetFrequency(channel, frequency);
                    break;
                }
                case '[' :
                {
                    float pan;

                    FMOD_Channel_GetPan(channel, &pan);
                    pan -= 0.1f;
                    FMOD_Channel_SetPan(channel, pan);
                    break;
                }
                case ']' :
                {
                    float pan;

                    FMOD_Channel_GetPan(channel, &pan);
                    pan += 0.1f;
                    FMOD_Channel_SetPan(channel, pan);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        {
            float frequency = 0, volume = 0, pan = 0;
            int playing = FALSE;

            if (channel)
            {
                FMOD_Channel_GetFrequency(channel, &frequency);
                FMOD_Channel_GetVolume(channel, &volume);
                FMOD_Channel_GetPan(channel, &pan);
                FMOD_Channel_IsPlaying(channel, &playing);
            }

            printf("Channel %s : Frequency %.1f Volume %.1f Pan %.1f  \r", playing ? "playing" : "stopped", frequency, volume, pan);
        }
        
        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_DSP_Release(dsp);
    ERRCHECK(result);
    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    return 0;
}
Ejemplo n.º 6
0
int jeu(SDL_Surface* ecran,int choix,int difficulte,int ArduinoClavier)
{





SDL_Event event; //pour pouvoir gerer les events
SDL_ShowCursor(SDL_DISABLE);//On n'affiche plus le curseur
SDL_Surface *imageDeFond = NULL, *Note = NULL, *Note_do = NULL, *Note_re = NULL, *Note_mi = NULL, *Note_fa = NULL, *Note_sol = NULL, *Note_la = NULL, *Note_si = NULL; //Initialisation des images : on crée un pointeur pour chaque image auquel on met la valeur NULL
SDL_Rect positionFond,positionNote[TAILLE_MAX], positionNote_do,positionNote_re,positionNote_mi,positionNote_fa,positionNote_sol,positionNote_la,positionNote_si; //Initialisation des positions des images

//Initialisation positions x et y
int i; for(i=0;i<TAILLE_MAX;i++)
        {positionNote[i].x=0; positionNote[i].y=0;} //Initialisation de TOUTES les notes du morceau

positionNote_do.y = positionNote_re.y = positionNote_mi.y = positionNote_fa.y = positionNote_sol.y = positionNote_la.y = positionNote_si.y = 658;
positionNote_do.x = 265;
positionNote_re.x = 408;
positionNote_mi.x = 548;
positionNote_fa.x = 690;
positionNote_sol.x = 834;
positionNote_la.x = 973;
positionNote_si.x = 1117;
positionFond.x = 0;
positionFond.y = 0;


imageDeFond = SDL_LoadBMP("images/fond.bmp");//on indique ou est l'image de fond


//Images
Note = SDL_LoadBMP("images/notes/note.bmp") ;
Note_do = SDL_LoadBMP("images/notes/do.bmp");
Note_re = SDL_LoadBMP("images/notes/re.bmp");
Note_mi = SDL_LoadBMP("images/notes/mi.bmp");
Note_fa = SDL_LoadBMP("images/notes/fa.bmp");
Note_sol = SDL_LoadBMP("images/notes/sol.bmp");
Note_la = SDL_LoadBMP("images/notes/la.bmp");
Note_si = SDL_LoadBMP("images/notes/si.bmp");
SDL_SetColorKey(Note, SDL_SRCCOLORKEY, SDL_MapRGB(Note->format, 0,0, 255));//transparence
//

 FILE* fichier = NULL;//pour lire la "partition"




/***********Musique***************
*********************************/

FMOD_SYSTEM *system;
FMOD_SOUND *musique;//musique :/
FMOD_RESULT resultat;
FMOD_System_Create(&system);
FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL);

/* On ouvre la musique en fonction du choix et on ouvre la partition qui correspond (c'est gros pour pas grand chose)*/
switch(choix)
{
    case 0 :
    resultat = FMOD_System_CreateSound(system, "musiques/FrereJacques.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/FrereJacques.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 1 :
    resultat = FMOD_System_CreateSound(system, "musiques/Muse.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Muse.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 2 :
    resultat = FMOD_System_CreateSound(system, "musiques/AuClairDeLaLune.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/AuClairDeLaLune.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 3 :
    resultat = FMOD_System_CreateSound(system, "musiques/Titanic.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Titanic.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 4 :
    resultat = FMOD_System_CreateSound(system, "musiques/MJ.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/MJ.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 5 :
    resultat = FMOD_System_CreateSound(system, "musiques/Clocks.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Clocks.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 6 :
    resultat = FMOD_System_CreateSound(system, "musiques/Laputa.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Laputa.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 7 :
    resultat = FMOD_System_CreateSound(system, "musiques/YMCA.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/YMCA.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 8 :
    resultat = FMOD_System_CreateSound(system, "musiques/Changes.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Changes.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 10 :
    resultat = FMOD_System_CreateSound(system, "musiques/Dancing_in_the_Dark.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Dancing_in_the_Dark.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 11 :
    resultat = FMOD_System_CreateSound(system, "musiques/Born_to_Run.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Born_to_Run.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 12 :
    resultat = FMOD_System_CreateSound(system, "musiques/Bruno Mars.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Bruno Mars.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 13 :
    resultat = FMOD_System_CreateSound(system, "musiques/Bad day.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Bad day.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 15 :
    resultat = FMOD_System_CreateSound(system, "musiques/The Fray.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/The Fray.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 16 :
    resultat = FMOD_System_CreateSound(system, "musiques/Led Zep.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Led Zep.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 17 :
    resultat = FMOD_System_CreateSound(system, "musiques/Naruto.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Naruto.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 18 :
    resultat = FMOD_System_CreateSound(system, "musiques/Somebody to love - Queen.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Somebody to love - Queen.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    case 19 :
    resultat = FMOD_System_CreateSound(system, "musiques/Viva.mid", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &musique);
    fichier = fopen("musiques/Viva.txt", "r"); //Le fichier texte qui contient la "partition"
    break;
    default:
    break;

}


   if (resultat != FMOD_OK)//verification que la musique marche
    {
        fprintf(stderr, "Impossible de lire le fichier audio.wav\n");
        exit(EXIT_FAILURE);
    }

//Bruit pour le fail (on est obligé de créer un autre systeme pour pas arreter la musique)
FMOD_SYSTEM *systemf;
FMOD_SOUND *fail = NULL;
FMOD_System_CreateSound(systemf, "fail.wav", FMOD_CREATESAMPLE, 0, &fail);
FMOD_RESULT resultatf;

    /* Création et initialisation d'un objet système */
    FMOD_System_Create(&systemf);
    FMOD_System_Init(systemf, 1, FMOD_INIT_NORMAL, NULL);

    /* Chargement du son et vérification du chargement */
    resultatf = FMOD_System_CreateSound(system, "fail.wav", FMOD_CREATESAMPLE, 0, &fail);
    if (resultatf != FMOD_OK)
    {
        fprintf(stderr, "Impossible de lire le fichier audio.wav\n");
        exit(EXIT_FAILURE);
    }

 /****************************
 Initialisation pour le texte
 ******************************/
    char caracteres[20] = "",caracteres2[20] = ""; // Tableau de char suffisamment grand pour le score
    TTF_Init(); //Initialisation de la banque de donnée pour le texte
    int compteur=0; //Pour le score
    SDL_Surface *score = NULL;
    SDL_Rect position;
    TTF_Font *police = NULL, *police2 = NULL; //TTF_OpenFont doit stocker son résultat dans une variable de type TTF_Font
    SDL_Color couleurNoire = {0, 0, 0}; //couleur police => noir
    police = TTF_OpenFont("police.ttf", 70);//police choisie, taille police
    police2 = TTF_OpenFont("score.ttf", 70);//police choisie, taille police
//////////////////////////////////////////////

 /***************************************************
        +Lecture du fichier texte (Yacine)
        +On met les notes a leur place (do,ré...)
            en fonction de la difficulté
 **************************************************/



char chaine[TAILLE_MAX]="";
int debut[TAILLE_MAX ];
int note[TAILLE_MAX ];
int tempsFin = 0 ;
 int j=0,compteurNotes=0;
 while (fgets(chaine, TAILLE_MAX, fichier) != NULL) //tant que le fichier n'a pas été totalement parcouru (fgets s'incremente automatiquement)
   {

        ///Easy
       if (difficulte==0){
    if (compteurNotes%3==0)//Pour la difficulté, on ne prend qu'une note sur 3 quand on a choisi l'option facile
            {
                sscanf(chaine, "%d - %d", &debut[j], &note[j]); // recupere la note et la date

switch (note[j])//On met en place les notes
{

   case 0 : //do
        positionNote[j].x = 250;
        break;
   case 1 : //ré
        positionNote[j].x = 395;
        break;
   case 2 : //mi
        positionNote[j].x = 525;
        break;
   case 3 : //fa
        positionNote[j].x = 680;
        break;
   case 4 : //sol
        positionNote[j].x = 820;
        break;
   case 5 : //la
        positionNote[j].x = 960;
        break;
   case 6 : //si
        positionNote[j].x = 1100;
        break;
    case 8 : // Pour la fin
        tempsFin = debut[j];
        positionNote[j].x = 20000;//pour pas afficher la note
   default :
        break;

        }
        j++;
            }
            compteurNotes++;
            }

        ///Normal
       if (difficulte==1){
    if (compteurNotes%2==0)//Pour la difficulté, on ne prend qu'une note sur deux quand on a choisi l'option facile
            {
                sscanf(chaine, "%d - %d", &debut[j], &note[j]); // recupere la note et la date

switch (note[j])//On met en place les notes
{

   case 0 : //do
        positionNote[j].x = 250;
        break;
   case 1 : //ré
        positionNote[j].x = 395;
        break;
   case 2 : //mi
        positionNote[j].x = 525;
        break;
   case 3 : //fa
        positionNote[j].x = 680;
        break;
   case 4 : //sol
        positionNote[j].x = 820;
        break;
   case 5 : //la
        positionNote[j].x = 960;
        break;
   case 6 : //si
        positionNote[j].x = 1100;
        break;
    case 8 : // Pour la fin
        tempsFin = debut[j];
        positionNote[j].x = 20000;//pour pas afficher la note
   default :
        break;

        }
        j++;
            }
            compteurNotes++;
            }

        ///Difficile
        if (difficulte==2){
            //On prend toutes les notes
                    sscanf(chaine, "%d - %d", &debut[j], &note[j]); // recupere la note et la date

switch (note[j])//On met en place les notes
{

   case 0 : //do
        positionNote[j].x = 250;
        break;
   case 1 : //ré
        positionNote[j].x = 395;
        break;
   case 2 : //mi
        positionNote[j].x = 525;
        break;
   case 3 : //fa
        positionNote[j].x = 680;
        break;
   case 4 : //sol
        positionNote[j].x = 820;
        break;
   case 5 : //la
        positionNote[j].x = 960;
        break;
   case 6 : //si
        positionNote[j].x = 1100;
        break;
    case 8 : // Pour la fin
        tempsFin = debut[j];
        positionNote[j].x = 20000;//pour pas afficher la note
   default :
        break;

        }
        j++;
            }


   }


 //////////////////////////////////////////////

int pourcent[TAILLE_MAX] = {0},pourcentFinal=0,totalNotes=0;//Pour le pourcentage de réussite
int k=0;//notes 1,2,3....
int tempsDebut=SDL_GetTicks();//SDL_GetTicks donne le temps qu'il s'est écoulé depuis le lancement du programme, on retire donc le temps qu'il s'est écoulé entre le lancement et le début du morceau
int a=0,z=0,e=0,r=0,t=0,y=0,u=0;//notes
int tempsPrecedent = 0, tempsActuel = 0, tempsNote[7]; //Timer (temps note permet de savoir a quel instant t la note a été jouée
int continuer = 1;

 //Boucle jeu

 if (ArduinoClavier) arduino(1);//On lance arduino pour avoir le numéro port série qui correspond

while (continuer)
{


/* On joue la musique au bon moment de manière à ce qu'elle soit synchronisée avec les notes qui défilent */
if ((tempsActuel>=2700)&&(tempsActuel<=2750))FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, musique, 0,NULL);


    /* On efface l'écran */
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255,255, 255));//255,255, 255 veut dire qu'on met un ecran noir
    /* On remet le fond */
SDL_BlitSurface(imageDeFond, NULL, ecran, &positionFond);

tempsActuel = SDL_GetTicks() - tempsDebut; //temps




/************************************************
 + On affiche les notes
 + On fait descendre les notes le long des lignes
    J'ai galeré pour ca !
*************************************************/


    if(tempsActuel>=debut[k+1]) k++; // passage à la note suivante



int l=k;

    do
    {
           if (tempsActuel>=debut[0]) positionNote[l].y= positionNote[l].y+tempsActuel/10*2-tempsPrecedent/10*2;//descente de la note en utilisant le temps comme réference (elle met du coup 2.7sec a desendre) (la condition corrige le bug de la 1ere note)

            if (positionNote[l].y>575) positionNote[l].y=10000; // si la note arrive en bas on la fait "disparaitre"

        SDL_BlitSurface(Note, NULL, ecran, &positionNote[l]);//on affiche les notes
        l--;
    }while(l>=0);



///La boucle do while est la car il faut la faire au moins une fois quand il n'y a qu'un seule note
///Pour afficher les notes précédentes (sinon on a qu'une seule note affichée)


/*Pour sortir du morceau à la fin*/
if (tempsActuel >= tempsFin) continuer = 0;



///


tempsPrecedent = tempsActuel; // comme on utilise le temps pour la boucle d'avant on le met ici (on pourrait le mettre à la toute fin, ce qui serait plus logique mais ici on comprend mieux)



/**************************************************************
*************************************************************
Fonction pour les touches
***********************************************************
**********************************************************/



/******************************************************
Switch pour savoir quelle touche a étée enfoncée. Si
une touche est enfoncée on donne a la variable la valeur
1 et on enregistre le temps a laquelle la note a été
"jouée"
*******************************************************/

SDL_PollEvent(&event);
switch(event.type)
{
case SDL_QUIT:
exit(EXIT_FAILURE);
break;
case SDL_KEYDOWN: /* Si appui sur une touche*/

    switch(event.key.keysym.sym)
    {
        case SDLK_q: //a
        a=1;
        tempsNote[0]=SDL_GetTicks() - tempsDebut;
        break;
        case SDLK_w: //z
        z=1;
        tempsNote[1]=SDL_GetTicks() - tempsDebut;
        break;
        case SDLK_e: //e
        e=1;
        tempsNote[2]=SDL_GetTicks() - tempsDebut;
        break;
        case SDLK_r: //r
        r=1;
        tempsNote[3]=SDL_GetTicks() - tempsDebut;
        break;
        case SDLK_t: //t
        t=1;
        tempsNote[4]=SDL_GetTicks() - tempsDebut;
        break;
        case SDLK_y: //y
        y=1;
        tempsNote[5]=SDL_GetTicks() - tempsDebut;
        break;
        case SDLK_u: //u
        u=1;
        tempsNote[6]=SDL_GetTicks() - tempsDebut;
        break;
        case SDLK_ESCAPE:
        continuer=0;
        break;
        default:
        break;
    }
break;

}




/*****************************************************************
On a donné à une variable la valeur 1 si l'evenement a été
réalisé, pour que deux évenements soient pris en compte en même
temps on laisse l'action que provoque l'evenement durer 250ms
(on utlise le temps enregistré avant pour savoir quand 250ms
 sont écoulées)
ce qui donne l'impression que les evenements sont simultannés
Si la variable=0, l'action n'est pas réalisée
******************************************************************/
if (a)
    {
        SDL_BlitSurface(Note_do, NULL, ecran, &positionNote_do);
        if(tempsActuel-tempsNote[0]>250) a=0;
    }
if (z)
    {
        SDL_BlitSurface(Note_re, NULL, ecran, &positionNote_re);
        if(tempsActuel-tempsNote[1]>250) z=0;
    }
if (e)
    {
        SDL_BlitSurface(Note_mi, NULL, ecran, &positionNote_mi);
        if(tempsActuel-tempsNote[2]>250) e=0;
    }
if (r)
    {
        SDL_BlitSurface(Note_fa, NULL, ecran, &positionNote_fa);
        if(tempsActuel-tempsNote[3]>250) r=0;
    }
if (t)
    {
        SDL_BlitSurface(Note_sol, NULL, ecran, &positionNote_sol);
        if(tempsActuel-tempsNote[4]>250) t=0;
    }
if (y)
    {
        SDL_BlitSurface(Note_la, NULL, ecran, &positionNote_la);
        if(tempsActuel-tempsNote[5]>250) y=0;
    }
if (u)
    {
        SDL_BlitSurface(Note_si, NULL, ecran, &positionNote_si);
        if(tempsActuel-tempsNote[6]>250) u=0;
    }


/*****************************************************************
Cette partie permet de déterminer quels boutons poussoirs sont enfoncés a partir du nombre
renvoyé par la fonction arduino.
Si un bouton est enfoncé on lui attribue un caractère propre, ainsi lors des tests de succès
cette information sera gérée exactement comme les évènements au clavier.


Bugs  incompréhensibles liés a l'ajout d'arduino:
On ne peux plus quitter la partie en cours (parfois si)
Au début de certains morceaux  des notes bizarres s'affichent
mais cela revient a la normale après 2-3 secondes.


                          Auteur : Yacine Saoudi
******************************************************************/

if (ArduinoClavier)
{

int arduinoIu=0;
arduinoIu=arduino(0);

char boutonArd[8];
sprintf(boutonArd, "%d", arduinoIu);
//on transforme le nombre stocké dans arduinoIu en chaine de caractère.

//cela permet de tester la présence ou non d'un caractère dans celle ci:
if(strstr(boutonArd, "1")!=NULL) a=1;
if(strstr(boutonArd, "2")!=NULL) z=1;
if(strstr(boutonArd, "3")!=NULL) e=1;
if(strstr(boutonArd, "4")!=NULL) r=1;
if(strstr(boutonArd, "5")!=NULL) t=1;
if(strstr(boutonArd, "6")!=NULL) y=1;
if(strstr(boutonArd, "7")!=NULL) u=1;

}



/***********************************************************************
Fonction réussit ou raté (si la note est "jouée" au bon moment)
************************************************************************/


l=k;//on teste toutes les notes qui on étées affichées

    do
    {
        //réussi
        if ((a)&&(positionNote[l].y>550)&&(positionNote[l].y<580)&&(positionNote[l].x == 250))  {compteur++; pourcent[l]=1;} //compteur => score
        if ((z)&&(positionNote[l].y>550)&&(positionNote[l].y<580)&&(positionNote[l].x == 395))  {compteur++; pourcent[l]=1;} //pourcent => la note spécifique l est réussie ou non (1= réussi)
        if ((e)&&(positionNote[l].y>550)&&(positionNote[l].y<580)&&(positionNote[l].x == 525))  {compteur++; pourcent[l]=1;}
        if ((r)&&(positionNote[l].y>550)&&(positionNote[l].y<580)&&(positionNote[l].x == 680))  {compteur++; pourcent[l]=1;}
        if ((t)&&(positionNote[l].y>550)&&(positionNote[l].y<580)&&(positionNote[l].x == 820))  {compteur++; pourcent[l]=1;}
        if ((y)&&(positionNote[l].y>550)&&(positionNote[l].y<580)&&(positionNote[l].x == 960))  {compteur++; pourcent[l]=1;}
        if ((u)&&(positionNote[l].y>550)&&(positionNote[l].y<580)&&(positionNote[l].x == 1100)) {compteur++; pourcent[l]=1;}
        //fail
        /*
        if ((a==0)&&(positionNote[l].y>560)&&(positionNote[l].y<570)&&(positionNote[l].x == 250)) FMOD_System_PlaySound(systemf, FMOD_CHANNEL_FREE, fail, 0, NULL);
        if ((z==0)&&(positionNote[l].y>560)&&(positionNote[l].y<570)&&(positionNote[l].x == 395)) FMOD_System_PlaySound(systemf, FMOD_CHANNEL_FREE, fail, 0, NULL);
        if ((e==0)&&(positionNote[l].y>560)&&(positionNote[l].y<570)&&(positionNote[l].x == 525)) FMOD_System_PlaySound(systemf, FMOD_CHANNEL_FREE, fail, 0, NULL);
        if ((r==0)&&(positionNote[l].y>560)&&(positionNote[l].y<570)&&(positionNote[l].x == 680)) FMOD_System_PlaySound(systemf, FMOD_CHANNEL_FREE, fail, 0, NULL);
        if ((t==0)&&(positionNote[l].y>560)&&(positionNote[l].y<570)&&(positionNote[l].x == 820)) FMOD_System_PlaySound(systemf, FMOD_CHANNEL_FREE, fail, 0, NULL);
        if ((y==0)&&(positionNote[l].y>560)&&(positionNote[l].y<570)&&(positionNote[l].x == 960)) FMOD_System_PlaySound(systemf, FMOD_CHANNEL_FREE, fail, 0, NULL);
        if ((u==0)&&(positionNote[l].y>560)&&(positionNote[l].y<570)&&(positionNote[l].x == 1100)) FMOD_System_PlaySound(systemf, FMOD_CHANNEL_FREE, fail, 0, NULL); //son de fausse note
        */
        l--;
    }while(l>=0); //j'aime bien les do while (mêmes raisons qu'au dessus)



/***********************************
Fonction pour le texte, ici le score
et le nom du morceau
************************************/

//En cas d'erreur (plus propre)
if(TTF_Init() == -1)
{

    fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
    exit(EXIT_FAILURE);
}

/*score*/


     /* Écriture du texte dans la SDL_Surface texte en mode Solid (car il change souvent)*/
     sprintf(caracteres, "Score : %d", compteur);
     SDL_FreeSurface(score);//On efface la surface précédente (sinon ca prend 2go de RAM)
     score = TTF_RenderText_Solid(police, caracteres, couleurNoire);

    //Position score//
        position.x = 20;
        position.y = 450;
        SDL_BlitSurface(score, NULL, ecran, &position); /* Blit du texte*/

/*titre*/

   /* Titre en fonction du choix */
   switch (choix)
   {
       case 0 :
       sprintf(caracteres2, "Frère Jacques");
       break;
       case 1 :
       sprintf(caracteres2, "Starlight - Muse");
       break;
       case 2 :
       sprintf(caracteres2, "Au Clair de la Lune");
       break;
       case 3 :
       sprintf(caracteres2, "Titanic");
       break;
       case 4 :
       sprintf(caracteres2, "Black or White - MJ");
       break;
       case 5 :
       sprintf(caracteres2, "Clocks - Coldplay");
       break;
       case 6 :
       sprintf(caracteres2, "Laputa");
       break;
       case 7 :
       sprintf(caracteres2, "YMCA");
       break;
       case 8 :
       sprintf(caracteres2, "Changes");
       break;
       case 10 :
       sprintf(caracteres2, "Dancing in the Dark");
       break;
       case 11 :
       sprintf(caracteres2, "Born to Run");
       break;
       case 12 :
       sprintf(caracteres2, "Just the way you are");
       break;
       case 13 :
       sprintf(caracteres2, "Bad day");
       break;
       case 15 :
       sprintf(caracteres2, "The Fray");
       break;
       case 16 :
       sprintf(caracteres2, "Starway to heaven");
       break;
       case 17 :
       sprintf(caracteres2, "Naruto");
       break;
       case 18 :
       sprintf(caracteres2, "Somebody to love - Queen");
       break;
       case 19 :
       sprintf(caracteres2, "Viva la Vida - Coldplay");
       break;
       default :
       break;
   }

     SDL_FreeSurface(score);//On efface la surface précédente (sinon ca prend 2go de RAM)
     score = TTF_RenderText_Solid(police2, caracteres2, couleurNoire);

    //Position score//
        position.x = 20;
        position.y = 60;
        SDL_BlitSurface(score, NULL, ecran, &position); /* Blit du texte*/


////////////////////////////////////////////////////////////////////////////////////////

/* On met à jour l'affichage */
SDL_Flip(ecran);

if (continuer==0) CloseCOM   ();//On ferme le port série
}

/******************************************************
Fonction pour obtenir le pourcentage de réussite
On utilise la variable pourcent (faire une vraie fonction
                                 de ca serait facile mais
                                 inutile)
Bug a corriger : Si on finit pas le morceau le pourcentage
est faux (narmol)
*****************************************************/

for(totalNotes=0;totalNotes<k;totalNotes++)
{
    if (pourcent[totalNotes]==1) pourcentFinal++;
}
 pourcentFinal=pourcentFinal*100/totalNotes;//on fait le pourcentage (il faut finir le morceau pour que le pourcentage soit juste)





///////////////////////////////////////////
/*Sortie de boucle*/
/////////////////////////////////////////
//Libération de l'espace
    //images
SDL_FreeSurface(imageDeFond);
SDL_FreeSurface(Note);
SDL_FreeSurface(Note_do);
SDL_FreeSurface(Note_re);
SDL_FreeSurface(Note_mi);
SDL_FreeSurface(Note_fa);
SDL_FreeSurface(Note_sol);
SDL_FreeSurface(Note_la);
SDL_FreeSurface(Note_si);
    //pour la musique
FMOD_Sound_Release(musique);
FMOD_Sound_Release(fail);
FMOD_System_Close(system);
FMOD_System_Release(system);

//return compteur;//le score (le pourcentage est plus interessant)
return pourcentFinal;//le pourcentage de réussite
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM     *system;
    FMOD_SOUND      *cdsound;
    FMOD_SOUND      *sound;
    FMOD_CHANNEL    *channel = 0;
    FMOD_RESULT      result;
    int              key, numtracks, currenttrack = 0;
    unsigned int     version;

    if (argc < 2)
    {
        printf("Usage: cdplayer <drivepath>\n");
        printf("Example: cdplayer /dev/cdrom\n");
        exit(-1);
    }

    printf("==================================================================\n");
    printf("CDPlayer Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("==================================================================\n\n");

    /*
        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, 1, FMOD_INIT_NORMAL, NULL);
    ERRCHECK(result);

    /*
        Bump up the file buffer size a bit from the 16k default for CDDA, because it is a slower medium.
    */
    result = FMOD_System_SetStreamBufferSize(system, 64*1024, FMOD_TIMEUNIT_RAWBYTES);
    ERRCHECK(result);

    result = FMOD_System_CreateStream(system, argv[1], FMOD_OPENONLY, 0, &cdsound);
    ERRCHECK(result);
    result = FMOD_Sound_GetNumSubSounds(cdsound, &numtracks);
    ERRCHECK(result);
    result = FMOD_Sound_GetSubSound(cdsound, currenttrack, &sound);
    ERRCHECK(result);

    for (;;)
    {
        FMOD_TAG tag;

        if (FMOD_Sound_GetTag(cdsound, 0, -1, &tag) != FMOD_OK)
        {
            break;
        }
        if (tag.datatype == FMOD_TAGDATATYPE_CDTOC)
        {
            dump_cddb_query((FMOD_CDTOC *)tag.data);
        }
    }

    printf("\n========================================\n");
    printf("Press SPACE to pause\n");
    printf("      n     to skip to next track\n");
    printf("      ESC   to exit\n");
    printf("========================================\n\n");

    /*
        Print out length of entire CD.  Did you know you can also play 'cdsound' and it will play the whole CD without gaps?
    */
    {
        unsigned int lenms;

        result = FMOD_Sound_GetLength(cdsound, &lenms, FMOD_TIMEUNIT_MS);
        ERRCHECK(result);

        printf("Total CD length %02d:%02d\n\n", lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100);
    }

    /*
        Play a CD track
    */
    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
    ERRCHECK(result);

    /*
        Main loop
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case ' ' :
                {
                    int paused;
                    FMOD_Channel_GetPaused(channel, &paused);
                    FMOD_Channel_SetPaused(channel, !paused);
                    break;
                }

                case 'n' :
                {
                    currenttrack++;
                    if (currenttrack >= numtracks)
                    {
                        currenttrack = 0;
                    }
                    result = FMOD_Sound_GetSubSound(cdsound, currenttrack, &sound);
                    ERRCHECK(result);
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
                    ERRCHECK(result);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        if (channel)
        {
            unsigned int ms, lenms, percent = 0;
            FMOD_BOOL    playing;
            FMOD_BOOL    paused;

            result = FMOD_Channel_GetPaused(channel, &paused);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }
            result = FMOD_Channel_IsPlaying(channel, &playing);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }
            result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }
            result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            printf("Track %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s\r", currenttrack + 1, numtracks, ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    return 0;
}
int menuPrincipal(int* contreordinateur, int* niveauordinateur, int* plateau)
{
    /* ecran de jeu */
    Image* screen;
    /* images du menu */
    Image *menu, *imageContreJoueur, *imageContreOrdi, *imageSelection, *imageBoutonJouer, *imageBoutonJouerSurvol, *imageBoutonPlus, *imageBoutonMoins, *imageOuvrir, *imageOuvrirSurvol;
    Image *imagePlateau[4], *imagePlateauSelectionne;
    /* images animees */
    Image *imageAnimeeRubis, *imageAnimeePerle;

    /* positions des images */
    Rectangle positionPlateau[4];
    Rectangle positionMenu, positionContreJoueur, positionContreOrdi, positionBoutonJouer, positionNiveau, positionTexteNiveau, positionBoutonPlus, positionBoutonMoins, positionOuvrir;
    Image *chiffres[10], *texte_niveau; int ich;
    Rectangle positionRubis, positionPerle, vecteurPerle, vecteurRubis;

    /* evenements */
    Evenements event;

    /* variables pour contenir les coordonnées de la souris */
    int sourisx;
    int sourisy;

    int retour;

    /* pour savoir si une partie est enregistrée */
    int partieEnregistree;
    FILE* fichier;

    /* boucle principale du programme */
    int done;

    #if SONS==1
        FMOD_SYSTEM *system;

        FMOD_SOUND *hello;
        FMOD_SOUND *menuMus;
        hello = 0;
        menuMus = 0;
        FMOD_System_Create(&system);
        FMOD_System_Init(system, 2, FMOD_INIT_NORMAL, NULL);

        FMOD_System_CreateSound(system, SON_HELLO, FMOD_CREATESAMPLE, 0, &hello); afficheVerifChargementSon(hello);
        FMOD_System_CreateSound(system, SON_MENU, FMOD_LOOP_NORMAL, 0, &menuMus); afficheVerifChargementSon(menuMus);

        if(hello!=0)    FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, hello, 0, NULL);
        if(menuMus!=0)  FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, menuMus, 0, NULL);
    #endif

    retour = 1; /* par défaut on accède au jeu après le menu */
    done = 0; /* sortie de boucle */

    partieEnregistree = 0; /* par défaut : aucune partie */
    fichier = 0;
    fichier = fopen(CONFIGSAUVE,"r");
    if(fichier!=0)
    {
        fclose(fichier);
        fichier = 0;
        fichier = fopen(PLATEAUSAUVE,"r");
        if(fichier!=0)
        {
            partieEnregistree = 1;
            fclose(fichier);
            fichier = 0;
        }
    }

    /* plateau 0 correspond à la partie enregistrée mais n'est pas séléctionnable comme plateau */
    if(*plateau==0)
        *plateau = 1;

    /* INITIALISATIONS POUR L'AFFICHAGE */

        /* on charge l'écran d'affichage */

        screen = afficheSetEcran();
        if (!screen)
        {
            printf("[!] Erreur de définition de l'écran video.\n");
            afficheErreur();
            return 1;
        }
        /* on initialise l'affichage video */
        if ( afficheInit() < 0 )
        {
            printf("[!] Erreur d'initialisation de l'affichage.\n");
            afficheErreur();
            return 1;
        }
        /* être sûr que l'écran soit fermé à la fin */
        atexit(afficheQuit);

        afficheSetTitre("Hexxagon : Menu du jeu","Hexxagon");

        /* MENU PRINCIPAL */

        menu = afficheChargeImage(MENU); afficheVerifChargement(menu);
        positionMenu.x = 0;
        positionMenu.y = 0;

        imageContreJoueur = afficheChargeImage(VSJOUEUR); afficheVerifChargement(imageContreJoueur);
        positionContreJoueur.x = 100;
        positionContreJoueur.y = screen->h - 120;
        positionContreJoueur.h = imageContreJoueur->h;
        positionContreJoueur.w = imageContreJoueur->w;

        imageContreOrdi = afficheChargeImage(VSORDI); afficheVerifChargement(imageContreOrdi);
        positionContreOrdi.x = 300;
        positionContreOrdi.y = screen->h - 120;
        positionContreOrdi.h = imageContreOrdi->h;
        positionContreOrdi.w = imageContreOrdi->w;

        imagePlateau[0] = afficheChargeImage(PLATEAU1_MENU); afficheVerifChargement(imagePlateau[0]);
        positionPlateau[0].x = 650;
        positionPlateau[0].y = 20;
        positionPlateau[0].h = imagePlateau[0]->h;
        positionPlateau[0].w = imagePlateau[0]->w;

        imagePlateau[1] = afficheChargeImage(PLATEAU2_MENU); afficheVerifChargement(imagePlateau[1]);
        positionPlateau[1].x = 800;
        positionPlateau[1].y = 180;
        positionPlateau[1].h = imagePlateau[1]->h;
        positionPlateau[1].w = imagePlateau[1]->w;

        imagePlateau[2] = afficheChargeImage(PLATEAU3_MENU); afficheVerifChargement(imagePlateau[2]);
        positionPlateau[2].x = 680;
        positionPlateau[2].y = 330;
        positionPlateau[2].h = imagePlateau[2]->h;
        positionPlateau[2].w = imagePlateau[2]->w;

        imagePlateau[3] = afficheChargeImage(PLATEAU4_MENU); afficheVerifChargement(imagePlateau[3]);
        positionPlateau[3].x = 800;
        positionPlateau[3].y = 480;
        positionPlateau[3].h = imagePlateau[3]->h;
        positionPlateau[3].w = imagePlateau[3]->w;

        /* pions qui se déplacent sur l'écran */
        imageAnimeePerle = afficheChargeImage(PION_JOUEUR_2); afficheVerifChargement(imageAnimeePerle);
        imageAnimeeRubis = afficheChargeImage(PION_JOUEUR_1); afficheVerifChargement(imageAnimeeRubis);

        positionPerle.x = 5;
        positionPerle.y = 5;
        positionRubis.x = 600;
        positionRubis.y = 400;
        vecteurPerle.x = 5;
        vecteurPerle.y = 5;
        vecteurRubis.x = -5;
        vecteurRubis.y = 5;

        if(partieEnregistree) /* on ne charge que si une partie est enregistrée */
        {
            imageOuvrir = IMG_Load(OUVRIR); afficheVerifChargement(imageOuvrir);
            imageOuvrirSurvol = IMG_Load(OUVRIRSURVOL); afficheVerifChargement(imageOuvrirSurvol);
            positionOuvrir.x = screen->w - imageOuvrir->w - 10;
            positionOuvrir.y = screen->h - imageOuvrir->h - 10;
            positionOuvrir.w = imageOuvrir->w;
            positionOuvrir.h = imageOuvrir->h;
        }

        imagePlateauSelectionne = afficheChargeImage(PLATEAU_SELECTIONNE_MENU); afficheVerifChargement(imagePlateau[0]);

        imageSelection = afficheChargeImage(SELECTIONMODE); afficheVerifChargement(imageSelection);

        imageBoutonJouer = afficheChargeImage(BOUTONJOUER); afficheVerifChargement(imageBoutonJouer);
        imageBoutonJouerSurvol = afficheChargeImage(BOUTONJOUERSURVOL); afficheVerifChargement(imageBoutonJouerSurvol);
        positionBoutonJouer.x = 600;
        positionBoutonJouer.y = screen->h - 120;
        positionBoutonJouer.h = imageBoutonJouer->h;
        positionBoutonJouer.w = imageBoutonJouer->w;

        chiffres[0] = afficheChargeImage(CHIFFRE0); afficheVerifChargement(chiffres[0]);
        chiffres[1] = afficheChargeImage(CHIFFRE1); afficheVerifChargement(chiffres[1]);
        chiffres[2] = afficheChargeImage(CHIFFRE2); afficheVerifChargement(chiffres[2]);
        chiffres[3] = afficheChargeImage(CHIFFRE3); afficheVerifChargement(chiffres[3]);
        chiffres[4] = afficheChargeImage(CHIFFRE4); afficheVerifChargement(chiffres[4]);
        chiffres[5] = afficheChargeImage(CHIFFRE5); afficheVerifChargement(chiffres[5]);
        chiffres[6] = afficheChargeImage(CHIFFRE6); afficheVerifChargement(chiffres[6]);
        chiffres[7] = afficheChargeImage(CHIFFRE7); afficheVerifChargement(chiffres[7]);
        chiffres[8] = afficheChargeImage(CHIFFRE8); afficheVerifChargement(chiffres[8]);
        chiffres[9] = afficheChargeImage(CHIFFRE9); afficheVerifChargement(chiffres[9]);
        positionNiveau.x = 370;
        positionNiveau.y = screen->h - 40;

        texte_niveau = afficheChargeImage(TEXTE_NIVEAU);
        positionTexteNiveau.x = 300;
        positionTexteNiveau.y = screen->h - 40;

        imageBoutonPlus = afficheChargeImage(BOUTONPLUS); afficheVerifChargement(imageBoutonPlus);
        imageBoutonMoins = afficheChargeImage(BOUTONMOINS); afficheVerifChargement(imageBoutonMoins);
        positionBoutonPlus.x = 425;
        positionBoutonPlus.y = screen->h - 40;
        positionBoutonPlus.w = imageBoutonPlus->w;
        positionBoutonPlus.h = imageBoutonPlus->h;
        positionBoutonMoins.x = 400;
        positionBoutonMoins.y = screen->h - 40;
        positionBoutonMoins.w = imageBoutonPlus->w;
        positionBoutonMoins.h = imageBoutonPlus->h;

        sourisx = 0;
        sourisy = 0;

    while (done==0)
    {
        /* vider l'écran */
        afficheVideEcran(screen);

        /* animer les pions qui se déplacent à l'écran */
        if(positionPerle.x>(screen->w-(imageAnimeePerle->w)*3/4) || positionPerle.x<=0)
        {
            vecteurPerle.x*=-1;
        }
        if(positionPerle.y<=0 || positionPerle.y>(screen->h-(imageAnimeePerle->h)*3/4))
        {
            vecteurPerle.y*=-1;
        }
        if(positionRubis.x>(screen->w-(imageAnimeeRubis->w)*3/4) || positionRubis.x<=0)
        {
            vecteurRubis.x*=-1;
        }
        if(positionRubis.y<=0 || positionRubis.y>(screen->h-(imageAnimeeRubis->h)*3/4))
        {
            vecteurRubis.y*=-1;
        }
        positionPerle.x += vecteurPerle.x;
        positionPerle.y += vecteurPerle.y;
        positionRubis.x += vecteurRubis.x;
        positionRubis.y += vecteurRubis.y;

        while(afficheEvenements(&event))
        {
            switch(afficheTypeEvenement(&event))
            {
                /* récupérer la position de la souris sur l'écran */
                case EVENT_SOURISBOUGE:
                {
                    sourisx = afficheCoordonneeSouris(&event,'x');
                    sourisy = afficheCoordonneeSouris(&event,'y');
                }
                break;

                /* fermer */
                case AFFICHE_FIN:
                {
                    done = 1;
                    retour = 0;
                }
                break;

                /* touche enfoncée */
                case EVENT_TOUCHEENFONCEE:
                {
                    /* fermer */
                    if(afficheToucheAppuyee(&event) == T_ECHAP)
                    {
                        done = 1;
                        retour = 0;
                    }

                    if(afficheToucheAppuyee(&event) == T_ESPACE)
                    {
                        done = 1;
                        retour = 1;
                    }

                    if((afficheToucheAppuyee(&event) == T_GAUCHE && *contreordinateur==1) || (afficheToucheAppuyee(&event) == T_DROITE && *contreordinateur==0))
                    {
                        *contreordinateur = ((*contreordinateur + 1) % 2);
                    }

                    if((afficheToucheAppuyee(&event) == T_HAUT || afficheToucheAppuyee(&event) == T_PN_PLUS) && *niveauordinateur<5 && *contreordinateur==1)
                    {
                        (*niveauordinateur)++;
                    }

                    if((afficheToucheAppuyee(&event) == T_BAS || afficheToucheAppuyee(&event) == T_PN_MOINS) && *niveauordinateur>1 && *contreordinateur==1)
                    {
                        (*niveauordinateur)--;
                    }

                    if(afficheToucheAppuyee(&event) == T_PN_ENTREE || afficheToucheAppuyee(&event) == T_ENTREE)
                    {
                        done = 1;
                    }
                }
                break;

                case EVENT_SOURISCLIC:
                {
                    if(sourisDansRectangle(sourisx,sourisy,positionContreJoueur)) /* clic sur contre joueur */
                    {
                        *contreordinateur = 0;
                    }
                    else if(sourisDansRectangle(sourisx,sourisy,positionContreOrdi)) /* clic sur contre ordi */
                    {
                        *contreordinateur = 1;
                    }
                    else if(sourisDansRectangle(sourisx,sourisy,positionBoutonJouer)) /* clic sur bouton jouer */
                    {
                        done = 1;
                    }
                    else if(sourisDansRectangle(sourisx,sourisy,positionPlateau[0]))
                    {
                        *plateau=1;
                    }
                    else if(sourisDansRectangle(sourisx,sourisy,positionPlateau[1]))
                    {
                        *plateau=2;
                    }
                    else if(sourisDansRectangle(sourisx,sourisy,positionPlateau[2]))
                    {
                        *plateau=3;
                    }
                    else if(sourisDansRectangle(sourisx,sourisy,positionPlateau[3]))
                    {
                        *plateau=4;
                    }

                    /* changer de niveau ordi */
                    if(sourisDansRectangle(sourisx,sourisy,positionBoutonPlus) && *niveauordinateur<5 && *contreordinateur==1)
                    {
                        (*niveauordinateur)++;
                    }
                    else if(sourisDansRectangle(sourisx,sourisy,positionBoutonMoins) && *niveauordinateur>1 && *contreordinateur==1)
                    {
                        (*niveauordinateur)--;
                    }

                    /* on souhaite reprendre la partie enregistrée (double if pour être sur de na pas tester le 2eme condition si la permiere est 0 */
                    if(partieEnregistree)
                        if(sourisDansRectangle(sourisx,sourisy,positionOuvrir))
                        {
                            fichier = fopen(CONFIGSAUVE,"r");
                            if(fscanf(fichier,"%d,%d",contreordinateur,niveauordinateur)==2)
                            {
                                *plateau = 0;
                                done = 1;
                            }
                            else
                            {
                                printf("[!] Erreur de lecture du fichier de configuration.\n");
                            }
                        }
                }
                break;
            }
        }

        afficheImageRect(positionMenu,menu,screen);

        if(*contreordinateur==1)
        {
            afficheImageRect(positionContreOrdi,imageSelection,screen);
            afficheImageRect(positionTexteNiveau,texte_niveau,screen);
            afficheImageRect(positionNiveau,chiffres[*niveauordinateur],screen);
        }
        else
        {
            afficheImageRect(positionContreJoueur,imageSelection,screen);
        }

        afficheImageRect(positionContreJoueur,imageContreJoueur,screen);
        afficheImageRect(positionContreOrdi,imageContreOrdi,screen);

        afficheImageRect(positionPlateau[*plateau-1],imagePlateauSelectionne,screen);
        afficheImageRect(positionPlateau[0],imagePlateau[0],screen);
        afficheImageRect(positionPlateau[1],imagePlateau[1],screen);
        afficheImageRect(positionPlateau[2],imagePlateau[2],screen);
        afficheImageRect(positionPlateau[3],imagePlateau[3],screen);

        if(*niveauordinateur<5 && *contreordinateur==1)
            afficheImageRect(positionBoutonPlus,imageBoutonPlus,screen);
        if(*niveauordinateur>1 && *contreordinateur==1)
            afficheImageRect(positionBoutonMoins,imageBoutonMoins,screen);


        if(sourisDansRectangle(sourisx,sourisy,positionBoutonJouer))
            afficheImageRect(positionBoutonJouer,imageBoutonJouerSurvol,screen);
        else
            afficheImageRect(positionBoutonJouer,imageBoutonJouer,screen);

         if(sourisDansRectangle(sourisx,sourisy,positionOuvrir)==1)
            afficheImageRect(positionOuvrir,imageOuvrirSurvol,screen);
        else
            afficheImageRect(positionOuvrir,imageOuvrir,screen);

        afficheImageRect(positionPerle,imageAnimeePerle,screen);
        afficheImageRect(positionRubis,imageAnimeeRubis,screen);

        afficheMiseAJour(screen);
    }

    #if SONS==1
        if(hello!=0)    FMOD_Sound_Release(hello);
        if(menuMus!=0)  FMOD_Sound_Release(menuMus);
        FMOD_System_Close(system);
        FMOD_System_Release(system);
    #endif

    afficheFree(menu);
    afficheFree(imageContreJoueur);
    afficheFree(imageContreOrdi);
    afficheFree(imageSelection);
    afficheFree(imageBoutonJouer);
    afficheFree(imageBoutonJouerSurvol);
    afficheFree(imageBoutonPlus);
    afficheFree(imageBoutonMoins);
    afficheFree(imagePlateau[0]);
    afficheFree(imagePlateau[1]);
    afficheFree(imagePlateau[2]);
    afficheFree(imagePlateauSelectionne);
    afficheFree(imageAnimeeRubis);
    afficheFree(imageAnimeePerle);
    afficheFree(texte_niveau);
    if(partieEnregistree)
    {
        afficheFree(imageOuvrir);
        afficheFree(imageOuvrirSurvol);
    }
    for(ich=0;ich<10;ich++)
        afficheFree(chiffres[ich]);
    afficheFree(screen);

    afficheQuit();

    return retour;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
	int att = 1, motion_state = 0, status = STOP;
	float volume;

	SDL_Event event;
	SDL_Surface *ecran = NULL, *fond = NULL, *play = NULL, *stop = NULL, *pause = NULL, *volumeup = NULL, *volumedown = NULL, *spectrum = NULL;
	SDL_Surface *iplay = NULL, *ipause = NULL, *istop = NULL, *ivolup = NULL, *ivoldo = NULL;

	SDL_Rect pos_fond, pos_spect, pos_play, pos_pause, pos_stop, pos_volumeup, pos_volumedown;

	printf("Démarrage de Freqalyzer\n");

	FMOD_SYSTEM *system;
	FMOD_SOUND *sound;
	FMOD_CHANNEL *channel=0;
	FMOD_RESULT result;
	FMOD_BOOL state;
	void *extradriverdata = 0;

	pos_fond.x = 0;
	pos_fond.y = 0;
	pos_spect.x = 100;
	pos_spect.y = 150;
	pos_play.x = 100;
	pos_play.y = 520;
	pos_pause.x = 100 + CONTROLLER_SIZE;
	pos_pause.y = 520;
	pos_stop.x = 100 + (CONTROLLER_SIZE * 2);
	pos_stop.y = 520;
	pos_volumeup.x = 100 + (CONTROLLER_SIZE * 3);
	pos_volumeup.y = 520;
	pos_volumedown.x = 100 + (CONTROLLER_SIZE * 4);
	pos_volumedown.y = 520;

	//Chargement en mémoire du système d'affichage SDL - Vidéo
	SDL_Init(SDL_INIT_VIDEO);

	if(SDL_Init(SDL_INIT_VIDEO) == -1)
	{
		fprintf(stderr, "Erreur d'initialisation de la SDL");
		exit(EXIT_FAILURE);
	}

	//Paramétrage et ouverture de la fenêtre
	ecran =  SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);

	spectrum = SDL_CreateRGBSurface(SDL_HWSURFACE, 600, 350, 32, 0, 0, 0, 0);
	SDL_FillRect(spectrum, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));

	//Titrage de la fenêtre
	SDL_WM_SetCaption("Freqalyzer", NULL);

	//Chargement des images
	fond = IMG_Load("../pictures/fond.jpg");
	W_GestionErreur(P_IMAGE, 0, fond, "fond.jpg");

	play = IMG_Load("../pictures/play.jpg");
	W_GestionErreur(P_IMAGE, 0, play, "play.jpg");

	pause = IMG_Load("../pictures/pause.jpg");
	W_GestionErreur(P_IMAGE, 0, pause, "pause.jpg");

	stop = IMG_Load("../pictures/stop.jpg");
	W_GestionErreur(P_IMAGE, 0, stop, "stop.jpg");

	volumeup = IMG_Load("../pictures/volume_up.jpg");
	W_GestionErreur(P_IMAGE, 0, volumeup, "volume_up.jpg");

	volumedown = IMG_Load("../pictures/volume_down.jpg");
	W_GestionErreur(P_IMAGE, 0, volumedown, "volume_down.jpg");

	iplay = IMG_Load("../pictures/iplay.jpg");
	W_GestionErreur(P_IMAGE, 0, iplay, "iplay.jpg");

	ipause = IMG_Load("../pictures/ipause.jpg");
	W_GestionErreur(P_IMAGE, 0, ipause, "ipause.jpg");

	istop = IMG_Load("../pictures/istop.jpg");
	W_GestionErreur(P_IMAGE, 0, istop, "istop.jpg");

	ivolup = IMG_Load("../pictures/ivolume_up.jpg");
	W_GestionErreur(P_IMAGE, 0, ivolup, "ivolume_up.jpg");

	ivoldo = IMG_Load("../pictures/ivolume_down.jpg");
	W_GestionErreur(P_IMAGE, 0, ivoldo, "ivolume_down.jpg");

	//Allocation de mémoire à system
	result = FMOD_System_Create(&system);
	W_GestionErreur(P_CREASON, result, NULL, "");

	//Initialisation
	result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, extradriverdata);
	W_GestionErreur(P_CHARGSON, result, NULL, "");

	result = FMOD_System_CreateSound(system, "../sounds/radio_sig.mp3", FMOD_2D | FMOD_CREATESTREAM, 0, &sound);

/*	//Chargement du son
	result = FMOD_System_CreateSound(system, argv[1], FMOD_2D | FMOD_CREATESTREAM, 0, &sound);
	if (result != 0)
	{
		printf("\nErreur de saisie, veuillez taper un chemin correct \n(ex : ./Freqalyser ../sounds/gameofthrones.mp3)\n");
		exit(EXIT_FAILURE);
	}*/

	while(att)
	{
		SDL_WaitEvent(&event);

		if (event.motion.x > 100 && event.motion.x < (100 + CONTROLLER_SIZE * 5) && event.motion.y > 520 && event.motion.y < (520 + CONTROLLER_SIZE))
		{
			motion_state = 1;
			W_event(ecran, iplay, ipause, istop, ivolup, ivoldo);
		}else
			motion_state = 0;

		switch(event.type)
		{
			case SDL_QUIT:
				att = 0;
				break;
			case SDL_MOUSEBUTTONUP:
				if (event.button.x > 100 && event.button.x < (100 + CONTROLLER_SIZE) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE))
				{
					//jouer le son et mettre en pause le programme le temps de sa lecture
					result=FMOD_System_PlaySound(system, sound, 0, 0, &channel);
					W_GestionErreur(P_LECTURE, result, NULL, "");
					unsigned int length;
					FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_MS);
					FMOD_Channel_GetVolume(channel, &volume);
					FMOD_Channel_GetVolume(channel, &volume);
					status = PLAY;
				}
				if (event.button.x > (100 + CONTROLLER_SIZE) && event.button.x < (100 + (CONTROLLER_SIZE * 2)) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE))
				{
					FMOD_System_GetChannel(system, 512, &channel);
					FMOD_Channel_GetPaused(channel, &state);
					if(state)
					{
						FMOD_Channel_SetPaused(channel, 0);
						status = PLAY;
					}
					else
					{
						FMOD_Channel_SetPaused(channel, 1);
						status = PAUSE;
					}
				}
				if (event.button.x > (100 + CONTROLLER_SIZE * 2) && event.button.x < (100 + CONTROLLER_SIZE * 3) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE))
				{
					FMOD_Channel_Stop(channel);
					status = STOP;
				}
				if (event.button.x > (100 + CONTROLLER_SIZE * 3) && event.button.x < (100 + CONTROLLER_SIZE * 4) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE))
					result = W_GestionVolume(&volume, channel, UP);
				if (event.button.x > (100 + CONTROLLER_SIZE * 4) && event.button.x < (100 + CONTROLLER_SIZE * 5) && event.button.y > 520 && event.button.y < (520 + CONTROLLER_SIZE))
					result = W_GestionVolume(&volume, channel, DOWN);
				break;
			case SDL_KEYDOWN:
				switch (event.key.keysym.sym)
				{
					case SDLK_ESCAPE:
 						att = 0;
						break;
					case SDLK_SPACE:
						//jouer le son et mettre en pause le programme le temps de sa lecture
						result=FMOD_System_PlaySound(system, sound, 0, 0, &channel);
						unsigned int length;
						FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_MS);
						FMOD_Channel_GetVolume(channel, &volume);
						FMOD_Channel_GetVolume(channel, &volume);
						status = PLAY;
						break;
					case SDLK_UP:
						result = W_GestionVolume(&volume, channel, UP);
						break;
					case SDLK_DOWN:
						result = W_GestionVolume(&volume, channel, DOWN);
						break;
					case SDLK_p:
						FMOD_System_GetChannel(system, 512, &channel);
						FMOD_Channel_GetPaused(channel, &state);
						if(state)
						{
							FMOD_Channel_SetPaused(channel, 0);
							status = PLAY;
						}
						else
						{
							FMOD_Channel_SetPaused(channel, 1);
							status = PAUSE;
						}
						break;
					case SDLK_s:
						FMOD_Channel_Stop(channel);
						status = STOP;
						break;
					default:
						break;
					}
			default:
				break;
		}

		//Affichage des surfaces
		SDL_BlitSurface(fond, NULL, ecran, &pos_fond);
		SDL_BlitSurface(spectrum, NULL, ecran, &pos_spect);
		switch (status)
		{
			case PLAY:
				SDL_BlitSurface(iplay, NULL, ecran, &pos_play);
				SDL_BlitSurface(pause, NULL, ecran, &pos_pause);
				SDL_BlitSurface(stop, NULL, ecran, &pos_stop);
				break;
			case PAUSE:
				SDL_BlitSurface(play, NULL, ecran, &pos_play);
				SDL_BlitSurface(ipause, NULL, ecran, &pos_pause);
				SDL_BlitSurface(stop, NULL, ecran, &pos_stop);
				break;
			case STOP:
				SDL_BlitSurface(play, NULL, ecran, &pos_play);
				SDL_BlitSurface(pause, NULL, ecran, &pos_pause);
				SDL_BlitSurface(istop, NULL, ecran, &pos_stop);
				break;
			default:
				break;
		}
		SDL_BlitSurface(volumeup, NULL, ecran, &pos_volumeup);
		SDL_BlitSurface(volumedown, NULL, ecran, &pos_volumedown);

		//Rafraîchissement de la fenêtre
		SDL_Flip(ecran);
		FMOD_System_Update(system);
	}

	//Fermeture et libération de l'objet system en mémoire
	FMOD_Sound_Release(sound);
	FMOD_System_Close(system);
	FMOD_System_Release(system);

	SDL_FreeSurface(spectrum);
	SDL_FreeSurface(fond);
	SDL_FreeSurface(play);
	SDL_FreeSurface(pause);
	SDL_FreeSurface(stop);
	SDL_FreeSurface(volumeup);
	SDL_FreeSurface(volumedown);
	SDL_FreeSurface(iplay);
	SDL_FreeSurface(ipause);
	SDL_FreeSurface(istop);
	SDL_FreeSurface(ivolup);
	SDL_FreeSurface(ivoldo);

	SDL_Quit();

	return EXIT_SUCCESS;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM      *system;
    FMOD_SOUND       *sound1, *sound2, *sound3;
    FMOD_CHANNEL     *channel = 0;
    FMOD_RESULT       result;
    int               key;
    unsigned int      version;

    /*
        Global Settings
    */
    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);
        getch();
        return 0;
    }

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

    result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound1);
    ERRCHECK(result);

    result = FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
    ERRCHECK(result);

    result = FMOD_System_CreateSound(system, "../media/jaguar.wav", FMOD_SOFTWARE, 0, &sound2);
    ERRCHECK(result);

    result = FMOD_System_CreateSound(system, "../media/swish.wav", FMOD_SOFTWARE, 0, &sound3);
    ERRCHECK(result);

    printf("===================================================================\n");
    printf("PlaySound Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===================================================================\n");
    printf("\n");
    printf("Press '1' to Play a mono sound using software mixing\n");
    printf("Press '2' to Play a mono sound using software mixing\n");
    printf("Press '3' to Play a stereo sound using software mixing\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Main loop.
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case '1' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
                case '2' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
                case '3' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound3, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            int          playing = 0;
            int          paused = 0;
            int          channelsplaying = 0;

            if (channel)
            {
                FMOD_SOUND *currentsound = 0;

                result = FMOD_Channel_IsPlaying(channel, &playing);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPaused(channel, &paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                FMOD_Channel_GetCurrentSound(channel, &currentsound);
                if (currentsound)
                {
                    result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }
            }

            result = FMOD_Sound_GetLength(sound1, &lenms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            FMOD_System_GetChannelsPlaying(system, &channelsplaying);

            printf("\rTime %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
            fflush(stdout);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(sound1);
    ERRCHECK(result);
    result = FMOD_Sound_Release(sound2);
    ERRCHECK(result);
    result = FMOD_Sound_Release(sound3);
    ERRCHECK(result);
    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    return 0;
}
Ejemplo n.º 11
0
 SoundManager::~SoundManager()
 {
   for_each(this->_sounds.begin(), this->_sounds.end(), releaseSounds);
   FMOD_System_Close(this->_system);
   FMOD_System_Release(this->_system);
 }
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM       *system;
    FMOD_SOUND        *sound;
    FMOD_CHANNEL      *channel;
    FMOD_DSP          *mydsp;
    FMOD_RESULT        result;
    int                key;
    unsigned int       version;
    float              pan = 0;

    /*
        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_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound);
    ERRCHECK(result);

    printf("===============================================================================\n");
    printf("Custom DSP example. Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===============================================================================\n");
    printf("Press 'f' to activate, deactivate user filter\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
    ERRCHECK(result);

    /*
        Create the DSP effects.
    */  
    { 
        FMOD_DSP_DESCRIPTION  dspdesc; 

        memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION)); 

        strcpy(dspdesc.name, "My first DSP unit"); 
        dspdesc.channels     = 0;                   // 0 = whatever comes in, else specify. 
        dspdesc.read         = myDSPCallback; 
        dspdesc.userdata     = (void *)0x12345678; 

        result = FMOD_System_CreateDSP(system, &dspdesc, &mydsp); 
        ERRCHECK(result); 
    } 

    /*
        Inactive by default.
    */
    FMOD_DSP_SetBypass(mydsp, TRUE);

    /*
        Main loop.
    */
    result = FMOD_System_AddDSP(system, mydsp, 0); 


    /*
        Main loop.
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case 'f' : 
                case 'F' : 
                {
                    static int active = FALSE;

                    FMOD_DSP_SetBypass(mydsp, active);

                    active = !active;
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    result = FMOD_DSP_Release(mydsp);
    ERRCHECK(result);

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

    return 0;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM        *system;
    FMOD_SOUND         *sound;
    FMOD_CHANNEL       *channel;
    FMOD_DSP           *dsplowpass, *dspchorus, *dsphead, *dspchannelmixer;
	FMOD_DSPCONNECTION *dsplowpassconnection, *dspchorusconnection;
    FMOD_RESULT         result;
    int                 key;
    unsigned int        version;
    float               pan = 0;

    /*
        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_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound);
    ERRCHECK(result);

    printf("===============================================================================\n");
    printf("DSP Effect per speaker example. Copyright (c) Firelight Technologies 2004-2015.\n");
    printf("===============================================================================\n");
    printf("Press 'L' to toggle reverb on/off on left speaker only\n");
    printf("Press 'R' to toggle chorus on/off on right speaker only\n");
    printf("Press '[' to pan sound left\n");
    printf("Press ']' to pan sound right\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
    ERRCHECK(result);

    /*
        Create the DSP effects.
    */  
    result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
    ERRCHECK(result);

    result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_CHORUS, &dspchorus);
    ERRCHECK(result);

    /*
        Connect up the DSP network
    */

    /*
        When a sound is played, a subnetwork is set up in the DSP network which looks like this.
        Wavetable is the drumloop sound, and it feeds its data from right to left.

        [DSPHEAD]<------------[DSPCHANNELMIXER]
    */  
    result = FMOD_System_GetDSPHead(system, &dsphead);
    ERRCHECK(result);

    result = FMOD_DSP_GetInput(dsphead, 0, &dspchannelmixer, 0);
    ERRCHECK(result);

    /*
        Now disconnect channeldsp head from wavetable to look like this.

        [DSPHEAD]             [DSPCHANNELMIXER]
    */
    result = FMOD_DSP_DisconnectFrom(dsphead, dspchannelmixer);
    ERRCHECK(result);

    /*
        Now connect the 2 effects to channeldsp head.
		Store the 2 connections this makes so we can set their speakerlevels later.

                  [DSPLOWPASS]
                 /x           
        [DSPHEAD]             [DSPCHANNELMIXER]
                 \y           
                  [DSPCHORUS]
    */
    result = FMOD_DSP_AddInput(dsphead, dsplowpass, &dsplowpassconnection); /* x = dsplowpassconnection */
    ERRCHECK(result);
    result = FMOD_DSP_AddInput(dsphead, dspchorus, &dspchorusconnection);   /* y = dspchorusconnection */
    ERRCHECK(result);
    
    /*
        Now connect the wavetable to the 2 effects

                  [DSPLOWPASS]
                 /x          \
        [DSPHEAD]             [DSPCHANNELMIXER]
                 \y          /
                  [DSPCHORUS]
    */
    result = FMOD_DSP_AddInput(dsplowpass, dspchannelmixer, NULL);  /* Null for connection - we dont care about it. */
    ERRCHECK(result);
    result = FMOD_DSP_AddInput(dspchorus, dspchannelmixer, NULL);   /* Null for connection - we dont care about it. */
    ERRCHECK(result);

    /*
        Now the drumloop will be twice as loud, because it is being split into 2, then recombined at the end.
        What we really want is to only feed the dspchannelmixer->dsplowpass through the left speaker, and 
        dspchannelmixer->dspchorus to the right speaker.
        We can do that simply by setting the pan, or speaker levels of the connections.

                  [DSPLOWPASS]
                 /x=1,0      \
        [DSPHEAD]             [DSPCHANNELMIXER]
                 \y=0,1      /
                  [DSPCHORUS]
    */
    {
        float leftinputon[2]  = { 1.0f, 0.0f };
        float rightinputon[2] = { 0.0f, 1.0f };
        float inputsoff[2]    = { 0.0f, 0.0f };

        result = FMOD_DSPConnection_SetLevels(dsplowpassconnection, FMOD_SPEAKER_FRONT_LEFT, leftinputon, 2);
        ERRCHECK(result);
        result = FMOD_DSPConnection_SetLevels(dsplowpassconnection, FMOD_SPEAKER_FRONT_RIGHT, inputsoff, 2);
        ERRCHECK(result);

        result = FMOD_DSPConnection_SetLevels(dspchorusconnection, FMOD_SPEAKER_FRONT_LEFT, inputsoff, 2);
        ERRCHECK(result);
        result = FMOD_DSPConnection_SetLevels(dspchorusconnection, FMOD_SPEAKER_FRONT_RIGHT, rightinputon, 2);
        ERRCHECK(result);
    }

    result = FMOD_DSP_SetBypass(dsplowpass, TRUE);
    result = FMOD_DSP_SetBypass(dspchorus, TRUE);

    result = FMOD_DSP_SetActive(dsplowpass, TRUE);
    result = FMOD_DSP_SetActive(dspchorus, TRUE);

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

            switch (key)
            {
                case 'l' : 
                case 'L' : 
                {
                    static int reverb = FALSE;

                    FMOD_DSP_SetBypass(dsplowpass, reverb);

                    reverb = !reverb;
                    break;
                }
                case 'r' : 
                case 'R' : 
                {
                    static int chorus = FALSE;

                    FMOD_DSP_SetBypass(dspchorus, chorus);

                    chorus = !chorus;
                    break;
                }
                case '[' :
                {
                    FMOD_Channel_GetPan(channel, &pan);
                    pan -= 0.1f;
                    if (pan < -1)
                    {
                        pan = -1;
                    }
                    FMOD_Channel_SetPan(channel, pan);
                    break;
                }
                case ']' :
                {
                    FMOD_Channel_GetPan(channel, &pan);
                    pan += 0.1f;
                    if (pan > 1)
                    {
                        pan = 1;
                    }
                    FMOD_Channel_SetPan(channel, pan);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        {
            int  channelsplaying = 0;

            FMOD_System_GetChannelsPlaying(system, &channelsplaying);

            printf("Channels Playing %2d : Pan = %.02f\r", channelsplaying, pan);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    result = FMOD_DSP_Release(dsplowpass);
    ERRCHECK(result);
    result = FMOD_DSP_Release(dspchorus);
    ERRCHECK(result);

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

    return 0;
}
Ejemplo n.º 14
0
sound_system_c::~sound_system_c() {
	fmod_errorcheck(FMOD_Sound_Release(music));
	fmod_errorcheck(FMOD_System_Close(fmod_system));
	fmod_errorcheck(FMOD_System_Release(fmod_system));
}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM      *system;
    FMOD_SOUND       *sound1, *sound2, *sound3;
    FMOD_CHANNEL     *channel = 0;
    FMOD_RESULT       result;
    int               key;
    unsigned int      version;
    void             *buff = 0;
    int               length = 0;
    FMOD_CREATESOUNDEXINFO exinfo;

    /*
        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, NULL);
    ERRCHECK(result);

    LoadFileIntoMemory("../media/drumloop.wav", &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;

    result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound1);
    ERRCHECK(result);

    result = FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
    ERRCHECK(result);

    free(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!

    LoadFileIntoMemory("../media/jaguar.wav", &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;    

    result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &sound2);
    ERRCHECK(result);

    free(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!

    LoadFileIntoMemory("../media/swish.wav", &buff, &length);
    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = length;    

    result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound3);
    ERRCHECK(result);

    free(buff); // don't need the original memory any more.  Note!  If loading as a stream, the memory must stay active so do not free it!

    printf("==========================================================================\n");
    printf("Load from memory example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("==========================================================================\n");
    printf("\n");
    printf("Press '1' to play a mono sound using hardware mixing\n");
    printf("Press '2' to play a mono sound using software mixing\n");
    printf("Press '3' to play a stereo sound using hardware mixing\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Main loop.
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case '1' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
                case '2' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
                case '3' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound3, 0, &channel);
                    ERRCHECK(result);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            int          playing = 0;
            int          paused = 0;
            int          channelsplaying = 0;

            if (channel)
            {
                FMOD_SOUND *currentsound = 0;

                result = FMOD_Channel_IsPlaying(channel, &playing);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPaused(channel, &paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                FMOD_Channel_GetCurrentSound(channel, &currentsound);
                if (currentsound)
                {
                    result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }
            }

            result = FMOD_Sound_GetLength(sound1, &lenms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            FMOD_System_GetChannelsPlaying(system, &channelsplaying);

            printf("\rTime %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
            fflush(stdout);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(sound1);
    ERRCHECK(result);
    result = FMOD_Sound_Release(sound2);
    ERRCHECK(result);
    result = FMOD_Sound_Release(sound3);
    ERRCHECK(result);
    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    return 0;
}
Ejemplo n.º 16
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM      *system;
    FMOD_SOUND       *sound1, *sound2;
    FMOD_CHANNEL     *channel = 0;
    FMOD_RESULT       result;
    FMOD_SPEAKERMODE  speakermode;
    int               key;
    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;
    }

    /* 
       Choose the speaker mode selected by the Windows control panel.
    */
    result = FMOD_System_GetDriverCaps(system, 0, 0, 0, &speakermode);
    ERRCHECK(result);

    result = FMOD_System_SetSpeakerMode(system, speakermode);
    ERRCHECK(result);

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

    result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE | FMOD_2D, 0, &sound1);
    ERRCHECK(result);
    result = FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
    ERRCHECK(result);

    result = FMOD_System_CreateSound(system, "../media/stereo.ogg", FMOD_SOFTWARE | FMOD_2D, 0,  &sound2);
    ERRCHECK(result);

    printf("==============================================================================\n");
    printf("Multi Speaker Output Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("==============================================================================\n");
    printf("\n");
    switch (speakermode)
    {
        case FMOD_SPEAKERMODE_MONO    :
        {
            printf("Using control panel speaker mode : MONO.\n");
            printf("\n");
            printf("Note! This output mode is very limited in its capability.\n");
            printf("Most functionality of this demo is only realized with at least FMOD_SPEAKERMODE_QUAD\n");
            printf("and above.\n");
            break;
        }
        case FMOD_SPEAKERMODE_STEREO  :
        {
            printf("Using control panel speaker mode : STEREO.\n");
            printf("\n");
            printf("Note! This output mode is very limited in its capability.\n");
            printf("Most functionality of this demo is only realized with FMOD_SPEAKERMODE_QUAD\n");
            printf("and above.\n");
            break;
        }
        case FMOD_SPEAKERMODE_QUAD :
        {
            printf("Using control panel speaker mode : QUAD.\n");
            printf("Side left, side right, center and subwoofer mix will be disabled.\n");
            break;
        }
        case FMOD_SPEAKERMODE_SURROUND :
        {
            printf("Using control panel speaker mode : SURROUND.\n");
            printf("Side left, side right, and subwoofer mix will be disabled.\n");
            break;
        }
        case FMOD_SPEAKERMODE_5POINT1 :
        {
            printf("Using control panel speaker mode : 5.1 surround.\n");
            printf("Side left and right mix will be disabled..\n");
            break;
        }
        case FMOD_SPEAKERMODE_7POINT1 :
        {
            printf("Using control panel speaker mode : 7.1 surround.\n");
            printf("Full capability.\n");
            break;
        }
    };
    printf("\n");

    printf("Press '1' to play a mono sound on the FRONT LEFT speaker.\n");
    printf("Press '2' to play a mono sound on the FRONT RIGHT speaker.\n");

    if (speakermode >= FMOD_SPEAKERMODE_SURROUND)
    {
        printf("Press '3' to play a mono sound on the CENTER speaker.\n");
    }
    else
    {
        printf("- CENTER Disabled\n");
    }

    if (speakermode >= FMOD_SPEAKERMODE_QUAD)
    {
        printf("Press '4' to play a mono sound on the REAR LEFT speaker.\n");
        printf("Press '5' to play a mono sound on the REAR RIGHT speaker.\n");
    }
    else
    {
        printf("- REAR LEFT Disabled\n");
        printf("- REAR RIGHT Disabled\n");
    }
    if (speakermode >= FMOD_SPEAKERMODE_7POINT1)
    {
        printf("Press '6' to play a mono sound on the SIDE LEFT speaker.\n");
        printf("Press '7' to play a mono sound on the SIDE RIGHT speaker.\n");
    }
    else
    {
        printf("- SIDE LEFT Disabled\n");
        printf("- SIDE RIGHT Disabled\n");
    }

    printf("\n");
    printf("Press '8' to play a stereo sound on the front speakers.\n");
    printf("Press '9' to play a stereo sound on the front speakers but channel swapped.\n");

    if (speakermode >= FMOD_SPEAKERMODE_SURROUND)
    {
        printf("Press '0' to play the right part of a stereo sound on the CENTER speaker.\n");
    }

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

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

            switch (key)
            {
                case '1' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
                    ERRCHECK(result);

                    result = FMOD_Channel_SetSpeakerMix(channel, 1.0f, 0, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

                    result = FMOD_Channel_SetPaused(channel, FALSE);
                    ERRCHECK(result);
                    break;
                }
                case '2' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
                    ERRCHECK(result);

                    result = FMOD_Channel_SetSpeakerMix(channel, 0, 1.0f, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

                    result = FMOD_Channel_SetPaused(channel, FALSE);
                    ERRCHECK(result);
                    break;
                }
                case '3' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_QUAD)
                    {
                        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 1.0f, 0, 0, 0, 0, 0);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetPaused(channel, FALSE);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '4' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_QUAD)
                    {
                        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 1.0f, 0, 0, 0);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetPaused(channel, FALSE);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '5' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_QUAD)
                    {
                        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 1.0f, 0, 0);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetPaused(channel, FALSE);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '6' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_7POINT1)
                    {
                        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 0, 1.0f, 0);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetPaused(channel, FALSE);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '7' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_7POINT1)
                    {
                        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 0, 0, 1.0f);
                        ERRCHECK(result);

                        result = FMOD_Channel_SetPaused(channel, FALSE);
                        ERRCHECK(result);
                    }
                    break;
                }
                case '8' :
                {
                    float  levels[2] = { 0, 1.0f };

                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, TRUE, &channel);
                    ERRCHECK(result);

                    /*
                        By default a stereo sound would play in all right and all left speakers, so this forces it to just the front.
                    */
                    result = FMOD_Channel_SetSpeakerMix(channel, 1.0f, 1.0f, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

                    result = FMOD_Channel_SetPaused(channel, FALSE);
                    ERRCHECK(result);

                    break;
                }
                case '9' :
                {
                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, TRUE, &channel);
                    ERRCHECK(result);

                    /*
                        Clear out all speakers first.
                    */
                    result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 0, 0, 0);
                    ERRCHECK(result);

                    /*
                        Put the left channel of the sound in the right speaker.
                    */
                    {
                        float  levels[2] = { 0, 1.0f };    /* This array represents the source stereo sound.  l/r */

                        result = FMOD_Channel_SetSpeakerLevels(channel, FMOD_SPEAKER_FRONT_LEFT, levels, 2);
                        ERRCHECK(result);
                    }
                    /*
                        Put the right channel of the sound in the left speaker.
                    */
                    {
                        float  levels[2] = { 1.0f, 0 };    /* This array represents the source stereo sound.  l/r */

                        result = FMOD_Channel_SetSpeakerLevels(channel, FMOD_SPEAKER_FRONT_RIGHT, levels, 2);
                        ERRCHECK(result);
                    }

                    result = FMOD_Channel_SetPaused(channel, FALSE);
                    ERRCHECK(result);

                    break;
                }
                case '0' :
                {
                    if (speakermode >= FMOD_SPEAKERMODE_SURROUND)   /* All formats that have a center speaker. */
                    {
                        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, TRUE, &channel);
                        ERRCHECK(result);

                        /*
                            Clear out all speakers first.
                        */
                        result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 0, 0, 0);
                        ERRCHECK(result);

                        /*
                            Put the right channel of the sound in the center speaker.
                        */
                        {
                            float  levels[2] = { 0, 1.0f };    /* This array represents the source stereo sound.  l/r */

                            result = FMOD_Channel_SetSpeakerLevels(channel, FMOD_SPEAKER_FRONT_CENTER, levels, 2);
                            ERRCHECK(result);
                        }

                        result = FMOD_Channel_SetPaused(channel, FALSE);
                        ERRCHECK(result);
                    }
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            int          playing = FALSE;
            int          paused = FALSE;
            int          channelsplaying = 0;

            if (channel)
            {
                FMOD_SOUND *currentsound = 0;

                result = FMOD_Channel_IsPlaying(channel, &playing);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPaused(channel, &paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }
               
                FMOD_Channel_GetCurrentSound(channel, &currentsound);
                if (currentsound)
                {
                    result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }
            }

            FMOD_System_GetChannelsPlaying(system, &channelsplaying);

            printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(sound1);
    ERRCHECK(result);
    result = FMOD_Sound_Release(sound2);
    ERRCHECK(result);
    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    return 0;
}
Ejemplo n.º 17
0
void QSPCallBacks::DeInit()
{
	CloseFile(qspStringFromPair(0, 0));
	FMOD_System_Close(m_sys);
	FMOD_System_Release(m_sys);
}
Ejemplo n.º 18
0
CubeAnim::~CubeAnim()
{
  FMOD_Sound_Release(musique);
  FMOD_System_Close(system);
  FMOD_System_Release(system);
}
Ejemplo n.º 19
0
FMODSound::~FMODSound()
{
  FMOD_System_Close(this->_system);
  FMOD_System_Release(this->_system);
}
Ejemplo n.º 20
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM      *system   = 0;
    FMOD_SOUND       *playlist = 0;
    FMOD_SOUND       *sound    = 0;
    FMOD_CHANNEL     *channel  = 0;
    FMOD_TAG          tag;
    FMOD_RESULT       result;
    FMOD_SOUND_TYPE   soundtype;
    FMOD_BOOL         isplaylist = 0;
    char             *title = NULL;
    int               count = 0;
    int               key;
    unsigned int      version;
    char              file[128];   

    /*
        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/playlist.m3u", FMOD_DEFAULT, 0, &playlist);
    ERRCHECK(result);

    result = FMOD_Sound_GetFormat(playlist, &soundtype, 0, 0, 0);
    ERRCHECK(result);

    isplaylist = (soundtype == FMOD_SOUND_TYPE_PLAYLIST);

    printf("===================================================================\n");
    printf("PlayList Example.  Copyright (c) Firelight Technologies 2004-2015.\n");
    printf("===================================================================\n");
    printf("\n");
    printf("Press 'n'     to play next sound in playlist\n");
    printf("Press 'space' to pause/unpause current sound\n");
    printf("Press 'Esc'   to quit\n");
    printf("\n");

    if (isplaylist)
    {
        printf("PLAYLIST loaded.\n");
        /*
            Get the first song in the playlist, create the sound and then play it.
        */
        result = FMOD_Sound_GetTag(playlist, "FILE", count, &tag);
        ERRCHECK(result);

        sprintf(file, "../media/%s", (char *)tag.data);

        result = FMOD_System_CreateSound(system, file, FMOD_DEFAULT, 0, &sound);
        ERRCHECK(result);

        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
        ERRCHECK(result);

        FMOD_Sound_GetTag(playlist, "TITLE", count, &tag);
        title = (char *)tag.data;

        count++;
    }
    else
    {
        printf("SOUND loaded.\n");

        /*
            This is just a normal sound, so just play it.
        */
        sound = playlist;

        result = FMOD_Sound_SetMode(sound, FMOD_LOOP_NORMAL);
        ERRCHECK(result);

        result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
        ERRCHECK(result);
    }

    printf("\n");

    /*
        Main loop.
    */
    do
    {
        FMOD_BOOL  isplaying = 0;

        if (channel && isplaylist)
        {
            /*
                When sound has finished playing, play the next sound in the playlist
            */

            FMOD_Channel_IsPlaying(channel, &isplaying);
            if (!isplaying)
            {
                if (sound)
                {
                    FMOD_Sound_Release(sound);

                    sound = NULL;
                }

                result = FMOD_Sound_GetTag(playlist, "FILE", count, &tag);
                if (result != FMOD_OK)
                {
                    count = 0;
                }
                else
                {
                    printf("playing next song in playlist...\n");

                    sprintf(file, "../media/%s", (char *)tag.data);

                    result = FMOD_System_CreateSound(system, file, FMOD_DEFAULT, 0, &sound);
                    ERRCHECK(result);

                    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
                    ERRCHECK(result);

                    FMOD_Sound_GetTag(playlist, "TITLE", count, &tag);
                    title = (char *)tag.data;

                    count++;
                }
            }
        }


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

            switch (key)
            {
                case 'n' :
                {
                    /*
                        Play the next song in the playlist
                    */
                    if (channel && isplaylist)
                    {
                        FMOD_Channel_Stop(channel);
                    }

                    break;
                }
                case ' ' :
                {
                    if (channel)
                    {
                        FMOD_BOOL paused;

                        FMOD_Channel_GetPaused(channel, &paused);
                        FMOD_Channel_SetPaused(channel, !paused);
                    }
                }
            }
        }

        FMOD_System_Update(system);

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            FMOD_BOOL    paused = 0;

            if (channel)
            {
                if (sound)
                {
                    result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }

                result = FMOD_Channel_GetPaused(channel, &paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }
            }

            printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : "Playing ", title);

        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    if (sound)
    {
        result = FMOD_Sound_Release(sound);
        ERRCHECK(result);
    }
    if (isplaylist)
    {
        result = FMOD_Sound_Release(playlist);
        ERRCHECK(result);
    }
    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    return 0;
}
//---------------------------------------
void ofSoundPlayer::closeFmod(){
	if(bFmodInitialized){
		FMOD_System_Close(sys);
		bFmodInitialized = false;
	}
}
Ejemplo n.º 22
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM     *system;
    FMOD_SOUND      *sound;
    FMOD_CHANNEL    *channel = 0;
    FMOD_RESULT       result;
    int               key;
    unsigned int      version;
    HANDLE            threadhandle;

    InitializeCriticalSection(&gCrit);
    
	threadhandle = (HANDLE)_beginthreadex(NULL, 0, ProcessQueue, 0, 0, 0);
    if (!threadhandle)
    {
        printf("Failed to create file thread.\n");
        return 0;
    }
    
    /*
        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, 1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = FMOD_System_SetStreamBufferSize(system, 32768, FMOD_TIMEUNIT_RAWBYTES);
    ERRCHECK(result);
    
    result = FMOD_System_SetFileSystem(system, myopen, myclose, myread, myseek, myasyncread, myasynccancel, 2048);
    ERRCHECK(result);

    printf("====================================================================\n");
    printf("Stream IO Example.  Copyright (c) Firelight Technologies 2004-2015.\n");
    printf("====================================================================\n");
    printf("\n");
    printf("\n");
    printf("====================== CALLING CREATESOUND ON MP3 =======================\n");
    
    result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_2D | FMOD_IGNORETAGS, 0, &sound);
    ERRCHECK(result);

    printf("====================== CALLING PLAYSOUND ON MP3 =======================\n");

    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        if (sound)
        {
            FMOD_OPENSTATE openstate;
            int starving;

            FMOD_Sound_GetOpenState(sound, &openstate, 0, &starving, 0);
            
            if (starving)
            {
                printf("Starving\n");
                result = FMOD_Channel_SetMute(channel, 1);
            }
            else
            {
                result = FMOD_Channel_SetMute(channel, 0);
                ERRCHECK(result);
            }
        }

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

            switch (key)
            {
                case ' ' :
                {
                    result = FMOD_Sound_Release(sound);
                    if (result == FMOD_OK)
                    {
                        sound = 0;
                        printf("Released sound.\n");
                    }
                    break;
                }
            }
        }

        FMOD_System_Update(system);
        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    if (sound)
    {
        result = FMOD_Sound_Release(sound);
        ERRCHECK(result);
    }
    result = FMOD_System_Close(system);
    ERRCHECK(result);
    result = FMOD_System_Release(system);
    ERRCHECK(result);

    gThreadQuit = 1;   

    return 0;
}
Ejemplo n.º 23
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM     *system;
    FMOD_SOUND      *sound;
    FMOD_RESULT      result;
    FMOD_TAG         tag;
    int              numtags, numtagsupdated, count;
    unsigned int     version;

    printf("==================================================================\n");
    printf("ReadTags Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("==================================================================\n\n");

    /*
        Global Settings
    */
    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);
        getch();
        return 0;
    }

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

    /*
        Open the specified file. Use FMOD_CREATESTREAM and FMOD_OPENONLY so it opens quickly
    */
    result = FMOD_System_CreateSound(system, "../media/wave.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_OPENONLY, 0, &sound);
    ERRCHECK(result);

    /*
        Read and display all tags associated with this file
    */
    for (;;)
    {
        /*
            An index of -1 means "get the first tag that's new or updated".
            If no tags are new or updated then getTag will return FMOD_ERR_TAGNOTFOUND.
            This is the first time we've read any tags so they'll all be new but after we've read them, 
            they won't be new any more.
        */
        if (FMOD_Sound_GetTag(sound, 0, -1, &tag) != FMOD_OK)
        {
            break;
        }
        if (tag.datatype == FMOD_TAGDATATYPE_STRING)
        {
            printf("%s = %s (%d bytes)\n", tag.name, (char *)tag.data, tag.datalen);
        }
        else
        {
            printf("%s = <binary> (%d bytes)\n", tag.name, tag.datalen);
        }
    }
    printf("\n");

    /*
        Read all the tags regardless of whether they're updated or not. Also show the tag type.
    */
    result = FMOD_Sound_GetNumTags(sound, &numtags, &numtagsupdated);
    ERRCHECK(result);
    for (count=0; count < numtags; count++)
    {
        result = FMOD_Sound_GetTag(sound, 0, count, &tag);
        ERRCHECK(result);

        switch (tag.type)
        {
            case FMOD_TAGTYPE_UNKNOWN :
                printf("FMOD_TAGTYPE_UNKNOWN  ");
                break;

            case FMOD_TAGTYPE_ID3V1 :
                printf("FMOD_TAGTYPE_ID3V1  ");
                break;

            case FMOD_TAGTYPE_ID3V2 :
                printf("FMOD_TAGTYPE_ID3V2  ");
                break;

            case FMOD_TAGTYPE_VORBISCOMMENT :
                printf("FMOD_TAGTYPE_VORBISCOMMENT  ");
                break;

            case FMOD_TAGTYPE_SHOUTCAST :
                printf("FMOD_TAGTYPE_SHOUTCAST  ");
                break;

            case FMOD_TAGTYPE_ICECAST :
                printf("FMOD_TAGTYPE_ICECAST  ");
                break;

            case FMOD_TAGTYPE_ASF :
                printf("FMOD_TAGTYPE_ASF  ");
                break;

            case FMOD_TAGTYPE_FMOD :
                printf("FMOD_TAGTYPE_FMOD  ");
                break;

            case FMOD_TAGTYPE_USER :
                printf("FMOD_TAGTYPE_USER  ");
                break;
        }

        if (tag.datatype == FMOD_TAGDATATYPE_STRING)
        {
            printf("%s = %s (%d bytes)\n", tag.name, (char *)tag.data, tag.datalen);
        }
        else
        {
            printf("%s = ??? (%d bytes)\n", tag.name, tag.datalen);
        }
    }
    printf("\n");

    /*
        Find a specific tag by name. Specify an index > 0 to get access to multiple tags of the same name.
    */
    result = FMOD_Sound_GetTag(sound, "ARTIST", 0, &tag);
    ERRCHECK(result);
    printf("%s = %s (%d bytes)\n", tag.name, (char *)tag.data, tag.datalen);
    printf("\n");

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

    return 0;
}
Ejemplo n.º 24
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-2014.\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);
        }

        fflush(stdout);
        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;
}
Ejemplo n.º 25
0
MY_FMOD::~MY_FMOD()
{
  FMOD_System_Close(system);
  FMOD_System_Release(system);
}
Ejemplo n.º 26
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM            *system;
    FMOD_SOUND             *sound;
    FMOD_CHANNEL           *channel = 0;
    FMOD_RESULT             result;
    FMOD_MODE               mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_HARDWARE;
    int                     key;
    int                     channels = 2;
    FMOD_CREATESOUNDEXINFO  createsoundexinfo;
    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, NULL);
    ERRCHECK(result);
        
    printf("============================================================================\n");
    printf("User Created Sound Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("============================================================================\n");
    printf("Sound played here is generated in realtime.  It will either play as a stream\n");
    printf("which means it is continually filled as it is playing, or it will play as a \n");
    printf("static sample, which means it is filled once as the sound is created, then  \n");
    printf("when played it will just play that short loop of data.                      \n");
    printf("============================================================================\n");
    printf("\n");

    do
    {
        printf("Press 1 to play as a runtime decoded stream. (will carry on infinitely)\n");
        printf("Press 2 to play as a static in memory sample. (loops a short block of data)\n");
        printf("Press Esc to quit.\n\n");
        key = getch();

    } while (key != 27 && key != '1' && key != '2');

    if (key == 27)
    {
        return 0;
    }
    else if (key == '1')
    {
        mode |= FMOD_CREATESTREAM;
    }

    memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    createsoundexinfo.cbsize            = sizeof(FMOD_CREATESOUNDEXINFO);              /* required. */
    createsoundexinfo.decodebuffersize  = 44100;                                       /* Chunk size of stream update in samples.  This will be the amount of data passed to the user callback. */
    createsoundexinfo.length            = 44100 * channels * sizeof(signed short) * 5; /* Length of PCM data in bytes of whole song (for Sound::getLength) */
    createsoundexinfo.numchannels       = channels;                                    /* Number of channels in the sound. */
    createsoundexinfo.defaultfrequency  = 44100;                                       /* Default playback rate of sound. */
    createsoundexinfo.format            = FMOD_SOUND_FORMAT_PCM16;                     /* Data format of sound. */
    createsoundexinfo.pcmreadcallback   = pcmreadcallback;                             /* User callback for reading. */
    createsoundexinfo.pcmsetposcallback = pcmsetposcallback;                           /* User callback for seeking. */

    result = FMOD_System_CreateSound(system, 0, mode, &createsoundexinfo, &sound);
    ERRCHECK(result);

    printf("Press space to pause, Esc to quit\n");
    printf("\n");

    /*
        Play the sound.
    */

    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case ' ' :
                {
                    int paused;
                    FMOD_Channel_GetPaused(channel, &paused);
                    FMOD_Channel_SetPaused(channel, !paused);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        if (channel)
        {
            unsigned int ms;
            unsigned int lenms;
            int          playing;
            int          paused;

            FMOD_Channel_IsPlaying(channel, &playing);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Channel_GetPaused(channel, &paused);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
            fflush(stdout);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    return 0;
}
Ejemplo n.º 27
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM    *systemA, *systemB;
    FMOD_SOUND     *soundA, *soundB;
    FMOD_CHANNEL   *channelA = 0, *channelB = 0;
    FMOD_RESULT     result;
    int             key, count, numdrivers, driver;
    unsigned int    version;

    /*
        Create Sound Card A
    */
    result = FMOD_System_Create(&systemA);
    ERRCHECK(result);

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

    printf("---------------------------------------------------------\n");    
    printf("Select soundcard A\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = FMOD_System_GetDriverInfo(systemA, 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);

    printf("\n");

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

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

    /*
        Create Sound Card B
    */
    result = FMOD_System_Create(&systemB);
    ERRCHECK(result);

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

    printf("---------------------------------------------------------\n");    
    printf("Select soundcard B\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

        result = FMOD_System_GetDriverInfo(systemB, 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);

    printf("\n");

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

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

    /*
        Load 1 sample into each soundcard.
    */
    result = FMOD_System_CreateSound(systemA, "../media/drumloop.wav", FMOD_HARDWARE, 0, &soundA);
    ERRCHECK(result);
    result = FMOD_Sound_SetMode(soundA, FMOD_LOOP_OFF);
    ERRCHECK(result);

    result = FMOD_System_CreateSound(systemB, "../media/jaguar.wav", FMOD_HARDWARE, 0, &soundB);
    ERRCHECK(result);

    printf("===========================================================================\n");
    printf("MultipleSoundCard Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("===========================================================================\n");
    printf("\n");
    printf("Press '1' to play a sound on soundcard A\n");
    printf("Press '2' to play a sound on soundcard B\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Main loop.
    */
    do
    {
        int  channelsplayingA = 0;
        int  channelsplayingB = 0;

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

            switch (key)
            {
                case '1' :
                {
                    result = FMOD_System_PlaySound(systemA, FMOD_CHANNEL_FREE, soundA, 0, &channelA);
                    ERRCHECK(result);
                    break;
                }
                case '2' :
                {
                    result = FMOD_System_PlaySound(systemB, FMOD_CHANNEL_FREE, soundB, 0, &channelB);
                    ERRCHECK(result);
                    break;
                }
            }
        }

        FMOD_System_Update(systemA);
        FMOD_System_Update(systemB);

        FMOD_System_GetChannelsPlaying(systemA, &channelsplayingA);
        FMOD_System_GetChannelsPlaying(systemB, &channelsplayingB);

        printf("Channels Playing on A %2d.   Channels Playing on B %2d.\r", channelsplayingA, channelsplayingB);

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = FMOD_Sound_Release(soundA);
    ERRCHECK(result);
    result = FMOD_System_Close(systemA);
    ERRCHECK(result);
    result = FMOD_System_Release(systemA);
    ERRCHECK(result);

    result = FMOD_Sound_Release(soundB);
    ERRCHECK(result);
    result = FMOD_System_Close(systemB);
    ERRCHECK(result);
    result = FMOD_System_Release(systemB);
    ERRCHECK(result);

    return 0;
}
Ejemplo n.º 28
0
int main(int argc, char *argv[])
{
    FMOD_SYSTEM      *system;
    FMOD_SOUND       *sound;
    FMOD_CHANNEL     *channel = 0;
    FMOD_RESULT       result;
    int               key;
    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, 1, FMOD_INIT_NORMAL, NULL);
    ERRCHECK(result);

    result = FMOD_System_SetFileSystem(system, myopen, myclose, myread, myseek, 0, 0, 2048);
    ERRCHECK(result);

    result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound);
    ERRCHECK(result);

    printf("====================================================================\n");
    printf("PlayStream Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("====================================================================\n");
    printf("\n");
    printf("Press space to pause, Esc to quit\n");
    printf("\n");

    /*
        Play the sound.
    */

    result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case ' ' :
                {
                    int paused;
                    FMOD_Channel_GetPaused(channel, &paused);
                    FMOD_Channel_SetPaused(channel, !paused);
                    break;
                }
            }
        }

        FMOD_System_Update(system);

        if (channel)
        {
            unsigned int ms;
            unsigned int lenms;
            int          playing;
            int          paused;

            FMOD_Channel_IsPlaying(channel, &playing);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Channel_GetPaused(channel, &paused);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            printf("\rTime %02d:%02d:%02d/%02d:%02d:%02d : %s", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
            fflush(stdout);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

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

    return 0;
}
Ejemplo n.º 29
0
SoundEngine::~SoundEngine()
{
    //libere fmod
    FMOD_System_Close(system);
	FMOD_System_Release(system);
}
Ejemplo n.º 30
0
float JiwokFMODWrapper::GetBPM(const char *filename)
{
 	FMOD_SYSTEM     *system;
	FMOD_SOUND      *sound;
	FMOD_RESULT       result;
	unsigned int      version;
	
	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, 1, FMOD_INIT_NORMAL, 0);
	
	ERRCHECK(result);
	
	result = FMOD_System_CreateStream(system,filename, FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
	// ERRCHECK(result);
	
	
	unsigned int  length = 0;
	int channels = 0, bits = 0;
	float frequency = 0;
	float volume = 0, pan = 0;
	int priority = 0;
	
	FMOD_SOUND_TYPE stype;
	FMOD_SOUND_FORMAT format;
	
	result = FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCMBYTES);
	ERRCHECK(result);
	
	result = FMOD_Sound_GetDefaults(sound, &frequency, &volume, &pan, &priority);
	ERRCHECK(result);
	
	result = FMOD_Sound_GetFormat(sound, &stype, &format, &channels, &bits);
	ERRCHECK(result);
	
	printf("result is %d",result);
	
	
	soundtouch::BPMDetect *bpm = new soundtouch::BPMDetect(channels,frequency);
	
	//void *data;
	//unsigned int read;
	unsigned int bytesread;
	
	#define CHUNKSIZE 32768 //4096
	
//	#define CHUNKSIZE 4096
	
	
	bytesread = 0;
	soundtouch::SAMPLETYPE* samples = new soundtouch::SAMPLETYPE[CHUNKSIZE];
	int sbytes = bits / 8;
	const unsigned int  NUMSAMPLES = CHUNKSIZE;
	unsigned int  bytes = NUMSAMPLES * sbytes;
	unsigned int  readbytes = 0;
	
	do
	{
		readbytes = 0;
		if(sbytes == 2) 
		{
			long int data[32768];
			result = FMOD_Sound_ReadData(sound, data, bytes, &readbytes );
			if(!result == FMOD_OK) break;
			for ( unsigned int  i = 0; i < readbytes/sbytes; ++i )
				samples[i] = (float) data[i] / 32768;
		} 
		else if(sbytes == 1) 
		{
			long int data[32768];
			result = FMOD_Sound_ReadData(sound, data, bytes, &readbytes );
			if(!result == FMOD_OK) break;
			for ( unsigned int  i = 0; i < (readbytes); ++i )
				samples[i] = (float) data[i] / 128;
		}
		
		bpm->inputSamples(samples, (readbytes /sbytes)/ channels );
		
		bytesread += readbytes;
	}
	while (result == FMOD_OK && readbytes == CHUNKSIZE*2);
	
	result = FMOD_Sound_Release(sound);
	ERRCHECK(result);
	result = FMOD_System_Close(system);
	ERRCHECK(result);
	result = FMOD_System_Release(system);
	ERRCHECK(result);
	
	float bpmg = bpm->getBpm();
	
	float bpm1 = bpmg;
	
	
	if ( bpmg < 1 ) return 0.;
	while ( bpmg > 190 ) bpmg /= 2.;
	while ( bpmg < 50 ) bpmg *= 2.;
	
	
	printf("bpmg bpmg is %f  bpm %f",bpmg,bpm1);

	
	return  bpmg;
}