Example #1
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 #2
0
        private static bool Assign(PlaySound ps)
        {
            if (ps == null)
            {
                return(false);
            }
            Channel ch = null;
            int     i;

            for (i = 0; i < numChannels; i++)
            {
                ch = channels[i];
                if (ps.entchannel != 0 && ch.entnum == ps.entnum && ch.entchannel == ps.entchannel)
                {
                    if (ch.bufferId != ps.bufferId)
                    {
                        AL10.AlSourceStop(ch.sourceId);
                    }

                    break;
                }

                if ((ch.entnum == Globals.cl.playernum + 1) && (ps.entnum != Globals.cl.playernum + 1) && ch.bufferId != -1)
                {
                    continue;
                }
                if (!ch.active)
                {
                    break;
                }
            }

            if (i == numChannels)
            {
                return(false);
            }
            ch.type = ps.type;
            if (ps.type == Channel.FIXED)
            {
                Math3D.VectorCopy(ps.origin, ch.origin);
            }
            ch.entnum        = ps.entnum;
            ch.entchannel    = ps.entchannel;
            ch.bufferChanged = (ch.bufferId != ps.bufferId);
            ch.bufferId      = ps.bufferId;
            ch.rolloff       = ps.attenuation * 2;
            ch.volumeChanged = (ch.volume != ps.volume);
            ch.volume        = ps.volume;
            ch.active        = true;
            ch.modified      = true;
            return(true);
        }
Example #3
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 #4
0
        static void UnqueueStreams()
        {
            if (!streamingEnabled)
            {
                return;
            }
            int source = channels[numChannels].sourceId;

            AL10.AlSourceStop(source);
            int count = AL10.AlGetSourcei(source, AL10.AL_BUFFERS_QUEUED);

            Com.DPrintf("unqueue " + count + " buffers\\n");
            while (count-- > 0)
            {
                AL10.AlSourceUnqueueBuffers(source, tmp);
            }

            streamQueue = 0;
        }
Example #5
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;
                }
            }
        }