static bool tagToString(uint32 tag, bool trim, UString &str) { tag = TO_BE_32(tag); const char *tS = reinterpret_cast<const char *>(&tag); if (!std::isprint(tS[0]) || !std::isprint(tS[1]) || !std::isprint(tS[2]) || !std::isprint(tS[3])) return false; str = UString::format("%c%c%c%c", tS[0], tS[1], tS[2], tS[3]); if (trim) str.trim(); return true; }
static bool tagToString(uint32 tag, bool trim, Common::UString &str) { tag = TO_BE_32(tag); const char *tS = (const char *) &tag; if (!std::isprint(tS[0]) || !std::isprint(tS[1]) || !std::isprint(tS[2]) || !std::isprint(tS[3])) return false; str = UString::sprintf("%c%c%c%c", tS[0], tS[1], tS[2], tS[3]); if (trim) str.trim(); return true; }
BaseSound::BaseSound(Audio::Mixer *mixer, File *file, uint32 base, bool bigendian) { _mixer = mixer; _file = file; uint res = 0; uint32 size; _file->seek(base + sizeof(uint32), SEEK_SET); if (bigendian) size = _file->readUint32BE(); else size = _file->readUint32LE(); // The Feeble Files uses set amount of voice offsets if (size == 0) size = 40000; res = size / sizeof(uint32); _offsets = (uint32 *)malloc(size + sizeof(uint32)); _freeOffsets = true; _file->seek(base, SEEK_SET); if (_file->read(_offsets, size) != size) error("Can't read offsets"); for (uint i = 0; i < res; i++) { #if defined(SCUMM_BIG_ENDIAN) if (!(bigendian)) _offsets[i] = FROM_LE_32(_offsets[i]); #endif if (bigendian) _offsets[i] = TO_BE_32(_offsets[i]); _offsets[i] += base; } // only needed for mp3 _offsets[res] = _file->size(); }
/** * Opens and inits all sound sample files. */ void SoundManager::openSampleFiles() { // Floppy and demo versions have no sample files, except for the Discworld 2 demo if (_vm->getFeatures() & GF_FLOPPY || (IsDemo && !TinselV2)) return; TinselFile f; if (_sampleIndex) // already allocated return; // open sample index file in binary mode if (f.open(_vm->getSampleIndex(sampleLanguage))) { // get length of index file f.seek(0, SEEK_END); // move to end of file _sampleIndexLen = f.pos(); // get file pointer f.seek(0, SEEK_SET); // back to beginning if (_sampleIndex == NULL) { // allocate a buffer for the indices _sampleIndex = (uint32 *)malloc(_sampleIndexLen); // make sure memory allocated if (_sampleIndex == NULL) { // disable samples if cannot alloc buffer for indices // TODO: Disabled sound if we can't load the sample index? return; } } // load data if (f.read(_sampleIndex, _sampleIndexLen) != (uint32)_sampleIndexLen) // file must be corrupt if we get to here error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); // close the file f.close(); // convert file size to size in DWORDs _sampleIndexLen /= sizeof(uint32); #ifdef SCUMM_BIG_ENDIAN // Convert all ids from LE to native format for (int i = 0; i < _sampleIndexLen; ++i) { _sampleIndex[i] = SWAP_BYTES_32(_sampleIndex[i]); } #endif // Detect format of soundfile by looking at 1st sample-index switch (TO_BE_32(_sampleIndex[0])) { case MKID_BE('MP3 '): debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected MP3 sound-data"); _soundMode = kMP3Mode; break; case MKID_BE('OGG '): debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected OGG sound-data"); _soundMode = kVorbisMode; break; case MKID_BE('FLAC'): debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected FLAC sound-data"); _soundMode = kFLACMode; break; default: debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected original sound-data"); break; } // Normally the 1st sample-index points to nothing at all _sampleIndex[0] = 0; } else { char buf[50]; sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleIndex(sampleLanguage)); GUI::MessageDialog dialog(buf, "OK"); dialog.runModal(); error(CANNOT_FIND_FILE, _vm->getSampleIndex(sampleLanguage)); } // open sample file in binary mode if (!_sampleStream.open(_vm->getSampleFile(sampleLanguage))) { char buf[50]; sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleFile(sampleLanguage)); GUI::MessageDialog dialog(buf, "OK"); dialog.runModal(); error(CANNOT_FIND_FILE, _vm->getSampleFile(sampleLanguage)); } /* // gen length of the largest sample sampleBuffer.size = _sampleStream.readUint32LE(); if (_sampleStream.eos() || _sampleStream.err()) error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); */ }