// 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; } }
void UpdateVolume2() { float value = CurrentVirtualChannel.GetTotalVolume() * CurrentVirtualChannel.GetRolloffFactor(); Al.alSourcef(alSource, Al.AL_GAIN, value); OpenALSoundWorld.CheckError(); }
void UpdateSample() { int state; Al.alGetSourcei(alSource, Al.AL_SOURCE_STATE, out state); OpenALSoundWorld.CheckError(); if (state == Al.AL_STOPPED) { CurrentVirtualChannel.Stop(); } }
//unsafe void UpdateMinDistance2() //{ // if( currentSound3DBuffer != null ) // { // float value = (float)CurrentVirtualChannel.MinDistance; // int hr = IDirectSound3DBuffer8.SetMinDistance( currentSound3DBuffer, value, // DSound.DS3D_IMMEDIATE ); // if( Wrapper.FAILED( hr ) ) // DirectSoundWorld.Warning( "IDirectSound3DBuffer8.SetMinDistance", hr ); // } //} //protected override void UpdateMinDistance() //{ // DirectSoundWorld.criticalSection.Enter(); // if( currentSound != null ) // UpdateMinDistance2(); // DirectSoundWorld.criticalSection.Leave(); //} unsafe void UpdatePitch2() { float pitch = (float)currentSound.waveFormat->nSamplesPerSec * CurrentVirtualChannel.GetTotalPitch(); int hr = IDirectSoundBuffer.SetFrequency(currentSoundBuffer, (uint)pitch); if (Wrapper.FAILED(hr)) { DirectSoundWorld.Warning("IDirectSoundBuffer.SetFrequency", hr); } }
unsafe void UpdateSample() { uint status; int hr = IDirectSoundBuffer.GetStatus(currentSoundBuffer, out status); if (Wrapper.FAILED(hr)) { DirectSoundWorld.Warning("IDirectSoundBuffer.GetStatus", hr); return; } if ((status & DSound.DSBSTATUS_PLAYING) == 0) { CurrentVirtualChannel.Stop(); } }
unsafe void UpdateVolume2() { float value = CurrentVirtualChannel.GetTotalVolume() * CurrentVirtualChannel.GetRolloffFactor(); int volume; if (value > 0.001f) { volume = (int)(20.0f * 100.0f * Math.Log10(value)); } else { volume = DSound.DSBVOLUME_MIN; } if (volume < DSound.DSBVOLUME_MIN) { volume = DSound.DSBVOLUME_MIN; } if (volume > DSound.DSBVOLUME_MAX) { volume = DSound.DSBVOLUME_MAX; } //update volume for dublicate buffers (IDirectSoundBuffer8.SetVolume problem) //it need have volume not equal to original buffer. bool isOriginalBuffer = false; IDirectSoundBuffer *originalBuffer = (IDirectSoundBuffer *) currentSound.soundBuffers[0].ToPointer(); isOriginalBuffer = originalBuffer == currentSoundBuffer; if (!isOriginalBuffer) { int originalBufferVolume = 0; IDirectSoundBuffer.GetVolume(originalBuffer, out originalBufferVolume); if (volume == originalBufferVolume) { if (volume == DSound.DSBVOLUME_MAX) { volume = DSound.DSBVOLUME_MAX - 1; } else { volume++; } } } //change volume int hr = IDirectSoundBuffer.SetVolume(currentSoundBuffer, volume); if (Wrapper.FAILED(hr)) { DirectSoundWorld.Warning("IDirectSoundBuffer.SetVolume", hr); } //update volume of dublicate buffers if (isOriginalBuffer) { List <DirectSoundRealChannel> realChannels = DirectSoundWorld.Instance.realChannels; for (int nRealChannel = 0; nRealChannel < realChannels.Count; nRealChannel++) { DirectSoundRealChannel realChannel = realChannels[nRealChannel]; if (realChannel != this && realChannel.currentSound == currentSound) { realChannel.UpdateVolume(); } } } }
public void UpdateFileStreamFromThread() { if (currentSound == null) { return; } //update buffers int processed; Al.alGetSourcei(alSource, Al.AL_BUFFERS_PROCESSED, out processed); OpenALSoundWorld.CheckError(); while (processed != 0) { int alStreamBuffer = 0; Al.alSourceUnqueueBuffers(alSource, 1, ref alStreamBuffer); OpenALSoundWorld.CheckError(); FileStream(alStreamBuffer); if (streamDataAvailable) { Al.alSourceQueueBuffers(alSource, 1, ref alStreamBuffer); OpenALSoundWorld.CheckError(); } processed--; } //play if buffer stopped (from behind internal buffers processed) int state; Al.alGetSourcei(alSource, Al.AL_SOURCE_STATE, out state); OpenALSoundWorld.CheckError(); bool stoppedNoQueued = false; if (state == Al.AL_STOPPED) { int queued; Al.alGetSourcei(alSource, Al.AL_BUFFERS_QUEUED, out queued); if (queued != 0) { Al.alSourcePlay(alSource); } else { stoppedNoQueued = true; } } //file stream played OpenALFileStreamSound fileStreamSound = (OpenALFileStreamSound)currentSound; if (!streamDataAvailable && stoppedNoQueued) { if ((currentSound.Mode & SoundMode.Loop) != 0) { //loop play. we need recreate vorbis file //stop and unqueues sources Al.alSourceStop(alSource); Al.alGetSourcei(alSource, Al.AL_BUFFERS_PROCESSED, out processed); OpenALSoundWorld.CheckError(); while (processed != 0) { int alStreamBuffer = 0; Al.alSourceUnqueueBuffers(alSource, 1, ref alStreamBuffer); OpenALSoundWorld.CheckError(); processed--; } //recreate vorbis file fileStreamSound.Rewind(); FileStreamStartPlay(); //Pause = false; Al.alSourcePlay(alSource); OpenALSoundWorld.CheckError(); } else { CurrentVirtualChannel.Stop(); } } }
void UpdatePitch2() { Al.alSourcef(alSource, Al.AL_PITCH, CurrentVirtualChannel.GetTotalPitch()); OpenALSoundWorld.CheckError(); }