internal void Play() { AL.Source(mSource.GetSourceId(), ALSourcei.Buffer, mData.GetBufferPointer()); if (mDoLoop) { AL.Source(mSource.GetSourceId(), ALSourceb.Looping, true); mSource.SetLooping(true); } else { AL.Source(mSource.GetSourceId(), ALSourceb.Looping, false); mSource.SetLooping(false); } AL.Source(mSource.GetSourceId(), ALSourcef.Gain, mVolume); mSource.SetFileName(mData.GetName()); AL.SourcePlay(mSource.GetSourceId()); mSource.SetFileName(""); mSource.SetLooping(false); }
public static int SoundPlay(string sound, bool looping, float volume = 1.0f) { if (!mAudioOn) { Console.WriteLine("Error playing audio: audio device not available."); return(-1); } volume = volume >= 0 && volume <= 1.0f ? volume : 1.0f; CachedSound soundToPlay = null; if (CachedSounds.ContainsKey(sound)) { soundToPlay = CachedSounds[sound]; } else { soundToPlay = new CachedSound(sound); CachedSounds.Add(sound, soundToPlay); } GLAudioSource source = null; int channelNumber = -1; for (int i = 0; i < mChannels; i++) { if (!mSources[i].IsPlaying) { source = mSources[i]; channelNumber = i; source.SetFileName(sound); break; } } if (source == null) { Console.WriteLine("Error playing audio file: all " + mChannels + " channels are busy."); return(-1); } AL.Source(source.GetSourceId(), ALSourcei.Buffer, soundToPlay.GetBufferPointer()); if (looping) { AL.Source(source.GetSourceId(), ALSourceb.Looping, true); } else { AL.Source(source.GetSourceId(), ALSourceb.Looping, false); } AL.Source(source.GetSourceId(), ALSourcef.Gain, volume); AL.SourcePlay(source.GetSourceId()); return(channelNumber); }