bool playMOD (int f, int a, int fromTrack) { if (soundOK) { stopMOD (a); setResourceForFatal (f); uint32_t length = openFileFromNum (f); if (length == 0) return NULL; char * memImage; memImage = loadEntireFileToMemory (bigDataFile, length); if (! memImage) return fatal (ERROR_MUSIC_MEMORY_LOW); mod[a] = BASS_MusicLoad (true, memImage, 0, length, BASS_MUSIC_LOOP|BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/, 0); delete memImage; if (! mod[a]) { } else { setMusicVolume (a, defVol); if (! BASS_ChannelPlay (mod[a], true) ) debugOut("playMOD: Error %d!\n", BASS_ErrorGetCode()); BASS_ChannelSetPosition (mod[a], MAKELONG(fromTrack, 0), BASS_POS_MUSIC_ORDER); BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP, BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP); } setResourceForFatal (-1); } return true; }
int cacheSound (int f) { setResourceForFatal (f); if (! soundOK) return 0; int a = findInSoundCache (f); if (a != -1) return a; if (f == -2) return -1; a = findEmptySoundSlot (); freeSound (a); uint32_t length = openFileFromNum (f); if (! length) return -1; char * memImage; bool tryAgain = true; while (tryAgain) { memImage = loadEntireFileToMemory (bigDataFile, length); tryAgain = memImage == NULL; if (tryAgain) { if (! forceRemoveSound ()) { fatal (ERROR_SOUND_MEMORY_LOW); return -1; } } } for (;;) { // soundWarning (" Trying to load sound into slot", a); soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535, 0); if (soundCache[a].sample) { soundCache[a].fileLoaded = f; delete memImage; setResourceForFatal (-1); return a; } warning (ERROR_SOUND_ODDNESS); soundCache[a].sample = NULL; soundCache[a].fileLoaded = -1; soundCache[a].looping = false; return -1; } }
bool playMOD (int f, int a, int fromTrack) { if (! soundOK) return true; stopMOD (a); setResourceForFatal (f); uint32_t length = openFileFromNum (f); if (length == 0) { finishAccess(); setResourceForFatal (-1); return false; } unsigned char * memImage; memImage = (unsigned char *) loadEntireFileToMemory (bigDataFile, length); if (! memImage) return fatal (ERROR_MUSIC_MEMORY_LOW); modCache[a].stream = alureCreateStreamFromMemory(memImage, length, 19200, 0, NULL); delete memImage; if (modCache[a].stream != NULL) { setMusicVolume (a, defVol); if (! alureSetStreamOrder (modCache[a].stream, fromTrack)) { debugOut( "Failed to set stream order: %s\n", alureGetErrorString()); } playStream (a, true, true); } else { debugOut("Failed to create stream from MOD: %s\n", alureGetErrorString()); warning (ERROR_MUSIC_ODDNESS); soundCache[a].stream = NULL; soundCache[a].playing = false; soundCache[a].playingOnSource = 0; } setResourceForFatal (-1); return true; }
int cacheSound (int f) { if (! soundOK) return -1; unsigned int chunkLength; int retval; bool loopy; loopy = cacheLoopySound; cacheLoopySound = false; setResourceForFatal (f); if (! soundOK) return 0; int a = findInSoundCache (f); if (a != -1) { if (soundCache[a].playing) { if (! alureStopSource(soundCache[a].playingOnSource, AL_TRUE)) { debugOut( "Failed to stop source: %s\n", alureGetErrorString()); } } if (! alureRewindStream (soundCache[a].stream)) { debugOut( "Failed to rewind stream: %s\n", alureGetErrorString()); } return a; } if (f == -2) return -1; a = findEmptySoundSlot (); freeSound (a); uint32_t length = openFileFromNum (f); if (! length) return -1; unsigned char * memImage; bool tryAgain = true; while (tryAgain) { memImage = (unsigned char*)loadEntireFileToMemory (bigDataFile, length); tryAgain = memImage == NULL; if (tryAgain) { if (! forceRemoveSound ()) { fatal (ERROR_SOUND_MEMORY_LOW); return -1; } } } chunkLength = 19200; // Small looping sounds need small chunklengths. if (loopy) { if (length < NUM_BUFS * chunkLength) { chunkLength = length / NUM_BUFS; } } else if (length < chunkLength) { chunkLength = length; } soundCache[a].stream = alureCreateStreamFromMemory(memImage, length, chunkLength, 0, NULL); delete memImage; if (soundCache[a].stream != NULL) { soundCache[a].fileLoaded = f; setResourceForFatal (-1); retval = a; } else { debugOut("Failed to create stream from sound: %s\n", alureGetErrorString()); warning (ERROR_SOUND_ODDNESS); soundCache[a].stream = NULL; soundCache[a].playing = false; soundCache[a].playingOnSource = 0; soundCache[a].fileLoaded = -1; soundCache[a].looping = false; retval = -1; } return retval; }