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_HARDWARE | FMOD_CREATESTREAM ; int key; int channels = 2; FMOD_CREATESOUNDEXINFO createsoundexinfo; unsigned int version; /* Initialisation du moteur audio */ 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); /* Choix de la question */ printf("Numéro de question (ou toute autre touche pour quitter) : \n"); key = getch(); if (key != '1' && key !='6') { return 0 ; } printf("%d\n",key-48) ; /* Création d'un buffer circulaire */ memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); createsoundexinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); createsoundexinfo.decodebuffersize = 3000; createsoundexinfo.length = 44100 * channels * sizeof(signed short) * 5; createsoundexinfo.numchannels = channels; createsoundexinfo.defaultfrequency = 44100; createsoundexinfo.format = FMOD_SOUND_FORMAT_PCM16; createsoundexinfo.pcmsetposcallback = pcmsetposcallback; if (key == '1') { mode |= FMOD_LOOP_NORMAL ; createsoundexinfo.pcmreadcallback = cb_question1; } else if (key == '6') { mode |= FMOD_LOOP_OFF ; createsoundexinfo.pcmreadcallback = cb_globale; } result = system->createSound(0, mode, &createsoundexinfo, &sound); ERRCHECK(result); /* Lecture du buffer */ printf("Espace = pause, Echap = quitter\n"); result = system->playSound(FMOD_CHANNEL_FREE, sound, 0, &channel); ERRCHECK(result); /* Boucle principale */ do { /* Lecture des commandes de l'utilisateur pendant la lecture et définition des changements à appliquer */ if (kbhit()) { key = getch(); switch (key) { case ' ' : { bool paused; channel->getPaused(&paused); channel->setPaused(!paused); break; } /* QUESTION 2 */ case '*' : { ampGauche /= 2.0f; ampDroite /= 2.0f; break; } case '/' : { ampGauche *= 2.0f; ampDroite *= 2.0f; break; } case '+' : { freq += 10.0f; break; } case '-' : { freq -= 10.0f; break; } case '>' : { ampGauche /= 2.0f; ampDroite *= 2.0f; break; } case '<' : { ampGauche *= 2.0f; ampDroite /= 2.0f; break; } case 'g' : { distorsion+=100; break; } case 'd' : { distorsion-=100; break; } } } /* Application des changements */ system->update(); /* Récupération et affichage de l'état de la lecture (en pause, arrêté, etc.) */ if (channel) { unsigned int ms; unsigned int lenms; bool playing; bool paused; 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); } result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } printf("Temps %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 ? "Pause " : playing ? "Lecture" : "Arret "); fflush(stdout); } Sleep(20); } while (key != 27); printf("\n"); /* Libération et fermeture du système audio */ result = sound->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 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 = 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/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound); ERRCHECK(result); printf("===============================================================================\n"); printf("Custom DSP example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("===============================================================================\n"); printf("Press 'f' to activate, deactivate user filter\n"); printf("Press 'Esc' to quit\n"); printf("\n"); result = system->playSound(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 = system->createDSP(&dspdesc, &mydsp); ERRCHECK(result); } /* Inactive by default. */ mydsp->setBypass(true); /* Main loop. */ result = system->addDSP(mydsp, 0); /* Main loop. */ do { if (_kbhit()) { key = _getch(); switch (key) { case 'f' : case 'F' : { static bool active = false; mydsp->setBypass(active); active = !active; break; } } } system->update(); Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = sound->release(); ERRCHECK(result); result = mydsp->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD::System *system = 0; FMOD::Sound *sound = 0; FMOD::Channel *channel = 0; FMOD_RESULT result; FMOD_CREATESOUNDEXINFO exinfo; int key, driver, recorddriver, numdrivers, count, outputfreq, bin; 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; } /* System initialization */ printf("---------------------------------------------------------\n"); printf("Select OUTPUT type\n"); printf("---------------------------------------------------------\n"); printf("1 : OSS - Open Sound System\n"); printf("2 : ALSA - Advanced Linux Sound Architecture\n"); printf("3 : ESD - Enlightenment Sound Daemon\n"); printf("4 : PULSEAUDIO - Pulse Audio Sound Server\n"); printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); } while (key != 27 && key < '1' && key > '5'); switch (key) { case '1' : result = system->setOutput(FMOD_OUTPUTTYPE_OSS); break; case '2' : result = system->setOutput(FMOD_OUTPUTTYPE_ALSA); break; case '3' : result = system->setOutput(FMOD_OUTPUTTYPE_ESD); break; case '4' : result = system->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO); break; default : return 1; } ERRCHECK(result); /* Enumerate playback devices */ result = system->getNumDrivers(&numdrivers); ERRCHECK(result); printf("---------------------------------------------------------\n"); printf("Choose a PLAYBACK driver\n"); printf("---------------------------------------------------------\n"); for (count=0; count < numdrivers; count++) { char name[256]; result = system->getDriverInfo(count, name, 256, 0); ERRCHECK(result); printf("%d : %s\n", count + 1, name); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); if (key == 27) { return 0; } driver = key - '1'; } while (driver < 0 || driver >= numdrivers); result = system->setDriver(driver); ERRCHECK(result); /* Enumerate record devices */ result = system->getRecordNumDrivers(&numdrivers); ERRCHECK(result); printf("---------------------------------------------------------\n"); printf("Choose a RECORD driver\n"); printf("---------------------------------------------------------\n"); for (count=0; count < numdrivers; count++) { char name[256]; result = system->getRecordDriverInfo(count, name, 256, 0); ERRCHECK(result); printf("%d : %s\n", count + 1, name); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); recorddriver = 0; do { key = getch(); if (key == 27) { return 0; } recorddriver = key - '1'; } while (recorddriver < 0 || recorddriver >= numdrivers); printf("\n"); result = system->setSoftwareFormat(OUTPUTRATE, FMOD_SOUND_FORMAT_PCM16, 1, 0, FMOD_DSP_RESAMPLER_LINEAR); ERRCHECK(result); result = system->init(32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); system->getSoftwareFormat(&outputfreq, 0, 0, 0, 0, 0); ERRCHECK(result); /* Create a sound to record to. */ memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.numchannels = 1; exinfo.format = FMOD_SOUND_FORMAT_PCM16; exinfo.defaultfrequency = OUTPUTRATE; exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5; result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound); ERRCHECK(result); /* Start the interface */ printf("=========================================================================\n"); printf("Pitch detection example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("=========================================================================\n"); printf("\n"); printf("Record something through the selected recording device and FMOD will\n"); printf("Determine the pitch. Sustain the tone for at least a second to get an\n"); printf("accurate reading.\n"); printf("Press 'Esc' to quit\n"); printf("\n"); result = system->recordStart(recorddriver, sound, true); ERRCHECK(result); Sleep(200); /* Give it some time to record something */ result = system->playSound(FMOD_CHANNEL_REUSE, sound, false, &channel); ERRCHECK(result); /* Dont hear what is being recorded otherwise it will feedback. Spectrum analysis is done before volume scaling in the DSP chain */ result = channel->setVolume(0); ERRCHECK(result); bin = 0; /* Main loop. */ do { static float spectrum[SPECTRUMSIZE]; float dominanthz = 0; float max; int dominantnote = 0; float binsize = BINSIZE; if (kbhit()) { key = getch(); } result = channel->getSpectrum(spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE); ERRCHECK(result); max = 0; for (count = 0; count < SPECTRUMSIZE; count++) { if (spectrum[count] > 0.01f && spectrum[count] > max) { max = spectrum[count]; bin = count; } } dominanthz = (float)bin * BINSIZE; /* dominant frequency min */ dominantnote = 0; for (count = 0; count < 120; count++) { if (dominanthz >= notefreq[count] && dominanthz < notefreq[count + 1]) { /* which is it closer to. This note or the next note */ if (fabs(dominanthz - notefreq[count]) < fabs(dominanthz - notefreq[count+1])) { dominantnote = count; } else { dominantnote = count + 1; } break; } } printf("Detected rate : %7.1f -> %7.1f hz. Detected musical note. %-3s (%7.1f hz)\r", dominanthz, ((float)bin + 0.99f) * BINSIZE, note[dominantnote], notefreq[dominantnote]); fflush(stdout); system->update(); Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = sound->release(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 0; }
/*============================================================================== Record example Copyright (c), Firelight Technologies Pty, Ltd 2004-2014. This example shows how to record continuously, and play back the same data as closely to the record cursor as possible without stuttering. ==============================================================================*/ #include "fmod.hpp" #include "common.h" #define LATENCY_MS (50) /* Some devices will require higher latency to avoid glitches */ int FMOD_Main() { FMOD::System *system = 0; FMOD::Sound *sound = 0; FMOD::Channel *channel = 0; FMOD_RESULT result = FMOD_OK; unsigned int version = 0; unsigned int soundlength = 0; bool dspenabled = false; void *extradriverdata = 0; unsigned int recordpos = 0; unsigned int recorddelta = 0; unsigned int minrecorddelta = (unsigned int)-1; unsigned int lastrecordpos = 0; unsigned int samplesrecorded = 0; unsigned int playpos = 0; float smootheddelta = 0; FMOD_CREATESOUNDEXINFO exinfo; 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(100, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); int recordrate; int recordchannels; result = system->getRecordDriverInfo(0, NULL, NULL, 0, 0, &recordrate, 0, &recordchannels); ERRCHECK(result); unsigned int adjustedlatency = (recordrate * LATENCY_MS) / 1000; unsigned int driftthreshold = adjustedlatency / 2; /* Create user sound to record into. */ memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.numchannels = recordchannels; exinfo.format = FMOD_SOUND_FORMAT_PCM16; exinfo.defaultfrequency = recordrate; exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5; /* 5 second buffer, doesnt really matter how big this is, but not too small of course. */ result = system->createSound(0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound); ERRCHECK(result); result = system->recordStart(0, sound, true); ERRCHECK(result); result = sound->getLength(&soundlength, FMOD_TIMEUNIT_PCM); ERRCHECK(result); /* Main loop */ do { Common_Update(); if (Common_BtnPress(BTN_ACTION1)) { FMOD_REVERB_PROPERTIES propon = FMOD_PRESET_CONCERTHALL; FMOD_REVERB_PROPERTIES propoff = FMOD_PRESET_OFF; dspenabled = !dspenabled; result = system->setReverbProperties(0, dspenabled ? &propon : &propoff); ERRCHECK(result); } result = system->update(); ERRCHECK(result); system->getRecordPosition(0, &recordpos); ERRCHECK(result); recorddelta = (recordpos >= lastrecordpos) ? (recordpos - lastrecordpos) : (recordpos + soundlength - lastrecordpos); lastrecordpos = recordpos; samplesrecorded += recorddelta; if (samplesrecorded >= adjustedlatency && !channel) { result = system->playSound(sound, 0, false, &channel); ERRCHECK(result); } if (channel && recorddelta) { /* If the record driver steps the position of the record cursor in larger increments than the user defined latency value, then we should increase our latency value to match. */ if (recorddelta < minrecorddelta) { minrecorddelta = recorddelta; if (adjustedlatency < recorddelta) { adjustedlatency = recorddelta; } } result = channel->getPosition(&playpos, FMOD_TIMEUNIT_PCM); ERRCHECK(result); /* Smooth total */ { const float dampratio = 0.97f; static float total = 0; total *= dampratio; total += (recordpos >= playpos) ? (recordpos - playpos) : (recordpos + soundlength - playpos); smootheddelta = total * (1.0f - dampratio); } if (smootheddelta < (adjustedlatency - driftthreshold) || smootheddelta > soundlength / 2) /* If play cursor is catching up to record (or passed it), slow playback down */ { channel->setFrequency(recordrate - (recordrate / 50)); /* Decrease speed by 2% */ } else if (smootheddelta > (adjustedlatency + driftthreshold)) /* If play cursor is falling too far behind record, speed playback up */ { channel->setFrequency(recordrate + (recordrate / 50)); /* Increase speed by 2% */ } else { channel->setFrequency(recordrate); /* Otherwise set to normal rate */ } } Common_Draw("=================================================="); Common_Draw("Record Example."); Common_Draw("Copyright (c) Firelight Technologies 2004-2014."); Common_Draw("=================================================="); Common_Draw(""); Common_Draw("Adjust LATENCY define to compensate for stuttering"); Common_Draw(""); Common_Draw("Press %s to %s DSP effect", Common_BtnStr(BTN_ACTION1), dspenabled ? "disable" : "enable"); Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT)); Common_Draw(""); Common_Draw("Default playback latency: %4d (%dms)", (recordrate * LATENCY_MS) / 1000, LATENCY_MS); Common_Draw("Current playback latency: %4d (%dms)", (int)smootheddelta, (int)smootheddelta * 1000 / recordrate); Common_Draw("Record position: %6d", recordpos); Common_Draw("Play Position: %6d", playpos); Common_Sleep(10); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = sound->release(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 0; }
int FMOD_Main() { FMOD::System *system = 0; FMOD::Sound *sound = 0; FMOD::Channel *channel = 0; FMOD::ChannelGroup *mastergroup = 0; FMOD::DSP *dsplowpass = 0; FMOD::DSP *dsphighpass = 0; FMOD::DSP *dspecho = 0; FMOD::DSP *dspflange = 0; FMOD_RESULT result; unsigned int version; void *extradriverdata = 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(32, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); result = system->getMasterChannelGroup(&mastergroup); ERRCHECK(result); result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_DEFAULT, 0, &sound); ERRCHECK(result); result = system->playSound(sound, 0, false, &channel); ERRCHECK(result); /* Create some effects to play with */ result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass); ERRCHECK(result); result = system->createDSPByType(FMOD_DSP_TYPE_HIGHPASS, &dsphighpass); ERRCHECK(result); result = system->createDSPByType(FMOD_DSP_TYPE_ECHO, &dspecho); ERRCHECK(result); result = system->createDSPByType(FMOD_DSP_TYPE_FLANGE, &dspflange); ERRCHECK(result); /* Add them to the master channel group. Each time an effect is added (to position 0) it pushes the others down the list. */ result = mastergroup->addDSP(0, dsplowpass); ERRCHECK(result); result = mastergroup->addDSP(0, dsphighpass); ERRCHECK(result); result = mastergroup->addDSP(0, dspecho); ERRCHECK(result); result = mastergroup->addDSP(0, dspflange); ERRCHECK(result); /* By default, bypass all effects. This means let the original signal go through without processing. It will sound 'dry' until effects are enabled by the user. */ result = dsplowpass->setBypass(true); ERRCHECK(result); result = dsphighpass->setBypass(true); ERRCHECK(result); result = dspecho->setBypass(true); ERRCHECK(result); result = dspflange->setBypass(true); ERRCHECK(result); /* Main loop */ do { Common_Update(); if (Common_BtnPress(BTN_MORE)) { bool paused; result = channel->getPaused(&paused); ERRCHECK(result); paused = !paused; result = channel->setPaused(paused); ERRCHECK(result); } if (Common_BtnPress(BTN_ACTION1)) { bool bypass; result = dsplowpass->getBypass(&bypass); ERRCHECK(result); bypass = !bypass; result = dsplowpass->setBypass(bypass); ERRCHECK(result); } if (Common_BtnPress(BTN_ACTION2)) { bool bypass; result = dsphighpass->getBypass(&bypass); ERRCHECK(result); bypass = !bypass; result = dsphighpass->setBypass(bypass); ERRCHECK(result); } if (Common_BtnPress(BTN_ACTION3)) { bool bypass; result = dspecho->getBypass(&bypass); ERRCHECK(result); bypass = !bypass; result = dspecho->setBypass(bypass); ERRCHECK(result); } if (Common_BtnPress(BTN_ACTION4)) { bool bypass; result = dspflange->getBypass(&bypass); ERRCHECK(result); bypass = !bypass; result = dspflange->setBypass(bypass); ERRCHECK(result); } result = system->update(); ERRCHECK(result); { bool paused = 0; bool dsplowpass_bypass; bool dsphighpass_bypass; bool dspecho_bypass; bool dspflange_bypass; dsplowpass ->getBypass(&dsplowpass_bypass); dsphighpass ->getBypass(&dsphighpass_bypass); dspecho ->getBypass(&dspecho_bypass); dspflange ->getBypass(&dspflange_bypass); if (channel) { result = channel->getPaused(&paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } } Common_Draw("=================================================="); Common_Draw("Effects Example."); Common_Draw("Copyright (c) Firelight Technologies 2004-2015."); Common_Draw("=================================================="); Common_Draw(""); Common_Draw("Press %s to pause/unpause sound", Common_BtnStr(BTN_MORE)); Common_Draw("Press %s to toggle dsplowpass effect", Common_BtnStr(BTN_ACTION1)); Common_Draw("Press %s to toggle dsphighpass effect", Common_BtnStr(BTN_ACTION2)); Common_Draw("Press %s to toggle dspecho effect", Common_BtnStr(BTN_ACTION3)); Common_Draw("Press %s to toggle dspflange effect", Common_BtnStr(BTN_ACTION4)); Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT)); Common_Draw(""); Common_Draw("%s : lowpass[%c] highpass[%c] echo[%c] flange[%c]", paused ? "Paused " : "Playing", dsplowpass_bypass ? ' ' : 'x', dsphighpass_bypass ? ' ' : 'x', dspecho_bypass ? ' ' : 'x', dspflange_bypass ? ' ' : 'x'); } Common_Sleep(50); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = mastergroup->removeDSP(dsplowpass); ERRCHECK(result); result = mastergroup->removeDSP(dsphighpass); ERRCHECK(result); result = mastergroup->removeDSP(dspecho); ERRCHECK(result); result = mastergroup->removeDSP(dspflange); ERRCHECK(result); result = dsplowpass->release(); ERRCHECK(result); result = dsphighpass->release(); ERRCHECK(result); result = dspecho->release(); ERRCHECK(result); result = dspflange->release(); ERRCHECK(result); result = sound->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 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; }
int main(int ac, const char **av) { // Create application window WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("Douceur"), NULL }; RegisterClassEx(&wc); HWND hwnd = CreateWindow(_T("Douceur"), _T("Douceur"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); // Initialize Direct3D if (CreateDeviceD3D(hwnd) < 0) { CleanupDeviceD3D(); UnregisterClass(_T("Douceur"), wc.hInstance); return 1; } // Show the window ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); // Setup ImGui binding ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext); // Load Fonts // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details) //ImGuiIO& io = ImGui::GetIO(); //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); bool show_test_window = true; ImVec4 clear_col = ImColor(114, 144, 154); // Main loop MSG msg; ZeroMemory(&msg, sizeof(msg)); std::string arduinoMsg; std::string arduinoDisplayMsg; bool messageEnded = true; FMOD::System *fmodSystem; FMOD::System_Create(&fmodSystem); FMOD::Sound *sound = 0; FMOD::Channel *channel = 0; FMOD::ChannelGroup *mastergroup = 0; fmodSystem->init(128, FMOD_INIT_NORMAL, 0); fmodSystem->getMasterChannelGroup(&mastergroup); fmodSystem->createSound("../DouceurExternal/audio-samples/Yamaha-1.wav", FMOD_LOOP_NORMAL, 0, &sound); unsigned int soundLength = 0; sound->getLength(&soundLength, FMOD_TIMEUNIT_MS); Serial arduino("COM6"); Board board(fmodSystem); while (msg.message != WM_QUIT) { fmodSystem->update(); if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); continue; } ImGui_ImplDX11_NewFrame(); static bool first = true; static int from = 0; static int to = 400; static float freq = 1.f; static float pan = 0.f; static float pitch = 0.f; if (!first) { fmodSystem->playSound(sound, mastergroup, false, &channel); first = true; to = soundLength; channel->getFrequency(&freq); channel->getPitch(&pitch); } { ImGui::SetNextWindowPos(ImVec2(10, 10)); ImGui::Begin("FPS", nullptr, ImVec2(0, 0), 0.3f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::End(); } if (false) { ImGui::Begin("SoloudTest"); bool changed = ImGui::SliderInt("from", (int*)&from, 0, soundLength - 1); changed |= ImGui::SliderInt("to", (int*)&to, 1, soundLength); changed |= ImGui::SliderFloat("freq", &freq, 0, 500000.f); changed |= ImGui::SliderFloat("pan", &pan, -1.f, 1.f); changed |= ImGui::SliderFloat("pitch", &pitch, 0.f, 10.f); if (changed) { if (from >= to) { from = to - 1; } channel->setLoopPoints(from, FMOD_TIMEUNIT_MS, to, FMOD_TIMEUNIT_MS); channel->setFrequency(freq); channel->setPan(pan); } ImGui::End(); } if (false) { ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! ImGui::ShowTestWindow(nullptr); } board.updateGui(); //Arduino test { if (arduino.IsConnected()) { if (ImGui::Begin("Arduino test")) { char buffer[2048]; if (messageEnded) { arduino.WriteData("A", 1); messageEnded = false; } while (!messageEnded) { int count = arduino.ReadData(buffer, 2047); if (count) { buffer[count] = '\0'; if (buffer[count - 1] == '@') { buffer[count - 1] = '\0'; messageEnded = true; } arduinoMsg += buffer; } else { break; } } if (messageEnded) { board.updatePadsVoltage(arduinoMsg); arduinoDisplayMsg = arduinoMsg; arduinoMsg.clear(); } ImGui::TextWrapped(arduinoDisplayMsg.c_str()); ImGui::Text("Message size : %i", arduinoDisplayMsg.size()); } ImGui::End(); board.displayPadsVoltage(); } } // Rendering g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col); ImGui::Render(); g_pSwapChain->Present(0, 0); } ImGui_ImplDX11_Shutdown(); CleanupDeviceD3D(); UnregisterClass(_T("Douceur"), wc.hInstance); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { FMOD::System *system; FMOD::Sound *sound1, *sound2, *sound3; FMOD::Channel *channel1 = 0, *channel2 = 0, *channel3 = 0; FMOD_RESULT result; int key, numdrivers; bool listenerflag = true; FMOD_VECTOR listenerpos = { 0.0f, 0.0f, -1.0f * DISTANCEFACTOR }; unsigned int version; FMOD_SPEAKERMODE speakermode; FMOD_CAPS caps; char name[256]; printf("===============================================================\n"); printf("3d Example. Copyright (c) Firelight Technologies 2004-2015.\n"); printf("===============================================================\n"); printf("This example plays 2 3D sounds in hardware. Optionally you can\n"); printf("play a 2D hardware sound as well.\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->getNumDrivers(&numdrivers); ERRCHECK(result); if (numdrivers == 0) { result = system->setOutput(FMOD_OUTPUTTYPE_NOSOUND); ERRCHECK(result); } else { result = system->getDriverCaps(0, &caps, 0, &speakermode); ERRCHECK(result); result = system->setSpeakerMode(speakermode); /* Set the user selected speaker mode. */ ERRCHECK(result); if (caps & FMOD_CAPS_HARDWARE_EMULATED) /* The user has the 'Acceleration' slider set to off! This is really bad for latency!. */ { /* You might want to warn the user about this. */ result = system->setDSPBufferSize(1024, 10); ERRCHECK(result); } result = system->getDriverInfo(0, name, 256, 0); ERRCHECK(result); if (strstr(name, "SigmaTel")) /* Sigmatel sound devices crackle for some reason if the format is PCM 16bit. PCM floating point output seems to solve it. */ { result = system->setSoftwareFormat(48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR); ERRCHECK(result); } } result = system->init(100, FMOD_INIT_NORMAL, 0); if (result == FMOD_ERR_OUTPUT_CREATEBUFFER) /* Ok, the speaker mode selected isn't supported by this soundcard. Switch it back to stereo... */ { result = system->setSpeakerMode(FMOD_SPEAKERMODE_STEREO); ERRCHECK(result); result = system->init(100, FMOD_INIT_NORMAL, 0);/* ... and re-init. */ ERRCHECK(result); } /* Set the distance units. (meters/feet etc). */ result = system->set3DSettings(1.0, DISTANCEFACTOR, 1.0f); ERRCHECK(result); /* Load some sounds */ result = system->createSound("../media/drumloop.wav", FMOD_3D, 0, &sound1); ERRCHECK(result); result = sound1->set3DMinMaxDistance(0.5f * DISTANCEFACTOR, 5000.0f * DISTANCEFACTOR); ERRCHECK(result); result = sound1->setMode(FMOD_LOOP_NORMAL); ERRCHECK(result); result = system->createSound("../media/jaguar.wav", FMOD_3D, 0, &sound2); ERRCHECK(result); result = sound2->set3DMinMaxDistance(0.5f * DISTANCEFACTOR, 5000.0f * DISTANCEFACTOR); ERRCHECK(result); result = sound2->setMode(FMOD_LOOP_NORMAL); ERRCHECK(result); result = system->createSound("../media/swish.wav", FMOD_SOFTWARE | FMOD_2D, 0, &sound3); ERRCHECK(result); /* Play sounds at certain positions */ { FMOD_VECTOR pos = { -10.0f * DISTANCEFACTOR, 0.0f, 0.0f }; FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f }; result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel1); ERRCHECK(result); result = channel1->set3DAttributes(&pos, &vel); ERRCHECK(result); result = channel1->setPaused(false); ERRCHECK(result); } { FMOD_VECTOR pos = { 15.0f * DISTANCEFACTOR, 0.0f, 0.0f }; FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f }; result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel2); ERRCHECK(result); result = channel2->set3DAttributes(&pos, &vel); ERRCHECK(result); result = channel2->setPaused(false); ERRCHECK(result); } /* Display help */ { int numchannels; result = system->getHardwareChannels(&numchannels); ERRCHECK(result); printf("Hardware channels : %d\n", numchannels); } printf("=========================================================================\n"); printf("Press 1 Pause/Unpause 16bit 3D sound at any time\n"); printf(" 2 Pause/Unpause 8bit 3D sound at any time\n"); printf(" 3 Play 16bit STEREO 2D sound at any time\n"); printf(" < Move listener left (in still mode)\n"); printf(" > Move listener right (in still mode)\n"); printf(" SPACE Stop/Start listener automatic movement\n"); printf(" ESC Quit\n"); printf("=========================================================================\n"); /* Main loop */ do { if (_kbhit()) { key = _getch(); if (key == '1') { bool paused; channel1->getPaused(&paused); channel1->setPaused(!paused); } if (key == '2') { bool paused; channel2->getPaused(&paused); channel2->setPaused(!paused); } if (key == '3') { result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel3); ERRCHECK(result); } if (key == ' ') { listenerflag = !listenerflag; } if (!listenerflag) { if (key == '<') { listenerpos.x -= 1.0f * DISTANCEFACTOR; if (listenerpos.x < -35 * DISTANCEFACTOR) { listenerpos.x = -35 * DISTANCEFACTOR; } } if (key == '>') { listenerpos.x += 1.0f * DISTANCEFACTOR; if (listenerpos.x > 36 * DISTANCEFACTOR) { listenerpos.x = 36 * DISTANCEFACTOR; } } } } // ========================================================================================== // UPDATE THE LISTENER // ========================================================================================== { static float t = 0; static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f }; FMOD_VECTOR forward = { 0.0f, 0.0f, 1.0f }; FMOD_VECTOR up = { 0.0f, 1.0f, 0.0f }; FMOD_VECTOR vel; if (listenerflag) { listenerpos.x = (float)sin(t * 0.05f) * 33.0f * DISTANCEFACTOR; // left right pingpong } // ********* NOTE ******* READ NEXT COMMENT!!!!! // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s). vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME); vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME); vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME); // store pos for next time lastpos = listenerpos; result = system->set3DListenerAttributes(0, &listenerpos, &vel, &forward, &up); ERRCHECK(result); t += (30 * (1.0f / (float)INTERFACE_UPDATETIME)); // t is just a time value .. it increments in 30m/s steps in this example // print out a small visual display { char s[80]; sprintf(s, "|.......................<1>......................<2>....................|"); s[(int)(listenerpos.x / DISTANCEFACTOR) + 35] = 'L'; printf("%s\r", s); } } system->update(); Sleep(INTERFACE_UPDATETIME - 1); } while (key != 27); printf("\n"); /* Shut down */ result = sound1->release(); ERRCHECK(result); result = sound2->release(); ERRCHECK(result); result = sound3->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 0; }
int FMOD_Main() { FMOD::System *system; FMOD::Sound *sound, *sound_to_play; FMOD::Channel *channel = 0; FMOD_RESULT result; unsigned int version; void *extradriverdata = 0; int numsubsounds; 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(32, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); /* This example uses an FSB file, which is a preferred pack format for fmod containing multiple sounds. This could just as easily be exchanged with a wav/mp3/ogg file for example, but in this case you wouldnt need to call getSubSound. Because getNumSubSounds is called here the example would work with both types of sound file (packed vs single). */ result = system->createSound(Common_MediaPath("wave_vorbis.fsb"), FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound); ERRCHECK(result); result = sound->getNumSubSounds(&numsubsounds); ERRCHECK(result); if (numsubsounds) { sound->getSubSound(0, &sound_to_play); ERRCHECK(result); } else { sound_to_play = sound; } /* Play the sound. */ result = system->playSound(sound_to_play, 0, false, &channel); ERRCHECK(result); /* Main loop. */ do { Common_Update(); if (Common_BtnPress(BTN_ACTION1)) { bool paused; result = channel->getPaused(&paused); ERRCHECK(result); result = channel->setPaused(!paused); ERRCHECK(result); } result = system->update(); ERRCHECK(result); { unsigned int ms = 0; unsigned int lenms = 0; bool playing = false; bool paused = false; if (channel) { result = channel->isPlaying(&playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = channel->getPaused(&paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = sound_to_play->getLength(&lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } } Common_Draw("=================================================="); Common_Draw("Play 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/%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"); } Common_Sleep(50); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = sound->release(); /* Release the parent, not the sound that was retrieved with getSubSound. */ ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 0; }
int main(int argc, char *argv[]) { FMOD::System *system = 0; FMOD::Sound *sound = 0; FMOD_RESULT result; FMOD_CREATESOUNDEXINFO exinfo; int key, recorddriver, numdrivers, count; unsigned int version; FILE *fp; unsigned int datalength = 0, soundlength; bool iscoreaudio = false; /* 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->setOutput(FMOD_OUTPUTTYPE_COREAUDIO); ERRCHECK(result); /* Enumerate record devices */ result = system->getRecordNumDrivers(&numdrivers); ERRCHECK(result); printf("---------------------------------------------------------\n"); printf("Choose a RECORD driver\n"); printf("---------------------------------------------------------\n"); for (count=0; count < numdrivers; count++) { char name[256]; result = system->getRecordDriverInfo(count, name, 256, 0); ERRCHECK(result); printf("%d : %s\n", count + 1, name); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); recorddriver = 0; do { key = getch(); if (key == 27) { return 0; } recorddriver = key - '1'; } while (recorddriver < 0 || recorddriver >= numdrivers); printf("\n"); result = system->init(32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.numchannels = 2; exinfo.defaultfrequency = 44100; if (iscoreaudio) { exinfo.format = FMOD_SOUND_FORMAT_PCMFLOAT; exinfo.length = exinfo.defaultfrequency * sizeof(float) * exinfo.numchannels * 2; } else { exinfo.format = FMOD_SOUND_FORMAT_PCM16; exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 2; } result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound); ERRCHECK(result); printf("========================================================================\n"); printf("Record to disk example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("========================================================================\n"); printf("\n"); printf("Press a key to start recording to record.wav\n"); printf("\n"); getch(); result = system->recordStart(recorddriver, sound, true); ERRCHECK(result); printf("Press 'Esc' to quit\n"); printf("\n"); fp = fopen("record.wav", "wb"); if (!fp) { printf("ERROR : could not open record.wav for writing.\n"); return 1; } /* Write out the wav header. As we don't know the length yet it will be 0. */ WriteWavHeader(fp, sound, datalength); result = sound->getLength(&soundlength, FMOD_TIMEUNIT_PCM); ERRCHECK(result); /* Main loop. */ do { static unsigned int lastrecordpos = 0; unsigned int recordpos = 0; if (kbhit()) { key = getch(); } system->getRecordPosition(recorddriver, &recordpos); ERRCHECK(result); if (recordpos != lastrecordpos) { void *ptr1, *ptr2; int blocklength; unsigned int len1, len2; blocklength = (int)recordpos - (int)lastrecordpos; if (blocklength < 0) { blocklength += soundlength; } /* Lock the sound to get access to the raw data. */ if(iscoreaudio) { sound->lock(lastrecordpos * 8, blocklength * 8, &ptr1, &ptr2, &len1, &len2); /* *8 = stereo 32bit. 1 sample = 8 bytes. */ } else { sound->lock(lastrecordpos * 4, blocklength * 4, &ptr1, &ptr2, &len1, &len2); /* *4 = stereo 16bit. 1 sample = 4 bytes. */ } /* Write it to disk. */ if (ptr1 && len1) { #ifdef __BIG_ENDIAN__ if (exinfo.format == FMOD_SOUND_FORMAT_PCM16) { signed short *wptr = (signed short *)ptr1; for (int count = 0; count < len1 >> 1; count++) { wptr[count] = SWAPENDIAN_WORD(wptr[count]); } } else if (exinfo.format == FMOD_SOUND_FORMAT_PCMFLOAT) { float *fptr = (float *)ptr1; for (int count = 0; count < len1 >> 2; count++) { SWAPENDIAN_FLOAT(fptr[count]); } } #endif datalength += fwrite(ptr1, 1, len1, fp); } if (ptr2 && len2) { #ifdef __BIG_ENDIAN__ if (exinfo.format == FMOD_SOUND_FORMAT_PCM16) { signed short *wptr = (signed short *)ptr2; for (int count = 0; count < len2 >> 1; count++) { wptr[count] = SWAPENDIAN_WORD(wptr[count]); } } else if (exinfo.format == FMOD_SOUND_FORMAT_PCMFLOAT) { float *fptr = (float *)ptr2; for (int count = 0; count < len2 >> 2; count++) { SWAPENDIAN_FLOAT(fptr[count]); } } #endif datalength += fwrite(ptr2, 1, len2, fp); } /* Unlock the sound to allow FMOD to use it again. */ sound->unlock(ptr1, ptr2, len1, len2); } lastrecordpos = recordpos; printf("\rRecord buffer pos = %6d : Record time = %02d:%02d", recordpos, datalength / exinfo.defaultfrequency / 4 / 60, (datalength / exinfo.defaultfrequency / 4) % 60); fflush(stdout); system->update(); Sleep(10); } while (key != 27); printf("\n"); /* Write back the wav header now that we know its length. */ WriteWavHeader(fp, sound, datalength); fclose(fp); /* Shut down */ result = sound->release(); 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; }
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-2015.\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; }
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 = 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; } /* Choose the speaker mode selected by the Windows control panel. */ result = system->getDriverCaps(0, 0, 0, &speakermode); ERRCHECK(result); result = system->setSpeakerMode(speakermode); ERRCHECK(result); result = system->init(32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE | FMOD_2D, 0, &sound1); ERRCHECK(result); result = sound1->setMode(FMOD_LOOP_OFF); ERRCHECK(result); result = system->createSound("../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 = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel); ERRCHECK(result); result = channel->setSpeakerMix(1.0f, 0, 0, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); break; } case '2' : { result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel); ERRCHECK(result); result = channel->setSpeakerMix(0, 1.0f, 0, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); break; } case '3' : { if (speakermode >= FMOD_SPEAKERMODE_SURROUND) /* All formats that have a center speaker. */ { result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel); ERRCHECK(result); result = channel->setSpeakerMix(0, 0, 1.0f, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } break; } case '4' : { if (speakermode >= FMOD_SPEAKERMODE_QUAD) { result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel); ERRCHECK(result); result = channel->setSpeakerMix(0, 0, 0, 0, 1.0f, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } break; } case '5' : { if (speakermode >= FMOD_SPEAKERMODE_QUAD) { result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel); ERRCHECK(result); result = channel->setSpeakerMix(0, 0, 0, 0, 0, 1.0f, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } break; } case '6' : { if (speakermode >= FMOD_SPEAKERMODE_7POINT1) { result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel); ERRCHECK(result); result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 1.0f, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } break; } case '7' : { if (speakermode >= FMOD_SPEAKERMODE_7POINT1) { result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel); ERRCHECK(result); result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 1.0f); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } break; } case '8' : { float levels[2] = { 0, 1.0f }; result = system->playSound(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 = channel->setSpeakerMix(1.0f, 1.0f, 0, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); break; } case '9' : { result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel); ERRCHECK(result); /* Clear out all speakers first. */ result = channel->setSpeakerMix(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 = channel->setSpeakerLevels(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 = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_RIGHT, levels, 2); ERRCHECK(result); } result = channel->setPaused(false); ERRCHECK(result); break; } case '0' : { if (speakermode >= FMOD_SPEAKERMODE_SURROUND) /* All formats that have a center speaker. */ { result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel); ERRCHECK(result); /* Clear out all speakers first. */ result = channel->setSpeakerMix(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 = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_CENTER, levels, 2); ERRCHECK(result); } result = channel->setPaused(false); ERRCHECK(result); } break; } } } system->update(); { unsigned int ms = 0; unsigned int lenms = 0; bool playing = false; bool paused = false; 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(¤tsound); 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 = sound1->release(); ERRCHECK(result); result = sound2->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 0; }
int FMOD_Main() { FMOD::System *system; FMOD::Sound *sound1, *sound2, *sound3; FMOD::Channel *channel = 0; FMOD_RESULT result; unsigned int version; void *extradriverdata = 0; void *buff = 0; int length = 0; FMOD_CREATESOUNDEXINFO exinfo; 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(32, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); Common_LoadFileMemory(Common_MediaPath("drumloop.wav"), &buff, &length); memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.length = length; result = system->createSound((const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY | FMOD_LOOP_OFF, &exinfo, &sound1); ERRCHECK(result); Common_UnloadFileMemory(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! Common_LoadFileMemory(Common_MediaPath("jaguar.wav"), &buff, &length); memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.length = length; result = system->createSound((const char *)buff, FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &sound2); ERRCHECK(result); Common_UnloadFileMemory(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! Common_LoadFileMemory(Common_MediaPath("swish.wav"), &buff, &length); memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.length = length; result = system->createSound((const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound3); ERRCHECK(result); Common_UnloadFileMemory(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! /* Main loop */ do { Common_Update(); if (Common_BtnPress(BTN_ACTION1)) { result = system->playSound(sound1, 0, false, &channel); ERRCHECK(result); } if (Common_BtnPress(BTN_ACTION2)) { result = system->playSound(sound2, 0, false, &channel); ERRCHECK(result); } if (Common_BtnPress(BTN_ACTION3)) { result = system->playSound(sound3, 0, false, &channel); ERRCHECK(result); } result = system->update(); ERRCHECK(result); { 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(¤tsound); 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); Common_Draw("=================================================="); Common_Draw("Load From Memory Example."); Common_Draw("Copyright (c) Firelight Technologies 2004-2014."); Common_Draw("=================================================="); Common_Draw(""); Common_Draw("Press %s to play a mono sound (drumloop)", Common_BtnStr(BTN_ACTION1)); Common_Draw("Press %s to play a mono sound (jaguar)", Common_BtnStr(BTN_ACTION2)); Common_Draw("Press %s to play a stereo sound (swish)", Common_BtnStr(BTN_ACTION3)); Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT)); Common_Draw(""); Common_Draw("Time %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"); Common_Draw("Channels Playing %2d", channelsplaying); } Common_Sleep(50); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = sound1->release(); ERRCHECK(result); result = sound2->release(); ERRCHECK(result); result = sound3->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 0; }
int FMOD_Main() { FMOD::Channel *channel = NULL; unsigned int samplesRecorded = 0; unsigned int samplesPlayed = 0; bool dspEnabled = false; void *extraDriverData = NULL; Common_Init(&extraDriverData); /* Create a System object and initialize. */ FMOD::System *system = NULL; FMOD_RESULT result = FMOD::System_Create(&system); ERRCHECK(result); unsigned int version = 0; 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(100, FMOD_INIT_NORMAL, extraDriverData); ERRCHECK(result); int numDrivers = 0; result = system->getRecordNumDrivers(NULL, &numDrivers); ERRCHECK(result); if (numDrivers == 0) { Common_Fatal("No recording devices found/plugged in! Aborting."); } /* Determine latency in samples. */ int nativeRate = 0; int nativeChannels = 0; result = system->getRecordDriverInfo(DEVICE_INDEX, NULL, 0, NULL, &nativeRate, NULL, &nativeChannels, NULL); ERRCHECK(result); unsigned int driftThreshold = (nativeRate * DRIFT_MS) / 1000; /* The point where we start compensating for drift */ unsigned int desiredLatency = (nativeRate * LATENCY_MS) / 1000; /* User specified latency */ unsigned int adjustedLatency = desiredLatency; /* User specified latency adjusted for driver update granularity */ int actualLatency = desiredLatency; /* Latency measured once playback begins (smoothened for jitter) */ /* Create user sound to record into, then start recording. */ FMOD_CREATESOUNDEXINFO exinfo = {0}; exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.numchannels = nativeChannels; exinfo.format = FMOD_SOUND_FORMAT_PCM16; exinfo.defaultfrequency = nativeRate; exinfo.length = nativeRate * sizeof(short) * nativeChannels; /* 1 second buffer, size here doesn't change latency */ FMOD::Sound *sound = NULL; result = system->createSound(0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound); ERRCHECK(result); result = system->recordStart(DEVICE_INDEX, sound, true); ERRCHECK(result); unsigned int soundLength = 0; result = sound->getLength(&soundLength, FMOD_TIMEUNIT_PCM); ERRCHECK(result); /* Main loop */ do { Common_Update(); /* Add a DSP effect -- just for fun */ if (Common_BtnPress(BTN_ACTION1)) { FMOD_REVERB_PROPERTIES propOn = FMOD_PRESET_CONCERTHALL; FMOD_REVERB_PROPERTIES propOff = FMOD_PRESET_OFF; dspEnabled = !dspEnabled; result = system->setReverbProperties(0, dspEnabled ? &propOn : &propOff); ERRCHECK(result); } result = system->update(); ERRCHECK(result); /* Determine how much has been recorded since we last checked */ unsigned int recordPos = 0; result = system->getRecordPosition(DEVICE_INDEX, &recordPos); if (result != FMOD_ERR_RECORD_DISCONNECTED) { ERRCHECK(result); } static unsigned int lastRecordPos = 0; unsigned int recordDelta = (recordPos >= lastRecordPos) ? (recordPos - lastRecordPos) : (recordPos + soundLength - lastRecordPos); lastRecordPos = recordPos; samplesRecorded += recordDelta; static unsigned int minRecordDelta = (unsigned int)-1; if (recordDelta && (recordDelta < minRecordDelta)) { minRecordDelta = recordDelta; /* Smallest driver granularity seen so far */ adjustedLatency = (recordDelta <= desiredLatency) ? desiredLatency : recordDelta; /* Adjust our latency if driver granularity is high */ } /* Delay playback until our desired latency is reached. */ if (!channel && samplesRecorded >= adjustedLatency) { result = system->playSound(sound, 0, false, &channel); ERRCHECK(result); } if (channel) { /* Stop playback if recording stops. */ bool isRecording = false; result = system->isRecording(DEVICE_INDEX, &isRecording); if (result != FMOD_ERR_RECORD_DISCONNECTED) { ERRCHECK(result); } if (!isRecording) { result = channel->setPaused(true); ERRCHECK(result); } /* Determine how much has been played since we last checked. */ unsigned int playPos = 0; result = channel->getPosition(&playPos, FMOD_TIMEUNIT_PCM); ERRCHECK(result); static unsigned int lastPlayPos = 0; unsigned int playDelta = (playPos >= lastPlayPos) ? (playPos - lastPlayPos) : (playPos + soundLength - lastPlayPos); lastPlayPos = playPos; samplesPlayed += playDelta; /* Compensate for any drift. */ int latency = samplesRecorded - samplesPlayed; actualLatency = (0.97f * actualLatency) + (0.03f * latency); int playbackRate = nativeRate; if (actualLatency < (adjustedLatency - driftThreshold)) { /* Play position is catching up to the record position, slow playback down by 2% */ playbackRate = nativeRate - (nativeRate / 50); } else if (actualLatency > (adjustedLatency + driftThreshold)) { /* Play position is falling behind the record position, speed playback up by 2% */ playbackRate = nativeRate + (nativeRate / 50); } channel->setFrequency((float)playbackRate); ERRCHECK(result); } Common_Draw("=================================================="); Common_Draw("Record Example."); Common_Draw("Copyright (c) Firelight Technologies 2004-2015."); Common_Draw("=================================================="); Common_Draw(""); Common_Draw("Adjust LATENCY define to compensate for stuttering"); Common_Draw("Current value is %dms", LATENCY_MS); Common_Draw(""); Common_Draw("Press %s to %s DSP effect", Common_BtnStr(BTN_ACTION1), dspEnabled ? "disable" : "enable"); Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT)); Common_Draw(""); Common_Draw("Adjusted latency: %4d (%dms)", adjustedLatency, adjustedLatency * 1000 / nativeRate); Common_Draw("Actual latency: %4d (%dms)", actualLatency, actualLatency * 1000 / nativeRate); Common_Draw(""); Common_Draw("Recorded: %5d (%ds)", samplesRecorded, samplesRecorded / nativeRate); Common_Draw("Played: %5d (%ds)", samplesPlayed, samplesPlayed / nativeRate); Common_Sleep(10); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = sound->release(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 0; }
int FMOD_Main() { FMOD::System *system; FMOD::Sound *sound; FMOD::Channel *channel = 0; FMOD_RESULT result; unsigned int version; void *extradriverdata = 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(32, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); result = system->createSound(Common_MediaPath("wave.mp3"), FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound); ERRCHECK(result); /* Play the sound. */ result = system->playSound(sound, 0, false, &channel); ERRCHECK(result); /* Main loop. */ do { Common_Update(); if (Common_BtnPress(BTN_ACTION1)) { bool paused; result = channel->getPaused(&paused); ERRCHECK(result); result = channel->setPaused(!paused); ERRCHECK(result); } result = system->update(); ERRCHECK(result); { unsigned int ms = 0; unsigned int lenms = 0; bool playing = false; bool paused = false; if (channel) { result = channel->isPlaying(&playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = channel->getPaused(&paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } } Common_Draw("=================================================="); Common_Draw("Play Stream Example."); Common_Draw("Copyright (c) Firelight Technologies 2004-2013."); 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/%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"); } Common_Sleep(50); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = sound->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 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 = 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); getch(); return 0; } result = system->init(1, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = system->createSound("../media/wave.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &sound); ERRCHECK(result); printf("====================================================================\n"); printf("PlayStream Example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("====================================================================\n"); printf("\n"); printf("Press space to pause, Esc to quit\n"); printf("\n"); /* Play the sound. */ 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; } } } system->update(); if (channel) { unsigned int ms; unsigned int lenms; bool playing; bool paused; channel->isPlaying(&playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = channel->getPaused(&paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { 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 = sound->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD::System *system; FMOD::Sound *sound1, *sound2, *sound3; FMOD::Channel *channel1 = 0, *channel2 = 0, *channel3 = 0; FMOD_RESULT result; int key; bool listenerflag = true; FMOD_VECTOR listenerpos = { 0.0f, 0.0f, -1.0f * DISTANCEFACTOR }; unsigned int version; printf("===============================================================\n"); printf("3d Example. Copyright (c) Firelight Technologies 2004-2005.\n"); printf("===============================================================\n"); printf("This example plays 2 3D sounds in hardware. Optionally you can\n"); printf("play a 2D hardware sound as well.\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(100, FMOD_INIT_NORMAL, 0); ERRCHECK(result); /* Set the distance units. (meters/feet etc). */ result = system->set3DSettings(1.0, DISTANCEFACTOR, 1.0f); ERRCHECK(result); /* Load some sounds */ result = system->createSound("../media/drumloop.wav", FMOD_HARDWARE | FMOD_3D, 0, &sound1); ERRCHECK(result); result = sound1->set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR); ERRCHECK(result); result = sound1->setMode(FMOD_LOOP_NORMAL); ERRCHECK(result); result = system->createSound("../media/jaguar.wav", FMOD_HARDWARE | FMOD_3D, 0, &sound2); ERRCHECK(result); result = sound2->set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR); ERRCHECK(result); result = sound2->setMode(FMOD_LOOP_NORMAL); ERRCHECK(result); result = system->createSound("../media/swish.wav", FMOD_HARDWARE | FMOD_2D, 0, &sound3); ERRCHECK(result); /* Play sounds at certain positions */ { FMOD_VECTOR pos = { -10.0f * DISTANCEFACTOR, 0.0f, 0.0f }; FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f }; result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel1); ERRCHECK(result); result = channel1->set3DAttributes(&pos, &vel); ERRCHECK(result); result = channel1->setPaused(false); ERRCHECK(result); } { FMOD_VECTOR pos = { 15.0f * DISTANCEFACTOR, 0.0f, 0.0f }; FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f }; result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel2); ERRCHECK(result); result = channel2->set3DAttributes(&pos, &vel); ERRCHECK(result); result = channel2->setPaused(false); ERRCHECK(result); } /* Display help */ { int num3d = 0, num2d = 0; result = system->getHardwareChannels(&num2d, &num3d, 0); ERRCHECK(result); printf("Hardware 2D channels : %d\n", num2d); printf("Hardware 3D channels : %d\n", num3d); } printf("=========================================================================\n"); printf("Press 1 Pause/Unpause 16bit 3D sound at any time\n"); printf(" 2 Pause/Unpause 8bit 3D sound at any time\n"); printf(" 3 Play 16bit STEREO 2D sound at any time\n"); printf(" < Move listener left (in still mode)\n"); printf(" > Move listener right (in still mode)\n"); printf(" SPACE Stop/Start listener automatic movement\n"); printf(" ESC Quit\n"); printf("=========================================================================\n"); /* Main loop */ do { if (kbhit()) { key = getch(); if (key == '1') { bool paused; channel1->getPaused(&paused); channel1->setPaused(!paused); } if (key == '2') { bool paused; channel2->getPaused(&paused); channel2->setPaused(!paused); } if (key == '3') { result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel3); ERRCHECK(result); } if (key == ' ') { listenerflag = !listenerflag; } if (!listenerflag) { if (key == '<') { listenerpos.x -= 1.0f * DISTANCEFACTOR; if (listenerpos.x < -35 * DISTANCEFACTOR) { listenerpos.x = -35 * DISTANCEFACTOR; } } if (key == '>') { listenerpos.x += 1.0f * DISTANCEFACTOR; if (listenerpos.x > 36 * DISTANCEFACTOR) { listenerpos.x = 36 * DISTANCEFACTOR; } } } } // ========================================================================================== // UPDATE THE LISTENER // ========================================================================================== { static float t = 0; static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f }; FMOD_VECTOR forward = { 0.0f, 0.0f, 1.0f }; FMOD_VECTOR up = { 0.0f, 1.0f, 0.0f }; FMOD_VECTOR vel; if (listenerflag) { listenerpos.x = (float)sin(t * 0.05f) * 33.0f * DISTANCEFACTOR; // left right pingpong } // ********* NOTE ******* READ NEXT COMMENT!!!!! // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s). vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME); vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME); vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME); // store pos for next time lastpos = listenerpos; result = system->set3DListenerAttributes(0, &listenerpos, &vel, &forward, &up); ERRCHECK(result); t += (30 * (1.0f / (float)INTERFACE_UPDATETIME)); // t is just a time value .. it increments in 30m/s steps in this example // print out a small visual display { char s[80]; sprintf(s, "|.......................<1>......................<2>....................|"); s[(int)(listenerpos.x / DISTANCEFACTOR) + 35] = 'L'; printf("%s\r", s); } } system->update(); Sleep(INTERFACE_UPDATETIME - 1); } while (key != 27); printf("\n"); /* Shut down */ result = sound1->release(); ERRCHECK(result); result = sound2->release(); ERRCHECK(result); result = sound3->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 0; }
int FMOD_Main() { FMOD::System *system = 0; FMOD_RESULT result; unsigned int version; void *extradriverdata = 0; unsigned int pluginhandle; InspectorState state = PLUGIN_SELECTOR; PluginSelectorState pluginselector = { 0 }; ParameterViewerState parameterviewer = { 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(32, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); result = system->getNumPlugins(FMOD_PLUGINTYPE_DSP, &pluginselector.numplugins); ERRCHECK(result); pluginselector.system = system; do { Common_Update(); if (state == PLUGIN_SELECTOR) { state = pluginSelectorDo(&pluginselector); if (state == PARAMETER_VIEWER) { result = pluginselector.system->getPluginHandle(FMOD_PLUGINTYPE_DSP, pluginselector.cursor, &pluginhandle); ERRCHECK(result); result = pluginselector.system->createDSPByPlugin(pluginhandle, ¶meterviewer.dsp); ERRCHECK(result); FMOD_RESULT result = parameterviewer.dsp->getNumParameters(¶meterviewer.numparams); ERRCHECK(result); parameterviewer.scroll = 0; } } else if (state == PARAMETER_VIEWER) { state = parameterViewerDo(¶meterviewer); if (state == PLUGIN_SELECTOR) { result = parameterviewer.dsp->release(); ERRCHECK(result); parameterviewer.dsp = 0; } } result = system->update(); ERRCHECK(result); Common_Sleep(INTERFACE_UPDATETIME - 1); } while (!Common_BtnPress(BTN_QUIT)); if (parameterviewer.dsp) { result = parameterviewer.dsp->release(); ERRCHECK(result); } result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 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(¤ttrack, 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; FMOD::Sound *sound; FMOD::Channel *channel; FMOD::DSP *mydsp; FMOD::ChannelGroup *mastergroup; FMOD_RESULT result; unsigned int version; void *extradriverdata = 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(32, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound); ERRCHECK(result); result = system->playSound(sound, 0, false, &channel); ERRCHECK(result); /* Create the DSP effect. */ { FMOD_DSP_DESCRIPTION dspdesc; memset(&dspdesc, 0, sizeof(dspdesc)); strncpy(dspdesc.name, "My first DSP unit", sizeof(dspdesc.name)); dspdesc.version = 0x00010000; dspdesc.numinputbuffers = 1; dspdesc.numoutputbuffers = 1; dspdesc.read = myDSPCallback; dspdesc.userdata = (void *)0x12345678; result = system->createDSP(&dspdesc, &mydsp); ERRCHECK(result); } /* Attach the DSP, inactive by default. */ result = mydsp->setBypass(true); ERRCHECK(result); result = system->getMasterChannelGroup(&mastergroup); ERRCHECK(result); result = mastergroup->addDSP(0, mydsp, 0); ERRCHECK(result); /* Main loop. */ do { bool bypass; Common_Update(); result = mydsp->getBypass(&bypass); ERRCHECK(result); if (Common_BtnPress(BTN_ACTION1)) { bypass = !bypass; result = mydsp->setBypass(bypass); ERRCHECK(result); } result = system->update(); ERRCHECK(result); Common_Draw("=================================================="); Common_Draw("Custom DSP Example."); Common_Draw("Copyright (c) Firelight Technologies 2004-2014."); Common_Draw("=================================================="); Common_Draw(""); Common_Draw("Press %s to toggle filter bypass", Common_BtnStr(BTN_ACTION1)); Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT)); Common_Draw(""); Common_Draw("Filter is %s", bypass ? "inactive" : "active"); Common_Sleep(50); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = sound->release(); ERRCHECK(result); result = mastergroup->removeDSP(mydsp); ERRCHECK(result); result = mydsp->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 0; }
bool DuckHuntMain::Init() { if (!D3DApp::Init()) return false; // Must init Effects first since InputLayouts depend on shader signatures. Effects::InitAll(md3dDevice); InputLayouts::InitAll(md3dDevice); RenderStates::InitAll(md3dDevice); mCrosshair = new Crosshair(md3dDevice); mTexMgr.Init(md3dDevice); DuckHuntMain::ShowCursors(false); mSky = new Sky(md3dDevice, L"Textures/desertcube1024.dds", 5000.0f); mSmap = new ShadowMap(md3dDevice, SMapSize, SMapSize); Terrain::InitInfo tii; tii.HeightMapFilename = L"Textures/myT5.raw"; tii.LayerMapFilename0 = L"Textures/grass.dds"; tii.LayerMapFilename1 = L"Textures/darkdirt.dds"; tii.LayerMapFilename2 = L"Textures/stone.dds"; tii.LayerMapFilename3 = L"Textures/lightdirt.dds"; tii.LayerMapFilename4 = L"Textures/snow.dds"; tii.BlendMapFilename = L"Textures/blend.dds"; tii.HeightScale = 50.0f; tii.HeightmapWidth = 2049; tii.HeightmapHeight = 2049; tii.CellSpacing = 0.5f; mTerrain.Init(md3dDevice, md3dImmediateContext, tii); //Sound result = FMOD::System_Create(&mSystem); result = mSystem->init(32, FMOD_INIT_NORMAL, 0); result = mSystem->createSound("Sounds/GunFire.wav", FMOD_DEFAULT, 0, &mGunFire); result = mGunFire->setMode(FMOD_LOOP_OFF); mCam.SetLens(0.25f*MathHelper::Pi, AspectRatio(), 1.0f, 1000.0f); mSsao = new Ssao(md3dDevice, md3dImmediateContext, mClientWidth, mClientHeight, mCam.GetFovY(), mCam.GetFarZ()); BuildScreenQuadGeometryBuffers(); testModelDuck = new BasicModel(md3dDevice, mTexMgr, "Models\\duck.obj", L"Textures\\DUCK.jpg"); BasicModelInstance testInstanceDuck; BasicModelInstance testInstanceDuck2; BasicModelInstance testInstanceDuck3; BasicModelInstance testInstanceDuck4; testInstanceDuck.Model = testModelDuck; testInstanceDuck2.Model = testModelDuck; testInstanceDuck3.Model = testModelDuck; testInstanceDuck4.Model = testModelDuck; //Duck 1 XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, -1.0f); XMMATRIX modelRot = XMMatrixRotationY(0.0f); XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f); //Duck 2 XMMATRIX modelScale2 = XMMatrixScaling(2.0f, 2.0f, -1.0f); XMMATRIX modelRot2 = XMMatrixRotationY(-1.0f); XMMATRIX modelOffset2 = XMMatrixTranslation(1.0f, 1.0f, -1.0f); //Duck3 XMMATRIX modelScale3 = XMMatrixScaling(1.5f, 1.5f, 1.5f); XMMATRIX modelRot3 = XMMatrixRotationY(0.5f); XMMATRIX modelOffset3 = XMMatrixTranslation(2.0f, 1.0f, -1.0f); //Duck4 XMMATRIX modelScale4 = XMMatrixScaling(0.5f, 0.5f, -1.0f); XMMATRIX modelRot4 = XMMatrixRotationY(1.0f); XMMATRIX modelOffset4 = XMMatrixTranslation(0.5f, 1.0f, -1.0f); //Duck 1 XMStoreFloat4x4(&testInstanceDuck.World, modelScale*modelRot*modelOffset); mModelInstances.push_back(testInstanceDuck); //Duck 2 XMStoreFloat4x4(&testInstanceDuck2.World, modelScale2*modelRot2*modelOffset2); mModelInstances.push_back(testInstanceDuck2); //Duck 3 XMStoreFloat4x4(&testInstanceDuck3.World, modelScale3*modelRot3*modelOffset3); mModelInstances.push_back(testInstanceDuck3); //Duck 4 XMStoreFloat4x4(&testInstanceDuck4.World, modelScale4*modelRot4*modelOffset4); mModelInstances.push_back(testInstanceDuck4); //create collision box for (unsigned i = 0; i < mModelInstances.size(); i++) { mModelInstances[i].Model->CreateCollisionBox(mModelInstances[i].Model->BasicVertices); } // // Compute scene bounding box. // XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity); XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity); for (UINT i = 0; i < mModelInstances.size(); ++i) { for (UINT j = 0; j < mModelInstances[i].Model->BasicVertices.size(); ++j) { XMFLOAT3 P = mModelInstances[i].Model->BasicVertices[j].Pos; minPt.x = MathHelper::Min(minPt.x, P.x); minPt.y = MathHelper::Min(minPt.x, P.x); minPt.z = MathHelper::Min(minPt.x, P.x); maxPt.x = MathHelper::Max(maxPt.x, P.x); maxPt.y = MathHelper::Max(maxPt.x, P.x); maxPt.z = MathHelper::Max(maxPt.x, P.x); } } // // Derive scene bounding sphere from bounding box. // mSceneBounds.Center = XMFLOAT3( 0.5f*(minPt.x + maxPt.x), 0.5f*(minPt.y + maxPt.y), 0.5f*(minPt.z + maxPt.z)); XMFLOAT3 extent( 0.5f*(maxPt.x - minPt.x), 0.5f*(maxPt.y - minPt.y), 0.5f*(maxPt.z - minPt.z)); mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z); return true; }
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 = 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); getch(); return 0; } result = system->init(100, FMOD_INIT_NORMAL, 0); ERRCHECK(result); /* Open the specified file. Use FMOD_CREATESTREAM and FMOD_OPENONLY so it opens quickly */ result = system->createSound("../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 (sound->getTag(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 = sound->getNumTags(&numtags, &numtagsupdated); ERRCHECK(result); for (count=0; count < numtags; count++) { result = sound->getTag(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 = sound->getTag("ARTIST", 0, &tag); ERRCHECK(result); printf("%s = %s (%d bytes)\n", tag.name, (char *)tag.data, tag.datalen); printf("\n"); /* Shut down */ result = sound->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 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; }
int FMOD_Main() { FMOD::System *system; FMOD::Sound *sound1, *sound2; FMOD::Channel *channel = 0; FMOD_RESULT result; unsigned int version; int selection = 0; void *extradriverdata = 0; FMOD_SPEAKERMODE speakermode = FMOD_SPEAKERMODE_STEREO; 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(32, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); result = system->getSoftwareFormat(0, &speakermode, 0); ERRCHECK(result); result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_2D | FMOD_LOOP_OFF, 0, &sound1); ERRCHECK(result); result = system->createSound(Common_MediaPath("stereo.ogg"), FMOD_2D | FMOD_LOOP_OFF, 0, &sound2); ERRCHECK(result); /* Main loop. */ do { Common_Update(); if (Common_BtnPress(BTN_UP) && (selection != 0)) { selection--; } if (Common_BtnPress(BTN_DOWN) && (selection != (SELECTION_COUNT - 1))) { selection++; } if (Common_BtnPress(BTN_ACTION1) && isSelectionAvailable(speakermode, selection)) { if (selection == 0) /* Mono front left */ { result = system->playSound(sound1, 0, true, &channel); ERRCHECK(result); result = channel->setMixLevelsOutput(1.0f, 0, 0, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } else if (selection == 1) /* Mono front right */ { result = system->playSound(sound1, 0, true, &channel); ERRCHECK(result); result = channel->setMixLevelsOutput(0, 1.0f, 0, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } else if (selection == 2) /* Mono center */ { result = system->playSound(sound1, 0, true, &channel); ERRCHECK(result); result = channel->setMixLevelsOutput(0, 0, 1.0f, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } else if (selection == 3) /* Mono surround left */ { result = system->playSound(sound1, 0, true, &channel); ERRCHECK(result); result = channel->setMixLevelsOutput(0, 0, 0, 0, 1.0f, 0, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } else if (selection == 4) /* Mono surround right */ { result = system->playSound(sound1, 0, true, &channel); ERRCHECK(result); result = channel->setMixLevelsOutput(0, 0, 0, 0, 0, 1.0f, 0, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } else if (selection == 5) /* Mono rear left */ { result = system->playSound(sound1, 0, true, &channel); ERRCHECK(result); result = channel->setMixLevelsOutput(0, 0, 0, 0, 0, 0, 1.0f, 0); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } else if (selection == 6) /* Mono rear right */ { result = system->playSound(sound1, 0, true, &channel); ERRCHECK(result); result = channel->setMixLevelsOutput(0, 0, 0, 0, 0, 0, 0, 1.0f); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } else if (selection == 7) /* Stereo front */ { result = system->playSound(sound2, 0, false, &channel); ERRCHECK(result); } else if (selection == 8) /* Stereo front channel swapped */ { float matrix[] = { 0.0f, 1.0f, 1.0f, 0.0f }; result = system->playSound(sound2, 0, true, &channel); ERRCHECK(result); result = channel->setMixMatrix(matrix, 2, 2); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } else if (selection == 9) /* Stereo (right only) center */ { float matrix[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; result = system->playSound(sound2, 0, true, &channel); ERRCHECK(result); result = channel->setMixMatrix(matrix, 3, 2); ERRCHECK(result); result = channel->setPaused(false); ERRCHECK(result); } } result = system->update(); ERRCHECK(result); { unsigned int ms = 0; unsigned int lenms = 0; bool playing = false; bool paused = false; 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(¤tsound); 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); } } } result = system->getChannelsPlaying(&channelsplaying); ERRCHECK(result); Common_Draw("=================================================="); Common_Draw("Multiple Speaker Example."); Common_Draw("Copyright (c) Firelight Technologies 2004-2015."); Common_Draw("=================================================="); Common_Draw(""); Common_Draw("Speaker mode is set to %s%s", SPEAKERMODE_STRING[speakermode], speakermode < FMOD_SPEAKERMODE_7POINT1 ? " causing some speaker options to be unavailable" : ""); Common_Draw(""); Common_Draw("Press %s or %s to select mode", Common_BtnStr(BTN_UP), Common_BtnStr(BTN_DOWN)); Common_Draw("Press %s to play the sound", Common_BtnStr(BTN_ACTION1)); for (int i = 0; i < SELECTION_COUNT; i++) { bool disabled = !isSelectionAvailable(speakermode, i); Common_Draw("[%c] %s%s", (selection == i) ? (disabled ? '-' : 'X') : ' ', disabled ? "[N/A] " : "", SELECTION_STRING[i]); } Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT)); Common_Draw(""); Common_Draw("Time %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"); Common_Draw("Channels playing: %d", channelsplaying); } Common_Sleep(50); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = sound1->release(); ERRCHECK(result); result = sound2->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 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 = 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); 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 = system->createStream("../media/wave.mp3", FMOD_OPENONLY | FMOD_LOOP_NORMAL | FMOD_LOWMEM | FMOD_CREATESTREAM, 0, &decodesound); ERRCHECK(result); result = decodesound->getLength(&decodesound_lengthbytes, FMOD_TIMEUNIT_PCMBYTES); ERRCHECK(result); result = decodesound->getFormat(0, 0, &decodesound_channels, 0); ERRCHECK(result); result = decodesound->getDefaults(&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 = system->createStream(0, FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL, &createsoundexinfo, &sound); ERRCHECK(result); printf("============================================================================\n"); printf("Manual Decode example. Copyright (c) Firelight Technologies 2004-2014.\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 = system->playSound(FMOD_CHANNEL_FREE, sound, 0, &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 position; channel->getPosition(&position, FMOD_TIMEUNIT_MS); if (position >= 1000) { position -= 1000; } channel->setPosition(position, FMOD_TIMEUNIT_MS); break; } case '>' : { unsigned int position; channel->getPosition(&position, FMOD_TIMEUNIT_MS); position += 1000; channel->setPosition(position, FMOD_TIMEUNIT_MS); break; } } } system->update(); if (channel) { unsigned int ms; unsigned int lenms; bool playing; bool paused; 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); } result = sound->getLength(&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 = decodesound->release(); ERRCHECK(result); decodesound = 0; /* This will make the read callback fail from now on. */ } LeaveCriticalSection(&decodecrit); /* Shut down */ result = sound->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); DeleteCriticalSection(&decodecrit); return 0; }
int FMOD_Main() { FMOD::System *system; FMOD::Sound *sound[3]; FMOD::Channel *channel = 0; FMOD::ChannelGroup *channelgroup = 0; FMOD_RESULT result; unsigned int version, dsp_block_len, count; int outputrate = 0; void *extradriverdata = 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(100, FMOD_INIT_NORMAL, extradriverdata); ERRCHECK(result); /* Get information needed later for scheduling. The mixer block size, and the output rate of the mixer. */ result = system->getDSPBufferSize(&dsp_block_len, 0); ERRCHECK(result); result = system->getSoftwareFormat(&outputrate, 0, 0); ERRCHECK(result); /* Load 3 sounds - these are just sine wave tones at different frequencies. C, D and E on the musical scale. */ result = system->createSound(Common_MediaPath("c.ogg"), FMOD_DEFAULT, 0, &sound[NOTE_C]); ERRCHECK(result); result = system->createSound(Common_MediaPath("d.ogg"), FMOD_DEFAULT, 0, &sound[NOTE_D]); ERRCHECK(result); result = system->createSound(Common_MediaPath("e.ogg"), FMOD_DEFAULT, 0, &sound[NOTE_E]); ERRCHECK(result); /* Create a channelgroup that the channels will play on. We can use this channelgroup as our clock reference. It also means we can pause and pitch bend the channelgroup, without affecting the offsets of the delays, because the channelgroup clock which the channels feed off, will be pausing and speeding up/slowing down and still keeping the children in sync. */ result = system->createChannelGroup("Parent", &channelgroup); ERRCHECK(result); unsigned int numsounds = sizeof(note) / sizeof(note[0]); /* Play all the sounds at once! Space them apart with set delay though so that they sound like they play in order. */ for (count = 0; count < numsounds; count++) { static unsigned long long clock_start = 0; unsigned int slen; FMOD::Sound *s = sound[note[count]]; /* Pick a note from our tune. */ result = system->playSound(s, channelgroup, true, &channel); /* Play the sound on the channelgroup we want to use as the parent clock reference (for setDelay further down) */ ERRCHECK(result); if (!clock_start) { result = channel->getDSPClock(0, &clock_start); ERRCHECK(result); clock_start += (dsp_block_len * 2); /* Start the sound into the future, by 2 mixer blocks worth. */ /* Should be enough to avoid the mixer catching up and hitting the clock value before we've finished setting up everything. */ /* Alternatively the channelgroup we're basing the clock on could be paused to stop it ticking. */ } else { float freq; result = s->getLength(&slen, FMOD_TIMEUNIT_PCM); /* Get the length of the sound in samples. */ ERRCHECK(result); result = s->getDefaults(&freq, 0); /* Get the default frequency that the sound was recorded at. */ ERRCHECK(result); slen = (unsigned int)((float)slen / freq * outputrate); /* Convert the length of the sound to 'output samples' for the output timeline. */ clock_start += slen; /* Place the sound clock start time to this value after the last one. */ } result = channel->setDelay(clock_start, 0, false); /* Schedule the channel to start in the future at the newly calculated channelgroup clock value. */ ERRCHECK(result); result = channel->setPaused(false); /* Unpause the sound. Note that you won't hear the sounds, they are scheduled into the future. */ ERRCHECK(result); } /* Main loop. */ do { Common_Update(); if (Common_BtnPress(BTN_ACTION1)) /* Pausing the channelgroup as the clock parent, will pause any scheduled sounds from continuing */ { /* If you paused the channel, this would not stop the clock it is delayed against from ticking, */ bool paused; /* and you'd have to recalculate the delay for the channel into the future again before it was unpaused. */ result = channelgroup->getPaused(&paused); ERRCHECK(result); result = channelgroup->setPaused(!paused); ERRCHECK(result); } if (Common_BtnPress(BTN_ACTION2)) { for (count = 0; count < 50; count++) { float pitch; result = channelgroup->getPitch(&pitch); ERRCHECK(result); pitch += 0.01f; result = channelgroup->setPitch(pitch); ERRCHECK(result); result = system->update(); ERRCHECK(result); Common_Sleep(10); } } if (Common_BtnPress(BTN_ACTION3)) { for (count = 0; count < 50; count++) { float pitch; result = channelgroup->getPitch(&pitch); ERRCHECK(result); if (pitch > 0.1f) { pitch -= 0.01f; } result = channelgroup->setPitch(pitch); ERRCHECK(result); result = system->update(); ERRCHECK(result); Common_Sleep(10); } } result = system->update(); ERRCHECK(result); /* Print some information */ { bool playing = false; bool paused = false; int chansplaying; if (channelgroup) { result = channelgroup->isPlaying(&playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } result = channelgroup->getPaused(&paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)) { ERRCHECK(result); } } result = system->getChannelsPlaying(&chansplaying); ERRCHECK(result); Common_Draw("=================================================="); Common_Draw("Gapless Playback 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 increase pitch", Common_BtnStr(BTN_ACTION2)); Common_Draw("Press %s to decrease pitch", Common_BtnStr(BTN_ACTION3)); Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT)); Common_Draw(""); Common_Draw("Channels Playing %d : %s", chansplaying, paused ? "Paused " : playing ? "Playing" : "Stopped"); } Common_Sleep(50); } while (!Common_BtnPress(BTN_QUIT)); /* Shut down */ result = sound[NOTE_C]->release(); ERRCHECK(result); result = sound[NOTE_D]->release(); ERRCHECK(result); result = sound[NOTE_E]->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); Common_Close(); return 0; }
int main(int argc, char *argv[]) { FMOD::System *system = 0; FMOD::Sound *sound = 0; FMOD_RESULT result; FMOD_CREATESOUNDEXINFO exinfo; int key, recorddriver, numdrivers, count; unsigned int version; FILE *fp; unsigned int datalength = 0, soundlength; /* Create a System object and initialize. */ result = FMOD::System_Create(&system); ERRCHECK(result); result = 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 initialization */ printf("---------------------------------------------------------\n"); printf("Select OUTPUT type\n"); printf("---------------------------------------------------------\n"); printf("1 : DirectSound\n"); printf("2 : Windows Multimedia WaveOut\n"); printf("3 : ASIO\n"); printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = _getch(); } while (key != 27 && key < '1' && key > '5'); switch (key) { case '1' : result = system->setOutput(FMOD_OUTPUTTYPE_DSOUND); break; case '2' : result = system->setOutput(FMOD_OUTPUTTYPE_WINMM); break; case '3' : result = system->setOutput(FMOD_OUTPUTTYPE_ASIO); break; default : return 1; } ERRCHECK(result); /* Enumerate record devices */ result = system->getRecordNumDrivers(&numdrivers); ERRCHECK(result); printf("---------------------------------------------------------\n"); printf("Choose a RECORD driver\n"); printf("---------------------------------------------------------\n"); for (count=0; count < numdrivers; count++) { char name[256]; result = system->getRecordDriverInfo(count, name, 256, 0); ERRCHECK(result); printf("%d : %s\n", count + 1, name); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); recorddriver = 0; do { key = _getch(); if (key == 27) { return 0; } recorddriver = key - '1'; } while (recorddriver < 0 || recorddriver >= numdrivers); printf("\n"); result = system->init(32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.numchannels = 1; exinfo.format = FMOD_SOUND_FORMAT_PCM16; exinfo.defaultfrequency = 44100; exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 2; result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound); ERRCHECK(result); printf("========================================================================\n"); printf("Record to disk example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("========================================================================\n"); printf("\n"); printf("Press a key to start recording to record.wav\n"); printf("\n"); _getch(); result = system->recordStart(recorddriver, sound, true); ERRCHECK(result); printf("Press 'Esc' to quit\n"); printf("\n"); fp = fopen("record.wav", "wb"); if (!fp) { printf("ERROR : could not open record.wav for writing.\n"); return 1; } /* Write out the wav header. As we don't know the length yet it will be 0. */ WriteWavHeader(fp, sound, datalength); result = sound->getLength(&soundlength, FMOD_TIMEUNIT_PCM); ERRCHECK(result); /* Main loop. */ do { static unsigned int lastrecordpos = 0; unsigned int recordpos = 0; if (_kbhit()) { key = _getch(); } system->getRecordPosition(recorddriver, &recordpos); ERRCHECK(result); if (recordpos != lastrecordpos) { void *ptr1, *ptr2; int blocklength; unsigned int len1, len2; blocklength = (int)recordpos - (int)lastrecordpos; if (blocklength < 0) { blocklength += soundlength; } /* Lock the sound to get access to the raw data. */ sound->lock(lastrecordpos * exinfo.numchannels * 2, blocklength * exinfo.numchannels * 2, &ptr1, &ptr2, &len1, &len2); /* * exinfo.numchannels * 2 = stereo 16bit. 1 sample = 4 bytes. */ /* Write it to disk. */ if (ptr1 && len1) { datalength += fwrite(ptr1, 1, len1, fp); } if (ptr2 && len2) { datalength += fwrite(ptr2, 1, len2, fp); } /* Unlock the sound to allow FMOD to use it again. */ sound->unlock(ptr1, ptr2, len1, len2); } lastrecordpos = recordpos; printf("%-23s. Record buffer pos = %6d : Record time = %02d:%02d\r", (timeGetTime() / 500) & 1 ? "Recording to record.wav" : "", recordpos, datalength / exinfo.defaultfrequency / exinfo.numchannels / 2 / 60, (datalength / exinfo.defaultfrequency / exinfo.numchannels / 2) % 60); system->update(); Sleep(10); } while (key != 27); printf("\n"); /* Write back the wav header now that we know its length. */ WriteWavHeader(fp, sound, datalength); fclose(fp); /* Shut down */ result = sound->release(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 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; /* 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); getch(); return 0; } result = system->setOutput(FMOD_OUTPUTTYPE_ALSA); ERRCHECK(result); result = system->init(32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound1); ERRCHECK(result); result = sound1->setMode(FMOD_LOOP_OFF); ERRCHECK(result); result = system->createSound("../media/jaguar.wav", FMOD_SOFTWARE, 0, &sound2); ERRCHECK(result); result = system->createSound("../media/swish.wav", FMOD_SOFTWARE, 0, &sound3); ERRCHECK(result); printf("===================================================================\n"); printf("PlaySound Example. Copyright (c) Firelight Technologies 2004-2014.\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 = system->playSound(FMOD_CHANNEL_FREE, sound1, 0, &channel); ERRCHECK(result); break; } case '2' : { result = system->playSound(FMOD_CHANNEL_FREE, sound2, 0, &channel); ERRCHECK(result); break; } case '3' : { result = system->playSound(FMOD_CHANNEL_FREE, sound3, 0, &channel); ERRCHECK(result); break; } } } 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(¤tsound); 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); fflush(stdout); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = sound1->release(); ERRCHECK(result); result = sound2->release(); ERRCHECK(result); result = sound3->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 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 = 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->createStream("../media/wave.mp3", FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound); ERRCHECK(result); printf("===============================================================================\n"); printf("Offline Decoding Example. Copyright (c) Firelight Technologies 2004-2015.\n"); printf("===============================================================================\n"); printf("\n"); printf("This program will open wave.mp3 and decode it into wave.raw using the\n"); printf("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 = sound->getLength(&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 = sound->readData((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 = sound->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 0; }