Пример #1
0
        private void InitBuffer(UUID objectId, UUID soundId, bool loop, bool global, Vector3 worldpos, float vol)
        {
            if (manager == null || !manager.SoundSystemAvailable)
            {
                return;
            }

            // Do not let this get garbage-collected.
            lock (allBuffers)
                allBuffers[objectId] = this;

            ContainerId   = objectId;
            Id            = soundId;
            position      = FromOMVSpace(worldpos);
            volumeSetting = vol;
            loopSound     = loop;

            Logger.Log(
                String.Format(
                    "Playing sound at <{0:0.0},{1:0.0},{2:0.0}> ID {3}",
                    position.x,
                    position.y,
                    position.z,
                    Id.ToString()),
                Helpers.LogLevel.Debug);

            // Set flags to determine how it will be played.
            mode = FMOD.MODE.SOFTWARE |  // Need software processing for all the features
                   FMOD.MODE._3D |       // Need 3D effects for placement
                   FMOD.MODE.OPENMEMORY; // Use sound data in memory

            // Set coordinate space interpretation.
            if (global)
            {
                mode |= FMOD.MODE._3D_WORLDRELATIVE;
            }
            else
            {
                mode |= FMOD.MODE._3D_HEADRELATIVE;
            }

            if (loopSound)
            {
                mode |= FMOD.MODE.LOOP_NORMAL;
            }

            // Fetch the sound data.
            manager.Instance.Client.Assets.RequestAsset(
                Id,
                AssetType.Sound,
                false,
                new AssetManager.AssetReceivedCallback(Assets_OnSoundReceived));
        }
Пример #2
0
        /// <summary>
        /// Plays audio from a file, as created by an external speech synthesizer.
        /// </summary>
        /// <param name="filename">Name of a WAV file</param>
        /// <param name="global"></param>
        /// <returns>Length of the sound in ms</returns>
        public uint Play(string speakfile, bool global, Vector3 pos)
        {
            uint len = 0;

            speakerPos = pos;
            filename   = speakfile;

            // Set flags to determine how it will be played.
            FMOD.MODE mode = FMOD.MODE.SOFTWARE;

            if (Surround)
            {
                mode |= FMOD.MODE._3D;

                // Set coordinate space interpretation.
                if (global)
                {
                    mode |= FMOD.MODE._3D_WORLDRELATIVE;
                }
                else
                {
                    mode |= FMOD.MODE._3D_HEADRELATIVE;
                }
            }


            System.Threading.AutoResetEvent done = new System.Threading.AutoResetEvent(false);

            invoke(new SoundDelegate(
                       delegate
            {
                try
                {
                    FMODExec(
                        system.createSound(filename,
                                           mode,
                                           ref extraInfo,
                                           ref sound));

                    // Register for callbacks.
                    RegisterSound(sound);

                    // Find out how long the sound should play
                    FMODExec(sound.getLength(ref len, TIMEUNIT.MS));

                    // Allocate a channel, initially paused.
                    FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));

                    // Set general Speech volume.
                    //TODO Set this in the GUI
                    volume = 1.0f;
                    FMODExec(channel.setVolume(volume));

                    if (Surround)
                    {
                        // Set attenuation limits so distant people get a little softer,
                        // but not TOO soft
                        if (compress)
                        {
                            FMODExec(sound.set3DMinMaxDistance(
                                         2f,      // Any closer than this gets no louder
                                         3.5f));  // Further than this gets no softer.
                        }
                        else
                        {
                            FMODExec(sound.set3DMinMaxDistance(
                                         2f,      // Any closer than this gets no louder
                                         10f));   // Further than this gets no softer.
                        }
                        // Set speaker position.
                        position = FromOMVSpace(speakerPos);
                        FMODExec(channel.set3DAttributes(
                                     ref position,
                                     ref ZeroVector));

                        Logger.Log(
                            String.Format(
                                "Speech at <{0:0.0},{1:0.0},{2:0.0}>",
                                position.x,
                                position.y,
                                position.z),
                            Helpers.LogLevel.Debug);
                    }

                    // SET a handler for when it finishes.
                    FMODExec(channel.setCallback(endCallback));
                    RegisterChannel(channel);

                    // Un-pause the sound.
                    FMODExec(channel.setPaused(false));
                }
                catch (Exception ex)
                {
                    Logger.Log("Error playing speech: ", Helpers.LogLevel.Error, ex);
                }
                finally
                {
                    done.Set();
                }
            }));

            done.WaitOne(30 * 1000, false);
            return(len);
        }
Пример #3
0
        private void InitBuffer(UUID objectId, UUID soundId, bool loop, bool global, Vector3 worldpos, float vol)
        {
            if (manager == null || !manager.SoundSystemAvailable) return;

            // Do not let this get garbage-collected.
            lock (allBuffers)
                allBuffers[objectId] = this;

            ContainerId = objectId;
            Id = soundId;
            position = FromOMVSpace(worldpos);
            volumeSetting = vol;
            loopSound = loop;

            Logger.Log(
                String.Format(
                    "Playing sound at <{0:0.0},{1:0.0},{2:0.0}> ID {3}",
                    position.x,
                    position.y,
                    position.z,
                    Id.ToString()),
                Helpers.LogLevel.Debug);

            // Set flags to determine how it will be played.
            mode = FMOD.MODE.SOFTWARE | // Need software processing for all the features
                FMOD.MODE._3D |         // Need 3D effects for placement
                FMOD.MODE.OPENMEMORY;   // Use sound data in memory

            // Set coordinate space interpretation.
            if (global)
                mode |= FMOD.MODE._3D_WORLDRELATIVE;
            else
                mode |= FMOD.MODE._3D_HEADRELATIVE;

            if (loopSound)
                mode |= FMOD.MODE.LOOP_NORMAL;

            // Fetch the sound data.
            manager.Instance.Client.Assets.RequestAsset(
                Id,
                AssetType.Sound,
                false,
                new AssetManager.AssetReceivedCallback(Assets_OnSoundReceived));
        }