Exemplo n.º 1
0
    void Update()
    {
        FMOD.VECTOR pos         = FMODUtils.Vector3ToFMOD(transform.position);
        FMOD.VECTOR vel         = FMODUtils.Vector3ToFMOD(Vector3.zero);         // Only needed if we use doppler effect.
        FMOD.VECTOR alt_pan_pos = FMODUtils.Vector3ToFMOD(Vector3.zero);         // FIXME: I do not know what this is.

        if (Volume < 0)
        {
            Volume = 0;
        }
        if (Speed < 0)
        {
            Speed = 0;
        }

        if (Channel != null)
        {
            Channel.set3DAttributes(ref pos, ref vel, ref alt_pan_pos);
            Channel.setVolume(Volume);

            Channel.setMute(Mute);

            SetSpeed(Speed);
        }
    }
Exemplo n.º 2
0
    public void Play()
    {
        // TODO: Replace hard-coded values by parameters.
        _system.playSound(Sound, null, false, out Channel);

        Channel.getFrequency(out _defaultFrequency);

        _system.createDSPByType(FMOD.DSP_TYPE.PITCHSHIFT, out _pitchShift);
        FMODUtils.ERRCHECK(Channel.addDSP(0, _pitchShift));
    }
Exemplo n.º 3
0
    public FMOD.Sound Load(string filename)
    {
        FMOD.Sound result;

        // We only use spatialization (hence 3D mode).
        if (FMODUtils.ERRCHECK(FMODSystem.createStream(filename, FMOD.MODE._3D, out result)))
        {
            return(null);
        }

        return(result);
    }
Exemplo n.º 4
0
    void Update()
    {
        if (_id != -1)
        {
            Quaternion rotation = transform.rotation;

            FMOD.VECTOR pos     = FMODUtils.Vector3ToFMOD(transform.position);
            FMOD.VECTOR vel     = FMODUtils.Vector3ToFMOD(Vector3.zero);             // Only needed if we use doppler effect.
            FMOD.VECTOR forward = FMODUtils.Vector3ToFMOD(rotation * Vector3.forward);
            FMOD.VECTOR up      = FMODUtils.Vector3ToFMOD(rotation * Vector3.up);

            _system.set3DListenerAttributes(_id, ref pos, ref vel, ref forward, ref up);
        }
    }
Exemplo n.º 5
0
    void Awake()
    {
        // FIXME: I do not know what's the best way to do this.
        // I need a way to make sure this is called before any use of
        // AudioMixer.
        // (So FMOD is loaded and initialised)
        // And I also need to be able to call FMODSystem.update at
        // each update (so spatialization works), and
        // FMODSystem.release (because FMOD is not fully reset when
        // editing) when the game closes.
        // This is my current solution. Feel free to improve it.
        if (Instance == null)
        {
            Instance = this;

            // So we do not need to reload FMOD between scenes.
            DontDestroyOnLoad(gameObject);

#if WIN64
            string dll = "fmod64";
#else
            string dll = "fmod";
#endif

            var path = System.IO.Path.GetFullPath("Assets\\" + dll);
            LoadLibrary(path);

            if (FMODUtils.ERRCHECK(FMOD.Factory.System_Create(out FMODSystem)))
            {
                Debug.LogError("Failed to create FMOD system.");
                return;
            }

            // TODO: I do not know what any of these values are! (except
            // FMOD.INITFLAGS.NORMAL)
            FMODSystem.setDSPBufferSize(DSP_BUFFER_SIZE, 10);
            FMODSystem.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)0);
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }
    }