Example #1
0
        static void Spatialize(channel_t ch)
        {
            Single[] origin = new Single[] { 0, 0, 0 };
            if (ch.entnum == cl.playernum + 1)
            {
                ch.leftvol  = ch.master_vol;
                ch.rightvol = ch.master_vol;
                return;
            }

            if (ch.fixed_origin)
            {
                Math3D.VectorCopy(ch.origin, origin);
            }
            else
            {
                CL_ents.GetEntitySoundOrigin(ch.entnum, origin);
            }
            SpatializeOrigin(origin, ( Single )ch.master_vol, ch.dist_mult, ch);
        }
Example #2
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;
                }
            }
        }
Example #3
0
        public static void PlayAllSounds(float[] listenerOrigin)
        {
            Channel       ch;
            int           sourceId;
            ALSourceState state;

            int[] tmp = new int[] { 0 };
            for (int i = 0; i < numChannels; i++)
            {
                ch = channels[i];
                if (ch.active)
                {
                    sourceId = ch.sourceId;
                    switch (ch.type)

                    {
                    case Channel.LISTENER:
                        Math3D.VectorCopy(listenerOrigin, sourceOrigin);
                        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
                            {
                                AL.Source(sourceId, ALSourcei.Buffer, ch.bufferId);
                            }
                            catch (Exception e)
                            {
                                AL.SourceStop(sourceId);
                                AL.Source(sourceId, ALSourcei.Buffer, ch.bufferId);
                            }
                        }

                        if (ch.volumeChanged)
                        {
                            AL.Source(sourceId, ALSourcef.Gain, ch.volume);
                        }

                        AL.Source(sourceId, ALSourcef.RolloffFactor, ch.rolloff);
                        AL.Source(sourceId, ALSource3f.Position, sourceOrigin[0], sourceOrigin[1], sourceOrigin[2]);
                        AL.SourcePlay(sourceId);
                        ch.modified = false;
                    }
                    else
                    {
                        AL.GetSource(sourceId, ALGetSourcei.SourceState, out tmp[0]);
                        state = (ALSourceState)tmp[0];
                        if (state == ALSourceState.Playing)
                        {
                            AL.Source(sourceId, ALSource3f.Position, sourceOrigin[0], sourceOrigin[1], sourceOrigin[2]);
                        }
                        else
                        {
                            ch.Clear();
                        }
                    }

                    ch.autosound = false;
                }
            }
        }