// public void Update() { if (currentSound == null) { return; } if ((currentSound.Mode & SoundMode.Mode3D) != 0) { UpdateVolume2(); } DirectSampleSound currentSampleSound = currentSound as DirectSampleSound; if (currentSampleSound != null) { UpdateSample(); return; } DirectDataStreamSound currentDataStreamSound = currentSound as DirectDataStreamSound; if (currentDataStreamSound != null) { UpdateStream(); } if (needStopVirtualChannel) { CurrentVirtualChannel.Stop(); needStopVirtualChannel = false; } }
public override Sound SoundCreate(VirtualFileStream stream, bool closeStreamAfterReading, SoundType soundType, SoundMode mode) { criticalSection.Enter(); DirectSound sound; bool initialized; if ((int)(mode & SoundMode.Stream) == 0) { sound = new DirectSampleSound(stream, soundType, null, mode, out initialized); if (closeStreamAfterReading) { stream.Close(); } } else { sound = new DirectFileStreamSound(stream, closeStreamAfterReading, soundType, null, mode, out initialized); } if (!initialized) { sound.Dispose(); sound = null; } criticalSection.Leave(); return(sound); }
public override Sound SoundCreate(string name, SoundMode mode) { criticalSection.Enter(); DirectSound sound; sound = (DirectSound)base.SoundCreate(name, mode); if (sound != null) { criticalSection.Leave(); return(sound); } VirtualFileStream stream = CreateFileStream(name); if (stream == null) { criticalSection.Leave(); DirectSoundWorld.Warning(string.Format("Creating sound \"{0}\" failed.", name)); return(null); } bool initialized; if ((int)(mode & SoundMode.Stream) == 0) { sound = new DirectSampleSound(stream, SoundType.Unknown, name, mode, out initialized); stream.Close(); } else { sound = new DirectFileStreamSound(stream, true, SoundType.Unknown, name, mode, out initialized); } if (!initialized) { sound.Dispose(); sound = null; } criticalSection.Leave(); return(sound); }
unsafe protected override void PostAttachVirtualChannel() { DirectSoundWorld.criticalSection.Enter(); int hr; currentSound = (DirectSound)CurrentVirtualChannel.CurrentSound; bool mode3d = (int)(currentSound.Mode & SoundMode.Mode3D) != 0; bool loop = (int)(currentSound.Mode & SoundMode.Loop) != 0; //DirectSampleSound DirectSampleSound currentSampleSound = currentSound as DirectSampleSound; if (currentSampleSound != null) { int lastBufferCount = currentSound.soundBuffers.Count; currentSoundBuffer = currentSound.GetBuffer(currentSampleSound.soundSamples.Length); if (currentSoundBuffer == null) { PreDetachVirtualChannel(); DirectSoundWorld.criticalSection.Leave(); return; } bool needFillData = false; if (lastBufferCount == 0) { needFillData = true; } bool restored = false; if (!currentSound.RestoreSoundBuffers(out restored)) { PreDetachVirtualChannel(); DirectSoundWorld.criticalSection.Leave(); return; } if (restored) { needFillData = true; } if (needFillData) { if (!currentSampleSound.FillSoundBuffersWithData()) { PreDetachVirtualChannel(); DirectSoundWorld.criticalSection.Leave(); return; } } } //DirectFileStreamSound, DirectDataStreamSound DirectFileStreamSound currentFileStreamSound = currentSound as DirectFileStreamSound; DirectDataStreamSound currentDataStreamSound = currentSound as DirectDataStreamSound; if (currentFileStreamSound != null || currentDataStreamSound != null) { int needBufferSize; if (currentFileStreamSound != null) { int numSamples = (int)currentFileStreamSound.vorbisFile.pcm_total(-1); int channels; int rate; currentFileStreamSound.vorbisFile.get_info(-1, out channels, out rate); int sizeInBytes = numSamples * channels * 2; needBufferSize = sizeInBytes / 2; if (needBufferSize > 65536 * 2) { needBufferSize = 65536 * 2; } } else { needBufferSize = currentDataStreamSound.creationBufferSize; } currentSoundBuffer = currentSound.GetBuffer(needBufferSize); if (currentSoundBuffer == null) { PreDetachVirtualChannel(); DirectSoundWorld.criticalSection.Leave(); return; } streamBuffer = (byte *)NativeUtils.Alloc(NativeMemoryAllocationType.SoundAndVideo, currentSound.bufferSize); streamBufferLength = 0; bool restored = false; if (!currentSound.RestoreSoundBuffers(out restored)) { PreDetachVirtualChannel(); DirectSoundWorld.criticalSection.Leave(); return; } if (restored) { //buffer will be cleared in the BeginStreamPlay() } } //currentSound3DBuffer if (mode3d) { void */*IDirectSound3DBuffer8*/ sound3DBuffer; GUID guid = DSound.IID_IDirectSound3DBuffer8; hr = IDirectSoundBuffer.QueryInterface(currentSoundBuffer, ref guid, &sound3DBuffer); if (Wrapper.FAILED(hr)) { PreDetachVirtualChannel(); DirectSoundWorld.Warning("IDirectSoundBuffer.QueryInterface", hr); DirectSoundWorld.criticalSection.Leave(); return; } currentSound3DBuffer = (IDirectSound3DBuffer8 *)sound3DBuffer; } //update parameters if (mode3d) { UpdatePosition2(); UpdateVelocity2(); } else { UpdatePan2(); } UpdatePitch2(); UpdateVolume2(); UpdateTime2(); if (currentFileStreamSound != null || currentDataStreamSound != null) { BeginStreamPlay(); } uint playFlags = 0; if (loop || currentFileStreamSound != null || currentDataStreamSound != null) { playFlags |= DSound.DSBPLAY_LOOPING; } hr = IDirectSoundBuffer.Play(currentSoundBuffer, 0, 0, playFlags); if (Wrapper.FAILED(hr)) { PreDetachVirtualChannel(); DirectSoundWorld.Warning("IDirectSoundBuffer.Play", hr); DirectSoundWorld.criticalSection.Leave(); return; } if (currentFileStreamSound != null) { DirectSoundWorld.Instance.fileStreamRealChannels.Add(this); } needStopVirtualChannel = false; DirectSoundWorld.criticalSection.Leave(); }
public override Sound SoundCreate( VirtualFileStream stream, bool closeStreamAfterReading, SoundType soundType, SoundMode mode ) { criticalSection.Enter(); DirectSound sound; bool initialized; if( (int)( mode & SoundMode.Stream ) == 0 ) { sound = new DirectSampleSound( stream, soundType, null, mode, out initialized ); if( closeStreamAfterReading ) stream.Close(); } else { sound = new DirectFileStreamSound( stream, closeStreamAfterReading, soundType, null, mode, out initialized ); } if( !initialized ) { sound.Dispose(); sound = null; } criticalSection.Leave(); return sound; }
public override Sound SoundCreate( string name, SoundMode mode ) { criticalSection.Enter(); DirectSound sound; sound = (DirectSound)base.SoundCreate( name, mode ); if( sound != null ) { criticalSection.Leave(); return sound; } VirtualFileStream stream = CreateFileStream( name ); if( stream == null ) { criticalSection.Leave(); DirectSoundWorld.Warning( string.Format( "Creating sound \"{0}\" failed.", name ) ); return null; } bool initialized; if( (int)( mode & SoundMode.Stream ) == 0 ) { sound = new DirectSampleSound( stream, SoundType.Unknown, name, mode, out initialized ); stream.Close(); } else { sound = new DirectFileStreamSound( stream, true, SoundType.Unknown, name, mode, out initialized ); } if( !initialized ) { sound.Dispose(); sound = null; } criticalSection.Leave(); return sound; }