//=========================================================================== // 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; }
bool C4MusicFileMOD::Play(bool loop) { // Load Song size_t iFileSize; if (!C4Group_ReadFile(FileName, &Data, &iFileSize)) return false; // init fmusic mod = FMUSIC_LoadSongEx(Data, 0, iFileSize, FSOUND_LOADMEMORY, 0, 0); if (!mod) { LogF("FMod: %s", FMOD_ErrorString(FSOUND_GetError())); return false; } // Play Song FMUSIC_PlaySong(mod); return true; }
BOOL C4MusicFileMOD::Play(BOOL loop) { // Load Song size_t iFileSize; if(!C4Group_ReadFile(FileName, &Data, &iFileSize)) return FALSE; // init fmusic mod = FMUSIC_LoadSongEx(Data, 0, iFileSize, FSOUND_LOADMEMORY, 0, 0); if (!mod) { sprintf(OSTR, "FMod: %s", FMOD_ErrorString(FSOUND_GetError())); Log(OSTR); return FALSE; } // Play Song FMUSIC_PlaySong(mod); return TRUE; }
glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) { FILE *file; long pos, len; glui32 type; char *buf; int offset = 0; int i; if (!chan) { gli_strict_warning("schannel_play_ext: invalid id."); return 0; } /* stop previous noise */ glk_schannel_stop(chan); if (repeats == 0) return 1; /* load sound resource into memory */ if (!giblorb_is_resource_map()) { char name[1024]; sprintf(name, "%s/SND%ld", gli_workdir, snd); file = fopen(name, "rb"); if (!file) return 0; fseek(file, 0, SEEK_END); len = ftell(file); buf = malloc(len); if (!buf) { fclose(file); return 0; } fseek(file, 0, 0); fread(buf, 1, len, file); fclose(file); /* identify by file magic the two types that fmod can do... */ type = 0; /* unidentified */ /* AIFF */ if (len > 4 && !memcmp(buf, "FORM", 4)) type = giblorb_ID_FORM; /* WAVE */ if (len > 4 && !memcmp(buf, "WAVE", 4)) type = giblorb_ID_WAVE; /* MIDI */ if (len > 4 && !memcmp(buf, "MThd", 4)) type = giblorb_ID_MIDI; /* Ogg Vorbis */ if (len > 4 && !memcmp(buf, "OggS", 4)) type = giblorb_ID_OGG; /* s3m */ if (len > 0x30 && !memcmp(buf + 0x2c, "SCRM", 4)) type = giblorb_ID_MOD; /* XM */ if (len > 20 && !memcmp(buf, "Extended Module: ", 17)) type = giblorb_ID_MOD; /* MOD */ if (len > 1084) { char resname[4]; memcpy(resname, buf + 1080, 4); if (!strcmp(resname+1, "CHN") || /* 4CHN, 6CHN, 8CHN */ !strcmp(resname+2, "CN") || /* 16CN, 32CN */ !strcmp(resname, "M.K.") || !strcmp(resname, "M!K!") || !strcmp(resname, "FLT4") || !strcmp(resname, "CD81") || !strcmp(resname, "OKTA") || !strcmp(resname, " ")) type = giblorb_ID_MOD; } if (!memcmp(buf, "\377\372", 2)) /* mp3 */ type = giblorb_ID_MP3; /* look for RIFF (future boy has broken resources...?) */ if (len > 128 && type == 0) for (i = 0; i < 124; i++) if (!memcmp(buf+i, "RIFF", 4)) { offset = i; type = giblorb_ID_WAVE; break; } if (type == 0) type = giblorb_ID_MP3; } else { giblorb_get_resource(giblorb_ID_Snd, snd, &file, &pos, &len, &type); if (!file) return 0; buf = malloc(len); if (!buf) return 0; fseek(file, pos, 0); fread(buf, 1, len, file); } switch (type) { case giblorb_ID_FORM: case giblorb_ID_WAVE: case giblorb_ID_MP3: chan->sample = FSOUND_Sample_Load(FSOUND_UNMANAGED, buf + offset, FSOUND_NORMAL|FSOUND_LOADMEMORY, 0, len); if (!chan->sample) { free(buf); return 0; } if (repeats != 1) FSOUND_Sample_SetMode(chan->sample, FSOUND_LOOP_NORMAL); else FSOUND_Sample_SetMode(chan->sample, FSOUND_LOOP_OFF); chan->channel = FSOUND_PlaySound(FSOUND_FREE, chan->sample); FSOUND_SetVolume(chan->channel, chan->volume / 256); FSOUND_SetPaused(chan->channel, 0); break; case giblorb_ID_MOD: case giblorb_ID_MIDI: chan->module = FMUSIC_LoadSongEx(buf, 0, len, FSOUND_LOADMEMORY, 0, 0); if (!chan->module) { free(buf); return 0; } if (repeats != 1) FMUSIC_SetLooping(chan->module, 1); else FMUSIC_SetLooping(chan->module, 0); FMUSIC_SetMasterVolume(chan->module, chan->volume / 256); FMUSIC_PlaySong(chan->module); break; default: gli_strict_warning("schannel_play_ext: unknown resource type."); } free(buf); return 1; }
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); }
bool CSoundManager::LoadSong(char *Filename, int Nr) { if (false == InitSuccessfull) return false; bool fromrar; char *pData; char Temp[256]; unsigned long Size; char Buffer[100]; fromrar = false; // Zuerst checken, ob sich der Song in einem MOD-Ordner befindet if (CommandLineParams.RunOwnLevelList == true) { sprintf_s(Temp, "levels/%s/%s", CommandLineParams.OwnLevelList, Filename); if (FileExists(Temp)) goto loadfile; } // Dann checken, ob sich das File im Standard Ordner befindet sprintf_s(Temp, "data/%s", Filename); if (FileExists(Temp)) goto loadfile; // Auch nicht? Dann ist es hoffentlich im RAR file if (urarlib_get(&pData, &Size, Filename, RARFILENAME, convertText(RARFILEPASSWORD)) == false) { sprintf_s(Temp, "\n-> Error loading %s from Archive !\n", Filename); Protokoll.WriteText(Temp, true); return false; } else fromrar = true; loadfile: int Nummer = Nr; if (its_Songs[Nummer] != NULL) { delete(its_Songs[Nummer]); its_Songs[Nummer] = NULL; } its_Songs[Nummer] = new CSong(); if (fromrar == false) its_Songs[Nummer]->SongData = FMUSIC_LoadSong(Temp); else { its_Songs[Nummer]->SongData = FMUSIC_LoadSongEx(pData, 0, Size, FSOUND_LOADMEMORY, NULL, 0); free(pData); } // Fehler beim Laden ? // if (its_Songs[Nummer]->SongData == NULL) { strcpy_s(Buffer, strlen("\n-> Error loading ") + 1, "\n-> Error loading "); strcat_s(Buffer, strlen(Filename) + 1, Filename); strcat_s(Buffer, 3, "\n"); Protokoll.WriteText(Buffer, true); //return (-1); return false; } its_LoadedSongs++; //its_Songs[Nummer].Name = Filename; its_Songs[Nummer]->Volume = 100; its_Songs[Nummer]->FadingVolume = 0.0f; // TODO FIX /* strcpy_s(Buffer, "Load Song : "); strcat_s(Buffer, Filename); strcat_s(Buffer, " successfull\n"); Protokoll.WriteText(Buffer, false); */ //return Nummer; return true; } // LoadSong