Example #1
0
        public static void AddLoopSounds()
        {
            if ((Globals.cl_paused.value != 0F) || (Globals.cls.state != Globals.ca_active) || !Globals.cl.sound_prepped)
            {
                RemoveUnusedLoopSounds();
                return;
            }

            Channel        ch;
            sfx_t          sfx;
            sfxcache_t     sc;
            int            num;
            entity_state_t ent;
            Object         key;
            int            sound = 0;

            for (int i = 0; i < Globals.cl.frame.num_entities; i++)
            {
                num   = (Globals.cl.frame.parse_entities + i) & (Defines.MAX_PARSE_ENTITIES - 1);
                ent   = Globals.cl_parse_entities[num];
                sound = ent.sound;
                if (sound == 0)
                {
                    continue;
                }
                key = ent.number;
                ch  = (Channel)looptable[key];
                if (ch != null)
                {
                    ch.autosound = true;
                    Math3D.VectorCopy(ent.origin, ch.origin);
                    continue;
                }

                sfx = Globals.cl.sound_precache[sound];
                if (sfx == null)
                {
                    continue;
                }
                sc = sfx.cache;
                if (sc == null)
                {
                    continue;
                }
                ch = Channel.PickForLoop(buffers.Get(sfx.bufferId), 6);
                if (ch == null)
                {
                    break;
                }
                ch.type = FIXED;
                Math3D.VectorCopy(ent.origin, ch.origin);
                ch.autosound = true;
                looptable.Add(key, ch);
                AL10.AlSourcei(ch.sourceId, AL10.AL_LOOPING, AL10.AL_TRUE);
            }

            RemoveUnusedLoopSounds();
        }
Example #2
0
 public static void Reset()
 {
     for (int i = 0; i < numChannels; i++)
     {
         AL10.AlSourceStop(sources.Get(i));
         AL10.AlSourcei(sources.Get(i), AL10.AL_BUFFER, 0);
         channels[i].Clear();
     }
 }
Example #3
0
        public static void DisableStreaming()
        {
            if (!streamingEnabled)
            {
                return;
            }
            UnqueueStreams();
            int source = channels[numChannels].sourceId;

            AL10.AlSourcei(source, AL10.AL_SOURCE_RELATIVE, AL10.AL_FALSE);
            numChannels++;
            streamingEnabled = false;
            Com.DPrintf("streaming disabled\\n");
        }
Example #4
0
        private static void RemoveUnusedLoopSounds()
        {
            Channel ch;

            for (Iterator iter = looptable.Values().iterator(); iter.HasNext();)
            {
                ch = (Channel)iter.Next();
                if (!ch.autosound)
                {
                    AL10.AlSourceStop(ch.sourceId);
                    AL10.AlSourcei(ch.sourceId, AL10.AL_LOOPING, AL10.AL_FALSE);
                    iter.Remove();
                    ch.Clear();
                }
            }
        }
Example #5
0
        static void EnableStreaming()
        {
            if (streamingEnabled)
            {
                return;
            }
            numChannels--;
            streamingEnabled = true;
            streamQueue      = 0;
            int source = channels[numChannels].sourceId;

            AL10.AlSourcei(source, AL10.AL_SOURCE_RELATIVE, AL10.AL_TRUE);
            AL10.AlSourcef(source, AL10.AL_GAIN, 1F);
            channels[numChannels].volumeChanged = true;
            Com.DPrintf("streaming enabled\\n");
        }
Example #6
0
        public static int Init(Int32Buffer buffers)
        {
            Channel.buffers = buffers;
            int sourceId;

            numChannels = 0;
            for (int i = 0; i < MAX_CHANNELS; i++)
            {
                try
                {
                    AL10.AlGenSources(tmp);
                    sourceId = tmp.Get(0);
                    if (sourceId <= 0)
                    {
                        break;
                    }
                }
                catch (OpenALException e)
                {
                    break;
                }

                sources.Put(i, sourceId);
                channels[i] = new Channel(sourceId);
                numChannels++;
                AL10.AlSourcef(sourceId, AL10.AL_GAIN, 1F);
                AL10.AlSourcef(sourceId, AL10.AL_PITCH, 1F);
                AL10.AlSourcei(sourceId, AL10.AL_SOURCE_RELATIVE, AL10.AL_FALSE);
                AL10.AlSource(sourceId, AL10.AL_VELOCITY, NULLVECTOR);
                AL10.AlSourcei(sourceId, AL10.AL_LOOPING, AL10.AL_FALSE);
                AL10.AlSourcef(sourceId, AL10.AL_REFERENCE_DISTANCE, 200F);
                AL10.AlSourcef(sourceId, AL10.AL_MIN_GAIN, 0.0005F);
                AL10.AlSourcef(sourceId, AL10.AL_MAX_GAIN, 1F);
            }

            sources.Limit = numChannels;
            return(numChannels);
        }
Example #7
0
        public static void PlayAllSounds(SingleBuffer listenerOrigin)
        {
            SingleBuffer sourceOrigin = sourceOriginBuffer;
            Channel      ch;
            int          sourceId;
            int          state;

            for (int i = 0; i < numChannels; i++)
            {
                ch = channels[i];
                if (ch.active)
                {
                    sourceId = ch.sourceId;
                    switch (ch.type)
                    {
                    case Channel.LISTENER:
                        sourceOrigin.Put(0, listenerOrigin.Get(0));
                        sourceOrigin.Put(1, listenerOrigin.Get(1));
                        sourceOrigin.Put(2, listenerOrigin.Get(2));
                        break;

                    case Channel.DYNAMIC:
                        CL_ents.GetEntitySoundOrigin(ch.entnum, entityOrigin);
                        ConvertVector(entityOrigin, sourceOrigin);
                        break;

                    case Channel.FIXED:
                        ConvertVector(ch.origin, sourceOrigin);
                        break;
                    }

                    if (ch.modified)
                    {
                        if (ch.bufferChanged)
                        {
                            try
                            {
                                AL10.AlSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId);
                            }
                            catch (OpenALException e)
                            {
                                AL10.AlSourceStop(sourceId);
                                AL10.AlSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId);
                            }
                        }

                        if (ch.volumeChanged)
                        {
                            AL10.AlSourcef(sourceId, AL10.AL_GAIN, ch.volume);
                        }

                        AL10.AlSourcef(sourceId, AL10.AL_ROLLOFF_FACTOR, ch.rolloff);
                        AL10.AlSource(sourceId, AL10.AL_POSITION, sourceOrigin);
                        AL10.AlSourcePlay(sourceId);
                        ch.modified = false;
                    }
                    else
                    {
                        state = AL10.AlGetSourcei(sourceId, AL10.AL_SOURCE_STATE);
                        if (state == AL10.AL_PLAYING)
                        {
                            AL10.AlSource(sourceId, AL10.AL_POSITION, sourceOrigin);
                        }
                        else
                        {
                            ch.Clear();
                        }
                    }

                    ch.autosound = false;
                }
            }
        }