public void Read(BinaryReader br) { offset = br.ReadInt64(); hash = br.ReadUInt32(); numSamplesInBytes = br.ReadInt32(); numSamplesInBytes_computed = SoundBankMono.GetPaddedSize(numSamplesInBytes); numSamples16Bit = br.ReadInt32(); unk5 = br.ReadInt32(); samplerate = br.ReadUInt16(); unk6 = br.ReadUInt16(); if (Header.size > 32) { unk7 = br.ReadInt32(); offsetToStates = br.ReadInt64(); numSamples16Bit2 = br.ReadUInt32(); unk11 = br.ReadUInt32(); unk12 = br.ReadUInt32(); numStates = br.ReadInt32(); if (numStates > 0) { is_compressed = true; states = new DviAdpcmDecoder.AdpcmState[numStates]; for (int j = 0; j < numStates; j++) { DviAdpcmDecoder.AdpcmState state = new DviAdpcmDecoder.AdpcmState(); state.valprev = br.ReadInt16(); state.index = br.ReadByte(); states[j] = state; } } } }
public void Initialize(AudioFile file, AudioWave wave) { _file = file; _wave = wave; _format = new WaveFormat(_wave.SamplesPerSecond, 16, 1); _lastBlock = -1; _looped = false; _state = new DviAdpcmDecoder.AdpcmState(); _leftOverBuffer = null; }
public void Play(bool looped) { try { Stop(); _looped = looped; _lastBlock = -1; _state = new DviAdpcmDecoder.AdpcmState(); _player = new WaveOutPlayer(-1, _format, _wave.BlockSize * 4, 3, Filler); _leftOverBuffer = null; } catch { MessageBox.Show("Audio play error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Read(BinaryReader br) { offset = br.ReadInt64(); hash = br.ReadUInt32(); numSamplesInBytes = br.ReadInt32(); numSamplesInBytes_computed = SoundBankMono.GetPaddedSize(numSamplesInBytes); numSamples16Bit = br.ReadInt32(); unk5 = br.ReadInt32(); samplerate = br.ReadUInt16(); unk6 = br.ReadUInt16(); if (Header.size > 32) { unk7 = br.ReadInt32(); offsetToStates = br.ReadInt64(); numSamples16Bit2 = br.ReadUInt32(); unk11 = br.ReadUInt32(); unk12 = br.ReadUInt32(); numStates = br.ReadInt32(); if (numStates > 0) { is_compressed = true; states = new DviAdpcmDecoder.AdpcmState[numStates]; for (int j = 0; j < numStates; j++) { DviAdpcmDecoder.AdpcmState state = new DviAdpcmDecoder.AdpcmState(); state.valprev = br.ReadInt16(); state.index = br.ReadByte(); states[j] = state; } } } }
private void Filler(IntPtr data, int size) { int blockCount = _wave.BlockCount; byte[] b = new byte[size]; if (_file != null && (_looped || _lastBlock < blockCount)) { MemoryStream ms = new MemoryStream(); if (_leftOverBuffer != null) { ms.Write(_leftOverBuffer, 0, _leftOverBuffer.Length); } while (ms.Position < size) { _lastBlock++; if (_lastBlock >= blockCount) { if (!_looped) { while (ms.Position < size) { ms.WriteByte(0); } break; } else { _lastBlock = 0; _state = new DviAdpcmDecoder.AdpcmState(); } } _file.SoundBank.ExportWaveBlockAsPCM(_wave.Index, _lastBlock, ref _state, _file.Stream, ms); } int extraData = (int)(ms.Position - size); ms.Seek(0, SeekOrigin.Begin); ms.Read(b, 0, size); if (extraData > 0) { _leftOverBuffer = new byte[extraData]; ms.Read(_leftOverBuffer, 0, extraData); } else { _leftOverBuffer = null; } } else { for (int i = 0; i < b.Length; i++) { b[i] = 0; } } System.Runtime.InteropServices.Marshal.Copy(b, 0, data, size); }