// Opens a wave file for reading public int Open(string strFileName, out WaveformatEx pwfx) { pwfx = default; mbIsReadingFromMemory = false; mpbData = null; mpbDataCur = 0; if (strFileName == null) { return(-1); } var name = strFileName; // note: used to only check for .wav when making a build name = PathX.SetFileExtension(name, ".ogg"); if (fileSystem.ReadFile(name, out var _) != -1) { return(OpenOGG(name, out pwfx)); } mpwfx = default; mhmmio = fileSystem.OpenFileRead(strFileName); if (mhmmio == null) { mdwSize = 0; return(-1); } if (mhmmio.Length <= 0) { mhmmio = null; return(-1); } if (ReadMMIO() != 0) { Close(); return(-1); } // ReadMMIO will fail if its an not a wave file mfileTime = mhmmio.Timestamp; if (ResetFile() != 0) { Close(); return(-1); } // After the reset, the size of the wav file is mck.cksize so store it now mdwSize = (int)(mck.cksize / sizeof(short)); mMemSize = (int)mck.cksize; if (mck.cksize != 0xffffffff) { pwfx = mpwfx.Format; return(0); } return(-1); }
unsafe int OpenOGG(string strFileName, out WaveformatEx pwfx) { pwfx = default; mhmmio = fileSystem.OpenFileRead(strFileName); if (mhmmio == null) { return(-1); } ISystem.EnterCriticalSection(CRITICAL_SECTION.SECTION_ONE); var ov = new OggVorbis_File(); if (OggVorbis.ov_openFile(mhmmio, ov) < 0) { ISystem.LeaveCriticalSection(CRITICAL_SECTION.SECTION_ONE); fileSystem.CloseFile(mhmmio); mhmmio = null; return(-1); } mfileTime = mhmmio.Timestamp; var vi = ov_info(ov, -1); mpwfx.Format.nSamplesPerSec = (int)vi->rate; mpwfx.Format.nChannels = (short)vi->channels; mpwfx.Format.wBitsPerSample = sizeof(short) * 8; mdwSize = (int)(ov_pcm_total(ov, -1) * vi->channels); // pcm samples * num channels mbIsReadingFromMemory = false; if (SoundSystemLocal.s_realTimeDecoding.Bool) { ov_clear(ov); fileSystem.CloseFile(mhmmio); mhmmio = null; mpwfx.Format.wFormatTag = WAVE_FORMAT_TAG.OGG; mhmmio = fileSystem.OpenFileRead(strFileName); mMemSize = mhmmio.Length; } else { ogg = ov; mpwfx.Format.wFormatTag = WAVE_FORMAT_TAG.PCM; mMemSize = mdwSize * sizeof(short); } pwfx = mpwfx.Format; ISystem.LeaveCriticalSection(CRITICAL_SECTION.SECTION_ONE); isOgg = true; return(0); }