Exemple #1
0
    static void S_SoundList()
    {
        int total = 0;

        for (int i = 0; i < num_sfx; i++)
        {
            sfx_t      sfx = _KnownSfx[i];
            sfxcache_t sc  = (sfxcache_t)Cache_Check(sfx.cache);
            if (sc == null)
            {
                continue;
            }

            int size = sc.length * sc.width * (sc.stereo + 1);
            total += size;
            if (sc.loopstart >= 0)
            {
                Con_Printf("L");
            }
            else
            {
                Con_Printf(" ");
            }
            Con_Printf("({0:d2}b) {1:g6} : {2}\n", sc.width * 8, size, sfx.name);
        }
        Con_Printf("Total resident: {0}\n", total);
    }
Exemple #2
0
        static sfx_t AliasName(String aliasname, String truename)
        {
            sfx_t sfx = null;
            Int32 i;

            for (i = 0; i < num_sfx; i++)
            {
                if (known_sfx[i].name == null)
                {
                    break;
                }
            }
            if (i == num_sfx)
            {
                if (num_sfx == MAX_SFX)
                {
                    Com.Error(ERR_FATAL, "S_FindName: out of sfx_t");
                }
                num_sfx++;
            }

            sfx      = known_sfx[i];
            sfx.name = aliasname;
            sfx.registration_sequence = s_registration_sequence;
            sfx.truename = truename;
            return(sfx);
        }
        /**
         * Loads a sound from a wav file.
         */
        public static sfxcache_t LoadSound(sfx_t s)
        {
            if (s.name[0] == '*')
            {
                return(null);
            }

            // see if still in memory
            var sc = s.cache;

            if (sc != null)
            {
                return(sc);
            }

            string name;

            // load it in
            if (s.truename != null)
            {
                name = s.truename;
            }
            else
            {
                name = s.name;
            }

            string namebuffer;

            if (name[0] == '#')
            {
                namebuffer = name[1..];
Exemple #4
0
        sfx_t AliasName(string aliasname, string truename)
        {
            sfx_t  sfx = null;
            string s;
            int    i;

            s = new string (truename);
            for (i = 0; i < num_sfx; i++)
            {
                if (known_sfx[i].name == null)
                {
                    break;
                }
            }
            if (i == num_sfx)
            {
                if (num_sfx == MAX_SFX)
                {
                    Com.Error(Defines.ERR_FATAL, "S_FindName: out of sfx_t");
                }
                num_sfx++;
            }

            sfx = known_sfx[i];
            sfx.Clear();
            sfx.name = new string (aliasname);
            sfx.registration_sequence = s_registration_sequence;
            sfx.truename = s;
            sfx.bufferId = i;
            return(sfx);
        }
Exemple #5
0
 public virtual void Clear( )
 {
     sfx       = null;
     dist_mult = leftvol = rightvol = end = pos = looping = entnum = entchannel = master_vol = 0;
     Math3D.VectorClear(origin);
     fixed_origin = autosound = false;
 }
Exemple #6
0
        static sfx_t RegisterSexedSound(entity_state_t ent, String base_renamed)
        {
            sfx_t sfx   = null;
            var   model = "male";
            var   n     = CS_PLAYERSKINS + ent.number - 1;

            if (cl.configstrings[n] != null)
            {
                var p = cl.configstrings[n].IndexOf('\\');
                if (p >= 0)
                {
                    p++;
                    model = cl.configstrings[n].Substring(p);
                    p     = model.IndexOf('/');
                    if (p > 0)
                    {
                        model = model.Substring(0, p - 1);
                    }
                }
            }

            if (model == null || model.Length == 0)
            {
                model = "male";
            }
            var sexedFilename = "#players/" + model + "/" + base_renamed.Substring(1);

            sfx = FindName(sexedFilename, false);
            if (sfx == null)
            {
                FileStream f = null;
                try
                {
                    f = FS.FOpenFile(sexedFilename.Substring(1));
                }
                catch (Exception e)
                {
                }

                if (f != null)
                {
                    try
                    {
                        FS.FCloseFile(f);
                    }
                    catch (Exception e1)
                    {
                    }

                    sfx = RegisterSound(sexedFilename);
                }
                else
                {
                    var maleFilename = "player/male/" + base_renamed.Substring(1);
                    sfx = AliasName(sexedFilename, maleFilename);
                }
            }

            return(sfx);
        }
Exemple #7
0
    static sfx_t S_FindName(string name)
    {
        if (String.IsNullOrEmpty(name))
        {
            Sys_Error("S_FindName: NULL or empty\n");
        }

        if (name.Length >= q_shared.MAX_QPATH)
        {
            Sys_Error("Sound name too long: {0}", name);
        }

        // see if already loaded
        for (int i = 0; i < num_sfx; i++)
        {
            if (_KnownSfx[i].name == name)// !Q_strcmp(known_sfx[i].name, name))
            {
                return(_KnownSfx[i]);
            }
        }

        if (num_sfx == q_shared.MAX_SFX)
        {
            Sys_Error("S_FindName: out of sfx_t");
        }

        sfx_t sfx = _KnownSfx[num_sfx];

        sfx.name = name;

        num_sfx++;
        return(sfx);
    }
Exemple #8
0
 static JOALSoundImpl( )
 {
     S.Register(new JOALSoundImpl());
     for (var i = 0; i < known_sfx.Length; i++)
     {
         known_sfx[i] = new sfx_t();
     }
 }
Exemple #9
0
 public virtual void Clear( )
 {
     prev         = next = null;
     sfx          = null;
     volume       = attenuation = begin = entnum = entchannel = 0;
     fixed_origin = false;
     Math3D.VectorClear(origin);
 }
Exemple #10
0
        static LWJGLSoundImpl()
        {
            S.Register(new LWJGLSoundImpl());

            for (int i = 0; i < known_sfx.Length; i++)
            {
                known_sfx[i] = new sfx_t();
            }
        }
Exemple #11
0
        public sfx_t RegisterSound(string name)
        {
            sfx_t sfx = FindName(name, true);

            sfx.registration_sequence = s_registration_sequence;
            if (!s_registering)
            {
                LoadSound(sfx);
            }
            return(sfx);
        }
Exemple #12
0
    public static void S_TouchSound(string sample)
    {
        if (!sound_controller.IsInitialized)
        {
            return;
        }

        sfx_t sfx = S_FindName(sample);

        Cache_Check(sfx.cache);
    }
Exemple #13
0
    public static int _PlayVolHash = 543; // hash S_PlayVol


    public static void S_Init()
    {
        Con_Printf("\nSound Initialization\n");

        for (int i = 0; i < _KnownSfx.Length; i++)
        {
            _KnownSfx[i] = new sfx_t();
        }

        bgmvolume         = new cvar_t("bgmvolume", "1", true);
        volume            = new cvar_t("volume", "0.7", true);
        nosound           = new cvar_t("nosound", "0");
        precache          = new cvar_t("precache", "1");
        loadas8bit        = new cvar_t("loadas8bit", "0");
        bgmbuffer         = new cvar_t("bgmbuffer", "4096");
        ambient_level     = new cvar_t("ambient_level", "0.3");
        ambient_fade      = new cvar_t("ambient_fade", "100");
        snd_noextraupdate = new cvar_t("snd_noextraupdate", "0");
        snd_show          = new cvar_t("snd_show", "0");
        _snd_mixahead     = new cvar_t("_snd_mixahead", "0.1", true);

        if (HasParam("-nosound"))
        {
            return;
        }

        for (int i = 0; i < channels.Length; i++)
        {
            channels[i] = new channel_t();
        }

        Cmd_AddCommand("play", S_Play);
        Cmd_AddCommand("playvol", S_PlayVol);
        Cmd_AddCommand("stopsound", S_StopAllSoundsC);
        Cmd_AddCommand("soundlist", S_SoundList);
        Cmd_AddCommand("soundinfo", S_SoundInfo_f);

        snd_initialized = true;

        S_Startup();

        SND_InitScaletable();

        num_sfx = 0;

        Con_Printf("Sound sampling rate: {0}\n", shm.speed);

        // provides a tick sound until washed clean
        ambient_sfx[q_shared.AMBIENT_WATER] = S_PrecacheSound("ambience/water1.wav");
        ambient_sfx[q_shared.AMBIENT_SKY]   = S_PrecacheSound("ambience/wind2.wav");

        S_StopAllSounds(true);
    }
Exemple #14
0
        static SND_DMA( )
        {
            for (var i = 0; i < known_sfx.Length; i++)
            {
                known_sfx[i] = new sfx_t();
            }

            for (var i = 0; i < MAX_PLAYSOUNDS; i++)
            {
                s_playsounds[i] = new playsound_t();
            }
        }
Exemple #15
0
        public void StartLocalSound(String sound)
        {
            sfx_t sfx = RegisterSound(sound);

            if (sfx == null)
            {
                Com.Printf("S_StartLocalSound: can't cache " + sound + "\\n");
                return;
            }

            StartSound(null, Globals.cl.playernum + 1, 0, sfx, 1, 1, 0F);
        }
Exemple #16
0
        sfx_t FindName(string name, bool create)
        {
            int   i;
            sfx_t sfx = null;

            if (name == null)
            {
                Com.Error(Defines.ERR_FATAL, "S_FindName: NULL\\n");
            }
            if (name.Length == 0)
            {
                Com.Error(Defines.ERR_FATAL, "S_FindName: empty name\\n");
            }
            if (name.Length >= Defines.MAX_QPATH)
            {
                Com.Error(Defines.ERR_FATAL, "Sound name too long: " + name);
            }
            for (i = 0; i < num_sfx; i++)
            {
                if (name.Equals(known_sfx[i].name))
                {
                    return(known_sfx[i]);
                }
            }

            if (!create)
            {
                return(null);
            }
            for (i = 0; i < num_sfx; i++)
            {
                if (known_sfx[i].name == null)
                {
                    break;
                }
            }
            if (i == num_sfx)
            {
                if (num_sfx == MAX_SFX)
                {
                    Com.Error(Defines.ERR_FATAL, "S_FindName: out of sfx_t");
                }
                num_sfx++;
            }

            sfx = known_sfx[i];
            sfx.Clear();
            sfx.name = name;
            sfx.registration_sequence = s_registration_sequence;
            sfx.bufferId = i;
            return(sfx);
        }
Exemple #17
0
    static sfxcache_t S_LoadSound(sfx_t s)
    {
        // see if still in memory
        sfxcache_t sc = (sfxcache_t)Cache_Check(s.cache);

        if (sc != null)
        {
            return(sc);
        }

        // load it in
        string namebuffer = "sound/" + s.name;

        byte[] data = COM_LoadFile(namebuffer);
        if (data == null)
        {
            Con_Printf("Couldn't load {0}\n", namebuffer);
            return(null);
        }

        wavinfo_t info = GetWavInfo(s.name, data);

        if (info.channels != 1)
        {
            Con_Printf("{0} is a stereo sample\n", s.name);
            return(null);
        }

        float stepscale = info.rate / (float)shm.speed;
        int   len       = (int)(info.samples / stepscale);

        len *= info.width * info.channels;

        s.cache = Cache_Alloc(len, s.name);
        if (s.cache == null)
        {
            return(null);
        }

        sc           = new sfxcache_t();
        sc.length    = info.samples;
        sc.loopstart = info.loopstart;
        sc.speed     = info.rate;
        sc.width     = info.width;
        sc.stereo    = info.channels;
        s.cache.data = sc;

        ResampleSfx(s, sc.speed, sc.width, new ByteArraySegment(data, info.dataofs));

        return(sc);
    }
Exemple #18
0
        sfx_t RegisterSexedSound(entity_state_t ent, string base_renamed)
        {
            sfx_t  sfx   = null;
            string model = null;
            int    n     = Globals.CS_PLAYERSKINS + ent.number - 1;

            if (Globals.cl.configstrings[n] != null)
            {
                int p = Globals.cl.configstrings[n].IndexOf('\\');
                if (p >= 0)
                {
                    p++;
                    model = Globals.cl.configstrings[n].Substring(p);
                    p     = model.IndexOf('/');
                    if (p > 0)
                    {
                        model = model.Substring(0, p);
                    }
                }
            }

            if (model == null || model.Length == 0)
            {
                model = "male";
            }
            string sexedFilename = "#players/" + model + "/" + base_renamed.Substring(1);

            sfx = FindName(sexedFilename, false);
            if (sfx != null)
            {
                return(sfx);
            }
            if (FS.FileLength(sexedFilename.Substring(1)) > 0)
            {
                return(RegisterSound(sexedFilename));
            }

            if (model.EqualsIgnoreCase("female"))
            {
                string femaleFilename = "player/female/" + base_renamed.Substring(1);
                if (FS.FileLength("sound/" + femaleFilename) > 0)
                {
                    return(AliasName(sexedFilename, femaleFilename));
                }
            }

            string maleFilename = "player/male/" + base_renamed.Substring(1);

            return(AliasName(sexedFilename, maleFilename));
        }
Exemple #19
0
        /*
         * ==============
         * S_LoadSound
         * ==============
         */
        public static sfxcache_t S_LoadSound(sfx_t s)
        {
            string namebuffer = new string(new char[256]);

            byte[]     data;
            sfxcache_t sc;

            // see if still in memory
            sc = s.cache;
            if (sc != null)
            {
                return(sc);
            }

            //Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
            // load it in
            namebuffer  = "sound/";
            namebuffer += s.name;
            namebuffer += ".mp3";

            //	Con_Printf ("loading %s\n",namebuffer);

            data = common.COM_LoadStackFile(namebuffer, null, 0);
            if (data == null)
            {
                console.Con_Printf("Couldn't load " + namebuffer + "\n");
                return(null);
            }

            sc      = new sfxcache_t();
            s.cache = sc;
            if (sc == null)
            {
                return(null);
            }

            sc.loopstart = -1;
            for (int kk = 0; kk < loops.Length; kk++)
            {
                if (s.name.CompareTo(loops[kk]) == 0)
                {
                    sc.loopstart = 1;
                    break;
                }
            }
            sc.data = data;

            return(sc);
        }
Exemple #20
0
    static void S_Play()
    {
        for (int i = 1; i < cmd_argc; i++)
        {
            string name = Cmd_Argv(i);
            int    k    = name.IndexOf('.');
            if (k == -1)
            {
                name += ".wav";
            }

            sfx_t sfx = S_PrecacheSound(name);
            S_StartSound(_PlayHash++, 0, sfx, ref listener_origin, 1.0f, 1.0f);
        }
    }
Exemple #21
0
        /*
         * =================
         * S_StaticSound
         * =================
         */
        public static void S_StaticSound(sfx_t sfx, double[] origin, double vol, double attenuation)
        {
            channel_t  ss;
            sfxcache_t sc;

            if (sfx == null)
            {
                return;
            }

            if (total_channels == MAX_CHANNELS)
            {
                console.Con_Printf("total_channels == MAX_CHANNELS\n");
                return;
            }

            ss = channels[total_channels];
            total_channels++;

            sc = S_LoadSound(sfx);
            if (sc == null)
            {
                return;
            }

            if (sc.loopstart == -1)
            {
                console.Con_Printf("Sound " + sfx.name + " not looped\n");
                return;
            }

            ss.sfx = sfx;
            mathlib.VectorCopy(origin, ref ss.origin);
            ss.master_vol = (int)vol;
            ss.dist_mult  = (attenuation / 64) / sound_nominal_clip_dist;

            SND_Spatialize(ss);

            MediaElement media = new MediaElement();

            ss.media       = media;
            media.AutoPlay = true;
            media.SetSource(new MemoryStream(sc.data));
            media.Tag         = ss;
            media.MediaEnded += media_MediaEnded;
            SetVolume(ss);
            Page.thePage.parentCanvas.Children.Add(media);
        }
        private sfx_t RegisterSexedSound(entity_state_t ent, string @base)
        {
            sfx_t sfx = null;

            // determine what model the client is using
            string model = null;
            var    n     = Defines.CS_PLAYERSKINS + ent.number - 1;

            if (Globals.cl.configstrings[n] != null)
            {
                var p = Globals.cl.configstrings[n].IndexOf('\\');

                if (p >= 0)
                {
                    p++;
                    model = Globals.cl.configstrings[n][p..];
Exemple #23
0
        public static sfx_t RegisterSound(String name)
        {
            sfx_t sfx = null;

            if (!sound_started)
            {
                return(null);
            }
            sfx = FindName(name, true);
            sfx.registration_sequence = s_registration_sequence;
            if (!s_registering)
            {
                WaveLoader.LoadSound(sfx);
            }
            return(sfx);
        }
Exemple #24
0
    static void S_PlayVol()
    {
        for (int i = 1; i < cmd_argc; i += 2)
        {
            string name = Cmd_Argv(i);
            int    k    = name.IndexOf('.');
            if (k == -1)
            {
                name += ".wav";
            }

            sfx_t sfx = S_PrecacheSound(name);
            float vol = float.Parse(Cmd_Argv(i + 1));
            S_StartSound(_PlayVolHash++, 0, sfx, ref listener_origin, vol, 1.0f);
        }
    }
        static entity_t[] _TempEntities = new entity_t[MAX_TEMP_ENTITIES]; // cl_temp_entities[MAX_TEMP_ENTITIES]

        #endregion Fields

        #region Methods

        // CL_InitTEnts
        static void InitTempEntities()
        {
            _SfxWizHit =  Sound.PrecacheSound ("wizard/hit.wav");
            _SfxKnigtHit = Sound.PrecacheSound ("hknight/hit.wav");
            _SfxTink1 = Sound.PrecacheSound ("weapons/tink1.wav");
            _SfxRic1 = Sound.PrecacheSound ("weapons/ric1.wav");
            _SfxRic2 = Sound.PrecacheSound ("weapons/ric2.wav");
            _SfxRic3 = Sound.PrecacheSound ("weapons/ric3.wav");
            _SfxRExp3 = Sound.PrecacheSound ("weapons/r_exp3.wav");

            for (int i = 0; i < _TempEntities.Length; i++)
                _TempEntities[i] = new entity_t();

            for (int i = 0; i < _Beams.Length; i++)
                _Beams[i] = new beam_t();
        }
Exemple #26
0
    public static sfx_t S_PrecacheSound(string sample)
    {
        if (!snd_initialized || nosound.value != 0)
        {
            return(null);
        }

        sfx_t sfx = S_FindName(sample);

        // cache it in
        if (precache.value != 0)
        {
            S_LoadSound(sfx);
        }

        return(sfx);
    }
Exemple #27
0
    static void SND_Spatialize(channel_t ch)
    {
        // anything coming from the view entity will allways be full volume
        if (ch.entnum == cl.viewentity)
        {
            ch.leftvol  = ch.master_vol;
            ch.rightvol = ch.master_vol;
            return;
        }

        // calculate stereo seperation and distance attenuation
        sfx_t   snd        = ch.sfx;
        Vector3 source_vec = ch.origin - listener_origin;

        float dist = Mathlib.Normalize(ref source_vec) * ch.dist_mult;
        float dot  = Vector3.Dot(listener_right, source_vec);

        float rscale, lscale;

        if (shm.channels == 1)
        {
            rscale = 1.0f;
            lscale = 1.0f;
        }
        else
        {
            rscale = 1.0f + dot;
            lscale = 1.0f - dot;
        }

        // add in distance effect
        float scale = (1.0f - dist) * rscale;

        ch.rightvol = (int)(ch.master_vol * scale);
        if (ch.rightvol < 0)
        {
            ch.rightvol = 0;
        }

        scale      = (1.0f - dist) * lscale;
        ch.leftvol = (int)(ch.master_vol * scale);
        if (ch.leftvol < 0)
        {
            ch.leftvol = 0;
        }
    }
Exemple #28
0
        public sfxcache_t LoadSound(sfx_t s)
        {
            if (s.isCached)
            {
                return(s.cache);
            }
            sfxcache_t sc = WaveLoader.LoadSound(s);

            if (sc != null)
            {
                InitBuffer(sc.data, s.bufferId, sc.speed);
                s.isCached   = true;
                s.cache.data = null;
            }

            return(sc);
        }
Exemple #29
0
        /*
        ==============
        S_LoadSound
        ==============
        */
        public static sfxcache_t S_LoadSound(sfx_t s)
        {
            string	        namebuffer = StringExtensions.StringOfLength(256);
            Uint8Array data;
            sfxcache_t	    sc;

            // see if still in memory
            sc = s.cache;
            if (sc != null)
                return sc;

            //Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
            // load it in
            namebuffer = "sound/";
            namebuffer += s.name;
            namebuffer += ".mp3";

            //	Con_Printf ("loading %s\n",namebuffer);

            data = common.COM_LoadStackFile(namebuffer, null, 0);
            if (data == null)
            {
                console.Con_Printf ("Couldn't load " + namebuffer + "\n");
                return null;
            }

            sc = new sfxcache_t ();
            s.cache = sc;
            if (sc == null)
                return null;

            sc.loopstart = -1;
            for(int kk = 0; kk < loops.Length; kk++)
            {
                if (s.name.CompareTo(loops[kk]) == 0)
                {
                    sc.loopstart = 1;
                    break;
                }
            }
            sc.data = data;

            return sc;
        }
Exemple #30
0
 public void StartSound(Single[] origin, Int32 entnum, Int32 entchannel, sfx_t sfx, Single fvol, Single attenuation, Single timeofs)
 {
     if (sfx == null)
     {
         return;
     }
     if (sfx.name[0] == '*')
     {
         sfx = RegisterSexedSound(Globals.cl_entities[entnum].current, sfx.name);
     }
     if (LoadSound(sfx) == null)
     {
         return;
     }
     if (attenuation != Defines.ATTN_STATIC)
     {
         attenuation *= 0.5F;
     }
     PlaySound.Allocate(origin, entnum, entchannel, buffers[sfx.bufferId], fvol, attenuation, timeofs);
 }
Exemple #31
0
    public static void CL_InitTEnts()
    {
        cl_sfx_wizhit    = S_PrecacheSound("wizard/hit.wav");
        cl_sfx_knighthit = S_PrecacheSound("hknight/hit.wav");
        cl_sfx_tink1     = S_PrecacheSound("weapons/tink1.wav");
        cl_sfx_ric1      = S_PrecacheSound("weapons/ric1.wav");
        cl_sfx_ric2      = S_PrecacheSound("weapons/ric2.wav");
        cl_sfx_ric3      = S_PrecacheSound("weapons/ric3.wav");
        cl_sfx_r_exp3    = S_PrecacheSound("weapons/r_exp3.wav");

        for (int i = 0; i < cl_temp_entities.Length; i++)
        {
            cl_temp_entities[i] = new entity_t();
        }

        for (int i = 0; i < cl_beams.Length; i++)
        {
            cl_beams[i] = new beam_t();
        }
    }
Exemple #32
0
 public void StartSound(float[] origin, int entnum, int entchannel, sfx_t sfx, float fvol, float attenuation, float timeofs)
 {
     if (sfx == null)
     {
         return;
     }
     if (sfx.name[0] == '*')
     {
         sfx = RegisterSexedSound(Globals.cl_entities[entnum].current, sfx.name);
     }
     if (LoadSound(sfx) == null)
     {
         return;
     }
     if (attenuation != Defines.ATTN_STATIC)
     {
         attenuation *= 0.5F;
     }
     PlaySound.Allocate(origin, entnum, entchannel, buffers.Get(sfx.bufferId), fvol, attenuation, timeofs);
 }
Exemple #33
0
        // ResampleSfx
        static void ResampleSfx(sfx_t sfx, int inrate, int inwidth, ByteArraySegment data)
        {
            sfxcache_t sc = (sfxcache_t)Cache.Check(sfx.cache);
            if (sc == null)
                return;

            float stepscale = (float)inrate / _shm.speed;	// this is usually 0.5, 1, or 2

            int outcount = (int)(sc.length / stepscale);
            sc.length = outcount;
            if (sc.loopstart != -1)
                sc.loopstart = (int)(sc.loopstart / stepscale);

            sc.speed = _shm.speed;
            if (_LoadAs8bit.Value != 0)
                sc.width = 1;
            else
                sc.width = inwidth;
            sc.stereo = 0;

            sc.data = new byte[outcount * sc.width]; // uze: check this later!!!

            // resample / decimate to the current source rate
            byte[] src = data.Data;
            if (stepscale == 1 && inwidth == 1 && sc.width == 1)
            {
                // fast special case
                for (int i = 0; i < outcount; i++)
                {
                    int v = src[data.StartIndex + i] - 128;
                    sc.data[i] = (byte)((sbyte)v); //((signed char *)sc.data)[i] = (int)( (unsigned char)(data[i]) - 128);
                }
            }
            else
            {
                // general case
                int samplefrac = 0;
                int fracstep = (int)(stepscale * 256);
                int sample;
                short[] sa = new short[1];
                for (int i = 0; i < outcount; i++)
                {
                    int srcsample = samplefrac >> 8;
                    samplefrac += fracstep;
                    if (inwidth == 2)
                    {
                        Buffer.BlockCopy(src, data.StartIndex + srcsample * 2, sa, 0, 2);
                        sample = Common.LittleShort(sa[0]);//  ((short *)data)[srcsample] );
                    }
                    else
                    {
                        sample = (int)(src[data.StartIndex + srcsample] - 128) << 8;
                        //sample = (int)( (unsigned char)(data[srcsample]) - 128) << 8;
                    }

                    if (sc.width == 2)
                    {
                        sa[0] = (short)sample;
                        Buffer.BlockCopy(sa, 0, sc.data, i * 2, 2); //((short *)sc->data)[i] = sample;
                    }
                    else
                    {
                        sc.data[i] = (byte)(sbyte)(sample >> 8); //((signed char *)sc->data)[i] = sample >> 8;
                    }
                }
            }
        }
Exemple #34
0
        /*
        ================
        S_Init
        ================
        */
        public static void S_Init()
        {
            int kk;

            for (kk = 0; kk < MAX_CHANNELS; kk++) channels[kk] = new channel_t();

            console.Con_Printf("\nSound Initialization\n");

            if (common.COM_CheckParm("-nosound") != 0)
                return;

            cmd.Cmd_AddCommand("play", S_Play);
            cmd.Cmd_AddCommand("playvol", S_PlayVol);
            cmd.Cmd_AddCommand("stopsound", S_StopAllSoundsC);
            cmd.Cmd_AddCommand("soundlist", S_SoundList);
            cmd.Cmd_AddCommand("soundinfo", S_SoundInfo_f);

            cvar_t.Cvar_RegisterVariable(nosound);
            cvar_t.Cvar_RegisterVariable(volume);
            cvar_t.Cvar_RegisterVariable(precache);
            cvar_t.Cvar_RegisterVariable(loadas8bit);
            cvar_t.Cvar_RegisterVariable(bgmvolume);
            cvar_t.Cvar_RegisterVariable(bgmbuffer);
            cvar_t.Cvar_RegisterVariable(ambient_level);
            cvar_t.Cvar_RegisterVariable(ambient_fade);
            cvar_t.Cvar_RegisterVariable(snd_noextraupdate);
            cvar_t.Cvar_RegisterVariable(snd_show);
            cvar_t.Cvar_RegisterVariable(_snd_mixahead);

            /*if (host_parms.memsize < 0x800000)
            {
                Cvar_Set ("loadas8bit", "1");
                Con_Printf ("loading all sounds as 8bit\n");
            }*/

            snd_initialized = true;

            S_Startup ();

            known_sfx = new sfx_t[MAX_SFX];
            for(kk = 0; kk < MAX_SFX; kk++) known_sfx[kk] = new sfx_t();
            num_sfx = 0;

            // provides a tick sound until washed clean

            //	if (shm.buffer)
            //		shm.buffer[4] = shm.buffer[5] = 0x7f;	// force a pop for debugging

            for(kk = 0; kk < bspfile.NUM_AMBIENTS; kk++) ambient_sfx[kk] = new sfx_t();
            ambient_sfx[bspfile.AMBIENT_WATER] = S_PrecacheSound ("ambience/water1.wav");
            ambient_sfx[bspfile.AMBIENT_SKY] = S_PrecacheSound ("ambience/wind2.wav");

            S_StopAllSounds (true);
        }
Exemple #35
0
        // =======================================================================
        // Start a sound effect
        // =======================================================================
        public static void S_StartSound(int entnum, int entchannel, sfx_t sfx, double[] origin, double fvol, double attenuation)
        {
            channel_t   target_chan, check;
            sfxcache_t	sc;
            int		    vol;
            int		    ch_idx;
            int		    skip;

            /*if (entnum != 195)
                return;*/

            if (sound_started == 0)
                return;

            if (sfx == null)
                return;

            if (nosound.value != 0)
                return;

            vol = (int)(fvol*255);

            // pick a channel to play on
            target_chan = SND_PickChannel(entnum, entchannel);
            if (target_chan == null)
                return;

            // spatialize
            mathlib.VectorCopy(origin, ref target_chan.origin);
            target_chan.dist_mult = attenuation / sound_nominal_clip_dist;
            target_chan.master_vol = vol;
            target_chan.entnum = entnum;
            target_chan.entchannel = entchannel;
            SND_Spatialize(target_chan);

            if (target_chan.leftvol == 0 && target_chan.rightvol == 0)
                return;		// not audible at all

            // new channel
            sc = S_LoadSound (sfx);
            if (sc == null)
            {
                target_chan.sfx = null;
                return;		// couldn't load the sound's data
            }

            target_chan.sfx = sfx;

            /*            if (sc.loopstart != -1)
                console.Con_Printf(sfx.name + " " + entnum + " " + entchannel + "\n");*/

            MediaElement media = new MediaElement();
            target_chan.media = media;
            media.AutoPlay = true;
            media.SetSource(new MemoryStream(sc.data));
            media.Tag = target_chan;
            /*if (sc.loopstart != -1)
            {
                media.MediaEnded += media_MediaEnded;
                target_chan.looping = 1;
            }
            else*/
                media.MediaEnded += media_MediaEnded2;
            SetVolume(target_chan);
            Page.thePage.parentCanvas.Children.Add(media);
        }
Exemple #36
0
        /*
        =================
        S_StaticSound
        =================
        */
        public static void S_StaticSound(sfx_t sfx, double[] origin, double vol, double attenuation)
        {
            channel_t	ss;
            sfxcache_t  sc;

            if (sfx == null)
                return;

            if (total_channels == MAX_CHANNELS)
            {
                console.Con_Printf ("total_channels == MAX_CHANNELS\n");
                return;
            }

            ss = channels[total_channels];
            total_channels++;

            sc = S_LoadSound (sfx);
            if (sc == null)
                return;

            if (sc.loopstart == -1)
            {
                console.Con_Printf ("Sound " + sfx.name + " not looped\n");
                return;
            }

            ss.sfx = sfx;
            mathlib.VectorCopy (origin, ref ss.origin);
            ss.master_vol = (int)vol;
            ss.dist_mult = (attenuation/64) / sound_nominal_clip_dist;

            SND_Spatialize (ss);

            MediaElement media = new MediaElement();
            ss.media = media;
            media.AutoPlay = true;
            media.SetSource(new MemoryStream(sc.data));
            media.Tag = ss;
            media.MediaEnded += media_MediaEnded;
            SetVolume(ss);
            Page.thePage.parentCanvas.Children.Add(media);
        }