HRESULT AudioData::LoadXwma(LPCTSTR strFileName) { // Open the file HANDLE hFile = CreateFile( strFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); if( INVALID_HANDLE_VALUE == hFile ) return HRESULT_FROM_WIN32( GetLastError() ); if( INVALID_SET_FILE_POINTER == SetFilePointer( hFile, 0, NULL, FILE_BEGIN ) ) return HRESULT_FROM_WIN32( GetLastError() ); DWORD dwChunkSize; DWORD dwChunkPosition; //check the file type, should be fourccWAVE or 'XWMA' FindChunk(hFile,fourccRIFF,dwChunkSize, dwChunkPosition ); DWORD filetype; ReadChunkData(hFile,&filetype,sizeof(DWORD),dwChunkPosition); if (filetype != fourccXWMA) return E_FAIL; //Locate the 'fmt ' chunk, and copy its contents into a WAVEFORMATEXTENSIBLE structure. FindChunk(hFile,fourccFMT, dwChunkSize, dwChunkPosition ); ReadChunkData(hFile, &wfx, dwChunkSize, dwChunkPosition ); //fill out the audio data buffer with the contents of the fourccDATA chunk FindChunk(hFile,fourccDATA,dwChunkSize, dwChunkPosition ); BYTE * pDataBuffer = new BYTE[dwChunkSize]; ReadChunkData(hFile, pDataBuffer, dwChunkSize, dwChunkPosition); //Populate an XAUDIO2_BUFFER structure. buffer.AudioBytes = dwChunkSize; //buffer containing audio data buffer.pAudioData = pDataBuffer; //size of the audio buffer in bytes buffer.Flags = XAUDIO2_END_OF_STREAM; // tell the source voice not to expect any data after this buffer //fill out the wma data buffer with the contents of the fourccDPDS chunk FindChunk(hFile, fourccDPDS, dwChunkSize, dwChunkPosition); UINT32 * pDataBufferWma = new UINT32[dwChunkSize/sizeof(UINT32)]; ReadChunkData(hFile, pDataBufferWma, dwChunkSize, dwChunkPosition); //Populate an XAUDIO2_BUFFER_WMA structure. wmabuffer.PacketCount = dwChunkSize/sizeof(UINT32); wmabuffer.pDecodedPacketCumulativeBytes = pDataBufferWma; // Don't forget to close the file. CloseHandle(hFile); return S_OK; }
/* ============ GetWavinfo ============ */ static wavinfo_t GetWavinfo( char *name, byte *wav, int wavlength ) { wavinfo_t info; Com_Memset( &info, 0, sizeof( info ) ); if ( !wav ) { return info; } iff_data = wav; iff_end = wav + wavlength; // find "RIFF" chunk FindChunk( "RIFF" ); if ( !( data_p && !strncmp( (char *)data_p + 8, "WAVE", 4 ) ) ) { Com_Printf( "Missing RIFF/WAVE chunks\n" ); return info; } // get "fmt " chunk iff_data = data_p + 12; // DumpChunks (); FindChunk( "fmt " ); if ( !data_p ) { Com_Printf( "Missing fmt chunk\n" ); return info; } data_p += 8; info.format = GetLittleShort(); info.channels = GetLittleShort(); info.rate = GetLittleLong(); data_p += 4 + 2; info.width = GetLittleShort() / 8; if ( info.format != 1 ) { #if defined RTCW_ET Com_Printf( "Unsupported format: %s\n", GetWaveFormatName( info.format ) ); #endif // RTCW_XX Com_Printf( "Microsoft PCM format only\n" ); return info; } // find data chunk FindChunk( "data" ); if ( !data_p ) { Com_Printf( "Missing data chunk\n" ); return info; } data_p += 4; info.samples = GetLittleLong() / info.width; info.dataofs = data_p - wav; return info; }
std::shared_ptr<Sound_Engine::Sound> Sound_Engine::LoadSound(std::string file){ std::string::size_type po = file.find_last_of('\\'); if(po == std::string::npos) po = file.find_last_of('/');// couldnt find it with the double slashes, try a single forward slash if(po == std::string::npos) {// no slashes.. there must be no path on this string so append our asset directory to where the sounds are stored file = Internal::Asset_Dir + "Sound\\" + file; }// else the user specified some sort of directory, so use that instead. std::ifstream f(file.c_str(), std::ios::beg | std::ios::binary); assert(f); // see if the sound data has been loaded already std::map<std::string, std::weak_ptr<Internal::Sub_Sound>>::iterator soundloaded = Internal::LoadedSounds.find(file); if(soundloaded != Internal::LoadedSounds.end()) {// the data exists std::shared_ptr<Internal::Sub_Sound> ptr(soundloaded->second.lock()); if(ptr){// the sound data still exists std::shared_ptr<Sound_Engine::Sound> sound_ptr = std::make_shared<Sound_Engine::Sound>();// create a new source sound_ptr->InternalSound = ptr; Internal::Sources[sound_ptr.get()] = sound_ptr;// insert into the sources return sound_ptr; } } std::shared_ptr<Sound_Engine::Sound> retsound = std::make_shared<Sound_Engine::Sound>(); Internal::Sources[retsound.get()] = retsound; retsound->InternalSound = std::make_shared<Internal::Sub_Sound>(); Internal::LoadedSounds[file]=retsound->InternalSound; retsound->InternalSound->buffer.Flags = XAUDIO2_END_OF_STREAM; // tell the source voice not to expect any data after this buffer DWORD dwChunkSize(0); DWORD dwChunkPosition(0); //check the file type, should be fourccWAVE or 'XWMA' FindChunk(f,fourccRIFF,dwChunkSize, dwChunkPosition ); DWORD filetype(0); ReadChunkData(f, &filetype, sizeof(DWORD), dwChunkPosition); if (filetype != fourccWAVE){ if(filetype != fourccXWMA){ f.close(); OUTPUT_DEBUG_MSG("File is not a .wav, or a xwma file... uh oh"); assert(true); } } FindChunk(f,fourccFMT, dwChunkSize, dwChunkPosition ); ReadChunkData(f, &retsound->InternalSound->wfx, dwChunkSize, dwChunkPosition ); FindChunk(f,fourccDATA,dwChunkSize, dwChunkPosition ); retsound->InternalSound->buffer.AudioBytes = dwChunkSize; //buffer containing audio data BYTE *temp = new BYTE[dwChunkSize]; //size of the audio buffer in bytes retsound->InternalSound->buffer.pAudioData = temp; ReadChunkData(f, temp, dwChunkSize, dwChunkPosition); if(filetype == fourccXWMA){// the file is an xwma file... we need an extra peice of data FindChunk(f,fourccDPDS, dwChunkSize, dwChunkPosition ); // the chunksize is how many bytess there are, so we have to divide by sizeof(uint32t) to get the number of uint32's in the buffer //so chunksize will be like 24, but that is how many bytes, we need 24/4 which is 6. Because there are 6 uint32's retsound->InternalSound->wmaBuffer.PacketCount = dwChunkSize / sizeof(UINT32); UINT32 *temp2 = new UINT32[retsound->InternalSound->wmaBuffer.PacketCount]; ReadChunkData(f, temp2, dwChunkSize, dwChunkPosition); retsound->InternalSound->wmaBuffer.pDecodedPacketCumulativeBytes= temp2; } f.close(); return retsound; }
bool Audio::AddAudioFile(const char* i_AudioPath, bool bLoop, float i_InitialVolume) { WAVEFORMATEXTENSIBLE wfx = { 0 }; XAUDIO2_BUFFER buffer = { 0 }; // Open the file HANDLE hFile = CreateFile( i_AudioPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); SetFilePointer(hFile, 0, NULL, FILE_BEGIN); DWORD dwChunkSize; DWORD dwChunkPosition; //check the file type, should be fourccWAVE or 'XWMA' FindChunk(hFile, fourccRIFF, dwChunkSize, dwChunkPosition); DWORD filetype; ReadChunkData(hFile, &filetype, sizeof(DWORD), dwChunkPosition); if (filetype != fourccWAVE) return false; FindChunk(hFile, fourccFMT, dwChunkSize, dwChunkPosition); ReadChunkData(hFile, &wfx, dwChunkSize, dwChunkPosition); //fill out the audio data buffer with the contents of the fourccDATA chunk FindChunk(hFile, fourccDATA, dwChunkSize, dwChunkPosition); BYTE * pDataBuffer = new BYTE[dwChunkSize]; ReadChunkData(hFile, pDataBuffer, dwChunkSize, dwChunkPosition); buffer.AudioBytes = dwChunkSize; //buffer containing audio data buffer.pAudioData = pDataBuffer; //size of the audio buffer in bytes buffer.Flags = XAUDIO2_END_OF_STREAM; // tell the source voice not to expect any data after this buffer if (bLoop) { buffer.LoopLength = 0; buffer.LoopCount = XAUDIO2_LOOP_INFINITE; } HRESULT hr; IXAudio2SourceVoice* pSourceVoice; if (FAILED(hr = s_pXAudio2->CreateSourceVoice(&pSourceVoice, (WAVEFORMATEX*)&wfx))) return false; if (FAILED(hr = pSourceVoice->SubmitSourceBuffer(&buffer))) return false; pSourceVoice->SetVolume(i_InitialVolume); s_SourceVoices.push_back(pSourceVoice); s_AudioBuffers.push_back(buffer); }
bool SPWavFile::LoadWave() { if (path == L"") { return false; } DWORD dwChunkSize; DWORD dwChunkPosition; DWORD filetype; // Check the file type, should be fourccWAVE or 'XWMA' FindChunk(fourccRIFF, dwChunkSize, dwChunkPosition ); ReadChunkData(&filetype, sizeof(DWORD), dwChunkPosition); if (filetype != fourccWAVE) { return false; } // Locate the 'fmt ' chunk, and copy its contents into a // WAVEFORMATEXTENSIBLE structure. FindChunk(fourccFMT, dwChunkSize, dwChunkPosition ); ReadChunkData(&wfx, dwChunkSize, dwChunkPosition ); // // Find the beginning position and the size of stream data. // FindChunk(fourccDATA, soundDataLength, soundDataOffset); SetPosition(soundDataOffset); // // Calculate sound length. // int stereo = wfx.nChannels; int numberBytePerChannalSample = wfx.wBitsPerSample / 8; int bytePerSample = stereo * numberBytePerChannalSample; int sampleRate = wfx.nSamplesPerSec; float seconds = soundDataLength / (float)(sampleRate * bytePerSample); songLength = seconds; // // Set loaded flag. // isLoaded = true; return true; }
void Sound::loadMusic(IXAudio2SourceVoice* &voice, std::string filename, BYTE* &soundBuffer, UINT32* &xwmaBuffer) { WAVEFORMATEXTENSIBLE wfx; ZeroMemory(&wfx, sizeof(WAVEFORMATEXTENSIBLE)); HANDLE fileHandle = CreateFile((const char*) filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); DWORD chunkSize = 0; DWORD chunkPos = 0; DWORD fileType = 0; FindChunk(fileHandle, 'FFIR', chunkSize, chunkPos); ReadChunkData(fileHandle, &fileType, sizeof(DWORD), chunkPos); FindChunk(fileHandle, ' tmf', chunkSize, chunkPos); ReadChunkData(fileHandle, &wfx, chunkSize, chunkPos); // Read in audio data FindChunk(fileHandle, 'atad', chunkSize, chunkPos); soundBuffer = new BYTE[chunkSize]; ReadChunkData(fileHandle, soundBuffer, chunkSize, chunkPos); XAUDIO2_BUFFER buffer; ZeroMemory(&buffer, sizeof(XAUDIO2_BUFFER)); buffer.AudioBytes = chunkSize; buffer.pAudioData = soundBuffer; buffer.Flags = XAUDIO2_END_OF_STREAM; buffer.LoopCount = XAUDIO2_LOOP_INFINITE; XAUDIO2_BUFFER_WMA wmaBuffer; ZeroMemory(&wmaBuffer, sizeof(XAUDIO2_BUFFER_WMA)); FindChunk(fileHandle, 'sdpd', chunkSize, chunkPos); // Divide chunk size by sizeof(DWORD) and assign wmaBuffer.PacketCount = chunkSize / 4; xwmaBuffer = (UINT32*) new BYTE[chunkSize]; ReadChunkData(fileHandle, xwmaBuffer, chunkSize, chunkPos); wmaBuffer.pDecodedPacketCumulativeBytes = xwmaBuffer; audio->CreateSourceVoice(&voice, (WAVEFORMATEX*) &wfx, XAUDIO2_VOICE_USEFILTER, 2.0f, NULL, &musicSendList, NULL); voice->SubmitSourceBuffer(&buffer, &wmaBuffer); CloseHandle(fileHandle); }
CHUNK_t* NewChunk(SAVESTATE_t* save, const char *tag) { int chunk = save->chunk_count; if (FindChunk(save, tag) != NULL) { return NULL; } if (save->chunks[chunk] != NULL) { return NULL; } save->chunks[chunk] = (CHUNK_t *) malloc(sizeof(CHUNK_t)); if (!save->chunks[chunk]) { return NULL; } save->chunks[chunk]->tag[0] = tag[0]; save->chunks[chunk]->tag[1] = tag[1]; save->chunks[chunk]->tag[2] = tag[2]; save->chunks[chunk]->tag[3] = tag[3]; save->chunks[chunk]->size = 0; save->chunks[chunk]->data = NULL; save->chunks[chunk]->pnt = 0; save->chunk_count++; return save->chunks[chunk]; }
bool MarkChunkAsPadding ( LFA_FileRef inFileRef, RiffState & inOutRiffState, long riffType, long tagID, long subtypeID ) { UInt32 len; UInt64 pos; atag tag; try { bool found = FindChunk ( inOutRiffState, tagID, riffType, subtypeID, NULL, &len, &pos ); if ( ! found ) return false; if ( subtypeID != 0 ) { pos -= 12; } else { pos -= 8; } tag.id = MakeUns32LE ( ckidPremierePadding ); LFA_Seek ( inFileRef, pos, SEEK_SET ); LFA_Write ( inFileRef, &tag, 4 ); pos += 8; AddTag ( inOutRiffState, ckidPremierePadding, len, pos, 0, 0, 0 ); } catch(...) { return false; // If a write fails, it throws, so we return false. } return true; }
CHUNK_t* NewChunk(SAVESTATE_t* save, const char *tag) { int chunk = save->chunk_count; if (FindChunk(save, tag) != nullptr) { printf("Error: chunk '%s' already exists", tag); return nullptr; } if (save->chunks[chunk] != nullptr) { puts("Error new chunk was not null."); } save->chunks[chunk] = (CHUNK_t *) malloc(sizeof(CHUNK_t)); if (!save->chunks[chunk]) { puts("Chunk could not be created"); return nullptr; } save->chunks[chunk]->tag[0] = tag[0]; save->chunks[chunk]->tag[1] = tag[1]; save->chunks[chunk]->tag[2] = tag[2]; save->chunks[chunk]->tag[3] = tag[3]; save->chunks[chunk]->size = 0; save->chunks[chunk]->data = nullptr; save->chunks[chunk]->pnt = 0; save->chunk_count++; return save->chunks[chunk]; }
sint64 VDAVIReadIndex::NextKey(sint64 samplePos) const { if (samplePos < 0) { if (IsKey(0)) return true; samplePos = 0; } if (samplePos >= mSampleCount) return -1; uint32 sectorIndex = FindSectorIndexBySample(samplePos); uint32 sampleOffset; uint32 chunkIndex; IndexEntry *ient = FindChunk(samplePos, sectorIndex, sampleOffset, chunkIndex); while(++chunkIndex < mChunkCount) { ient = &mIndex[chunkIndex >> kBlockSizeBits][chunkIndex & kBlockMask]; if ((sint32)ient->mSizeAndKeyFrameFlag < 0) { sectorIndex = FindSectorIndexByChunk(chunkIndex); return mSectors[sectorIndex].mChunkOffset + ient->mSampleOffset; } } return -1; }
char* GetRomOnly(SAVESTATE_t *save, int *size) { CHUNK_t* chunk = FindChunk(save, ROM_tag); *size = 0; if (!chunk) return nullptr; *size = chunk->size; return (char *) chunk->data; }
void LoadLCD(SAVESTATE_t* save, LCD_t* lcd) { CHUNK_t* chunk = FindChunk(save,LCD_tag); chunk->pnt = 0; lcd->active = ReadInt(chunk); lcd->word_len = ReadInt(chunk); lcd->x = ReadInt(chunk); lcd->y = ReadInt(chunk); lcd->z = ReadInt(chunk); lcd->cursor_mode = (LCD_CURSOR_MODE) ReadInt(chunk); lcd->contrast = ReadInt(chunk); lcd->base_level = ReadInt(chunk); ReadBlock(chunk, lcd->display, DISPLAY_SIZE); lcd->front = ReadInt(chunk); ReadBlock(chunk, (unsigned char *) lcd->queue, LCD_MAX_SHADES * DISPLAY_SIZE); lcd->shades = ReadInt(chunk); lcd->mode = (LCD_MODE) ReadInt(chunk); lcd->time = ReadDouble(chunk); lcd->ufps = ReadDouble(chunk); lcd->ufps_last = ReadDouble(chunk); lcd->lastgifframe= ReadDouble(chunk); lcd->write_avg = ReadDouble(chunk); lcd->write_last = ReadDouble(chunk); }
sint64 VDAVIReadIndex::PrevKey(sint64 samplePos) const { if (samplePos <= 0) return -1; if (samplePos >= mSampleCount) return NearestKey(samplePos); uint32 sectorIndex = FindSectorIndexBySample(samplePos); uint32 sampleOffset; uint32 chunkIndex; IndexEntry *ient = FindChunk(samplePos, sectorIndex, sampleOffset, chunkIndex); if (chunkIndex == 0) return -1; --chunkIndex; for(;;) { ient = &mIndex[chunkIndex >> kBlockSizeBits][chunkIndex & kBlockMask]; if ((sint32)ient->mSizeAndKeyFrameFlag < 0) { sectorIndex = FindSectorIndexByChunk(chunkIndex); return mSectors[sectorIndex].mChunkOffset + ient->mSampleOffset; } if (!chunkIndex) break; chunkIndex -= ient->mPrevKeyDistance; } return -1; }
/** * LoadBasicChunks */ void LoadBasicChunks(void) { byte *cptr; int numObjects; // Allocate RAM for savescene data InitialiseSaveScenes(); // CHUNK_TOTAL_ACTORS seems to be missing in the released version, hard coding a value // TODO: Would be nice to just change 511 to MAX_SAVED_ALIVES cptr = FindChunk(MASTER_SCNHANDLE, CHUNK_TOTAL_ACTORS); RegisterActors((cptr != NULL) ? READ_LE_UINT32(cptr) : 511); // CHUNK_TOTAL_GLOBALS seems to be missing in some versions. // So if it is missing, set a reasonably high value for the number of globals. cptr = FindChunk(MASTER_SCNHANDLE, CHUNK_TOTAL_GLOBALS); RegisterGlobals((cptr != NULL) ? READ_LE_UINT32(cptr) : 512); cptr = FindChunk(INV_OBJ_SCNHANDLE, CHUNK_TOTAL_OBJECTS); numObjects = (cptr != NULL) ? READ_LE_UINT32(cptr) : 0; cptr = FindChunk(INV_OBJ_SCNHANDLE, CHUNK_OBJECTS); #ifdef SCUMM_BIG_ENDIAN //convert to native endianness INV_OBJECT *io = (INV_OBJECT *)cptr; for (int i = 0; i < numObjects; i++, io++) { io->id = FROM_LE_32(io->id); io->hIconFilm = FROM_LE_32(io->hIconFilm); io->hScript = FROM_LE_32(io->hScript); io->attribute = FROM_LE_32(io->attribute); } #endif RegisterIcons(cptr, numObjects); cptr = FindChunk(MASTER_SCNHANDLE, CHUNK_TOTAL_POLY); if (cptr != NULL) MaxPolygons(*cptr); if (TinselV2) { // Global processes cptr = FindChunk(MASTER_SCNHANDLE, CHUNK_NUM_PROCESSES); assert(cptr && (*cptr < 100)); int num = *cptr; cptr = FindChunk(MASTER_SCNHANDLE, CHUNK_PROCESSES); assert(!num || cptr); GlobalProcesses(num, cptr); // CdPlay() stuff cptr = FindChunk(MASTER_SCNHANDLE, CHUNK_CDPLAY_HANDLE); assert(cptr); uint32 playHandle = READ_LE_UINT32(cptr); assert(playHandle < 512); SetCdPlayHandle(playHandle); } }
void ReadHeader() { FindChunk("RIFF"); size = read_value<int>(); unsigned char data[4]; stream.read(data, sizeof(data)); Compare(data, "WAVE"); }
void LoadCPU(SAVESTATE_t* save, CPU_t* cpu) { CHUNK_t* chunk = FindChunk(save, CPU_tag); chunk->pnt = 0; cpu->a = ReadChar(chunk); cpu->f = ReadChar(chunk); cpu->b = ReadChar(chunk); cpu->c = ReadChar(chunk); cpu->d = ReadChar(chunk); cpu->e = ReadChar(chunk); cpu->h = ReadChar(chunk); cpu->l = ReadChar(chunk); cpu->ap = ReadChar(chunk); cpu->fp = ReadChar(chunk); cpu->bp = ReadChar(chunk); cpu->cp = ReadChar(chunk); cpu->dp = ReadChar(chunk); cpu->ep = ReadChar(chunk); cpu->hp = ReadChar(chunk); cpu->lp = ReadChar(chunk); cpu->ixl = ReadChar(chunk); cpu->ixh = ReadChar(chunk); cpu->iyl = ReadChar(chunk); cpu->iyh = ReadChar(chunk); cpu->pc = ReadShort(chunk); cpu->sp = ReadShort(chunk); cpu->i = ReadChar(chunk); cpu->r = ReadChar(chunk); cpu->bus = ReadChar(chunk); cpu->imode = ReadInt(chunk); cpu->interrupt = ReadInt(chunk); cpu->ei_block = ReadInt(chunk); cpu->iff1 = ReadInt(chunk); cpu->iff2 = ReadInt(chunk); cpu->halt = ReadInt(chunk); cpu->read = ReadInt(chunk); cpu->write = ReadInt(chunk); cpu->output = ReadInt(chunk); cpu->input = ReadInt(chunk); cpu->prefix = ReadInt(chunk); int i; for(i = 0; i < 256; i++) { interrupt_t *val = &cpu->pio.interrupt[i]; val->interrupt_val = ReadInt(chunk); val->skip_factor = ReadInt(chunk); val->skip_count = ReadInt(chunk); } }
void LoadTIMER(SAVESTATE_t* save, timerc* time) { CHUNK_t* chunk = FindChunk(save,TIMER_tag); chunk->pnt = 0; time->tstates = ReadLong(chunk); time->freq = (uint32_t) ReadLong(chunk); time->elapsed = ReadDouble(chunk); time->lasttime = ReadDouble(chunk); // this isn't used. }
/** * Keeps the code array pointer up to date. */ void LockCode(INT_CONTEXT *ic) { if (ic->GSort == GS_MASTER) { if (TinselV2) // Get the srcipt handle from a specific global chunk ic->code = (byte *)LockMem(hMasterScript); else ic->code = (byte *)FindChunk(MASTER_SCNHANDLE, CHUNK_PCODE); } else ic->code = (byte *)LockMem(ic->hCode); }
bool VDAVIReadIndex::IsKey(sint64 samplePos) const { if ((uint64)samplePos >= (uint64)mSampleCount) return false; uint32 sectorIndex = FindSectorIndexBySample(samplePos); uint32 sampleOffset; uint32 chunkIndex; IndexEntry *ient = FindChunk(samplePos, sectorIndex, sampleOffset, chunkIndex); return (sint32)ient->mSizeAndKeyFrameFlag < 0; }
void* CFX_StaticStore::Alloc(size_t size) { size = FX_4BYTEALIGN(size); ASSERT(size != 0); FX_STATICSTORECHUNK* pChunk = FindChunk(size); ASSERT(pChunk->iFreeSize >= size); uint8_t* p = (uint8_t*)pChunk; p += sizeof(FX_STATICSTORECHUNK) + pChunk->iChunkSize - pChunk->iFreeSize; pChunk->iFreeSize -= size; m_iAllocatedSize += size; return p; }
LevelChunk* Level::GetChunk(const Vector2i& index) { SharedPtr<LevelChunk> chunk(FindChunk(index)); if (chunk) return chunk; chunk = new LevelChunk(_context); chunk->Init(this, index); _chunks.Add(chunk); return chunk; }
void VDAVIReadIndex::FindSampleRange(VDAVIReadIndexIterator& it, sint64 samplePos, uint32 maxSamples) const { uint32 sectorIndex = FindSectorIndexBySample(samplePos); uint32 sampleOffset; uint32 chunkIndex; FindChunk(samplePos, sectorIndex, sampleOffset, chunkIndex); it.mSectorIndex = sectorIndex; it.mSectorLimit = mSectors[it.mSectorIndex + 1].mChunkOffset; it.mChunkIndex = chunkIndex; it.mChunkOffset = sampleOffset * mSampleSize; }
void DoHailScene(SCNHANDLE scene) { // Find scene structure const SCENE_STRUC *ss = GetSceneStruc(FindChunk(scene, CHUNK_SCENE)); if (ss != NULL && ss->hSceneScript) { TP_INIT init; init.event = NOEVENT; init.hTinselCode = ss->hSceneScript; g_scheduler->createProcess(PID_TCODE, SceneTinselProcess, &init, sizeof(init)); } }
void LoadSoundFromFile(LPCWSTR filename, WAVEFORMATEX& waveFormat, XAUDIO2_BUFFER& buffer) { // Open the file HANDLE hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(INVALID_HANDLE_VALUE == hFile) exit(EXIT_FAILURE); if(INVALID_SET_FILE_POINTER == SetFilePointer(hFile, 0, NULL, FILE_BEGIN)) exit(EXIT_FAILURE); //locate the riff chunk and check the filetype DWORD dwChunkSize; DWORD dwChunkPosition; //check the file type, should be fourccWAVE or 'XWMA' FindChunk(hFile, fourccRIFF, dwChunkSize, dwChunkPosition); DWORD filetype; ReadChunkData(hFile,&filetype, sizeof(DWORD), dwChunkPosition); if(filetype != fourccWAVE) exit(EXIT_FAILURE); //locate the "fmt" chunk and copy it into a WAVEFMTEXTENSIBLE structure (wfx) //WAVEFORMATEXTENSIBLE wfx = {0}; FindChunk(hFile,fourccFMT, dwChunkSize, dwChunkPosition); ReadChunkData(hFile, &waveFormat, dwChunkSize, dwChunkPosition); //Locate the 'data' chunk, and read its contents into a buffer //fill out the audio data buffer with the contents of the fourccDATA chunk FindChunk(hFile,fourccDATA, dwChunkSize, dwChunkPosition); BYTE * pDataBuffer = new BYTE[dwChunkSize]; ReadChunkData(hFile, pDataBuffer, dwChunkSize, dwChunkPosition); //Populate an XAUDIO2_BUFFER structure buffer.AudioBytes = dwChunkSize; //buffer containing audio data buffer.pAudioData = pDataBuffer; //size of the audio buffer in bytes buffer.Flags = XAUDIO2_END_OF_STREAM; // tell the source voice not to expect any data after this buffer }
void ReadFormatChunk() { FindChunk("fmt "); int size = read_value<int>(); if (size < 16) { throw wave_reader_exception(); } compression = (Compression) read_value<short int>(); numberChannels = read_value<short int>(); samplesPerSecond = read_value<int>(); averageBytesPerSecond = read_value<int>(); blockAlign = read_value<short int>(); bitsPerSample = read_value<short int>(); }
/** * Allocates enough RAM to hold the global Glitter variables. */ void RegisterGlobals(int num) { if (pGlobals == NULL) { numGlobals = num; hMasterScript = !TinselV2 ? 0 : READ_LE_UINT32(FindChunk(MASTER_SCNHANDLE, CHUNK_MASTER_SCRIPT)); // Allocate RAM for pGlobals and make sure it's allocated pGlobals = (int32 *)calloc(numGlobals, sizeof(int32)); if (pGlobals == NULL) { error("Cannot allocate memory for global data"); } // Allocate RAM for interpret contexts and make sure it's allocated icList = (INT_CONTEXT *)calloc(NUM_INTERPRET, sizeof(INT_CONTEXT)); if (icList == NULL) { error("Cannot allocate memory for interpret contexts"); } g_scheduler->setResourceCallback(FreeInterpretContextPr); } else { // Check size is still the same assert(numGlobals == num); memset(pGlobals, 0, numGlobals * sizeof(int32)); memset(icList, 0, NUM_INTERPRET * sizeof(INT_CONTEXT)); } if (TinselV2) { // read initial values CdCD(nullContext); Common::File f; if (!f.open(GLOBALS_FILENAME)) error(CANNOT_FIND_FILE, GLOBALS_FILENAME); int32 length = f.readSint32LE(); if (length != num) error(FILE_IS_CORRUPT, GLOBALS_FILENAME); for (int i = 0; i < length; ++i) pGlobals[i] = f.readSint32LE(); if (f.eos() || f.err()) error(FILE_IS_CORRUPT, GLOBALS_FILENAME); f.close(); } }
void LoadSTDINT(SAVESTATE_t* save, STDINT_t* stdint) { int i; CHUNK_t* chunk = FindChunk(save,STDINT_tag); chunk->pnt = 0; stdint->intactive = ReadChar(chunk); stdint->lastchk1 = ReadDouble(chunk); stdint->timermax1 = ReadDouble(chunk); stdint->lastchk2 = ReadDouble(chunk); stdint->timermax2 = ReadDouble(chunk); for(i = 0; i < 4; i++) { stdint->freq[i] = ReadDouble(chunk); } stdint->mem = ReadInt(chunk); stdint->xy = ReadInt(chunk); }
/** * Start up a SceneTinselProcess() running the scene * script for various events. */ void SendSceneTinselProcess(TINSEL_EVENT event) { SCENE_STRUC *ss; if (g_SceneHandle != (SCNHANDLE)NULL) { ss = (SCENE_STRUC *) FindChunk(g_SceneHandle, CHUNK_SCENE); if (ss->hSceneScript) { TP_INIT init; init.event = event; init.hTinselCode = ss->hSceneScript; g_scheduler->createProcess(PID_TCODE, SceneTinselProcess, &init, sizeof(init)); } } }
bool RewriteChunk ( LFA_FileRef inFileRef, RiffState & inOutRiffState, long tagID, long parentID, const char * inData ) { UInt32 len; UInt64 pos; try { if ( FindChunk ( inOutRiffState, tagID, parentID, 0, NULL, &len, &pos ) ) { LFA_Seek ( inFileRef, pos, SEEK_SET ); LFA_Write ( inFileRef, inData, len ); } } catch ( ... ) { return false; } return true; }
bool PutChunk ( LFA_FileRef inFileRef, RiffState & inOutRiffState, long riffType, long tagID, const char * inBuffer, UInt32 inBufferSize ) { UInt32 len; UInt64 pos; atag tag; // Make sure we're writting an even number of bytes. Required by the RIFF specification. XMP_Assert ( (inBufferSize & 1) == 0 ); try { bool found = FindChunk ( inOutRiffState, tagID, 0, 0, NULL, &len, &pos ); if ( found ) { if ( len == inBufferSize ) { LFA_Seek ( inFileRef, pos, SEEK_SET ); LFA_Write ( inFileRef, inBuffer, inBufferSize ); return true; } pos -= 8; tag.id = MakeUns32LE ( ckidPremierePadding ); LFA_Seek ( inFileRef, pos, SEEK_SET ); LFA_Write ( inFileRef, &tag, 4 ); if ( len > inBufferSize ) { pos += 8; AddTag ( inOutRiffState, ckidPremierePadding, len, pos, 0, 0, 0 ); } } } catch ( ... ) { // If a write fails, it throws, so we return false return false; } bool ok = MakeChunk ( inFileRef, inOutRiffState, riffType, (inBufferSize + 8) ); if ( ! ok ) return false; return WriteChunk ( inFileRef, tagID, inBuffer, inBufferSize ); }