Example #1
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 = system->getVersion(&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 = system->init(1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->setStreamBufferSize(32768, FMOD_TIMEUNIT_RAWBYTES);
    ERRCHECK(result);
    
    result = system->setFileSystem(myopen, myclose, myread, myseek, myasyncread, myasynccancel, 2048);
    ERRCHECK(result);

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

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

    result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
    ERRCHECK(result);

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

            sound->getOpenState(&openstate, 0, &starving, 0);
            
            if (starving)
            {
                printf("Starving\n");
                result = channel->setMute(true);
            }
            else
            {
                result = channel->setMute(false);
                ERRCHECK(result);
            }
        }

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

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

        system->update();
        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    if (sound)
    {
        result = sound->release();
        ERRCHECK(result);
    }
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    gThreadQuit = true;   

    return 0;
}
Example #2
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;

    memset(gCurrentTrackArtist, 0, 256);
    memset(gCurrentTrackTitle, 0, 256);
    strcpy(gOutputFileName, "output.mp3");   /* Start off like this then rename if a title tag comes along */

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

    if (argc < 2)
    {
        printf("Usage:   ripnetstream <url>\n");
        return -1;
    }

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

    result = system->getVersion(&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 = system->init(100, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->setStreamBufferSize(gFileBufferSize, FMOD_TIMEUNIT_RAWBYTES);
    ERRCHECK(result);

    result = system->attachFileSystem(myopen, myclose, myread, 0);
    ERRCHECK(result);

    printf("Buffering...\n\n");

    result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
    ERRCHECK(result);

    /*
        Main loop
    */
    do
    {
        static bool mute = false;

        if (sound && !channel)
        {
            result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
        }

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

            switch (key)
            {
                case ' ' :
                {
                    if (channel)
                    {
                        bool paused;
                        channel->getPaused(&paused);
                        channel->setPaused(!paused);
                    }
                    break;
                }
                case 'm' :
                case 'M' :
                {
                    if (channel)
                    {
                        channel->getMute(&mute);
                        channel->setMute(!mute);
                    }
                    break;
                }
            }
        }

        system->update();

        if (channel)
        {
            bool         playing = false;
            int          tagsupdated = 0;

            sound->getNumTags(0, &tagsupdated);

            if (tagsupdated)
            {
                printf("\n");
                printf("\n");
                for (;;)
                {
                    FMOD_TAG tag;

                    if (sound->getTag(0, -1, &tag) != FMOD_OK)
                    {
                        break;
                    }

                    if (tag.datatype == FMOD_TAGDATATYPE_STRING)
                    {
                        printf("[%-11s] %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
                        
                        sound->getFormat(&gSoundType, 0, 0, 0);
                    
                        if (!strcmp(tag.name, "ARTIST"))
                        {
                            if (strncmp(gCurrentTrackArtist, (const char *)tag.data, 256))
                            {
                                strncpy(gCurrentTrackArtist, (const char *)tag.data, 256);
                                gUpdateFileName = true;
                            }
                        }
                        if (!strcmp(tag.name, "TITLE"))
                        {
                            if (strncmp(gCurrentTrackTitle, (const char *)tag.data, 256))
                            {
                                strncpy(gCurrentTrackTitle, (const char *)tag.data, 256);
                                gUpdateFileName = true;
                            }
                        }
                    }
                }
                printf("\n");
            }

            result = channel->isPlaying(&playing);
            if (result != FMOD_OK || !playing)
            {
                sound->release();
                sound = 0;               
                channel = 0;
            }
            else
            {
                unsigned int    ms = 0, percent = 0;
                bool            paused = false;
                bool            starving = false;
                FMOD_OPENSTATE  openstate;

                result = sound->getOpenState(&openstate, &percent, &starving, 0);
                ERRCHECK(result);
        
                channel->setVolume(starving ? 0.0f : 1.0f);     /* Don't use mute because the user is setting that. */
                ERRCHECK(result);

                result = channel->getPaused(&paused);
                result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
                printf("Time %02d:%02d:%02d : (%3d%%%) %s SPACE = pause. 'm' = mute. ESC = quit.\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, percent, (openstate == FMOD_OPENSTATE_BUFFERING || starving) ? "Buffering..." : openstate == FMOD_OPENSTATE_CONNECTING ? "Connecting..." : paused ? "Paused       " : playing ? "Playing      " : "Stopped      ", percent, starving ? "STARVING" : "        ");

            }
        }

       
        if (sound)
        {
            FMOD_OPENSTATE openstate = FMOD_OPENSTATE_READY;

            sound->getOpenState(&openstate, 0, 0, 0);

            if (openstate == FMOD_OPENSTATE_ERROR)
            {
                sound->release();
                sound = 0;               
                channel = 0;
            }
        }

        if (!sound)
        {
            printf("\n");
            printf("Error occurred or stream ended.  Restarting stream..\n");
            result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
            ERRCHECK(result);
            Sleep(1000);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = sound->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}
Example #3
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;

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

    if (argc < 2)
    {
        printf("Usage:   netstream <url>\n");
        printf("Example: netstream http://www.fmod.org/stream.mp3\n\n");
        return -1;
    }

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

    result = system->getVersion(&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 = system->init(1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    /*
        Bump up the file buffer size a little bit for netstreams (to account for lag).
    */
    result = system->setStreamBufferSize(64*1024, FMOD_TIMEUNIT_RAWBYTES);
    ERRCHECK(result);

    result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING,  0, &sound);
    ERRCHECK(result);

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

    /*
        Main loop
    */
    do
    {
        unsigned int    ms = 0, percent = 0;
        bool            playing = false;
        bool            paused = false;
        bool            starving = false;
        FMOD_OPENSTATE  openstate;

        if (!channel)
        {
            result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
        }

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

            switch (key)
            {
                case ' ' :
                {
                    if (channel)
                    {
                        bool paused;
                        channel->getPaused(&paused);
                        channel->setPaused(!paused);
                    }
                    break;
                }
            }
        }

        system->update();

        for (;;)
        {
            FMOD_TAG tag;
            if (sound->getTag(0, -1, &tag) != FMOD_OK)
            {
                break;
            }
            if (tag.datatype == FMOD_TAGDATATYPE_STRING)
            {
                printf("%s = %s (%d bytes)       \n", tag.name, tag.data, tag.datalen);
            }
            else if (tag.type == FMOD_TAGTYPE_FMOD)
            {
                if (!strcmp(tag.name, "Sample Rate Change"))
                {
                    channel->setFrequency(*((float *)tag.data));
                }
            }
        }

        result = sound->getOpenState(&openstate, &percent, &starving, 0);
        ERRCHECK(result);
        
        if (channel)
        {
            result = channel->getPaused(&paused);
            ERRCHECK(result);
            result = channel->isPlaying(&playing);
            ERRCHECK(result);
            result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
            ERRCHECK(result);
            result = channel->setMute(starving);
            ERRCHECK(result);
        }
           
        printf("Time %02d:%02d:%02d : %s : (%3d%%%) %s     \r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, openstate == FMOD_OPENSTATE_BUFFERING ? "Buffering..." : openstate == FMOD_OPENSTATE_CONNECTING ? "Connecting..." : paused ? "Paused       " : playing ? "Playing      " : "Stopped      ", percent, starving ? "STARVING" : "        ");

        Sleep(10);

    } while (key != 27);

    printf("\n");

    printf("Shutting down.\n");
   
    if (channel)
    {
        result = channel->stop();
        ERRCHECK(result);
    }

    /*
        If we pressed escape before it is ready, wait for it to finish opening before we release it.
    */
    do
    {
        FMOD_OPENSTATE openstate;

        result = sound->getOpenState(&openstate, 0, 0, 0);
        ERRCHECK(result);

        if (openstate == FMOD_OPENSTATE_READY)
        {
            break;
        }

        printf("Waiting for sound to finish opening before trying to release it....\r");

        Sleep(10);
    } while (1);

    /*
        Shut down
    */
    result = sound->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}
Example #4
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 = system->getVersion(&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 = system->init(1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

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

    result = system->createStream(argv[1], FMOD_OPENONLY, 0, &cdsound);
    ERRCHECK(result);
    result = cdsound->getNumSubSounds(&numtracks);
    ERRCHECK(result);
    result = cdsound->getSubSound(currenttrack, &sound);
    ERRCHECK(result);

    for (;;)
    {
        FMOD_TAG tag;

        if (cdsound->getTag(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 = cdsound->getLength(&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 = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
    ERRCHECK(result);

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

            switch (key)
            {
                case ' ' :
                {
                    bool paused;
                    channel->getPaused(&paused);
                    channel->setPaused(!paused);
                    break;
                }

                case 'n' :
                {
                    currenttrack++;
                    if (currenttrack >= numtracks)
                    {
                        currenttrack = 0;
                    }
                    result = cdsound->getSubSound(currenttrack, &sound);
                    ERRCHECK(result);
                    result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
                    ERRCHECK(result);
                    break;
                }
            }
        }

        system->update();

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

            result = channel->getPaused(&paused);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }
            result = channel->isPlaying(&playing);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }
            result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }
            result = sound->getLength(&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 = sound->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}
Example #5
0
int main(int argc, char *argv[])
{
    FMOD::System    *system;
    FMOD::Sound     *cdsound;
    FMOD::Channel   *channel = 0;
    FMOD_RESULT      result;
    int              key;
    unsigned int     currenttrack = 0, numtracks;
    unsigned int     version;

    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 = system->getVersion(&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 = system->init(1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

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

    /*
        Try a few drive letters.
    */
    result = system->createStream("d:", FMOD_OPENONLY, 0, &cdsound);
    if (result != FMOD_OK)
    {
        result = system->createStream("e:", FMOD_OPENONLY, 0, &cdsound);
        if (result != FMOD_OK)
        {
            result = system->createStream("f:", FMOD_OPENONLY, 0, &cdsound);
            ERRCHECK(result);
        }
    }
    result = cdsound->getNumSubSounds((int *)&numtracks);
    ERRCHECK(result);

    for (;;)
    {
        FMOD_TAG tag;

        if (cdsound->getTag(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("      <     re-wind 10 seconds\n");
    printf("      >     fast-forward 10 seconds\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 = cdsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
        ERRCHECK(result);

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

    /*
        Play whole CD
    */
    result = system->playSound(FMOD_CHANNEL_FREE, cdsound, false, &channel);
    ERRCHECK(result);

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

            switch (key)
            {
                case ' ' :
                {
                    bool paused;
                    channel->getPaused(&paused);
                    channel->setPaused(!paused);
                    break;
                }

                case '<' :
                {
                    unsigned int ms;

                    channel->getPosition(&ms, FMOD_TIMEUNIT_SENTENCE_MS);

                    if (ms >= 10000)
                    {
                        ms -= 10000;
                    }
                    else
                    {
                        ms = 0;
                    }

                    channel->setPosition(ms, FMOD_TIMEUNIT_SENTENCE_MS);
                    break;
                }

                case '>' :
                {
                    unsigned int ms;

                    channel->getPosition(&ms, FMOD_TIMEUNIT_SENTENCE_MS);

                    ms += 10000;

                    channel->setPosition(ms, FMOD_TIMEUNIT_SENTENCE_MS);
                    break;
                }

                case 'n' :
                {
                    channel->getPosition(&currenttrack, FMOD_TIMEUNIT_SENTENCE_SUBSOUND);

                    currenttrack++;
                    if (currenttrack >= numtracks)
                    {
                        currenttrack = 0;
                    }

                    channel->setPosition(currenttrack, FMOD_TIMEUNIT_SENTENCE_SUBSOUND);
                    break;
                }
            }
        }

        system->update();

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

            result = channel->getPaused(&paused);
            ERRCHECK(result);
            result = channel->isPlaying(&playing);
            ERRCHECK(result);
            result = channel->getPosition(&ms, FMOD_TIMEUNIT_SENTENCE_MS);
            ERRCHECK(result);
            result = cdsound->getLength(&lenms, FMOD_TIMEUNIT_SENTENCE_MS);
            ERRCHECK(result);

            result = FMOD::File_GetDiskBusy(&busy);
            ERRCHECK(result);

            printf("Track %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s (%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", busy ? "*" : " ");
        }

        Sleep(50);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = cdsound->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}
int FMOD_Main()
{
    FMOD::System    *system = 0;
    FMOD::Sound     *sound = 0;
    FMOD::Channel   *channel = 0;
    FMOD_RESULT      result = FMOD_OK;
    FMOD_OPENSTATE   openstate = FMOD_OPENSTATE_READY;
    unsigned int     version = 0;
    void            *extradriverdata = 0;
    const int        tagcount = 4;
    int              tagindex = 0;
    char             tagstring[tagcount][128] = { 0 };
    
    Common_Init(&extradriverdata);
    
    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        Common_Fatal("FMOD lib version %08x doesn't match header version %08x", version, FMOD_VERSION);
    }

    result = system->init(1, FMOD_INIT_NORMAL, extradriverdata);
    ERRCHECK(result);

    /* Increase the file buffer size a little bit to account for Internet lag. */
    result = system->setStreamBufferSize(64*1024, FMOD_TIMEUNIT_RAWBYTES);
    ERRCHECK(result);

    result = system->createSound("http://shoutmedia.abc.net.au:10426", FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
    ERRCHECK(result);

    /*
        Main loop
    */
    do
    {
        unsigned int    pos = 0;
        unsigned int    percent = 0;
        bool            playing = false;
        bool            paused = false;
        bool            starving = false;
        const char     *state = "Stopped";
        
        Common_Update();

        if (Common_BtnPress(BTN_ACTION1))
        {
            if (channel)
            {
                bool paused = false;
                
                result = channel->getPaused(&paused);
                ERRCHECK(result);
                result = channel->setPaused(!paused);
                ERRCHECK(result);
            }
        }
        
        result = system->update();
        ERRCHECK(result);
        
        result = sound->getOpenState(&openstate, &percent, &starving, 0);
        ERRCHECK(result);
        
        if (channel)
        {
            FMOD_TAG tag;
        
            /*
                Read any tags that have arrived, this could happen if a radio station switches
                to a new song.
            */
            while (sound->getTag(0, -1, &tag) == FMOD_OK)
            {
                if (tag.datatype == FMOD_TAGDATATYPE_STRING)
                {
                    sprintf(tagstring[tagindex], "%s = '%s' (%d bytes)", tag.name, (char *)tag.data, tag.datalen);
                    tagindex = (tagindex + 1) % tagcount;
                }
                else if (tag.type == FMOD_TAGTYPE_FMOD)
                {
                    /* When a song changes, the sample rate may also change, so compensate here. */
                    if (!strcmp(tag.name, "Sample Rate Change"))
                    {
                        float frequency = *((float *)tag.data);
                        
                        result = channel->setFrequency(frequency);
                        ERRCHECK(result);
                    }
                }
            }
            
            result = channel->getPaused(&paused);
            ERRCHECK(result);
            
            result = channel->isPlaying(&playing);
            ERRCHECK(result);
            
            result = channel->getPosition(&pos, FMOD_TIMEUNIT_MS);
            ERRCHECK(result);
            
            /* Silence the stream until we have sufficient data for smooth playback. */
            result = channel->setMute(starving);
            ERRCHECK(result);
        }
        else
        {
             /* This may fail if the stream isn't ready yet, so don't check the error code. */
            system->playSound(sound, 0, false, &channel);
        }
        
        if (openstate == FMOD_OPENSTATE_BUFFERING)
        {
            state = "Buffering...";
        }
        else if (openstate == FMOD_OPENSTATE_CONNECTING)
        {
            state = "Connecting...";
        }
        else if (paused)
        {
            state = "Paused";
        }
        else if (playing)
        {
            state = "Playing";
        }

        Common_Draw("==================================================");
        Common_Draw("Net Stream Example.");
        Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
        Common_Draw("==================================================");
        Common_Draw("");
        Common_Draw("Press %s to toggle pause", Common_BtnStr(BTN_ACTION1));
        Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
        Common_Draw("");
        Common_Draw("Time = %02d:%02d:%02d", pos / 1000 / 60, pos / 1000 % 60, pos / 10 % 100);
        Common_Draw("State = %s %s", state, starving ? "(STARVING)" : "");
        Common_Draw("Buffer Percentage = %d", percent);
        Common_Draw("");
        Common_Draw("Tags:");
        for (int i = tagindex; i < (tagindex + tagcount); i++)
        {
            Common_Draw("%s", tagstring[i % tagcount]);
            Common_Draw("");
        }

        Common_Sleep(50);
    } while (!Common_BtnPress(BTN_QUIT));

    /*
        Stop the channel, then wait for it to finish opening before we release it.
    */    
    if (channel)
    {
        result = channel->stop();
        ERRCHECK(result);
    }

    do
    {
        Common_Update();
        Common_Draw("Waiting for sound to finish opening before trying to release it....", Common_BtnStr(BTN_ACTION1));
        Common_Sleep(50);
        
        result = system->update();
        ERRCHECK(result);

        result = sound->getOpenState(&openstate, 0, 0, 0);
        ERRCHECK(result);
    } while (openstate != FMOD_OPENSTATE_READY);

    /*
        Shut down
    */
    result = sound->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    Common_Close();
    
    return 0;
}