void sound_load(const char* filename) { sound_unload(); strcpy(current_file, filename); #if defined WIN32 wchar_t wide_filename[PATH_LENGTH]; fl_utf8towc(current_file, PATH_LENGTH, wide_filename, PATH_LENGTH); if (FMOD_System_CreateStream(_system, (char*) wide_filename, FMOD_DEFAULT | FMOD_UNICODE | FMOD_ACCURATETIME, 0, &_sound) != FMOD_OK) return; #else if (FMOD_System_CreateStream(_system,current_file, FMOD_DEFAULT | FMOD_ACCURATETIME, 0, &_sound) != FMOD_OK) return; #endif loaded = true; }
bool ModuleIrisAudio::MePlay(wstring filePath, int volume, int rate){ string sfilepath = WStringToString(filePath); const char* fpath = sfilepath.c_str(); if (channels == 0){ if (meChannel != NULL){ BOOL isPlaying; FMOD_Channel_IsPlaying(meChannel, &isPlaying); if (isPlaying) FMOD_Channel_Stop(meChannel); } } FMOD_RESULT result; result = FMOD_System_CreateStream(fmodSystem, fpath, FMOD_DEFAULT, 0, &me); if (result != FMOD_OK) return false; result = FMOD_System_PlaySound(fmodSystem, FMOD_CHANNEL_FREE, me, true, &meChannel); if (result != FMOD_OK) return false; FMOD_Channel_SetMode(meChannel, FMOD_LOOP_NORMAL); FMOD_Channel_SetVolume(meChannel, volume / 100.0f); float frequancy; FMOD_Channel_GetFrequency(meChannel, &frequancy); FMOD_Channel_SetFrequency(meChannel, frequancy * (rate / 100.0)); FMOD_Channel_SetPaused(meChannel, FALSE); return true; }
sound_system_c::sound_system_c(const char *song_name) { // Init FMOD fmod_errorcheck(FMOD_System_Create(&fmod_system)); fmod_errorcheck(FMOD_System_SetSoftwareFormat(fmod_system, OUTPUTRATE, FMOD_SOUND_FORMAT_PCM16, 2, 0, FMOD_DSP_RESAMPLER_LINEAR)); fmod_errorcheck(FMOD_System_Init(fmod_system, 32, FMOD_INIT_NORMAL, 0)); // Init song fmod_errorcheck(FMOD_System_CreateStream(fmod_system, song_name, FMOD_LOOP_NORMAL | FMOD_2D | FMOD_HARDWARE | FMOD_UNIQUE, 0, &music)); }
INT32 I_RegisterSong(void *data, size_t len) { FMOD_CREATESOUNDEXINFO fmt; memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); fmt.length = len; FMR(FMOD_System_CreateStream(fsys, (char *)data, FMOD_OPENMEMORY_POINT, &fmt, &music_stream)); return 1337; }
cSoundSourceFmod(cSoundSystemFmod *soundsystem, const float x, const float y, const float z, const char *filename) : mSoundSystem(soundsystem), mpChannel(0), mb3D(true), mpSound(0), mfMinDistance(100.0f), mfMaxDistance(100000.0f) { if(mSoundSystem && mSoundSystem->mpSystem){ result = FMOD_System_CreateStream(mSoundSystem->mpSystem, filename, (FMOD_MODE)(FMOD_SOFTWARE | FMOD_3D), 0, &mpSound); ERRCHECK(result); SetPosition(x,y,z); SetVelocity(0,0,0); } }
//loads a soundfile void Sound::Load(const char * filename) { s_current_sound = (char *)filename; if (s_enabled) { s_result = FMOD_Sound_Release(s_sound); s_result = FMOD_System_CreateStream(s_fmod_system, s_current_sound, FMOD_SOFTWARE, 0, &s_sound); assert(s_result == FMOD_OK); } }
FMOD_CHANNEL* Game::playMusic (const char* songName) { FMOD_SOUND *audiostream; songchan = NULL; FMOD_System_CreateStream (system, songName, FMOD_DEFAULT, 0, &audiostream); FMOD_Channel_SetChannelGroup (songchan, songMusic); FMOD_System_PlaySound(system,audiostream,songMusic,false,&songchan); //cursong = audiostream; return songchan; }
//loads a soundfile void Sound::load (const char * filename) { currentSound = (char *)filename; if (possible && on) { result = FMOD_Sound_Release(sound); result = FMOD_System_CreateStream(fmodsystem, currentSound, FMOD_LOOP_NORMAL, 0, &sound); if (result != FMOD_OK) { possible = false; printf("%s: %s\n", FMOD_ErrorString(result), filename); } } }
bool FmodSound::Load( const std::string & musicFileName ) { if( IsLoaded() ) Free(); FMOD_RESULT ret; ret = FMOD_System_CreateStream(m_pSystem, musicFileName.c_str(), FMOD_HARDWARE | FMOD_2D | FMOD_LOOP_NORMAL, 0, &m_pSound); assert( ret == FMOD_OK ); return ret == FMOD_OK; }
void Sound::load(const std::string &filename) { currentSound = filename; if (possible && isOn) { result = FMOD_Sound_Release(sound); result = FMOD_System_CreateStream(fmodsystem, currentSound.c_str(), FMOD_SOFTWARE, 0, &sound); if (result != FMOD_OK) possible = false; } }
void Audio::playBGM(const QString &filename) { FMOD_RESULT result = FMOD_System_CreateStream(System, filename.toLocal8Bit(), FMOD_LOOP_NORMAL, NULL, &BGM); if (result == FMOD_OK) { FMOD_Sound_SetLoopCount(BGM, -1); FMOD_System_PlaySound(System, FMOD_CHANNEL_FREE, BGM, false, &BGMChannel); FMOD_Channel_SetVolume(BGMChannel, Config.BGMVolume); FMOD_System_Update(System); } }
void CDA_Startup (qboolean notify) { #ifdef UQE_FMOD_CDAUDIO int i; int numdrives; if (fmod_musicCD) return; // bump up the file buffer size a bit from the 16k default for CDDA, because it is a slower medium. result = FMOD_System_SetStreamBufferSize(fmod_system, 64*1024, FMOD_TIMEUNIT_RAWBYTES); FMOD_ERROR(result, notify, false); result = FMOD_System_GetNumCDROMDrives(fmod_system, &numdrives); FMOD_ERROR(result, notify, false); for(i = 0; i < numdrives; i++) { char drivename[MAX_QPATH]; char scsiname[MAX_QPATH]; char devicename[MAX_QPATH]; result = FMOD_System_GetCDROMDriveName(fmod_system, i, drivename, MAX_QPATH, scsiname, MAX_QPATH, devicename, MAX_QPATH); FMOD_ERROR(result, notify, false); if(result == FMOD_OK) { result = FMOD_System_CreateStream(fmod_system, drivename, FMOD_OPENONLY, 0, &fmod_musicCD); if(result == FMOD_OK) { result = FMOD_Sound_GetNumSubSounds(fmod_musicCD, &numtracks); FMOD_ERROR(result, notify, false); if(result == FMOD_OK) { Con_Printf("CD Audio Initialized (%s)\n", drivename); SND_InitialisedCD = true; break; } } } } FMOD_ERROR(result, notify, false); #else CDAudio_Init(); #endif }
FMOD_SOUND * bmx_FMOD_System_CreateStream(FMOD_SYSTEM *system, const char * filename, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO * exInfo, FMOD_RESULT * result) { FMOD_SOUND * sound; *result = FMOD_System_CreateStream(system, filename, mode, exInfo, &sound); if (*result) { return 0; } return sound; }
void Java_org_fmod_realtimestitching_Example_cUpdate(JNIEnv *env, jobject thiz) { FMOD_RESULT result = FMOD_OK; /* 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(gChannel, &gCurrentSubSoundID, (FMOD_TIMEUNIT)(FMOD_TIMEUNIT_SENTENCE_SUBSOUND | FMOD_TIMEUNIT_BUFFERED)); CHECK_RESULT(result); if (gCurrentSubSoundID != gSubSoundID) { /* Release the sound that isn't playing any more. */ result = FMOD_Sound_Release(gSubSound[gSubSoundID]); CHECK_RESULT(result); /* Replace it with a new sound in our list. */ result = FMOD_System_CreateStream(gSystem, gSoundName[gSentenceID], FMOD_DEFAULT, 0, &gSubSound[gSubSoundID]); CHECK_RESULT(result); result = FMOD_Sound_SetSubSound(gSound, gSubSoundID, gSubSound[gSubSoundID]); CHECK_RESULT(result); sprintf(s, "Replacing subsound %d / 2 with sound %d / %d\n", gSubSoundID, gSentenceID, NUMSOUNDS); __android_log_write(ANDROID_LOG_INFO, "fmod_realtimestitching", s); gSentenceID++; if (gSentenceID >= NUMSOUNDS) { gSentenceID = 0; } gSubSoundID = gCurrentSubSoundID; } result = FMOD_System_Update(gSystem); CHECK_RESULT(result); }
Sound::Sound(const char *file, int _mode,Vector &_pos, Vector&_vel, FMOD_SYSTEM *_system, FMOD_RESULT &_result) { system = _system; result = &_result; if(_mode > 1) { mode =_mode = 0; }else { mode = _mode; } switch(_mode) { case SOUND: *result = FMOD_System_CreateSound(system, file, FMOD_DEFAULT, 0, &sound); this->setSoundMode(FMOD_LOOP_OFF); break; case STREAM: *result = FMOD_System_CreateStream(system, file, FMOD_DEFAULT, 0,&sound); this->setSoundMode(FMOD_LOOP_NORMAL); break; } ERRCHECK(); pos = &_pos; vel = &_vel; f_pos.x = pos->X_Y_Z[0]; f_pos.y = pos->X_Y_Z[1]; f_pos.z = pos->X_Y_Z[2]; f_vel.x = vel->X_Y_Z[0]; f_vel.y = vel->X_Y_Z[1]; f_vel.z = vel->X_Y_Z[2]; //*result = channel->set3DAttributes(&f_pos,&f_vel); *result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, true, &channel); ERRCHECK(); *result = FMOD_Channel_Set3DAttributes(channel,&f_pos,&f_vel); ERRCHECK(); *result = FMOD_Channel_SetPaused(channel, true); ERRCHECK(); }
bool Chunk::Load( const std::string & musicFileName ) { m_pSystem = gpSystem; if( IsLoaded() ) Free(); FMOD_RESULT ret = FMOD_System_CreateStream(m_pSystem, musicFileName.c_str(), FMOD_HARDWARE | FMOD_2D | FMOD_LOOP_NORMAL, 0, &m_pSound); /* FMOD_RESULT ret = m_pSystem->createStream( musicFileName.c_str(), FMOD_HARDWARE | FMOD_2D | FMOD_LOOP_NORMAL, 0, &m_pSound); */ return ret == FMOD_OK; }
void PlayLoopAudio(char* filename) { FMOD_SOUND *sound; FMOD_RESULT result; int key; unsigned int version; // Create a System object and initialize. if (systemFMOD == NULL) { result = FMOD_System_Create(&systemFMOD); result = FMOD_System_Init(systemFMOD, 1, FMOD_INIT_NORMAL, NULL); } result = FMOD_System_CreateStream(systemFMOD, filename, FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound); //Play the sound. result = FMOD_System_PlaySound(systemFMOD, FMOD_CHANNEL_FREE, sound, 0, &channel); }
void InitSound( void ) { if( FMOD_System_Create( &fmodSystem ) != FMOD_OK ) { musicOn = soundOn = false; return; } result = FMOD_System_Init( fmodSystem, 32, FMOD_INIT_NORMAL, NULL ); for( int index = 0; index < kNumSounds; ++index ) { result = FMOD_System_CreateStream( fmodSystem, QuickResourceName( "snd", index+128, ".wav" ), FMOD_SOFTWARE | FMOD_LOOP_OFF, NULL, &sound[index] ); if( result != FMOD_OK ) { musicOn = soundOn = false; return; } } }
unsigned int JiwokFMODWrapper::GetLength(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; result = FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_MS); ERRCHECK(result); result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return length; }
void AudioManager::Load( const AudioManager::AudioType Type, const string& ID, const string& Path, const FMOD_MODE Mode, FMOD_CREATESOUNDEXINFO* ExInfo ) { // Create local variables. FMOD_RESULT FMODResult; SoundData Sound = { nullptr, nullptr }; // Check arguments. if( Type == MaxAudioTypes ) throw exception(); // Load the specified audio file and insert it into the appropriate audio map. if( Initialized ) { if( AudioMaps[ Type ].Instance.find( ID ) != AudioMaps[ Type ].Instance.end() ) throw exception(); if( !( Type % 2 ) ) FMODResult = FMOD_System_CreateSound( SystemInstance, Path.c_str(), Mode, ExInfo, &Sound.Instance ); else FMODResult = FMOD_System_CreateStream( SystemInstance, Path.c_str(), Mode, ExInfo, &Sound.Instance ); if( FMODResult != FMOD_OK ) throw exception(); if( FMOD_System_CreateChannelGroup( SystemInstance, nullptr, &Sound.Group ) != FMOD_OK ) throw exception(); if( FMOD_ChannelGroup_AddGroup( ChannelGroups[ AudioMaps[ Type ].Group ].Instance, Sound.Group ) != FMOD_OK ) throw exception(); AudioMaps[ Type ].Instance[ ID ] = Sound; } }
void SSVisualizer::Startup( SubsystemCollection* const subsystemCollection ) { //set up FMOD FMOD_System_Create(&m_SoundSystem); FMOD_System_SetSoftwareFormat(m_SoundSystem, 48000, FMOD_SOUND_FORMAT_PCM16, 2, 0, FMOD_DSP_RESAMPLER_LINEAR); FMOD_System_Init(m_SoundSystem, 32, FMOD_INIT_NORMAL, nullptr); FMOD_System_CreateStream(m_SoundSystem, "../../../asset/music/Metroid_The_Crimson_Depths_OC_ReMix.mp3", FMOD_LOOP_NORMAL | FMOD_2D | FMOD_HARDWARE | FMOD_UNIQUE, nullptr, &m_Song); FMOD_System_PlaySound(m_SoundSystem, FMOD_CHANNEL_FREE, m_Song, false, &m_Channel); //set up GL m_RenderProgram.LoadCompleteShaderProgramFromFile("../../../shader/ParticleRender.glsl", true); glGenBuffers(1, &m_VBO); glGenVertexArrays(1, &m_VAO); glBindVertexArray(m_VAO); glBindBuffer(GL_ARRAY_BUFFER, m_VBO); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Particle2), nullptr); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Particle2), (unsigned char*) nullptr + sizeof(glm::vec4)); glBufferData(GL_ARRAY_BUFFER, sizeof(Particle2) * SPECTRUM_SIZE, nullptr, GL_DYNAMIC_DRAW); //set up allocator m_Allocator = new StackAllocator(sizeof(Particle2) * SPECTRUM_SIZE * 3); //get a bit more than needed but oh well m_Marker = m_Allocator->GetMarker(); }
cSoundSourceFmod(cSoundSystemFmod *soundsystem, const char *buffer, const int size, const int channels, const int bitrate, const int frequency) : mSoundSystem(soundsystem), mpChannel(0), mb3D(false), mpSound(0), mfMinDistance(100.0f), mfMaxDistance(100000.0f) { if(mSoundSystem && mSoundSystem->mpSystem){ FMOD_CREATESOUNDEXINFO exinfo; memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.length = size; exinfo.numchannels = channels; exinfo.defaultfrequency = frequency; switch(bitrate){ case 8:exinfo.format = FMOD_SOUND_FORMAT_PCM8;break; case 16:exinfo.format = FMOD_SOUND_FORMAT_PCM16;break; case 24:exinfo.format = FMOD_SOUND_FORMAT_PCM24;break; case 32:exinfo.format = FMOD_SOUND_FORMAT_PCM32;break; } result = FMOD_System_CreateStream(mSoundSystem->mpSystem, buffer, (FMOD_MODE)(FMOD_OPENRAW | FMOD_OPENMEMORY | FMOD_SOFTWARE | FMOD_2D), &exinfo, &mpSound); ERRCHECK(result); } SetPosition(0.0f,0.0f,0.0f); SetVelocity(0.0f,0.0f,0.0f); }
int main(int argc, char *argv[]) { FMOD_RESULT result; FMOD_EVENTSYSTEM *eventsystem; FMOD_EVENTGROUP *eventgroup; FMOD_EVENT *event; int key; printf("======================================================================\n"); printf("Programmer Sound. Copyright (c) Firelight Technologies 2006-2011.\n"); printf("======================================================================\n"); ERRCHECK(result = FMOD_EventSystem_Create(&eventsystem)); ERRCHECK(result = FMOD_EventSystem_Init(eventsystem, 64, FMOD_INIT_NORMAL, 0, FMOD_EVENT_INIT_NORMAL)); ERRCHECK(result = FMOD_EventSystem_SetMediaPath(eventsystem, (char *)MEDIA_PATH)); ERRCHECK(result = FMOD_EventSystem_Load(eventsystem, "examples.fev", 0, 0)); ERRCHECK(result = FMOD_EventSystem_GetGroup(eventsystem, "examples/FeatureDemonstration/SequencingAndStitching", FMOD_EVENT_DEFAULT, &eventgroup)); ERRCHECK(result = FMOD_EventSystem_GetSystemObject(eventsystem, &sys)); ERRCHECK(result = FMOD_System_CreateStream(sys, FSB_NAME, FMOD_2D | FMOD_NONBLOCKING | FMOD_SOFTWARE, 0, &fsb)); initIndexMap(fsb); printf("======================================================================\n"); printf("Press 'Space' to start the 'Programmer Sound' event\n"); printf("Press '>' to increase sound index\n"); printf("Press '<' to decrease sound index\n"); printf("Press 'Esc' to quit\n"); printf("======================================================================\n"); printf("Sound index = %d\n", g_sound_index + 1); key = 0; do { if (_kbhit()) { key = _getch(); switch(key) { case ' ' : ERRCHECK(result = FMOD_EventGroup_GetEvent(eventgroup, "ProgrammerSounds", FMOD_EVENT_DEFAULT, &event)); ERRCHECK(result = FMOD_Event_SetCallback(event, eventcallback, 0)); ERRCHECK(result = FMOD_Event_Start(event)); break; case '>' : case '.': ++g_sound_index; g_sound_index = (g_sound_index >= SOUND_INDEX_MAX) ? SOUND_INDEX_MAX - 1 : g_sound_index; printf("Sound index = %d\n", g_sound_index + 1); break; case '<' : case ',': --g_sound_index; g_sound_index = (g_sound_index < 0) ? 0 : g_sound_index; printf("Sound index = %d\n", g_sound_index + 1); break; } } ERRCHECK(result = FMOD_EventSystem_Update(eventsystem)); Sleep(10); } while (key != 27); ERRCHECK(result = FMOD_EventSystem_Unload(eventsystem)); ERRCHECK(result = FMOD_Sound_Release(fsb)); ERRCHECK(result = FMOD_EventSystem_Release(eventsystem)); return 0; }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *cdsound; FMOD_CHANNEL *channel = 0; FMOD_RESULT result; int key; unsigned int numtracks, currenttrack = 0; unsigned int version; printf("==================================================================\n"); printf("CDPlayer Example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("==================================================================\n\n"); /* 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); /* Bump up the file buffer size a bit from the 16k default for CDDA, because it is a slower medium. */ result = FMOD_System_SetStreamBufferSize(system, 64*1024, FMOD_TIMEUNIT_RAWBYTES); ERRCHECK(result); /* Try a few drive letters. */ result = FMOD_System_CreateStream(system, "d:", FMOD_OPENONLY, 0, &cdsound); if (result != FMOD_OK) { result = FMOD_System_CreateStream(system, "e:", FMOD_OPENONLY, 0, &cdsound); if (result != FMOD_OK) { result = FMOD_System_CreateStream(system, "f:", FMOD_OPENONLY, 0, &cdsound); ERRCHECK(result); } } result = FMOD_Sound_GetNumSubSounds(cdsound, &numtracks); ERRCHECK(result); for (;;) { FMOD_TAG tag; if (FMOD_Sound_GetTag(cdsound, 0, -1, &tag) != FMOD_OK) { break; } if (tag.datatype == FMOD_TAGDATATYPE_CDTOC) { dump_cddb_query((FMOD_CDTOC *)tag.data); } } printf("\n========================================\n"); printf("Press SPACE to pause\n"); printf(" n to skip to next track\n"); printf(" < re-wind 10 seconds\n"); printf(" > fast-forward 10 seconds\n"); printf(" ESC to exit\n"); printf("========================================\n\n"); /* Print out length of entire CD. Did you know you can also play 'cdsound' and it will play the whole CD without gaps? */ { unsigned int lenms; result = FMOD_Sound_GetLength(cdsound, &lenms, FMOD_TIMEUNIT_MS); ERRCHECK(result); printf("Total CD length %02d:%02d\n\n", lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100); } /* Play whole CD */ result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, cdsound, FALSE, &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 ms; FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_SENTENCE_MS); if (ms >= 10000) { ms -= 10000; } else { ms = 0; } FMOD_Channel_SetPosition(channel, ms, FMOD_TIMEUNIT_SENTENCE_MS); break; } case '>' : { unsigned int ms; FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_SENTENCE_MS); ms += 10000; FMOD_Channel_SetPosition(channel, ms, FMOD_TIMEUNIT_SENTENCE_MS); break; } case 'n' : { FMOD_Channel_GetPosition(channel, ¤ttrack, FMOD_TIMEUNIT_SENTENCE_SUBSOUND); currenttrack++; if (currenttrack >= numtracks) { currenttrack = 0; } FMOD_Channel_SetPosition(channel, currenttrack, FMOD_TIMEUNIT_SENTENCE_SUBSOUND); break; } } } FMOD_System_Update(system); if (channel) { unsigned int ms; unsigned int lenms; FMOD_BOOL playing; FMOD_BOOL paused; int busy; result = FMOD_Channel_GetPaused(channel, &paused); ERRCHECK(result); result = FMOD_Channel_IsPlaying(channel, &playing); ERRCHECK(result); result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_SENTENCE_MS); ERRCHECK(result); result = FMOD_Sound_GetLength(cdsound, &lenms, FMOD_TIMEUNIT_SENTENCE_MS); ERRCHECK(result); result = FMOD_File_GetDiskBusy(&busy); ERRCHECK(result); printf("Track %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s (%s)\r", currenttrack + 1, numtracks, ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", busy ? "*" : " "); } Sleep(50); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(cdsound); 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 *cdsound; FMOD_SOUND *sound; FMOD_CHANNEL *channel = 0; FMOD_RESULT result; int key, numtracks, currenttrack = 0; unsigned int version; if (argc < 2) { printf("Usage: cdplayer <volumename>\n"); printf("Example: cdplayer \"Audio CD\"\n"); exit(-1); } printf("==================================================================\n"); printf("CDPlayer Example. Copyright (c) Firelight Technologies 2004-2011.\n"); printf("==================================================================\n\n"); /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = 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); /* Bump up the file buffer size a bit from the 16k default for CDDA, because it is a slower medium. */ result = FMOD_System_SetStreamBufferSize(system, 64*1024, FMOD_TIMEUNIT_RAWBYTES); ERRCHECK(result); result = FMOD_System_CreateStream(system, argv[1], FMOD_OPENONLY, 0, &cdsound); ERRCHECK(result); result = FMOD_Sound_GetNumSubSounds(cdsound, &numtracks); ERRCHECK(result); result = FMOD_Sound_GetSubSound(cdsound, currenttrack, &sound); ERRCHECK(result); for (;;) { FMOD_TAG tag; if (FMOD_Sound_GetTag(cdsound, 0, -1, &tag) != FMOD_OK) { break; } if (tag.datatype == FMOD_TAGDATATYPE_CDTOC) { dump_cddb_query((FMOD_CDTOC *)tag.data); } } printf("\n========================================\n"); printf("Press SPACE to pause\n"); printf(" n to skip to next track\n"); printf(" ESC to exit\n"); printf("========================================\n\n"); /* Print out length of entire CD. Did you know you can also play 'cdsound' and it will play the whole CD without gaps? */ { unsigned int lenms; result = FMOD_Sound_GetLength(cdsound, &lenms, FMOD_TIMEUNIT_MS); ERRCHECK(result); printf("Total CD length %02d:%02d\n\n", lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100); } /* Play a CD track */ result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &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 'n' : { currenttrack++; if (currenttrack >= numtracks) { currenttrack = 0; } result = FMOD_Sound_GetSubSound(cdsound, currenttrack, &sound); ERRCHECK(result); result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel); ERRCHECK(result); break; } } } FMOD_System_Update(system); if (channel) { unsigned int ms, lenms, percent = 0; FMOD_BOOL playing; FMOD_BOOL paused; 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_IsPlaying(channel, &playing); 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("\rTrack %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s", currenttrack + 1, numtracks, ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped"); fflush(stdout); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(cdsound); 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_RESULT result; 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, 0); ERRCHECK(result); result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound); ERRCHECK(result); printf("===============================================================================\n"); printf("Offline Decoding Example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("===============================================================================\n"); printf("\n"); printf("This program will open wave.mp3 and decode it into wave.raw using the\n"); printf("FMOD_Sound_ReadData function.\n"); printf("\n"); /* Decode the sound and write it to a .raw file. */ { void *data; unsigned int length = 0, read; unsigned int bytesread; FILE *outfp; #define CHUNKSIZE 4096 result = FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCMBYTES); ERRCHECK(result); outfp = fopen("output.raw", "wb"); if (!outfp) { printf("Error! Could not open output.raw output file.\n"); return 0; } data = malloc(CHUNKSIZE); if (!data) { printf("Error! Failed to allocate %d bytes.\n", CHUNKSIZE); return 0; } bytesread = 0; do { result = FMOD_Sound_ReadData(sound, (char *)data, CHUNKSIZE, &read); fwrite((char *)data, read, 1, outfp); bytesread += read; printf("writing %d bytes of %d to output.raw\r", bytesread, length); } while (result == FMOD_OK && read == CHUNKSIZE); /* Loop terminates when either 1. the read function returns an error. (ie FMOD_ERR_FILE_EOF etc). 2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi). If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size, but this will not usually happen if FMOD_ACCURATETIME is used. (this will give the correct length for VBR formats) */ printf("\n"); if (outfp) { fclose(outfp); } } printf("\n"); /* Shut down */ result = FMOD_Sound_Release(sound); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }
/* ======================================= FMODEx 文件读取 ======================================= */ CR_API sFMT_PRT* load_fmodex ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { uint_t size; void_t* data; ansi_t* path; sFMT_PRT* rett; FMOD_MODE mode; iXMM_FMOD* port; FMOD_SOUND* sound; FMOD_RESULT result; FMOD_CHANNEL* channel; FMOD_CREATESOUNDEXINFO ex_info; /* 必须先初始化 */ if (s_fmodex == NULL) return (NULL); mode = FMOD_LOOP_OFF | FMOD_2D | FMOD_HARDWARE | FMOD_ACCURATETIME; /* 不支持文件区段功能 */ switch (param->type) { case CR_LDR_ANSI: data = NULL; result = FMOD_System_CreateStream(s_fmodex, param->name.ansi, mode, NULL, &sound); break; case CR_LDR_WIDE: data = NULL; path = utf16_to_local(CR_LOCAL, param->name.wide); if (path == NULL) return (NULL); result = FMOD_System_CreateStream(s_fmodex, path, mode, NULL, &sound); mem_free(path); break; case CR_LDR_BUFF: if (cut_size(&size, param->buff.size)) return (NULL); data = mem_dup(param->buff.data, param->buff.size); if (data == NULL) return (NULL); path = (ansi_t*)data; mode |= FMOD_OPENMEMORY; mem_zero(&ex_info, sizeof(ex_info)); ex_info.cbsize = sizeof(ex_info); ex_info.length = size; result = FMOD_System_CreateStream(s_fmodex, path, mode, &ex_info, &sound); break; default: return (NULL); } /* 无法支持的格式 */ if (result != FMOD_OK) goto _failure1; /* 生成播放通道对象 */ result = FMOD_System_PlaySound(s_fmodex, FMOD_CHANNEL_FREE, sound, TRUE, &channel); if (result != FMOD_OK) goto _failure2; /* 生成媒体播放接口对象 */ port = struct_new(iXMM_FMOD); if (port == NULL) goto _failure3; struct_zero(port, iXMM_FMOD); port->m_dat = data; port->m_snd = sound; port->m_chn = channel; if (!fmodex_info(port)) { iXMM_FMOD_release((iXMMEDIA*)port); return (NULL); } port->xmms.__volume__ = 100; port->xmms.__vptr__ = &s_xmms_vtbl; /* 返回读取的文件数据 */ rett = struct_new(sFMT_PRT); if (rett == NULL) { iXMM_FMOD_release((iXMMEDIA*)port); return (NULL); } CR_NOUSE(datin); rett->type = CR_FMTZ_PRT; rett->port = (iPORT*)port; rett->more = "iXMMEDIA"; rett->infor = port->m_inf; return (rett); _failure3: FMOD_Channel_Stop(channel); _failure2: FMOD_Sound_Release(sound); _failure1: TRY_FREE(data); return (NULL); }
void Java_org_fmod_realtimestitching_Example_cBegin(JNIEnv *env, jobject thiz) { FMOD_RESULT result = FMOD_OK; FMOD_CREATESOUNDEXINFO exinfo; result = FMOD_System_Create(&gSystem); CHECK_RESULT(result); result = FMOD_System_Init(gSystem, 1, FMOD_INIT_NORMAL, 0); CHECK_RESULT(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(gSystem, 0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &gSound); CHECK_RESULT(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(gSystem, gSoundName[0], FMOD_DEFAULT, 0, &gSubSound[0]); CHECK_RESULT(result); result = FMOD_System_CreateStream(gSystem, gSoundName[1], FMOD_DEFAULT, 0, &gSubSound[1]); CHECK_RESULT(result); result = FMOD_Sound_SetSubSound(gSound, 0, gSubSound[0]); CHECK_RESULT(result); result = FMOD_Sound_SetSubSound(gSound, 1, gSubSound[1]); CHECK_RESULT(result); /* Set up the gapless sentence to contain these first 2 streams. */ { int soundlist[2] = { 0, 1 }; result = FMOD_Sound_SetSubSoundSentence(gSound, soundlist, 2); CHECK_RESULT(result); } gSubSoundID = 0; gSentenceID = 2; /* The next sound to be appended to the stream. */ sprintf(s, "Inserted subsound %d / 2 with sound %d / %d\n", 0, 0, NUMSOUNDS); __android_log_write(ANDROID_LOG_INFO, "fmod_realtimestitching", s); sprintf(s, "Inserted subsound %d / 2 with sound %d / %d\n", 1, 1, NUMSOUNDS); __android_log_write(ANDROID_LOG_INFO, "fmod_realtimestitching", s); /* Play the sound. */ result = FMOD_System_PlaySound(gSystem, FMOD_CHANNEL_FREE, gSound, 0, &gChannel); CHECK_RESULT(result); }
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-2014.\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; }
boolean I_StartDigSong(const char *musicname, boolean looping) { char *data; size_t len; FMOD_CREATESOUNDEXINFO fmt; lumpnum_t lumpnum = W_CheckNumForName(va("O_%s",musicname)); if (lumpnum == LUMPERROR) { lumpnum = W_CheckNumForName(va("D_%s",musicname)); if (lumpnum == LUMPERROR) return false; midimode = true; } else midimode = false; data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); len = W_LumpLength(lumpnum); memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); #ifdef HAVE_LIBGME if ((UINT8)data[0] == 0x1F && (UINT8)data[1] == 0x8B) { #ifdef HAVE_ZLIB UINT8 *inflatedData; size_t inflatedLen; z_stream stream; int zErr; // Somewhere to handle any error messages zlib tosses out memset(&stream, 0x00, sizeof (z_stream)); // Init zlib stream // Begin the inflation process inflatedLen = *(UINT32 *)(data + (len-4)); // Last 4 bytes are the decompressed size, typically inflatedData = (UINT8 *)Z_Calloc(inflatedLen, PU_MUSIC, NULL); // Make room for the decompressed data stream.total_in = stream.avail_in = len; stream.total_out = stream.avail_out = inflatedLen; stream.next_in = (UINT8 *)data; stream.next_out = inflatedData; zErr = inflateInit2(&stream, 32 + MAX_WBITS); if (zErr == Z_OK) // We're good to go { zErr = inflate(&stream, Z_FINISH); if (zErr == Z_STREAM_END) { // Run GME on new data if (!gme_open_data(inflatedData, inflatedLen, &gme, 44100)) { gme_equalizer_t gmeq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; Z_Free(inflatedData); // GME supposedly makes a copy for itself, so we don't need this lying around Z_Free(data); // We don't need this, either. gme_start_track(gme, 0); current_track = 0; gme_set_equalizer(gme,&gmeq); fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.defaultfrequency = 44100; fmt.numchannels = 2; fmt.length = -1; fmt.decodebuffersize = (44100 * 2) / 35; fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); FMR(FMOD_Channel_SetPriority(music_channel, 0)); return true; } } else { const char *errorType; switch (zErr) { case Z_ERRNO: errorType = "Z_ERRNO"; break; case Z_STREAM_ERROR: errorType = "Z_STREAM_ERROR"; break; case Z_DATA_ERROR: errorType = "Z_DATA_ERROR"; break; case Z_MEM_ERROR: errorType = "Z_MEM_ERROR"; break; case Z_BUF_ERROR: errorType = "Z_BUF_ERROR"; break; case Z_VERSION_ERROR: errorType = "Z_VERSION_ERROR"; break; default: errorType = "unknown error"; } CONS_Alert(CONS_ERROR,"Encountered %s when running inflate: %s\n", errorType, stream.msg); } (void)inflateEnd(&stream); } else // Hold up, zlib's got a problem { const char *errorType; switch (zErr) { case Z_ERRNO: errorType = "Z_ERRNO"; break; case Z_STREAM_ERROR: errorType = "Z_STREAM_ERROR"; break; case Z_DATA_ERROR: errorType = "Z_DATA_ERROR"; break; case Z_MEM_ERROR: errorType = "Z_MEM_ERROR"; break; case Z_BUF_ERROR: errorType = "Z_BUF_ERROR"; break; case Z_VERSION_ERROR: errorType = "Z_VERSION_ERROR"; break; default: errorType = "unknown error"; } CONS_Alert(CONS_ERROR,"Encountered %s when running inflateInit: %s\n", errorType, stream.msg); } Z_Free(inflatedData); // GME didn't open jack, but don't let that stop us from freeing this up #else //CONS_Alert(CONS_ERROR,"Cannot decompress VGZ; no zlib support\n"); #endif } else if (!gme_open_data(data, len, &gme, 44100)) { gme_equalizer_t gmeq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; Z_Free(data); // We don't need this anymore. gme_start_track(gme, 0); current_track = 0; gme_set_equalizer(gme,&gmeq); fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.defaultfrequency = 44100; fmt.numchannels = 2; fmt.length = -1; fmt.decodebuffersize = (44100 * 2) / 35; fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); FMR(FMOD_Channel_SetPriority(music_channel, 0)); return true; } #endif fmt.length = len; { FMOD_RESULT e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT|(looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream); if (e != FMOD_OK) { if (e == FMOD_ERR_FORMAT) CONS_Alert(CONS_WARNING, "Failed to play music lump %s due to invalid format.\n", W_CheckNameForNum(lumpnum)); else FMR(e); return false; } } FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); if (midimode) FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); else FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); FMR(FMOD_Channel_SetPriority(music_channel, 0)); current_track = 0; // Try to find a loop point in streaming music formats (ogg, mp3) if (looping) { FMOD_RESULT e; FMOD_TAG tag; unsigned int loopstart, loopend; // A proper LOOPPOINT is its own tag, stupid. e = FMOD_Sound_GetTag(music_stream, "LOOPPOINT", 0, &tag); if (e != FMOD_ERR_TAGNOTFOUND) { FMR(e); loopstart = atoi((char *)tag.data); // assumed to be a string data tag. FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM)); if (loopstart > 0) FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM)); return true; } // Use LOOPMS for time in miliseconds. e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag); if (e != FMOD_ERR_TAGNOTFOUND) { FMR(e); loopstart = atoi((char *)tag.data); // assumed to be a string data tag. FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_MS, &loopend, FMOD_TIMEUNIT_PCM)); if (loopstart > 0) FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_MS, loopend, FMOD_TIMEUNIT_PCM)); return true; } // Try to fetch it from the COMMENT tag, like A.J. Freda e = FMOD_Sound_GetTag(music_stream, "COMMENT", 0, &tag); if (e != FMOD_ERR_TAGNOTFOUND) { char *loopText; // Handle any errors that arose, first FMR(e); // Figure out where the number starts loopText = strstr((char *)tag.data,"LOOPPOINT="); if (loopText != NULL) { // Skip the "LOOPPOINT=" part. loopText += 10; // Convert it to our looppoint // FMOD seems to ensure the tag is properly NULL-terminated. // atoi will stop when it reaches anything that's not a number. loopstart = atoi(loopText); // Now do the rest like above FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM)); if (loopstart > 0) FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM)); } return true; } } // No special loop point, but we're playing so it's all good. return true; }