static void SubmitBuffer(DynSoundData sound) { if (sound.Instance.IsDisposed) { return; } var offset = sound.BufferCount * sound.BufferLength; if (offset < sound.Data.Length) { sound.Instance.SubmitBuffer(sound.Data, offset, Math.Min(sound.BufferLength, sound.Data.Length - offset)); } else { sound.BufferCount = 0; sound.Instance.SubmitBuffer(sound.Data, 0, Math.Min(sound.BufferLength, sound.Data.Length)); } ++sound.BufferCount; }
private void LoadWaveFileIntoBuffers(out GCHandle handle, out DynSoundData sound, string filename) { sound = new DynSoundData(); WaveFormat dataFormat; using (var stream = AssetManager.FileProvider.OpenStream(filename, VirtualFileMode.Open, VirtualFileAccess.Read)) using (var memoryStream = new MemoryStream(new byte[stream.Length])) { stream.CopyTo(memoryStream); memoryStream.Position = 0; var waveStreamReader = new SoundStream(memoryStream); dataFormat = waveStreamReader.Format; sound.Data = new byte[waveStreamReader.Length]; handle = GCHandle.Alloc(sound.Data, GCHandleType.Pinned); if (waveStreamReader.Read(sound.Data, 0, (int)waveStreamReader.Length) != waveStreamReader.Length) { throw new AudioSystemInternalException("The data length read in wave soundStream does not correspond to the stream's length."); } } sound.Instance = new DynamicSoundEffectInstance(defaultEngine, dataFormat.SampleRate, (AudioChannels)dataFormat.Channels, (AudioDataEncoding)dataFormat.BitsPerSample); }
private void LoadWaveFileIntoBuffers(out GCHandle handle, out DynSoundData sound, string filename) { sound = new DynSoundData(); WaveFormat dataFormat; using (var stream = AssetManager.FileProvider.OpenStream(filename, VirtualFileMode.Open, VirtualFileAccess.Read)) using (var memoryStream = new MemoryStream(new byte[stream.Length])) { stream.CopyTo(memoryStream); memoryStream.Position = 0; var waveStreamReader = new SoundStream(memoryStream); dataFormat = waveStreamReader.Format; sound.Data = new byte[waveStreamReader.Length]; handle = GCHandle.Alloc(sound.Data, GCHandleType.Pinned); if (waveStreamReader.Read(sound.Data, 0, (int)waveStreamReader.Length) != waveStreamReader.Length) throw new AudioSystemInternalException("The data length read in wave soundStream does not correspond to the stream's length."); } sound.Instance = new DynamicSoundEffectInstance(defaultEngine, dataFormat.SampleRate, (AudioChannels)dataFormat.Channels, (AudioDataEncoding)dataFormat.BitsPerSample); }
static void SubmitBuffer(DynSoundData sound) { if(sound.Instance.IsDisposed) return; var offset = sound.BufferCount * sound.BufferLength; if (offset < sound.Data.Length) { sound.Instance.SubmitBuffer(sound.Data, offset, Math.Min(sound.BufferLength, sound.Data.Length - offset)); } else { sound.BufferCount = 0; sound.Instance.SubmitBuffer(sound.Data, 0, Math.Min(sound.BufferLength, sound.Data.Length)); } ++sound.BufferCount; }