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, numdrivers, count, outputfreq, bin; unsigned int version; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } /* System initialization */ printf("---------------------------------------------------------\n"); printf("Select OUTPUT type\n"); printf("---------------------------------------------------------\n"); printf("1 : DirectSound\n"); printf("2 : Windows Multimedia WaveOut\n"); printf("3 : ASIO\n"); printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); } while (key != 27 && key < '1' && key > '5'); switch (key) { case '1' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_DSOUND); break; case '2' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_WINMM); break; case '3' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ASIO); break; default : return 1; } ERRCHECK(result); /* Enumerate playback devices */ result = FMOD_System_GetNumDrivers(system, &numdrivers); ERRCHECK(result); printf("---------------------------------------------------------\n"); printf("Choose a PLAYBACK driver\n"); printf("---------------------------------------------------------\n"); for (count=0; count < numdrivers; count++) { char name[256]; result = FMOD_System_GetDriverName(system, count, name, 256); ERRCHECK(result); printf("%d : %s\n", count + 1, name); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); if (key == 27) { return 0; } driver = key - '1'; } while (driver < 0 || driver >= numdrivers); result = FMOD_System_SetDriver(system, driver); ERRCHECK(result); /* Enumerate record devices */ result = FMOD_System_GetRecordNumDrivers(system, &numdrivers); ERRCHECK(result); printf("---------------------------------------------------------\n"); printf("Choose a RECORD driver\n"); printf("---------------------------------------------------------\n"); for (count=0; count < numdrivers; count++) { char name[256]; result = FMOD_System_GetRecordDriverName(system, count, name, 256); ERRCHECK(result); printf("%d : %s\n", count + 1, name); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); if (key == 27) { return 0; } driver = key - '1'; } while (driver < 0 || driver >= numdrivers); printf("\n"); result = FMOD_System_SetRecordDriver(system, driver); ERRCHECK(result); result = FMOD_System_SetSoftwareFormat(system, OUTPUTRATE, FMOD_SOUND_FORMAT_PCM16, 1, 0); ERRCHECK(result); result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); FMOD_System_GetSoftwareFormat(system, &outputfreq, 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 = FMOD_System_CreateSound(system, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound); ERRCHECK(result); /* Start the interface */ printf("=========================================================================\n"); printf("Pitch detection example. Copyright (c) Firelight Technologies 2004-2005.\n"); printf("=========================================================================\n"); printf("\n"); printf("Record something through the selected recording device and FMOD will\n"); printf("Determine the pitch. Sustain the tone for at least a second to get an\n"); printf("accurate reading.\n"); printf("Press 'Esc' to quit\n"); printf("\n"); result = FMOD_System_RecordStart(system, sound, TRUE); ERRCHECK(result); Sleep(200); /* Give it some time to record something */ result = FMOD_System_PlaySound(system, FMOD_CHANNEL_REUSE, sound, FALSE, &channel); ERRCHECK(result); /* Dont hear what is being recorded otherwise it will feedback. Spectrum analysis is done before volume scaling in the DSP chain */ result = FMOD_Channel_SetVolume(channel, 0); ERRCHECK(result); bin = 0; /* Main loop. */ do { static float spectrum[SPECTRUMSIZE]; float dominanthz = 0; float max; int dominantnote = 0; float binsize = BINSIZE; if (kbhit()) { key = getch(); } result = FMOD_Channel_GetSpectrum(channel, spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE); ERRCHECK(result); max = 0; for (count = 0; count < SPECTRUMSIZE; count++) { if (spectrum[count] > 0.01f && spectrum[count] > max) { max = spectrum[count]; bin = count; } } dominanthz = (float)bin * BINSIZE; /* dominant frequency min */ dominantnote = 0; for (count = 0; count < 120; count++) { if (dominanthz >= notefreq[count] && dominanthz < notefreq[count + 1]) { /* which is it closer to. This note or the next note */ if (fabs(dominanthz - notefreq[count]) < fabs(dominanthz - notefreq[count+1])) { dominantnote = count; } else { dominantnote = count + 1; } break; } } printf("Detected rate : %7.1f -> %7.1f hz. Detected musical note. %-3s (%7.1f hz)\r", dominanthz, ((float)bin + 0.99f) * BINSIZE, note[dominantnote], notefreq[dominantnote]); FMOD_System_Update(system); Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_CHANNEL *channel = 0; FMOD_RESULT result; int key; unsigned int version; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); result = FMOD_System_SetFileSystem(system, myopen, myclose, myread, myseek, 0, 0, 2048); ERRCHECK(result); result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound); ERRCHECK(result); printf("====================================================================\n"); printf("PlayStream Example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("====================================================================\n"); printf("\n"); printf("Press space to pause, Esc to quit\n"); printf("\n"); /* Play the sound. */ result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel); ERRCHECK(result); /* Main loop. */ do { if (_kbhit()) { key = _getch(); switch (key) { case ' ' : { int paused; FMOD_Channel_GetPaused(channel, &paused); FMOD_Channel_SetPaused(channel, !paused); break; } } } FMOD_System_Update(system); if (channel) { unsigned int ms; unsigned int lenms; int playing; int paused; FMOD_Channel_IsPlaying(channel, &playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPaused(channel, &paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } printf("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(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_CHANNEL *channel = 0; FMOD_RESULT result; FMOD_MODE mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_HARDWARE; int key; int channels = 2; FMOD_CREATESOUNDEXINFO createsoundexinfo; unsigned int version; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); printf("============================================================================\n"); printf("User Created Sound Example. Copyright (c) Firelight Technologies 2004-2015.\n"); printf("============================================================================\n"); printf("Sound played here is generated in realtime. It will either play as a stream\n"); printf("which means it is continually filled as it is playing, or it will play as a \n"); printf("static sample, which means it is filled once as the sound is created, then \n"); printf("when played it will just play that short loop of data. \n"); printf("============================================================================\n"); printf("\n"); do { printf("Press 1 to play as a runtime decoded stream. (will carry on infinitely)\n"); printf("Press 2 to play as a static in memory sample. (loops a short block of data)\n"); printf("Press Esc to quit.\n\n"); key = _getch(); } while (key != 27 && key != '1' && key != '2'); if (key == 27) { return 0; } else if (key == '1') { mode |= FMOD_CREATESTREAM; } memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); createsoundexinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); /* required. */ createsoundexinfo.decodebuffersize = 44100; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */ createsoundexinfo.length = 44100 * channels * sizeof(signed short) * 5; /* Length of PCM data in bytes of whole song (for Sound::getLength) */ createsoundexinfo.numchannels = channels; /* Number of channels in the sound. */ createsoundexinfo.defaultfrequency = 44100; /* Default playback rate of sound. */ createsoundexinfo.format = FMOD_SOUND_FORMAT_PCM16; /* Data format of sound. */ createsoundexinfo.pcmreadcallback = pcmreadcallback; /* User callback for reading. */ createsoundexinfo.pcmsetposcallback = pcmsetposcallback; /* User callback for seeking. */ result = FMOD_System_CreateSound(system, 0, mode, &createsoundexinfo, &sound); ERRCHECK(result); printf("Press space to pause, Esc to quit\n"); printf("\n"); /* Play the sound. */ result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel); ERRCHECK(result); /* Main loop. */ do { if (_kbhit()) { key = _getch(); switch (key) { case ' ' : { int paused; FMOD_Channel_GetPaused(channel, &paused); FMOD_Channel_SetPaused(channel, !paused); break; } } } FMOD_System_Update(system); if (channel) { unsigned int ms; unsigned int lenms; int playing; int paused; FMOD_Channel_IsPlaying(channel, &playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPaused(channel, &paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped"); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
int menuPrincipal(int* contreordinateur, int* niveauordinateur, int* plateau) { /* ecran de jeu */ Image* screen; /* images du menu */ Image *menu, *imageContreJoueur, *imageContreOrdi, *imageSelection, *imageBoutonJouer, *imageBoutonJouerSurvol, *imageBoutonPlus, *imageBoutonMoins, *imageOuvrir, *imageOuvrirSurvol; Image *imagePlateau[4], *imagePlateauSelectionne; /* images animees */ Image *imageAnimeeRubis, *imageAnimeePerle; /* positions des images */ Rectangle positionPlateau[4]; Rectangle positionMenu, positionContreJoueur, positionContreOrdi, positionBoutonJouer, positionNiveau, positionTexteNiveau, positionBoutonPlus, positionBoutonMoins, positionOuvrir; Image *chiffres[10], *texte_niveau; int ich; Rectangle positionRubis, positionPerle, vecteurPerle, vecteurRubis; /* evenements */ Evenements event; /* variables pour contenir les coordonnées de la souris */ int sourisx; int sourisy; int retour; /* pour savoir si une partie est enregistrée */ int partieEnregistree; FILE* fichier; /* boucle principale du programme */ int done; #if SONS==1 FMOD_SYSTEM *system; FMOD_SOUND *hello; FMOD_SOUND *menuMus; hello = 0; menuMus = 0; FMOD_System_Create(&system); FMOD_System_Init(system, 2, FMOD_INIT_NORMAL, NULL); FMOD_System_CreateSound(system, SON_HELLO, FMOD_CREATESAMPLE, 0, &hello); afficheVerifChargementSon(hello); FMOD_System_CreateSound(system, SON_MENU, FMOD_LOOP_NORMAL, 0, &menuMus); afficheVerifChargementSon(menuMus); if(hello!=0) FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, hello, 0, NULL); if(menuMus!=0) FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, menuMus, 0, NULL); #endif retour = 1; /* par défaut on accède au jeu après le menu */ done = 0; /* sortie de boucle */ partieEnregistree = 0; /* par défaut : aucune partie */ fichier = 0; fichier = fopen(CONFIGSAUVE,"r"); if(fichier!=0) { fclose(fichier); fichier = 0; fichier = fopen(PLATEAUSAUVE,"r"); if(fichier!=0) { partieEnregistree = 1; fclose(fichier); fichier = 0; } } /* plateau 0 correspond à la partie enregistrée mais n'est pas séléctionnable comme plateau */ if(*plateau==0) *plateau = 1; /* INITIALISATIONS POUR L'AFFICHAGE */ /* on charge l'écran d'affichage */ screen = afficheSetEcran(); if (!screen) { printf("[!] Erreur de définition de l'écran video.\n"); afficheErreur(); return 1; } /* on initialise l'affichage video */ if ( afficheInit() < 0 ) { printf("[!] Erreur d'initialisation de l'affichage.\n"); afficheErreur(); return 1; } /* être sûr que l'écran soit fermé à la fin */ atexit(afficheQuit); afficheSetTitre("Hexxagon : Menu du jeu","Hexxagon"); /* MENU PRINCIPAL */ menu = afficheChargeImage(MENU); afficheVerifChargement(menu); positionMenu.x = 0; positionMenu.y = 0; imageContreJoueur = afficheChargeImage(VSJOUEUR); afficheVerifChargement(imageContreJoueur); positionContreJoueur.x = 100; positionContreJoueur.y = screen->h - 120; positionContreJoueur.h = imageContreJoueur->h; positionContreJoueur.w = imageContreJoueur->w; imageContreOrdi = afficheChargeImage(VSORDI); afficheVerifChargement(imageContreOrdi); positionContreOrdi.x = 300; positionContreOrdi.y = screen->h - 120; positionContreOrdi.h = imageContreOrdi->h; positionContreOrdi.w = imageContreOrdi->w; imagePlateau[0] = afficheChargeImage(PLATEAU1_MENU); afficheVerifChargement(imagePlateau[0]); positionPlateau[0].x = 650; positionPlateau[0].y = 20; positionPlateau[0].h = imagePlateau[0]->h; positionPlateau[0].w = imagePlateau[0]->w; imagePlateau[1] = afficheChargeImage(PLATEAU2_MENU); afficheVerifChargement(imagePlateau[1]); positionPlateau[1].x = 800; positionPlateau[1].y = 180; positionPlateau[1].h = imagePlateau[1]->h; positionPlateau[1].w = imagePlateau[1]->w; imagePlateau[2] = afficheChargeImage(PLATEAU3_MENU); afficheVerifChargement(imagePlateau[2]); positionPlateau[2].x = 680; positionPlateau[2].y = 330; positionPlateau[2].h = imagePlateau[2]->h; positionPlateau[2].w = imagePlateau[2]->w; imagePlateau[3] = afficheChargeImage(PLATEAU4_MENU); afficheVerifChargement(imagePlateau[3]); positionPlateau[3].x = 800; positionPlateau[3].y = 480; positionPlateau[3].h = imagePlateau[3]->h; positionPlateau[3].w = imagePlateau[3]->w; /* pions qui se déplacent sur l'écran */ imageAnimeePerle = afficheChargeImage(PION_JOUEUR_2); afficheVerifChargement(imageAnimeePerle); imageAnimeeRubis = afficheChargeImage(PION_JOUEUR_1); afficheVerifChargement(imageAnimeeRubis); positionPerle.x = 5; positionPerle.y = 5; positionRubis.x = 600; positionRubis.y = 400; vecteurPerle.x = 5; vecteurPerle.y = 5; vecteurRubis.x = -5; vecteurRubis.y = 5; if(partieEnregistree) /* on ne charge que si une partie est enregistrée */ { imageOuvrir = IMG_Load(OUVRIR); afficheVerifChargement(imageOuvrir); imageOuvrirSurvol = IMG_Load(OUVRIRSURVOL); afficheVerifChargement(imageOuvrirSurvol); positionOuvrir.x = screen->w - imageOuvrir->w - 10; positionOuvrir.y = screen->h - imageOuvrir->h - 10; positionOuvrir.w = imageOuvrir->w; positionOuvrir.h = imageOuvrir->h; } imagePlateauSelectionne = afficheChargeImage(PLATEAU_SELECTIONNE_MENU); afficheVerifChargement(imagePlateau[0]); imageSelection = afficheChargeImage(SELECTIONMODE); afficheVerifChargement(imageSelection); imageBoutonJouer = afficheChargeImage(BOUTONJOUER); afficheVerifChargement(imageBoutonJouer); imageBoutonJouerSurvol = afficheChargeImage(BOUTONJOUERSURVOL); afficheVerifChargement(imageBoutonJouerSurvol); positionBoutonJouer.x = 600; positionBoutonJouer.y = screen->h - 120; positionBoutonJouer.h = imageBoutonJouer->h; positionBoutonJouer.w = imageBoutonJouer->w; chiffres[0] = afficheChargeImage(CHIFFRE0); afficheVerifChargement(chiffres[0]); chiffres[1] = afficheChargeImage(CHIFFRE1); afficheVerifChargement(chiffres[1]); chiffres[2] = afficheChargeImage(CHIFFRE2); afficheVerifChargement(chiffres[2]); chiffres[3] = afficheChargeImage(CHIFFRE3); afficheVerifChargement(chiffres[3]); chiffres[4] = afficheChargeImage(CHIFFRE4); afficheVerifChargement(chiffres[4]); chiffres[5] = afficheChargeImage(CHIFFRE5); afficheVerifChargement(chiffres[5]); chiffres[6] = afficheChargeImage(CHIFFRE6); afficheVerifChargement(chiffres[6]); chiffres[7] = afficheChargeImage(CHIFFRE7); afficheVerifChargement(chiffres[7]); chiffres[8] = afficheChargeImage(CHIFFRE8); afficheVerifChargement(chiffres[8]); chiffres[9] = afficheChargeImage(CHIFFRE9); afficheVerifChargement(chiffres[9]); positionNiveau.x = 370; positionNiveau.y = screen->h - 40; texte_niveau = afficheChargeImage(TEXTE_NIVEAU); positionTexteNiveau.x = 300; positionTexteNiveau.y = screen->h - 40; imageBoutonPlus = afficheChargeImage(BOUTONPLUS); afficheVerifChargement(imageBoutonPlus); imageBoutonMoins = afficheChargeImage(BOUTONMOINS); afficheVerifChargement(imageBoutonMoins); positionBoutonPlus.x = 425; positionBoutonPlus.y = screen->h - 40; positionBoutonPlus.w = imageBoutonPlus->w; positionBoutonPlus.h = imageBoutonPlus->h; positionBoutonMoins.x = 400; positionBoutonMoins.y = screen->h - 40; positionBoutonMoins.w = imageBoutonPlus->w; positionBoutonMoins.h = imageBoutonPlus->h; sourisx = 0; sourisy = 0; while (done==0) { /* vider l'écran */ afficheVideEcran(screen); /* animer les pions qui se déplacent à l'écran */ if(positionPerle.x>(screen->w-(imageAnimeePerle->w)*3/4) || positionPerle.x<=0) { vecteurPerle.x*=-1; } if(positionPerle.y<=0 || positionPerle.y>(screen->h-(imageAnimeePerle->h)*3/4)) { vecteurPerle.y*=-1; } if(positionRubis.x>(screen->w-(imageAnimeeRubis->w)*3/4) || positionRubis.x<=0) { vecteurRubis.x*=-1; } if(positionRubis.y<=0 || positionRubis.y>(screen->h-(imageAnimeeRubis->h)*3/4)) { vecteurRubis.y*=-1; } positionPerle.x += vecteurPerle.x; positionPerle.y += vecteurPerle.y; positionRubis.x += vecteurRubis.x; positionRubis.y += vecteurRubis.y; while(afficheEvenements(&event)) { switch(afficheTypeEvenement(&event)) { /* récupérer la position de la souris sur l'écran */ case EVENT_SOURISBOUGE: { sourisx = afficheCoordonneeSouris(&event,'x'); sourisy = afficheCoordonneeSouris(&event,'y'); } break; /* fermer */ case AFFICHE_FIN: { done = 1; retour = 0; } break; /* touche enfoncée */ case EVENT_TOUCHEENFONCEE: { /* fermer */ if(afficheToucheAppuyee(&event) == T_ECHAP) { done = 1; retour = 0; } if(afficheToucheAppuyee(&event) == T_ESPACE) { done = 1; retour = 1; } if((afficheToucheAppuyee(&event) == T_GAUCHE && *contreordinateur==1) || (afficheToucheAppuyee(&event) == T_DROITE && *contreordinateur==0)) { *contreordinateur = ((*contreordinateur + 1) % 2); } if((afficheToucheAppuyee(&event) == T_HAUT || afficheToucheAppuyee(&event) == T_PN_PLUS) && *niveauordinateur<5 && *contreordinateur==1) { (*niveauordinateur)++; } if((afficheToucheAppuyee(&event) == T_BAS || afficheToucheAppuyee(&event) == T_PN_MOINS) && *niveauordinateur>1 && *contreordinateur==1) { (*niveauordinateur)--; } if(afficheToucheAppuyee(&event) == T_PN_ENTREE || afficheToucheAppuyee(&event) == T_ENTREE) { done = 1; } } break; case EVENT_SOURISCLIC: { if(sourisDansRectangle(sourisx,sourisy,positionContreJoueur)) /* clic sur contre joueur */ { *contreordinateur = 0; } else if(sourisDansRectangle(sourisx,sourisy,positionContreOrdi)) /* clic sur contre ordi */ { *contreordinateur = 1; } else if(sourisDansRectangle(sourisx,sourisy,positionBoutonJouer)) /* clic sur bouton jouer */ { done = 1; } else if(sourisDansRectangle(sourisx,sourisy,positionPlateau[0])) { *plateau=1; } else if(sourisDansRectangle(sourisx,sourisy,positionPlateau[1])) { *plateau=2; } else if(sourisDansRectangle(sourisx,sourisy,positionPlateau[2])) { *plateau=3; } else if(sourisDansRectangle(sourisx,sourisy,positionPlateau[3])) { *plateau=4; } /* changer de niveau ordi */ if(sourisDansRectangle(sourisx,sourisy,positionBoutonPlus) && *niveauordinateur<5 && *contreordinateur==1) { (*niveauordinateur)++; } else if(sourisDansRectangle(sourisx,sourisy,positionBoutonMoins) && *niveauordinateur>1 && *contreordinateur==1) { (*niveauordinateur)--; } /* on souhaite reprendre la partie enregistrée (double if pour être sur de na pas tester le 2eme condition si la permiere est 0 */ if(partieEnregistree) if(sourisDansRectangle(sourisx,sourisy,positionOuvrir)) { fichier = fopen(CONFIGSAUVE,"r"); if(fscanf(fichier,"%d,%d",contreordinateur,niveauordinateur)==2) { *plateau = 0; done = 1; } else { printf("[!] Erreur de lecture du fichier de configuration.\n"); } } } break; } } afficheImageRect(positionMenu,menu,screen); if(*contreordinateur==1) { afficheImageRect(positionContreOrdi,imageSelection,screen); afficheImageRect(positionTexteNiveau,texte_niveau,screen); afficheImageRect(positionNiveau,chiffres[*niveauordinateur],screen); } else { afficheImageRect(positionContreJoueur,imageSelection,screen); } afficheImageRect(positionContreJoueur,imageContreJoueur,screen); afficheImageRect(positionContreOrdi,imageContreOrdi,screen); afficheImageRect(positionPlateau[*plateau-1],imagePlateauSelectionne,screen); afficheImageRect(positionPlateau[0],imagePlateau[0],screen); afficheImageRect(positionPlateau[1],imagePlateau[1],screen); afficheImageRect(positionPlateau[2],imagePlateau[2],screen); afficheImageRect(positionPlateau[3],imagePlateau[3],screen); if(*niveauordinateur<5 && *contreordinateur==1) afficheImageRect(positionBoutonPlus,imageBoutonPlus,screen); if(*niveauordinateur>1 && *contreordinateur==1) afficheImageRect(positionBoutonMoins,imageBoutonMoins,screen); if(sourisDansRectangle(sourisx,sourisy,positionBoutonJouer)) afficheImageRect(positionBoutonJouer,imageBoutonJouerSurvol,screen); else afficheImageRect(positionBoutonJouer,imageBoutonJouer,screen); if(sourisDansRectangle(sourisx,sourisy,positionOuvrir)==1) afficheImageRect(positionOuvrir,imageOuvrirSurvol,screen); else afficheImageRect(positionOuvrir,imageOuvrir,screen); afficheImageRect(positionPerle,imageAnimeePerle,screen); afficheImageRect(positionRubis,imageAnimeeRubis,screen); afficheMiseAJour(screen); } #if SONS==1 if(hello!=0) FMOD_Sound_Release(hello); if(menuMus!=0) FMOD_Sound_Release(menuMus); FMOD_System_Close(system); FMOD_System_Release(system); #endif afficheFree(menu); afficheFree(imageContreJoueur); afficheFree(imageContreOrdi); afficheFree(imageSelection); afficheFree(imageBoutonJouer); afficheFree(imageBoutonJouerSurvol); afficheFree(imageBoutonPlus); afficheFree(imageBoutonMoins); afficheFree(imagePlateau[0]); afficheFree(imagePlateau[1]); afficheFree(imagePlateau[2]); afficheFree(imagePlateauSelectionne); afficheFree(imageAnimeeRubis); afficheFree(imageAnimeePerle); afficheFree(texte_niveau); if(partieEnregistree) { afficheFree(imageOuvrir); afficheFree(imageOuvrirSurvol); } for(ich=0;ich<10;ich++) afficheFree(chiffres[ich]); afficheFree(screen); afficheQuit(); return retour; }
/* FMOD System factory functions. */ inline FMOD_RESULT System_Create(System **system) { return FMOD_System_Create((FMOD_SYSTEM **)system); }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *sound1, *sound2, *sound3; FMOD_CHANNEL *channel = 0; FMOD_RESULT result; int key; unsigned int version; /* Global Settings */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); getch(); return 0; } result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound1); ERRCHECK(result); result = FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF); ERRCHECK(result); result = FMOD_System_CreateSound(system, "../media/jaguar.wav", FMOD_SOFTWARE, 0, &sound2); ERRCHECK(result); result = FMOD_System_CreateSound(system, "../media/swish.wav", FMOD_SOFTWARE, 0, &sound3); ERRCHECK(result); printf("===================================================================\n"); printf("PlaySound Example. Copyright (c) Firelight Technologies 2004-2011.\n"); printf("===================================================================\n"); printf("\n"); printf("Press '1' to Play a mono sound using software mixing\n"); printf("Press '2' to Play a mono sound using software mixing\n"); printf("Press '3' to Play a stereo sound using software mixing\n"); printf("Press 'Esc' to quit\n"); printf("\n"); /* Main loop. */ do { if (kbhit()) { key = getch(); switch (key) { case '1' : { result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel); ERRCHECK(result); break; } case '2' : { result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, 0, &channel); ERRCHECK(result); break; } case '3' : { result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound3, 0, &channel); ERRCHECK(result); break; } } } FMOD_System_Update(system); { unsigned int ms = 0; unsigned int lenms = 0; int playing = 0; int paused = 0; int channelsplaying = 0; if (channel) { FMOD_SOUND *currentsound = 0; result = FMOD_Channel_IsPlaying(channel, &playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPaused(channel, &paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } FMOD_Channel_GetCurrentSound(channel, ¤tsound); if (currentsound) { result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } } } result = FMOD_Sound_GetLength(sound1, &lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } FMOD_System_GetChannelsPlaying(system, &channelsplaying); printf("\rTime %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying); fflush(stdout); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound1); ERRCHECK(result); result = FMOD_Sound_Release(sound2); ERRCHECK(result); result = FMOD_Sound_Release(sound3); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_CHANNEL *channel = 0; FMOD_DSP *dsp = 0; FMOD_RESULT result; int key; unsigned int version; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); getch(); return 0; } result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); /* Create DSP units for each type of noise we want. */ result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_OSCILLATOR, &dsp); ERRCHECK(result); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_RATE, 440.0f); ERRCHECK(result); printf("======================================================================\n"); printf("GenerateTone Example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("======================================================================\n\n"); printf("\n"); printf("Press '1' to play a sine wave\n"); printf("Press '2' to play a square wave\n"); printf("Press '3' to play a triangle wave\n"); printf("Press '4' to play a saw wave\n"); printf("Press '5' to play a white noise\n"); printf("Press 's' to stop channel\n"); printf("\n"); printf("Press 'v'/'V' to change channel volume\n"); printf("Press 'f'/'F' to change channel frequency\n"); printf("Press '['/']' to change channel pan\n"); printf("Press 'Esc' to quit\n"); printf("\n"); /* Main loop */ do { if (kbhit()) { key = getch(); switch (key) { case '1' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.5f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 0); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case '2' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.125f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 1); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case '3' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.5f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 2); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case '4' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.125f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 4); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case '5' : { result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel); FMOD_Channel_SetVolume(channel, 0.25f); result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 5); ERRCHECK(result); FMOD_Channel_SetPaused(channel, FALSE); break; } case 's' : { FMOD_Channel_Stop(channel); break; } case 'v' : { float volume; FMOD_Channel_GetVolume(channel, &volume); volume -= 0.1f; FMOD_Channel_SetVolume(channel, volume); break; } case 'V' : { float volume; FMOD_Channel_GetVolume(channel, &volume); volume += 0.1f; FMOD_Channel_SetVolume(channel, volume); break; } case 'f' : { float frequency; FMOD_Channel_GetFrequency(channel, &frequency); frequency -= 500.0f; FMOD_Channel_SetFrequency(channel, frequency); break; } case 'F' : { float frequency; FMOD_Channel_GetFrequency(channel, &frequency); frequency += 500.0f; FMOD_Channel_SetFrequency(channel, frequency); break; } case '[' : { float pan; FMOD_Channel_GetPan(channel, &pan); pan -= 0.1f; FMOD_Channel_SetPan(channel, pan); break; } case ']' : { float pan; FMOD_Channel_GetPan(channel, &pan); pan += 0.1f; FMOD_Channel_SetPan(channel, pan); break; } } } FMOD_System_Update(system); { float frequency = 0, volume = 0, pan = 0; int playing = FALSE; if (channel) { FMOD_Channel_GetFrequency(channel, &frequency); FMOD_Channel_GetVolume(channel, &volume); FMOD_Channel_GetPan(channel, &pan); FMOD_Channel_IsPlaying(channel, &playing); } printf("Channel %s : Frequency %.1f Volume %.1f Pan %.1f \r", playing ? "playing" : "stopped", frequency, volume, pan); fflush(stdout); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_DSP_Release(dsp); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *systemA, *systemB; FMOD_SOUND *soundA, *soundB; FMOD_CHANNEL *channelA = 0, *channelB = 0; FMOD_RESULT result; int key, count, numdrivers, driver; unsigned int version; /* Create Sound Card A */ result = FMOD_System_Create(&systemA); ERRCHECK(result); result = FMOD_System_GetVersion(systemA, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_GetNumDrivers(systemA, &numdrivers); ERRCHECK(result); printf("---------------------------------------------------------\n"); printf("Select soundcard A\n"); printf("---------------------------------------------------------\n"); for (count=0; count < numdrivers; count++) { char name[256]; result = FMOD_System_GetDriverName(systemA, count, name, 256); ERRCHECK(result); printf("%d : %s\n", count + 1, name); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); if (key == 27) { return 0; } driver = key - '1'; } while (driver < 0 || driver >= numdrivers); printf("\n"); result = FMOD_System_SetDriver(systemA, driver); ERRCHECK(result); result = FMOD_System_Init(systemA, 32, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); /* Create Sound Card B */ result = FMOD_System_Create(&systemB); ERRCHECK(result); result = FMOD_System_GetVersion(systemB, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_GetNumDrivers(systemB, &numdrivers); ERRCHECK(result); printf("---------------------------------------------------------\n"); printf("Select soundcard B\n"); printf("---------------------------------------------------------\n"); for (count=0; count < numdrivers; count++) { char name[256]; result = FMOD_System_GetDriverName(systemA, count, name, 256); ERRCHECK(result); printf("%d : %s\n", count + 1, name); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); if (key == 27) { return 0; } driver = key - '1'; } while (driver < 0 || driver >= numdrivers); printf("\n"); result = FMOD_System_SetDriver(systemB, driver); ERRCHECK(result); result = FMOD_System_Init(systemB, 32, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); /* Load 1 sample into each soundcard. */ result = FMOD_System_CreateSound(systemA, "../media/drumloop.wav", FMOD_HARDWARE, 0, &soundA); ERRCHECK(result); result = FMOD_Sound_SetMode(soundA, FMOD_LOOP_OFF); ERRCHECK(result); result = FMOD_System_CreateSound(systemB, "../media/jaguar.wav", FMOD_HARDWARE, 0, &soundB); ERRCHECK(result); printf("===========================================================================\n"); printf("MultipleSoundCard Example. Copyright (c) Firelight Technologies 2004-2005.\n"); printf("===========================================================================\n"); printf("\n"); printf("Press '1' to play a sound on soundcard A\n"); printf("Press '2' to play a sound on soundcard B\n"); printf("Press 'Esc' to quit\n"); printf("\n"); /* Main loop. */ do { int channelsplayingA = 0; int channelsplayingB = 0; if (kbhit()) { key = getch(); switch (key) { case '1' : { result = FMOD_System_PlaySound(systemA, FMOD_CHANNEL_FREE, soundA, 0, &channelA); ERRCHECK(result); break; } case '2' : { result = FMOD_System_PlaySound(systemB, FMOD_CHANNEL_FREE, soundB, 0, &channelB); ERRCHECK(result); break; } } } FMOD_System_Update(systemA); FMOD_System_Update(systemB); FMOD_System_GetChannelsPlaying(systemA, &channelsplayingA); FMOD_System_GetChannelsPlaying(systemB, &channelsplayingB); printf("Channels Playing on A %2d. Channels Playing on B %2d.\r", channelsplayingA, channelsplayingB); Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(soundA); ERRCHECK(result); result = FMOD_System_Close(systemA); ERRCHECK(result); result = FMOD_System_Release(systemA); ERRCHECK(result); result = FMOD_Sound_Release(soundB); ERRCHECK(result); result = FMOD_System_Close(systemB); ERRCHECK(result); result = FMOD_System_Release(systemB); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_CHANNEL *channel; FMOD_DSP *mydsp; FMOD_RESULT result; int key; unsigned int version; float pan = 0; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound); ERRCHECK(result); printf("===============================================================================\n"); printf("Custom DSP example. Copyright (c) Firelight Technologies 2004-2011.\n"); printf("===============================================================================\n"); printf("Press 'f' to activate, deactivate user filter\n"); printf("Press 'Esc' to quit\n"); printf("\n"); result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel); ERRCHECK(result); /* Create the DSP effects. */ { FMOD_DSP_DESCRIPTION dspdesc; memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION)); strcpy(dspdesc.name, "My first DSP unit"); dspdesc.channels = 0; // 0 = whatever comes in, else specify. dspdesc.read = myDSPCallback; dspdesc.userdata = (void *)0x12345678; result = FMOD_System_CreateDSP(system, &dspdesc, &mydsp); ERRCHECK(result); } /* Inactive by default. */ FMOD_DSP_SetBypass(mydsp, TRUE); /* Main loop. */ result = FMOD_System_AddDSP(system, mydsp, 0); /* Main loop. */ do { if (kbhit()) { key = getch(); switch (key) { case 'f' : case 'F' : { static int active = FALSE; FMOD_DSP_SetBypass(mydsp, active); active = !active; break; } } } FMOD_System_Update(system); Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_DSP_Release(mydsp); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_CHANNEL *channel; FMOD_DSP *dsplowpass, *dspchorus, *dsphead, *dspchannelmixer; FMOD_DSPCONNECTION *dsplowpassconnection, *dspchorusconnection; FMOD_RESULT result; int key; unsigned int version; float pan = 0; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound); ERRCHECK(result); printf("===============================================================================\n"); printf("DSP Effect per speaker example. Copyright (c) Firelight Technologies 2004-2015.\n"); printf("===============================================================================\n"); printf("Press 'L' to toggle reverb on/off on left speaker only\n"); printf("Press 'R' to toggle chorus on/off on right speaker only\n"); printf("Press '[' to pan sound left\n"); printf("Press ']' to pan sound right\n"); printf("Press 'Esc' to quit\n"); printf("\n"); result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel); ERRCHECK(result); /* Create the DSP effects. */ result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_LOWPASS, &dsplowpass); ERRCHECK(result); result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_CHORUS, &dspchorus); ERRCHECK(result); /* Connect up the DSP network */ /* When a sound is played, a subnetwork is set up in the DSP network which looks like this. Wavetable is the drumloop sound, and it feeds its data from right to left. [DSPHEAD]<------------[DSPCHANNELMIXER] */ result = FMOD_System_GetDSPHead(system, &dsphead); ERRCHECK(result); result = FMOD_DSP_GetInput(dsphead, 0, &dspchannelmixer, 0); ERRCHECK(result); /* Now disconnect channeldsp head from wavetable to look like this. [DSPHEAD] [DSPCHANNELMIXER] */ result = FMOD_DSP_DisconnectFrom(dsphead, dspchannelmixer); ERRCHECK(result); /* Now connect the 2 effects to channeldsp head. Store the 2 connections this makes so we can set their speakerlevels later. [DSPLOWPASS] /x [DSPHEAD] [DSPCHANNELMIXER] \y [DSPCHORUS] */ result = FMOD_DSP_AddInput(dsphead, dsplowpass, &dsplowpassconnection); /* x = dsplowpassconnection */ ERRCHECK(result); result = FMOD_DSP_AddInput(dsphead, dspchorus, &dspchorusconnection); /* y = dspchorusconnection */ ERRCHECK(result); /* Now connect the wavetable to the 2 effects [DSPLOWPASS] /x \ [DSPHEAD] [DSPCHANNELMIXER] \y / [DSPCHORUS] */ result = FMOD_DSP_AddInput(dsplowpass, dspchannelmixer, NULL); /* Null for connection - we dont care about it. */ ERRCHECK(result); result = FMOD_DSP_AddInput(dspchorus, dspchannelmixer, NULL); /* Null for connection - we dont care about it. */ ERRCHECK(result); /* Now the drumloop will be twice as loud, because it is being split into 2, then recombined at the end. What we really want is to only feed the dspchannelmixer->dsplowpass through the left speaker, and dspchannelmixer->dspchorus to the right speaker. We can do that simply by setting the pan, or speaker levels of the connections. [DSPLOWPASS] /x=1,0 \ [DSPHEAD] [DSPCHANNELMIXER] \y=0,1 / [DSPCHORUS] */ { float leftinputon[2] = { 1.0f, 0.0f }; float rightinputon[2] = { 0.0f, 1.0f }; float inputsoff[2] = { 0.0f, 0.0f }; result = FMOD_DSPConnection_SetLevels(dsplowpassconnection, FMOD_SPEAKER_FRONT_LEFT, leftinputon, 2); ERRCHECK(result); result = FMOD_DSPConnection_SetLevels(dsplowpassconnection, FMOD_SPEAKER_FRONT_RIGHT, inputsoff, 2); ERRCHECK(result); result = FMOD_DSPConnection_SetLevels(dspchorusconnection, FMOD_SPEAKER_FRONT_LEFT, inputsoff, 2); ERRCHECK(result); result = FMOD_DSPConnection_SetLevels(dspchorusconnection, FMOD_SPEAKER_FRONT_RIGHT, rightinputon, 2); ERRCHECK(result); } result = FMOD_DSP_SetBypass(dsplowpass, TRUE); result = FMOD_DSP_SetBypass(dspchorus, TRUE); result = FMOD_DSP_SetActive(dsplowpass, TRUE); result = FMOD_DSP_SetActive(dspchorus, TRUE); /* Main loop. */ do { if (_kbhit()) { key = _getch(); switch (key) { case 'l' : case 'L' : { static int reverb = FALSE; FMOD_DSP_SetBypass(dsplowpass, reverb); reverb = !reverb; break; } case 'r' : case 'R' : { static int chorus = FALSE; FMOD_DSP_SetBypass(dspchorus, chorus); chorus = !chorus; break; } case '[' : { FMOD_Channel_GetPan(channel, &pan); pan -= 0.1f; if (pan < -1) { pan = -1; } FMOD_Channel_SetPan(channel, pan); break; } case ']' : { FMOD_Channel_GetPan(channel, &pan); pan += 0.1f; if (pan > 1) { pan = 1; } FMOD_Channel_SetPan(channel, pan); break; } } } FMOD_System_Update(system); { int channelsplaying = 0; FMOD_System_GetChannelsPlaying(system, &channelsplaying); printf("Channels Playing %2d : Pan = %.02f\r", channelsplaying, pan); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_DSP_Release(dsplowpass); ERRCHECK(result); result = FMOD_DSP_Release(dspchorus); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_CHANNEL *channel = 0; FMOD_RESULT result; int key; FMOD_CREATESOUNDEXINFO createsoundexinfo; unsigned int version, decodesound_lengthbytes = 0; int decodesound_channels; float decodesound_rate; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); InitializeCriticalSection(&decodecrit); /* First create the 'decoder sound'. Note it is a stream that does not initially read any data, because FMOD_OPENONLY has been specified. We could use createSound instead of createStream but that would allocate memory for the whole sound which is a waste. */ result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_OPENONLY | FMOD_LOOP_NORMAL | FMOD_LOWMEM | FMOD_CREATESTREAM, 0, &decodesound); ERRCHECK(result); result = FMOD_Sound_GetLength(decodesound, &decodesound_lengthbytes, FMOD_TIMEUNIT_PCMBYTES); ERRCHECK(result); result = FMOD_Sound_GetFormat(decodesound, 0, 0, &decodesound_channels, 0); ERRCHECK(result); result = FMOD_Sound_GetDefaults(decodesound, &decodesound_rate, 0, 0, 0); ERRCHECK(result); /* Now create a user created PCM stream that we will feed data into, and play. */ memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); createsoundexinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); /* required. */ createsoundexinfo.decodebuffersize = 44100; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */ createsoundexinfo.numchannels = decodesound_channels; /* Number of channels in the sound. */ createsoundexinfo.length = decodesound_lengthbytes; /* Length of PCM data in bytes of whole song. -1 = infinite. */ createsoundexinfo.defaultfrequency = (int)decodesound_rate; /* Default playback rate of sound. */ createsoundexinfo.format = FMOD_SOUND_FORMAT_PCM16; /* Data format of sound. */ createsoundexinfo.pcmreadcallback = pcmreadcallback; /* User callback for reading. */ createsoundexinfo.pcmsetposcallback = pcmsetposcallback; /* User callback for seeking. */ result = FMOD_System_CreateStream(system, 0, FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL, &createsoundexinfo, &sound); ERRCHECK(result); printf("============================================================================\n"); printf("Manual Decode example. Copyright (c) Firelight Technologies 2004-2011.\n"); printf("============================================================================\n"); printf("Sound played here decoded in realtime by the user with a 'decoder sound' \n"); printf("The mp3 is created as a stream opened with FMOD_OPENONLY. This is the \n"); printf("'decoder sound'. The playback sound is a 16bit PCM FMOD_OPENUSER created \n"); printf("sound with a pcm read callback. When the callback happens, we call readData\n"); printf("on the decoder sound and use the pcmreadcallback data pointer as the parameter.\n"); printf("============================================================================\n"); printf("\n"); printf("Press space to pause, Esc to quit\n"); printf("Press '<' to rewind 1 second.\n"); printf("Press '>' to fast forward 1 second.\n"); printf("\n"); /* Play the sound. */ result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel); ERRCHECK(result); /* Main loop. */ do { if (_kbhit()) { key = _getch(); switch (key) { case ' ' : { int paused; FMOD_Channel_GetPaused(channel, &paused); FMOD_Channel_SetPaused(channel, !paused); break; } case '<' : { unsigned int position; FMOD_Channel_GetPosition(channel, &position, FMOD_TIMEUNIT_MS); if (position >= 1000) { position -= 1000; } FMOD_Channel_SetPosition(channel, position, FMOD_TIMEUNIT_MS); break; } case '>' : { unsigned int position; FMOD_Channel_GetPosition(channel, &position, FMOD_TIMEUNIT_MS); position += 1000; FMOD_Channel_SetPosition(channel, position, FMOD_TIMEUNIT_MS); break; } } } FMOD_System_Update(system); if (channel) { unsigned int ms; unsigned int lenms; int playing; int paused; FMOD_Channel_IsPlaying(channel, &playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPaused(channel, &paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped"); } Sleep(20); } while (key != 27); printf("\n"); EnterCriticalSection(&decodecrit); { /* Remove the sound - wait! it might be still in use! Instead of releasing the decode sound first we could release it last, but this protection is here to make the issue obvious. */ result = FMOD_Sound_Release(decodesound); ERRCHECK(result); decodesound = 0; /* This will make the read callback fail from now on. */ } LeaveCriticalSection(&decodecrit); /* Shut down */ result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); DeleteCriticalSection(&decodecrit); return 0; }
float JiwokFMODWrapper::GetBPM(const char *filename) { FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_RESULT result; unsigned int version; result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { //printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = FMOD_System_CreateStream(system,filename, FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound); // ERRCHECK(result); unsigned int length = 0; int channels = 0, bits = 0; float frequency = 0; float volume = 0, pan = 0; int priority = 0; FMOD_SOUND_TYPE stype; FMOD_SOUND_FORMAT format; result = FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCMBYTES); ERRCHECK(result); result = FMOD_Sound_GetDefaults(sound, &frequency, &volume, &pan, &priority); ERRCHECK(result); result = FMOD_Sound_GetFormat(sound, &stype, &format, &channels, &bits); ERRCHECK(result); printf("result is %d",result); soundtouch::BPMDetect *bpm = new soundtouch::BPMDetect(channels,frequency); //void *data; //unsigned int read; unsigned int bytesread; #define CHUNKSIZE 32768 //4096 // #define CHUNKSIZE 4096 bytesread = 0; soundtouch::SAMPLETYPE* samples = new soundtouch::SAMPLETYPE[CHUNKSIZE]; int sbytes = bits / 8; const unsigned int NUMSAMPLES = CHUNKSIZE; unsigned int bytes = NUMSAMPLES * sbytes; unsigned int readbytes = 0; do { readbytes = 0; if(sbytes == 2) { long int data[32768]; result = FMOD_Sound_ReadData(sound, data, bytes, &readbytes ); if(!result == FMOD_OK) break; for ( unsigned int i = 0; i < readbytes/sbytes; ++i ) samples[i] = (float) data[i] / 32768; } else if(sbytes == 1) { long int data[32768]; result = FMOD_Sound_ReadData(sound, data, bytes, &readbytes ); if(!result == FMOD_OK) break; for ( unsigned int i = 0; i < (readbytes); ++i ) samples[i] = (float) data[i] / 128; } bpm->inputSamples(samples, (readbytes /sbytes)/ channels ); bytesread += readbytes; } while (result == FMOD_OK && readbytes == CHUNKSIZE*2); result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); float bpmg = bpm->getBpm(); float bpm1 = bpmg; if ( bpmg < 1 ) return 0.; while ( bpmg > 190 ) bpmg /= 2.; while ( bpmg < 50 ) bpmg *= 2.; printf("bpmg bpmg is %f bpm %f",bpmg,bpm1); return bpmg; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *sound; FMOD_SOUND *subsound[2]; FMOD_CREATESOUNDEXINFO exinfo; FMOD_CHANNEL *channel = 0; FMOD_RESULT result; int key; unsigned int subsoundid, sentenceid; unsigned int version; const char *soundname[NUMSOUNDS] = { "../media/e.ogg", /* Ma- */ "../media/d.ogg", /* ry */ "../media/c.ogg", /* had */ "../media/d.ogg", /* a */ "../media/e.ogg", /* lit- */ "../media/e.ogg", /* tle */ "../media/e.ogg", /* lamb, */ "../media/e.ogg", /* ..... */ "../media/d.ogg", /* lit- */ "../media/d.ogg", /* tle */ "../media/d.ogg", /* lamb, */ "../media/d.ogg", /* ..... */ "../media/e.ogg", /* lit- */ "../media/e.ogg", /* tle */ "../media/e.ogg", /* lamb, */ "../media/e.ogg", /* ..... */ "../media/e.ogg", /* Ma- */ "../media/d.ogg", /* ry */ "../media/c.ogg", /* had */ "../media/d.ogg", /* a */ "../media/e.ogg", /* lit- */ "../media/e.ogg", /* tle */ "../media/e.ogg", /* lamb, */ "../media/e.ogg", /* its */ "../media/d.ogg", /* fleece */ "../media/d.ogg", /* was */ "../media/e.ogg", /* white */ "../media/d.ogg", /* as */ "../media/c.ogg", /* snow. */ "../media/c.ogg", /* ..... */ "../media/c.ogg", /* ..... */ "../media/c.ogg", /* ..... */ }; /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); /* Set up the FMOD_CREATESOUNDEXINFO structure for the user stream with room for 2 subsounds. (our subsound double buffer) */ memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.defaultfrequency = 44100; exinfo.numsubsounds = 2; exinfo.numchannels = 1; exinfo.format = FMOD_SOUND_FORMAT_PCM16; /* Create the 'parent' stream that contains the substreams. Set it to loop so that it loops between subsound 0 and 1. */ result = FMOD_System_CreateStream(system, 0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound); ERRCHECK(result); /* Add 2 of our streams as children of the parent. They should be the same format (ie mono/stereo and bitdepth) as the parent sound. When subsound 0 has finished and it is playing subsound 1, we will swap subsound 0 with a new sound, and the same for when subsound 1 has finished, causing a continual double buffered flip, which means continuous sound. */ result = FMOD_System_CreateStream(system, soundname[0], FMOD_DEFAULT, 0, &subsound[0]); ERRCHECK(result); result = FMOD_System_CreateStream(system, soundname[1], FMOD_DEFAULT, 0, &subsound[1]); ERRCHECK(result); result = FMOD_Sound_SetSubSound(sound, 0, subsound[0]); ERRCHECK(result); result = FMOD_Sound_SetSubSound(sound, 1, subsound[1]); ERRCHECK(result); /* Set up the gapless sentence to contain these first 2 streams. */ { int soundlist[2] = { 0, 1 }; result = FMOD_Sound_SetSubSoundSentence(sound, soundlist, 2); ERRCHECK(result); } subsoundid = 0; sentenceid = 2; /* The next sound to be appeneded to the stream. */ printf("=============================================================================\n"); printf("Real-time stitching example. Copyright (c) Firelight Technologies 2004-2015.\n"); printf("=============================================================================\n"); printf("\n"); printf("Press space to pause, Esc to quit\n"); printf("\n"); printf("Inserted subsound %d / 2 with sound %d / %d\n", 0, 0, NUMSOUNDS); printf("Inserted subsound %d / 2 with sound %d / %d\n", 1, 1, NUMSOUNDS); /* Play the sound. */ result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel); ERRCHECK(result); /* Main loop. */ do { unsigned int currentsubsoundid; if (_kbhit()) { key = _getch(); switch (key) { case ' ' : { int paused; FMOD_Channel_GetPaused(channel, &paused); FMOD_Channel_SetPaused(channel, !paused); break; } } } FMOD_System_Update(system); /* Replace the subsound that just finished with a new subsound, to create endless seamless stitching! Note that this polls the currently playing subsound using the FMOD_TIMEUNIT_BUFFERED flag. Remember streams are decoded / buffered ahead in advance! Don't use the 'audible time' which is FMOD_TIMEUNIT_SENTENCE_SUBSOUND by itself. When streaming, sound is processed ahead of time, and things like stream buffer / sentence manipulation (as done below) is required to be in 'buffered time', or else there will be synchronization problems and you might end up releasing a sub-sound that is still playing! */ result = FMOD_Channel_GetPosition(channel, ¤tsubsoundid, (FMOD_TIMEUNIT)(FMOD_TIMEUNIT_SENTENCE_SUBSOUND | FMOD_TIMEUNIT_BUFFERED)); ERRCHECK(result); if (currentsubsoundid != subsoundid) { /* Release the sound that isn't playing any more. */ result = FMOD_Sound_Release(subsound[subsoundid]); ERRCHECK(result); /* Replace it with a new sound in our list. */ result = FMOD_System_CreateStream(system, soundname[sentenceid], FMOD_DEFAULT, 0, &subsound[subsoundid]); ERRCHECK(result); result = FMOD_Sound_SetSubSound(sound, subsoundid, subsound[subsoundid]); ERRCHECK(result); printf("Replacing subsound %d / 2 with sound %d / %d\n", subsoundid, sentenceid, NUMSOUNDS); sentenceid++; if (sentenceid >= NUMSOUNDS) { sentenceid = 0; } subsoundid = currentsubsoundid; } Sleep(50); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound); /* Freeing a parent subsound also frees its children. */ ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }