UINT64 InformacionArchivoEx::_ObtenerTiempoCancionCDAudio(const TCHAR *Path, FMOD::System *InstanciaFMOD) {
	char Letra[3]; 
	Letra[0] = static_cast<char>(Path[0]);
	Letra[1] = ':';
	Letra[2] = '\0';
	UINT Milisegundos = 0;
	FMOD::Sound	 *Stream = NULL;
	FMOD::Sound	 *PistaCD = NULL;
	FMOD_RESULT Error = InstanciaFMOD->createStream(Letra, FMOD_OPENONLY, 0, &Stream);
	if (Stream != NULL) {
		Stream->getSubSound(InfoPath.Pista - 1, &PistaCD); // no s'identifica la pista en els cds d'audio posible error en funcio Info
		if (PistaCD != NULL) {
			PistaCD->getLength(&Milisegundos, FMOD_TIMEUNIT_MS);
			PistaCD->release();
			Stream->release();
		}
	}
	return Milisegundos;
}
Exemplo n.º 2
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_HARDWARE | FMOD_CREATESTREAM;
    unsigned int version;

    if (argc != 3) {
        std::cout << "unpacker.exe fsbPath outdirPath" << std::endl;
        return 1;
    }

    auto fsbPath = std::string(argv[1]);
    auto outPath = std::string(argv[2]);

    //fsbPath = "LoL_SFX_ziggs.fsb";
    //fsbPath = "LoL_SFX_karma_base.fsb";
    //fsbPath = "LoL_SFX_fiddlesticks.fsb";


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

    //system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER);
    result = system->init(1, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    auto codecHandle = registerLeagueCodec(system, 50);

    int numsubsounds;
    FMOD::Sound *subSound = nullptr;
    char name[256];
    int soundNum = 0;

    try {
        result = system->createSound(fsbPath.c_str(), mode, nullptr, &sound);
        ERRCHECK(result);

        result = sound->getNumSubSounds(&numsubsounds);
        ERRCHECK(result);
        soundNum = 0;


        sound->getSubSound(0, &subSound);
        subSound->getName(name, 256);
        subSound->release();

        makePath(outPath.c_str());
        sound->release();
        system->close();
        system->release();

        std::set<std::string> writtenFiles;

        FMOD::Channel* channel;
        bool playing;
        for (int sndIdx = 0; sndIdx < numsubsounds; sndIdx++) {
            ERRCHECK(FMOD::System_Create(&system));
            ERRCHECK(system->getVersion(&version));
            system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER_NRT);
            auto outFilePath = outPath + "\\" + std::string(name) + ".wav";
            if (writtenFiles.find(outFilePath) != writtenFiles.end()) {
                int cnt = 1;
                char arr[80];
                do {
                    _itoa_s(cnt, arr, 10);
                    outFilePath = outPath + "\\" + std::string(name) + "_" + std::string(arr) + ".wav";
                    cnt++;
                } while (writtenFiles.find(outFilePath) != writtenFiles.end());
            }
            writtenFiles.insert(outFilePath);
            ERRCHECK(system->init(1, FMOD_INIT_STREAM_FROM_UPDATE, (void*)outFilePath.c_str()));
            auto codecHandle = registerLeagueCodec(system, 50);
            system->createSound(fsbPath.c_str(), mode, nullptr, &sound);
            sound->getSubSound(sndIdx, &subSound);
            system->playSound(FMOD_CHANNEL_FREE, subSound, false, &channel);
            do {
                
                system->update();
                channel->isPlaying(&playing);
            } while (playing);
            subSound->release();


            if (sndIdx < numsubsounds - 1) {
                sound->getSubSound(sndIdx+1, &subSound);
                subSound->getName(name, 256);
                subSound->release();
                outFilePath = outPath + "\\" + std::string(name) + ".wav";
            }
            sound->release();
            system->close();
            system->release();
        }
    }
    catch (const std::runtime_error& error) {
        std::cout << "Exception caught:" << std::endl;
        std::cout << "   " << error.what() << std::endl;
    }

    return 0;
}
Exemplo n.º 3
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;
}
Exemplo 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 = 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(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->createSound("../media/example.fsb", FMOD_DEFAULT, 0, &fsb);
    ERRCHECK(result);

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

    result = fsb->getNumSubSounds(&numsubsounds);
    ERRCHECK(result);

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

        result = fsb->getSubSound(count, &subsound);
        ERRCHECK(result);

        result = subsound->getName(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';

                fsb->getSubSound(index, &subsound);
               
                result = system->playSound(FMOD_CHANNEL_FREE, subsound, false, &channel);
                ERRCHECK(result);
            }
        }

        system->update();

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

            if (channel)
            {
                FMOD::Sound *currentsound = 0;

                result = channel->isPlaying(&playing);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = channel->getPaused(&paused);
                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);
                }
               
                channel->getCurrentSound(&currentsound);
                if (currentsound)
                {
                    result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }
            }

            system->getChannelsPlaying(&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 = fsb->release();
    ERRCHECK(result);
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}