Exemplo n.º 1
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);
        }
Exemplo n.º 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;
                }
            }
        }