예제 #1
0
 internal GLAudioPlayThread(CachedSound data, GLAudioSource source, bool doLoop = false, float volume = 1.0f)
 {
     mData   = data;
     mSource = source;
     mDoLoop = doLoop;
     mVolume = volume;
 }
예제 #2
0
        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);
        }