Ejemplo n.º 1
0
        // Resets the internal mck pointer so reading starts from the beginning of the file again
        public unsafe int ResetFile()
        {
            if (mbIsReadingFromMemory)
            {
                mpbDataCur = 0;
            }
            else
            {
                if (mhmmio == null)
                {
                    return(-1);
                }

                // Seek to the data
                if (mhmmio.Seek(mckRiff.dwDataOffset + sizeof(int), FS_SEEK.SET) == -1)
                {
                    return(-1);
                }

                // Search the input file for for the 'fmt ' chunk.
                mck.ckid = 0;
                do
                {
                    byte ioin;
                    if (mhmmio.Read(&ioin, 1) == 0)
                    {
                        return(-1);
                    }
                    mck.ckid = (mck.ckid >> 8) | (ioin << 24);
                } while (mck.ckid != SoundSystemLocal.mmioFOURCC('d', 'a', 't', 'a'));

                uint mck_cksize;
                mhmmio.Read((byte *)&mck_cksize, 4);
                Debug.Assert(!isOgg);
                mck.cksize = LittleUInt(mck_cksize);
                mseekBase  = mhmmio.Tell;
            }

            return(0);
        }
Ejemplo n.º 2
0
        // Support function for reading from a multimedia I/O stream. mhmmio must be valid before calling.  This function uses it to update mckRiff, and mpwfx.
        unsafe int ReadMMIO()
        {
            Mminfo        ckIn;          // chunk info. for general use.
            PcmWaveFormat pcmWaveFormat; // Temp PCM structure to load in.

            mpwfx = default;

            fixed(void *mckRiff_ = &mckRiff) mhmmio.Read((byte *)mckRiff_, 12);

            Debug.Assert(!isOgg);
            mckRiff.ckid         = LittleInt(mckRiff.ckid);
            mckRiff.cksize       = LittleUInt(mckRiff.cksize);
            mckRiff.fccType      = LittleInt(mckRiff.fccType);
            mckRiff.dwDataOffset = 12;

            // Check to make sure this is a valid wave file
            if (mckRiff.ckid != SoundSystemLocal.fourcc_riff || mckRiff.fccType != SoundSystemLocal.mmioFOURCC('W', 'A', 'V', 'E'))
            {
                return(-1);
            }

            // Search the input file for for the 'fmt ' chunk.
            ckIn.dwDataOffset = 12;
            do
            {
                if (mhmmio.Read((byte *)&ckIn, 8) != 8)
                {
                    return(-1);
                }
                Debug.Assert(!isOgg);
                ckIn.ckid          = LittleInt(ckIn.ckid);
                ckIn.cksize        = LittleUInt(ckIn.cksize);
                ckIn.dwDataOffset += (int)(ckIn.cksize - 8);
            } while (ckIn.ckid != SoundSystemLocal.mmioFOURCC('f', 'm', 't', ' '));

            // Expect the 'fmt' chunk to be at least as large as <PCMWAVEFORMAT>; if there are extra parameters at the end, we'll ignore them
            if (ckIn.cksize < sizeof(PcmWaveFormat))
            {
                return(-1);
            }

            // Read the 'fmt ' chunk into <pcmWaveFormat>.
            if (mhmmio.Read((byte *)&pcmWaveFormat, sizeof(PcmWaveFormat)) != sizeof(PcmWaveFormat))
            {
                return(-1);
            }
            Debug.Assert(!isOgg);
            pcmWaveFormat.wf.wFormatTag      = (WAVE_FORMAT_TAG)LittleShort((short)pcmWaveFormat.wf.wFormatTag);
            pcmWaveFormat.wf.nChannels       = LittleShort(pcmWaveFormat.wf.nChannels);
            pcmWaveFormat.wf.nSamplesPerSec  = LittleInt(pcmWaveFormat.wf.nSamplesPerSec);
            pcmWaveFormat.wf.nAvgBytesPerSec = LittleInt(pcmWaveFormat.wf.nAvgBytesPerSec);
            pcmWaveFormat.wf.nBlockAlign     = LittleShort(pcmWaveFormat.wf.nBlockAlign);
            pcmWaveFormat.wBitsPerSample     = LittleShort(pcmWaveFormat.wBitsPerSample);

            // Copy the bytes from the pcm structure to the waveformatex_t structure
            mpwfx.memcpy(ref pcmWaveFormat);

            // Allocate the waveformatex_t, but if its not pcm format, read the next word, and thats how many extra bytes to allocate.
            if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_TAG.PCM)
            {
                mpwfx.Format.cbSize = 0;
            }
            else
            {
                return(-1);  // we don't handle these (32 bit wavefiles, etc)

#if false
                // Read in length of extra bytes.
                word cbExtraBytes = 0L;
                if (mhmmio.Read((char *)&cbExtraBytes, sizeof(word)) != sizeof(word))
                {
                    return(-1);
                }

                mpwfx.Format.cbSize = cbExtraBytes;

                // Now, read those extra bytes into the structure, if cbExtraAlloc != 0.
                if (mhmmio.Read((char *)(((byte *)&(mpwfx.Format.cbSize)) + sizeof(word)), cbExtraBytes) != cbExtraBytes)
                {
                    memset(&mpwfx, 0, sizeof(waveformatextensible_t)); return(-1);
                }
#endif
            }

            return(0);
        }