// Lecture des sons. Ils sont lu par streaming c'est à dire qu'ils sont chargés pendant la lecture. void CSoundManager::Jouer ( std::string const & Filename, ECanaux Canal, bool bLoop ) { if (!m_bCanauxJeu && Canal != CANAL_MUSIQUE) return; if (m_pSon[Canal]) FSOUND_Stream_Close (m_pSon[Canal]); // Si bLoop == true alors le son boucle. if (bLoop) { FSOUND_SetLoopMode (0, FSOUND_LOOP_NORMAL); m_pSon[Canal] = FSOUND_Stream_Open((DIRECTORY + Filename).c_str(), FSOUND_LOOP_NORMAL, 0, 0); FSOUND_SetVolume (Canal, 64); FSOUND_SetVolumeAbsolute (Canal, 64); } // Sinon il est jouer une seule fois. else { m_pSon[Canal] = FSOUND_Stream_Open((DIRECTORY + Filename).c_str(), FSOUND_NORMAL, 0, 0); FSOUND_SetVolume (Canal, 255); FSOUND_SetVolumeAbsolute (Canal, 255); } FSOUND_Stream_Play (Canal, m_pSon[Canal]); }
bool C4MusicFileMP3::Play(bool loop) { #ifndef USE_MP3 return false; #endif // Load Song size_t iFileSize; if (!C4Group_ReadFile(FileName, &Data, &iFileSize)) return false; // init fsound int loop_flag = loop ? FSOUND_LOOP_NORMAL : 0; stream = FSOUND_Stream_Open(Data, FSOUND_LOADMEMORY | FSOUND_NORMAL | FSOUND_2D | loop_flag, 0, iFileSize); if (!stream) return false; // Play Song Channel = FSOUND_Stream_Play(FSOUND_FREE, stream); if (Channel == -1) return false; // Set highest priority if (!FSOUND_SetPriority(Channel, 255)) return false; return true; }
bool C4MusicFileOgg::Play(bool loop) { // Load Song size_t iFileSize; if (!C4Group_ReadFile(FileName, &Data, &iFileSize)) return false; // init fsound int loop_flag = loop ? FSOUND_LOOP_NORMAL : 0; stream = FSOUND_Stream_Open(Data, FSOUND_LOADMEMORY | FSOUND_NORMAL | FSOUND_2D | loop_flag, 0, iFileSize); if (!stream) return false; // Play Song Channel = FSOUND_Stream_Play(FSOUND_FREE, stream); if (Channel == -1) return false; // Set highest priority if (!FSOUND_SetPriority(Channel, 255)) return false; Playing = true; FSOUND_Stream_SetEndCallback(stream, &C4MusicFileOgg::OnEnd, this); return true; }
//=========================================================================== // DM_FModExtPlayBuffer //=========================================================================== int DM_FModExtPlayBuffer(int looped) { if(!ext_inited) return false; DM_FModExtReset(); // Try playing as a module first. if((module = FMUSIC_LoadSongEx(song, 0, song_size, FSOUND_LOADMEMORY, NULL, 0))) { FMUSIC_SetLooping(module, looped); } else { // Try as a stream. stream = FSOUND_Stream_Open(song, FSOUND_LOADMEMORY | (looped ? FSOUND_LOOP_NORMAL : 0), 0, song_size); if(!stream) return false; } DM_FModExtStartPlaying(); //ext_looped_play = looped; return true; }
void World::setMusic( const char *musicfile ) { FILE *fp = fopen( musicfile, "r" ); if (!fp) { printf("File no exist: %s\n", musicfile ); } else fclose(fp); mp3file = FSOUND_Stream_Open( musicfile, 0,0, 0 ); }
void SoundSystem::playMusic(const FileName &fileName) { stopMusic(); if(!mute && fileName!=FileName("none") && fileName!=FileName("")) { musicStream = FSOUND_Stream_Open(fileName.c_str(), FSOUND_LOOP_NORMAL, 0, 0); musicChannel = FSOUND_Stream_Play(FSOUND_FREE, musicStream); TRACE("Playing music: " + fileName.str()); } }
/// Play from memory. bool CMusicChannelFMod::playSync(const std::string &filepath, bool loop) { CIFile ifile; ifile.allowBNPCacheFileOnOpen(false); ifile.setCacheFileOnOpen(false); ifile.open(filepath); // try to load the music in memory uint32 fs = ifile.getFileSize(); if (!fs) { nlwarning("NLSOUND FMod Driver: Empty music file"); return false; } // read Buffer nlassert(!_MusicBuffer); _MusicBuffer = new uint8[fs]; try { ifile.serialBuffer(_MusicBuffer, fs); } catch (...) { nlwarning("NLSOUND FMod Driver: Error while reading music file"); delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } // open FMOD stream _MusicStream = FSOUND_Stream_Open((const char*)_MusicBuffer, FSOUND_2D | FSOUND_LOADMEMORY | (loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF), 0, fs); if (!_MusicStream) { nlwarning("NLSOUND FMod Driver: Error while creating the FMOD stream for music file"); delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } if (!playStream()) { nlwarning("NLSOUND FMod Driver: Error While trying to play sync music file"); FSOUND_Stream_Close(_MusicStream); _MusicStream = NULL; delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } return true; }
void LecteurAudio::nouveauTitre(QString titre, QString fichier) { // Si un fichier etait en cours de lecture, on le ferme if (fluxAudio) { // Si la fermeture s'est mal passee on affiche un message if (!FSOUND_Stream_Close(fluxAudio)) { qWarning("Probleme a la fermeture d'un flux audio (nouveauTitre - LecteurAudio.cpp)"); return; } } // On affiche le titre du nouveau morceau afficheurTitre->setText(titre); afficheurTitre->setCursorPosition(0); afficheurTitre->setToolTip(fichier); // Ouverture du nouveau fichier fluxAudio = FSOUND_Stream_Open(fichier.toLatin1().data(), FSOUND_NORMAL, 0, 0); if (!fluxAudio) { qWarning("Impossible d'ouvrir le fichier audio (nouveauTitre - LecteurAudio.cpp)"); return; } // Mise en place de la fonction de callback appelee en fin de lecture if (!FSOUND_Stream_SetEndCallback(fluxAudio, finTitre, this)) { qWarning("Impossible d'initialiser la fonction de callback de fin de lecture (nouveauTitre - LecteurAudio.cpp)"); return; } // Mise en place de la fonction de callback appelee a chaque passage sur un TAG if (!FSOUND_Stream_SetSyncCallback(fluxAudio, passageTag, this)) { qWarning("Impossible d'initialiser la fonction de callback de passage sur un TAG (nouveauTitre - LecteurAudio.cpp)"); return; } // On ajoute tous les tag indicateurs de temps, a chaque seconde du morceau ajouterTags(); // On recupere la duree totale du fichier int dureeMs = FSOUND_Stream_GetLengthMs(fluxAudio); // Initialisation du selecteur de temps positionTemps->setMaximum(dureeMs); // On met le lecteur a l'arret arreter(); }
bool FMODStreamOut::Open(const char *FileName) { static const char * szhttp = "http://"; bNetStream = (strncmp(FileName,szhttp,strlen(szhttp)) == 0); FMODEngine::eOpenMode openmode = m_Engine.GetOpenMode(); int nFlags = FMOD_STREAM_FORMAT_FLAGS|(openmode == FMODEngine::OpenMode_MPEGACCURATE ? FSOUND_MPEGACCURATE:0); #ifdef WIN32 if(bNetStream) nFlags |= FSOUND_NONBLOCKING; #else if(bNetStream) nFlags = FSOUND_NORMAL|FSOUND_NONBLOCKING;// on linux and mac, HW2D does not work on net streams. #endif StreamPointer = FSOUND_Stream_Open(FileName,nFlags,0,0); return StreamPointer != NULL; }
/// Play async, if bnp give path of bnp and position and size of file inside, else just path to file with fileSize 0. bool CMusicChannelFMod::playAsync(const std::string &filepath, bool loop, uint fileOffset , uint fileSize) { nlassert(!_MusicBuffer); // open fmod stream async _MusicStream = FSOUND_Stream_Open((const char *)filepath.c_str(), FSOUND_2D | ( loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF) | FSOUND_NONBLOCKING, fileOffset, fileSize); nlassert(_MusicStream); // with FSOUND_NONBLOCKING, the file is surely not ready, but still try now (will retry to replay at each updateMusic()) playStream(); nlassert(!_MusicBuffer); return true; }
void Title::Init(GameEngine* game) { image1=ChargementImage("IMG/title.png"); image2=ChargementImage("IMG/cursor.pcx"); image02.x = 300; image02.y = 515; fondu = SDL_CreateRGBSurface(SDL_HWSURFACE, 800, 600, 32, 0, 0, 0, 0); SDL_FillRect(fondu, NULL, SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 0)); musique1 = FSOUND_Stream_Open("SOUND/music.mp3", 0, 0, 0); sonCurseurDeplacement = FSOUND_Sample_Load(FSOUND_FREE, "SOUND/cursormove.wav", 0, 0, 0); sonCurseurValider = FSOUND_Sample_Load(FSOUND_FREE, "SOUND/cursorselect.wav", 0, 0, 0); positionCurseur = 1; quit = false; }
LLAudioStreamFMOD::LLAudioStreamFMOD(const std::string& url) : mInternetStream(NULL), mReady(false) { mInternetStreamURL = url; mInternetStream = FSOUND_Stream_Open(url.c_str(), FSOUND_NORMAL | FSOUND_NONBLOCKING, 0, 0); if (!mInternetStream) { llwarns << "Couldn't open fmod stream, error " << FMOD_ErrorString(FSOUND_GetError()) << llendl; mReady = false; return; } mReady = true; }
void Ambient::enterState() { if(baseBuffer != NULL && baseSize > 0) { base = FSOUND_Stream_Open(static_cast<const char*>(baseBuffer), FSOUND_LOADMEMORY | FSOUND_LOOP_NORMAL, 0, baseSize); if(base == NULL) { reportFMODError("FSOUND_Stream_Open"); } else { baseChannel = FSOUND_Stream_Play(FSOUND_FREE, base); if(baseChannel == -1) { reportFMODError("FSOUND_Stream_Play"); } else { isActive = true; play(); } } } }
void CAudioManager::LoadStream(int id, std::string filename){ if(m_bValidAudio == false) return; STREAM temp; FSOUND_STREAM *handle = NULL; handle = FSOUND_Stream_Open(filename.c_str(),FSOUND_2D,0,0); if(handle == NULL){ //error return; } else{ //good temp.AudioID = id; temp.handle = handle; temp.filename = filename; //temp.channelPlaying = -1; temp.streamSizeBytes = FSOUND_Stream_GetLength(handle); temp.streamSizeMs = FSOUND_Stream_GetLengthMs(handle); m_Stream.push_back(temp); } }
//=========================================================================== // DM_FModExtPlayFile //=========================================================================== int DM_FModExtPlayFile(const char *path, int looped) { if(!ext_inited) return false; DM_FModExtReset(); // Try playing as a module first. if((module = FMUSIC_LoadSong(path))) { FMUSIC_SetLooping(module, looped); } else { // Try as a stream. stream = FSOUND_Stream_Open(path, looped ? FSOUND_LOOP_NORMAL : 0, 0, 0); if(!stream) return false; // Failed...! } DM_FModExtStartPlaying(); //ext_looped_play = looped; return true; }
void LecteurAudio::joueurNouveauFichier(QString nomFichier) { // Si un fichier etait en cours de lecture, on le ferme if (fluxAudio) { // Si la fermeture s'est mal passee on affiche un message if (!FSOUND_Stream_Close(fluxAudio)) { qWarning("Probleme a la fermeture d'un flux audio (joueurNouveauFichier - LecteurAudio.cpp)"); return; } } // Si le nom de fichier est vide, il faut arreter le lecteur if (nomFichier.isEmpty()) { // On efface l'afficheur de titre afficheurTitre->clear(); afficheurTitre->setToolTip(tr("Aucun titre")); // On met le lecteur a l'arret etatActuel = arret; // On sort de la fonction return; } // Creation du chemin complet du fichier QString chemin(G_dossierMusiquesJoueur + "/" + nomFichier); // Ouverture du nouveau fichier fluxAudio = FSOUND_Stream_Open(chemin.toLatin1().data(), FSOUND_NORMAL, 0, 0); // Si l'ouverture s'est mal passee on affiche un message if (!fluxAudio) { qWarning("Impossible d'ouvrir le fichier audio (joueurNouveauFichier - LecteurAudio.cpp)"); // On affiche le message en clair afficheurTitre->setEchoMode(QLineEdit::Normal); // Changement de la couleur du texte en rouge QPalette palette(afficheurTitre->palette()); palette.setColor(QPalette::Normal, QPalette::Text, Qt::red); afficheurTitre->setPalette(palette); // On affiche le titre du nouveau morceau en rouge (indique que le fichier n'est pas present ou impossible a ouvrir) afficheurTitre->setText(nomFichier + tr(" : fichier introuvable ou impossible à ouvrir")); afficheurTitre->setCursorPosition(0); afficheurTitre->setToolTip(tr("Fichier introuvable ou impossible à ouvrir : ") + chemin); // On quitte la fonction return; } // Si l'ouverture du fichier s'est bien passee on ecrit en noir avec des asterisques else { // On masque le titre afficheurTitre->setEchoMode(QLineEdit::Password); // On ecrit en noir QPalette palette(afficheurTitre->palette()); palette.setColor(QPalette::Normal, QPalette::Text, Qt::black); afficheurTitre->setPalette(palette); } // On affiche le titre du nouveau morceau afficheurTitre->setText(nomFichier); afficheurTitre->setCursorPosition(0); afficheurTitre->setToolTip(tr("Titre masqué")); // On met le lecteur a l'arret etatActuel = arret; // La lecture reprend depuis le debut joueurPositionTemps = 0; }
bool CMenu::load(TiXmlNode* t_nodePtr) { TiXmlNode* a_nodePtr = 0; TiXmlNode* a_subNodePtr = 0; TiXmlElement* a_elemPtr = 0; CMenuItem* a_menuItemPtr = 0; std::string a_key = ""; std::string a_str = ""; bool r_ret = true; FSOUND_STREAM* a_sound = 0; ////////////////////////////////////////////////////////////////////////// // clear old menu clear(); ////////////////////////////////////////////////////////////////////////// // Start to play level music a_elemPtr = t_nodePtr->ToElement(); getAttributeStr(a_elemPtr, "music", a_str); a_str = SOUND_BASE + a_str; a_sound = FSOUND_Stream_Open(a_str.c_str(), FSOUND_LOOP_NORMAL, 0, 0); if (a_sound && !g_mute) { FSOUND_Stream_Play(0, a_sound); } ////////////////////////////////////////////////////////////////////////// // load textures for menu a_nodePtr = t_nodePtr->FirstChild("texturelist"); for(a_subNodePtr = a_nodePtr->FirstChild("texture"); a_subNodePtr; a_subNodePtr = a_nodePtr->IterateChildren("texture", a_subNodePtr)) { a_elemPtr = a_subNodePtr->ToElement(); if(!getAttributeStr(a_elemPtr, "key", a_key)) { r_ret = false; } if(r_ret) { if(m_textureMap[a_key] == 0) { m_textureMap[a_key] = new CTexture(a_elemPtr, GFX_BASE); } } } ////////////////////////////////////////////////////////////////////////// // load menu items for(a_nodePtr = t_nodePtr->FirstChild("menuitem"); a_nodePtr; a_nodePtr = t_nodePtr->IterateChildren("menuitem", a_nodePtr)) { a_menuItemPtr = new CMenuItem(this); r_ret &= a_menuItemPtr->load(a_nodePtr); m_menuItems.push_back(a_menuItemPtr); } return r_ret; }
static inline VOID M_StartFMODSong(LPVOID data, int len, int looping, HWND hDlg) { const int loops = FSOUND_LOOP_NORMAL|FSOUND_LOADMEMORY; const int nloop = FSOUND_LOADMEMORY; M_FreeMusic(); if (looping) mod = FMUSIC_LoadSongEx(data, 0, len, loops, NULL, 0); else mod = FMUSIC_LoadSongEx(data, 0, len, nloop, NULL, 0); if (mod) { FMUSIC_SetLooping(mod, (signed char)looping); FMUSIC_SetPanSeperation(mod, 0.0f); } else { if (looping) fmus = FSOUND_Stream_Open(data, loops, 0, len); else fmus = FSOUND_Stream_Open(data, nloop, 0, len); } if (!fmus && !mod) { MessageBoxA(hDlg, FMOD_ErrorString(FSOUND_GetError()), "Error", MB_OK|MB_APPLMODAL); return; } // Scan the OGG for the COMMENT= field for a custom loop point if (looping && fmus) { const BYTE *origpos, *dataum = data; size_t scan, size = len; CHAR buffer[512]; BOOL titlefound = FALSE, artistfound = FALSE; unsigned int loopstart = 0; origpos = dataum; for(scan = 0; scan < size; scan++) { if (!titlefound) { if (*dataum++ == 'T') if (*dataum++ == 'I') if (*dataum++ == 'T') if (*dataum++ == 'L') if (*dataum++ == 'E') if (*dataum++ == '=') { size_t titlecount = 0; CHAR title[256]; BYTE length = *(dataum-10) - 6; while(titlecount < length) title[titlecount++] = *dataum++; title[titlecount] = '\0'; sprintf(buffer, "Title: %s", title); SendMessage(GetDlgItem(hDlg, IDC_TITLE), WM_SETTEXT, 0, (LPARAM)(LPCSTR)buffer); titlefound = TRUE; } } } dataum = origpos; for(scan = 0; scan < size; scan++) { if (!artistfound) { if (*dataum++ == 'A') if (*dataum++ == 'R') if (*dataum++ == 'T') if (*dataum++ == 'I') if (*dataum++ == 'S') if (*dataum++ == 'T') if (*dataum++ == '=') { size_t artistcount = 0; CHAR artist[256]; BYTE length = *(dataum-11) - 7; while(artistcount < length) artist[artistcount++] = *dataum++; artist[artistcount] = '\0'; sprintf(buffer, "By: %s", artist); SendMessage(GetDlgItem(hDlg, IDC_ARTIST), WM_SETTEXT, 0, (LPARAM)(LPCSTR)buffer); artistfound = TRUE; } } } dataum = origpos; for(scan = 0; scan < size; scan++) { if (*dataum++ == 'C'){ if (*dataum++ == 'O'){ if (*dataum++ == 'M'){ if (*dataum++ == 'M'){ if (*dataum++ == 'E'){ if (*dataum++ == 'N'){ if (*dataum++ == 'T'){ if (*dataum++ == '='){ if (*dataum++ == 'L'){ if (*dataum++ == 'O'){ if (*dataum++ == 'O'){ if (*dataum++ == 'P'){ if (*dataum++ == 'P'){ if (*dataum++ == 'O'){ if (*dataum++ == 'I'){ if (*dataum++ == 'N'){ if (*dataum++ == 'T'){ if (*dataum++ == '=') { size_t newcount = 0; CHAR looplength[64]; while (*dataum != 1 && newcount < 63) { looplength[newcount++] = *dataum++; } looplength[newcount] = '\n'; loopstart = atoi(looplength); } else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} else dataum--;} } if (loopstart > 0) { const int length = FSOUND_Stream_GetLengthMs(fmus); const int freq = 44100; const unsigned int loopend = (unsigned int)((freq/1000.0f)*length-(freq/1000.0f)); if (!FSOUND_Stream_SetLoopPoints(fmus, loopstart, loopend)) { printf("FMOD(Start,FSOUND_Stream_SetLoopPoints): %s\n", FMOD_ErrorString(FSOUND_GetError())); } } } if (mod) FMUSIC_PlaySong(mod); if (fmus) fsoundchannel = FSOUND_Stream_PlayEx(FSOUND_FREE, fmus, NULL, FALSE); M_SetVolume(128); }
/* [ [DESCRIPTION] main entry point into streamer example. [PARAMETERS] 'argc' Number of command line parameters. 'argv' Parameter list [RETURN_VALUE] void [REMARKS] [SEE_ALSO] ] */ int main(int argc, char *argv[]) { FSOUND_STREAM *stream; FSOUND_SAMPLE *sptr; char key; if (FSOUND_GetVersion() < FMOD_VERSION) { printf("Error : You are using the wrong DLL version! You should be using FMOD %.02f\n", FMOD_VERSION); return 1; } if (argc < 2) { printf("-------------------------------------------------------------\n"); printf("FMOD Streamer example.\n"); printf("Copyright (c) Firelight Technologies Pty, Ltd, 1999-2004.\n"); printf("-------------------------------------------------------------\n"); printf("Syntax: stream infile.[mp2 mp3 wav ogg wma asf]\n\n"); return 1; } #if defined(WIN32) || defined(_WIN64) || defined(__CYGWIN32__) || defined(__WATCOMC__) FSOUND_SetOutput(FSOUND_OUTPUT_WINMM); #elif defined(__linux__) FSOUND_SetOutput(FSOUND_OUTPUT_OSS); #endif // Set custom file callbacks? This doesnt have to be done, its just here as an example. FSOUND_File_SetCallbacks(myopen, myclose, myread, myseek, mytell); // ========================================================================================== // SELECT DRIVER // ========================================================================================== { long i,driver=0; char key; // The following list are the drivers for the output method selected above. printf("---------------------------------------------------------\n"); switch (FSOUND_GetOutput()) { case FSOUND_OUTPUT_NOSOUND: printf("NoSound"); break; case FSOUND_OUTPUT_WINMM: printf("Windows Multimedia Waveout"); break; case FSOUND_OUTPUT_DSOUND: printf("Direct Sound"); break; case FSOUND_OUTPUT_A3D: printf("A3D"); break; case FSOUND_OUTPUT_OSS: printf("Open Sound System"); break; case FSOUND_OUTPUT_ESD: printf("Enlightenment Sound Daemon"); break; case FSOUND_OUTPUT_ALSA: printf("ALSA"); break; }; printf(" Driver list\n"); printf("---------------------------------------------------------\n"); for (i=0; i < FSOUND_GetNumDrivers(); i++) { printf("%d - %s\n", i+1, FSOUND_GetDriverName(i)); // print driver names } printf("---------------------------------------------------------\n"); // print driver names printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); if (key == 27) exit(0); driver = key - '1'; } while (driver < 0 || driver >= FSOUND_GetNumDrivers()); FSOUND_SetDriver(driver); // Select sound card (0 = default) } // ========================================================================================== // INITIALIZE // ========================================================================================== if (!FSOUND_Init(44100, 32, 0)) { printf("Error!\n"); printf("%s\n", FMOD_ErrorString(FSOUND_GetError())); FSOUND_Close(); return 1; } FSOUND_Stream_SetBufferSize(1000); // ========================================================================================== // OPEN STREAM (use #if 1 for streaming from memory) // ========================================================================================== #if 0 { FILE *fp; int length; char *data; fp = fopen(argv[1], "rb"); if (!fp) { printf("Error!\n"); printf("File Not Found\n"); FSOUND_Close(); return 1; } fseek(fp, 0, SEEK_END); length = ftell(fp); fseek(fp, 0, SEEK_SET); data = (char *)malloc(length); fread(data, length, 1, fp); fclose(fp); stream = FSOUND_Stream_Open(data, FSOUND_NORMAL | FSOUND_MPEGACCURATE | FSOUND_LOADMEMORY, 0, length); // The memory pointer MUST remain valid while streaming! } #else if (!strnicmp(argv[1], "http:", 5)) { printf("Connecting to %s, please wait (this may take some time)....\n", argv[1]); } stream = FSOUND_Stream_Open(argv[1], FSOUND_NORMAL | FSOUND_MPEGACCURATE, 0, 0); if (!stream) { printf("Error!\n"); printf("%s\n", FMOD_ErrorString(FSOUND_GetError())); FSOUND_Close(); return 1; } #endif // ========================================================================================== // SET AN END OF STREAM CALLBACK AND RIFF SYNCH POINTS CALLBACK // ========================================================================================== FSOUND_Stream_SetEndCallback(stream, endcallback, 0); FSOUND_Stream_SetSyncCallback(stream, endcallback, 0); printf("=========================================================================\n"); printf("Press SPACE to pause/unpause\n"); printf("Press 'f' to fast forward 2 seconds\n"); printf("Press ESC to quit\n"); printf("=========================================================================\n"); printf("Playing stream...\n\n"); sptr = FSOUND_Stream_GetSample(stream); if (sptr) { int freq; FSOUND_Sample_GetDefaults(sptr, &freq, NULL, NULL, NULL); printf("Name : %s\n", FSOUND_Sample_GetName(sptr)); printf("Frequency : %d\n\n", freq); } key = 0; do { if (channel < 0) { // ========================================================================================== // PLAY STREAM // ========================================================================================== channel = FSOUND_Stream_PlayEx(FSOUND_FREE, stream, NULL, TRUE); FSOUND_SetPaused(channel, FALSE); } if (kbhit()) { key = getch(); if (key == ' ') { FSOUND_SetPaused(channel, !FSOUND_GetPaused(channel)); } if (key == 'f') { FSOUND_Stream_SetTime(stream, FSOUND_Stream_GetTime(stream) + 2000); } } printf("pos %6d/%6d time %02d:%02d/%02d:%02d cpu %5.02f%% \r", FSOUND_Stream_GetPosition(stream), FSOUND_Stream_GetLength(stream), FSOUND_Stream_GetTime(stream) / 1000 / 60, FSOUND_Stream_GetTime(stream) / 1000 % 60, FSOUND_Stream_GetLengthMs(stream) / 1000 / 60, FSOUND_Stream_GetLengthMs(stream) / 1000 % 60, FSOUND_GetCPUUsage()); Sleep(10); } while (key != 27); printf("\n"); FSOUND_Stream_Close(stream); FSOUND_Close(); return 0; }
int main(int argc, char ** argv) { int finp = 0,first = 1; SDL_Surface * menu = NULL; SDL_Surface * ecran = NULL; SDL_Rect position_menu; SDL_Event event; FSOUND_STREAM * musique = NULL; SDL_Init(SDL_INIT_VIDEO); TTF_Init(); FSOUND_Init(44100,32,0); ecran = SDL_SetVideoMode(800,800,32,SDL_HWSURFACE | SDL_DOUBLEBUF); if(ecran == NULL) exit(EXIT_FAILURE); SDL_WM_SetCaption("Prozet zz1",NULL); menu = IMG_Load("./dessin/menu.jpg"); if(menu == NULL) exit(EXIT_FAILURE); position_menu.x = 0; position_menu.y = 0; musique = FSOUND_Stream_Open("./son/jourdefoot.mp3",0,0,0); if(musique == NULL) exit(EXIT_FAILURE); while(finp == 0) { if(first == 1) { SDL_BlitSurface(menu,NULL,ecran,&position_menu); SDL_Flip(ecran); FSOUND_Stream_Play(FSOUND_FREE,musique); first = 0; } SDL_WaitEvent(&event); switch(event.type) { case SDL_QUIT: finp = 1; break; case SDL_MOUSEBUTTONDOWN: if(event.button.button == SDL_BUTTON_LEFT) { if(event.button.x >= 250 && event.button.x <= 550) { if(event.button.y >= 300 && event.button.y <= 400) { FSOUND_Stream_Stop(musique); mode_solo(ecran); first = 1; } else { if(event.button.y >= 450 && event.button.y <= 550) { FSOUND_Stream_Stop(musique); mode_local_serveur(ecran); first = 1; } else { if(event.button.y >= 600 && event.button.y <= 700) { FSOUND_Stream_Stop(musique); mode_local_client(ecran); first = 1; } } } } } break; } } FSOUND_Stream_Stop(musique); FSOUND_Stream_Close(musique); FSOUND_Close(); SDL_FreeSurface(menu); SDL_FreeSurface(ecran); TTF_Quit(); SDL_Quit(); return(EXIT_SUCCESS); }
Status Target::Response() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, _targetTex); //camera spot light GLfloat white_light[] = {1.0, 1.0, 1.0, 1.0}; GLfloat uplightpoz[] = {0, 20, 0, 1}; GLfloat uplightdir[]={0, -1, 0}; glLightfv(GL_LIGHT2, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, uplightdir); glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 60); glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 50); glLightfv(GL_LIGHT3, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT3, GL_SPOT_DIRECTION, uplightdir); glLightf(GL_LIGHT3, GL_SPOT_CUTOFF, 60); glLightf(GL_LIGHT3, GL_SPOT_EXPONENT, 50); glLightfv(GL_LIGHT4, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT4, GL_SPOT_DIRECTION, uplightdir); glLightf(GL_LIGHT4, GL_SPOT_CUTOFF, 60); glLightf(GL_LIGHT4, GL_SPOT_EXPONENT, 50); glLightfv(GL_LIGHT5, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT5, GL_SPOT_DIRECTION, uplightdir); glLightf(GL_LIGHT5, GL_SPOT_CUTOFF, 60); glLightf(GL_LIGHT5, GL_SPOT_EXPONENT, 50); glLightfv(GL_LIGHT6, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT6, GL_SPOT_DIRECTION, uplightdir); glLightf(GL_LIGHT6, GL_SPOT_CUTOFF, 60); glLightf(GL_LIGHT6, GL_SPOT_EXPONENT, 50); glLightfv(GL_LIGHT7, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT7, GL_SPOT_DIRECTION, uplightdir); glLightf(GL_LIGHT7, GL_SPOT_CUTOFF, 60); glLightf(GL_LIGHT7, GL_SPOT_EXPONENT, 50); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glPushMatrix(); glTranslatef(targetPoz1.x, 0, targetPoz1.z); glLightfv(GL_LIGHT2, GL_POSITION,uplightpoz); if (flag1 == 1) { glDisable(GL_LIGHT2); glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); } else if (collision(BulletPoz)==1) { glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); //if hit the target, play clap sound hitTarget = FSOUND_Stream_Open( "Resources\\Sound\\hitTarget.wav" , FSOUND_2D , 0 , 0 ); FSOUND_Stream_Play(0,hitTarget); flag1 = 1; } glCallList(targetList); glPopMatrix(); glPushMatrix(); glTranslatef(targetPoz2.x, 0, targetPoz2.z); glLightfv(GL_LIGHT3, GL_POSITION,uplightpoz); if (flag2 == 1) { glDisable(GL_LIGHT3); glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); } else if (collision(BulletPoz)==2) { glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); //if hit the target, play clap sound hitTarget = FSOUND_Stream_Open( "Resources\\Sound\\hitTarget.wav" , FSOUND_2D , 0 , 0 ); FSOUND_Stream_Play(0,hitTarget); flag2 = 1; } glCallList(targetList); glPopMatrix(); glPushMatrix(); glTranslatef(targetPoz3.x, 0, targetPoz3.z); glLightfv(GL_LIGHT4, GL_POSITION,uplightpoz); if (flag3 == 1) { glDisable(GL_LIGHT4); glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); } else if (collision(BulletPoz)==3) { glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); //if hit the target, play clap sound hitTarget = FSOUND_Stream_Open( "Resources\\Sound\\hitTarget.wav" , FSOUND_2D , 0 , 0 ); FSOUND_Stream_Play(0,hitTarget); flag3 = 1; } glCallList(targetList); glPopMatrix(); glPushMatrix(); glTranslatef(targetPoz4.x, 0, targetPoz4.z); glLightfv(GL_LIGHT5, GL_POSITION,uplightpoz); if (flag4 == 1) { glDisable(GL_LIGHT5); glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); } else if (collision(BulletPoz)==4) { glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); //if hit the target, play clap sound hitTarget = FSOUND_Stream_Open( "Resources\\Sound\\hitTarget.wav" , FSOUND_2D , 0 , 0 ); FSOUND_Stream_Play(0,hitTarget); flag4 = 1; } glCallList(targetList); glPopMatrix(); glPushMatrix(); glTranslatef(targetPoz5.x, 0, targetPoz5.z); glLightfv(GL_LIGHT6, GL_POSITION,uplightpoz); if (flag5 == 1) { glDisable(GL_LIGHT6); glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); } else if (collision(BulletPoz)==5) { glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); //if hit the target, play clap sound hitTarget = FSOUND_Stream_Open( "Resources\\Sound\\hitTarget.wav" , FSOUND_2D , 0 , 0 ); FSOUND_Stream_Play(0,hitTarget); flag5 = 1; } glCallList(targetList); glPopMatrix(); glPushMatrix(); glTranslatef(targetPoz6.x, 0, targetPoz6.z); glLightfv(GL_LIGHT7, GL_POSITION,uplightpoz); if (flag6 == 1) { glDisable(GL_LIGHT7); glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); } else if (collision(BulletPoz)==6) { glTranslatef(0, -1.6, 0); glRotatef(90, 1, 0, 0); //if hit the target, play clap sound hitTarget = FSOUND_Stream_Open( "Resources\\Sound\\hitTarget.wav" , FSOUND_2D , 0 , 0 ); FSOUND_Stream_Play(0,hitTarget); flag6 = 1; } glCallList(targetList); glPopMatrix(); glDisable(GL_TEXTURE_2D); if (flag1==1&&flag2==1&&flag3==1&&flag4==1&&flag5==1&&flag6==1) { return WIN; } }
/* [ [DESCRIPTION] [PARAMETERS] [RETURN_VALUE] [REMARKS] [SEE_ALSO] ] */ int main(int argc, char *argv[]) { FSOUND_STREAM *stream; int read_percent = 0, i, driver = 0, channel = -1, status = 0, openstate, bitrate; unsigned int flags; char s[256] = ""; char key; if (FSOUND_GetVersion() < FMOD_VERSION) { printf("Error : You are using the wrong DLL version! You should be using FMOD %.02f\n", FMOD_VERSION); return 1; } if ((argc < 2) || (strnicmp(argv[1], "http:", 5))) { printf("-------------------------------------------------------------\n"); printf("FMOD netstream example.\n"); printf("Copyright (c) Firelight Technologies Pty, Ltd, 1999-2004.\n"); printf("-------------------------------------------------------------\n"); printf("Syntax: netstream <url>\n"); printf("Example: netstream http://www.fmod.org/stream.mp3\n\n"); return 1; } #if defined(WIN32) || defined(_WIN64) || defined(__CYGWIN32__) || defined(__WATCOMC__) FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND); #elif defined(__linux__) FSOUND_SetOutput(FSOUND_OUTPUT_OSS); #endif // ========================================================================================== // SELECT DRIVER // ========================================================================================== printf("---------------------------------------------------------\n"); switch (FSOUND_GetOutput()) { case FSOUND_OUTPUT_NOSOUND: printf("NoSound"); break; case FSOUND_OUTPUT_WINMM: printf("Windows Multimedia Waveout"); break; case FSOUND_OUTPUT_DSOUND: printf("Direct Sound"); break; case FSOUND_OUTPUT_A3D: printf("A3D"); break; case FSOUND_OUTPUT_OSS: printf("Open Sound System"); break; case FSOUND_OUTPUT_ESD: printf("Enlightenment Sound Daemon"); break; case FSOUND_OUTPUT_ALSA: printf("ALSA"); break; }; printf(" Driver list\n"); printf("---------------------------------------------------------\n"); for (i=0; i < FSOUND_GetNumDrivers(); i++) { printf("%d - %s\n", i+1, FSOUND_GetDriverName(i)); } printf("---------------------------------------------------------\n"); printf("Press a corresponding number or ESC to quit\n"); do { key = getch(); if (key == 27) exit(0); driver = key - '1'; } while (driver < 0 || driver >= FSOUND_GetNumDrivers()); FSOUND_SetDriver(driver); // ========================================================================================== // INITIALIZE // ========================================================================================== if (!FSOUND_Init(44100, 32, 0)) { printf("Error!\n"); printf("%s\n", FMOD_ErrorString(FSOUND_GetError())); FSOUND_Close(); return 1; } /* Internet streams can work with a much smaller stream buffer than normal streams because they use another level of buffering on top of the stream buffer. */ FSOUND_Stream_SetBufferSize(100); /* Here's where we set the size of the network buffer and some buffering parameters. In this case we want a network buffer of 64k, we want it to prebuffer 60% of that when we first connect, and we want it to rebuffer 80% of that whenever we encounter a buffer underrun. */ FSOUND_Stream_Net_SetBufferProperties(64000, 60, 80); /* Open the stream using FSOUND_NONBLOCKING because the connect/buffer process might take a long time */ stream = FSOUND_Stream_Open(argv[1], FSOUND_NORMAL | FSOUND_NONBLOCKING, 0, 0); if (!stream) { printf("Error!\n"); printf("%s\n", FMOD_ErrorString(FSOUND_GetError())); FSOUND_Close(); return 1; } printf("\nPress ESC to quit...\n\n"); key = 0; do { if (kbhit()) { key = getch(); } /* Play the stream if it's not already playing */ if (channel < 0) { channel = FSOUND_Stream_PlayEx(FSOUND_FREE, stream, NULL, TRUE); FSOUND_SetPaused(channel, FALSE); if (channel != -1) { FSOUND_Stream_Net_SetMetadataCallback(stream, metacallback, 0); } } openstate = FSOUND_Stream_GetOpenState(stream); if ((openstate == -1) || (openstate == -3)) { printf("\nERROR: failed to open stream!\n"); printf("SERVER: %s\n", FSOUND_Stream_Net_GetLastServerStatus()); break; } FSOUND_Stream_Net_GetStatus(stream, &status, &read_percent, &bitrate, &flags); /* Show how much of the net buffer is used and what the status is */ if (metanum) { printf("%s - %s\n", artist, title); metanum = 0; } s[0] = 0; strncat(s, bar, (read_percent >> 1) + (read_percent & 1)); strncat(s, nobar, (100 - read_percent) >> 1); printf("|%s| %d%% %s\r", s, read_percent, status_str[status]); Sleep(16); } while (key != 27); printf("\n"); FSOUND_Stream_Close(stream); FSOUND_Close(); return 0; }
int main ( int argc, char* args[] ) { init(); srand(time(NULL)); int FPS = 0; ///////GLOBAL LOADING tex_spikes = loadTexture("data/gfx/Spikes.png"); tex_block1 = loadTexture("data/gfx/block1.png"); tex_menu = loadTexture("data/gfx/menu.png"); tex_playgame = loadTexture("data/gfx/playgame.png"); tex_selectlevel = loadTexture("data/gfx/selectlevel.png"); tex_editor = loadTexture("data/gfx/editor.png"); tex_exit = loadTexture("data/gfx/exitmenu.png"); tex_player1 = loadTexture("data/gfx/player.png"); tex_door = loadTexture("data/gfx/door.png"); tex_font = loadTexture("data/gfx/font.png"); tex_done = loadTexture("data/gfx/ok.png"); tex_gold = loadTexture("data/gfx/gold.png"); tex_silver = loadTexture("data/gfx/silver.png"); tex_bronze = loadTexture("data/gfx/bronze.png"); tex_eyes = loadTexture("data/gfx/playgame.png"); tex_arrow = loadTexture("data/gfx/arrow.png"); tex_info = loadTexture("data/gfx/info.png"); ///////soundsss sample_playerJump = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/jump.wav",0,0,0); FSOUND_Sample_SetDefaults(sample_playerJump, -1,100,-1,-1); sample_playerHit = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/hit.wav",0,0,0); FSOUND_Sample_SetDefaults(sample_playerHit, -1,100,-1,-1); sample_playerForce = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/force.wav",0,0,0); FSOUND_Sample_SetDefaults(sample_playerForce, -1,100,-1,-1); song2 = FSOUND_Stream_Open( "data/music/Random-SitgesSavepoint.mp3",FSOUND_LOOP_NORMAL,0,0); FSOUND_Stream_Play( 1, song2 ); FSOUND_Stream_SetLoopCount(song2,-1); //FSOUND_SetVolume(1,80); std::ifstream file ("data/levels/score.lvl"); while ( !file.eof() ) { o_scores.push_back(new Score()); file >> o_scores.back()->i_number; file >> o_scores.back()->b_unlocked; file >> o_scores.back()->i_highScore; file >> o_scores.back()->i_B; file >> o_scores.back()->i_S; file >> o_scores.back()->i_G; } file.close(); //o_scores.pop_back(); gameState = new StateMenu(); currentGameState = STATE_MENU; /* for ( int n = 0; n < 100; n++ ) { o_scores.push_back( new Score () ); o_scores.back()->b_unlocked = true; o_scores.back()->i_highScore = 0; o_scores.back()->i_B = 0; o_scores.back()->i_G = 0; o_scores.back()->i_S = 0; }*/ //saving FPSA = SDL_GetTicks(); while ( nextGameState != STATE_EXIT ) { FPS = SDL_GetTicks(); gameState->handleEvents(); gameState->logic(); FPSA = SDL_GetTicks(); gameState->render(); changeGameState(); //////////////////////////// if ( (SDL_GetTicks() - FPS) < 1000/60 ) { //SDL_Delay( ( 1000/60) - (SDL_GetTicks() - FPS) ); } SDL_Delay(2); } FSOUND_Stream_Close(song2); FSOUND_Close(); return 0; }