Example #1
0
 public void StartSound(float[] origin, int entnum, int entchannel, sfx_t sfx, float fvol, float attenuation, float timeofs)
 {
 }
Example #2
0
        public static sfxcache_t LoadSound(sfx_t s)
        {
            if (s.name[0] == '*')
            {
                return(null);
            }
            sfxcache_t sc = s.cache;

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

            if (s.truename != null)
            {
                name = s.truename;
            }
            else
            {
                name = s.name;
            }
            string namebuffer;

            if (name[0] == '#')
            {
                namebuffer = name.Substring(1);
            }
            else
            {
                namebuffer = "sound/" + name;
            }
            byte[] data = FS.LoadFile(namebuffer);
            if (data == null)
            {
                Com.DPrintf("Couldn't load " + namebuffer + "\\n");
                return(null);
            }

            int       size = data.Length;
            wavinfo_t info = GetWavinfo(s.name, data, size);

            if (info.channels != 1)
            {
                Com.Printf(s.name + " is a stereo sample - ignoring\\n");
                return(null);
            }

            float stepscale;

            if (DONT_DO_A_RESAMPLING_FOR_JOAL_AND_LWJGL)
            {
                stepscale = 1;
            }
            else
            {
                stepscale = (float)info.rate / S.GetDefaultSampleRate();
            }
            int len = (int)(info.samples / stepscale);

            len = len * info.width * info.channels;
            if (len >= maxsamplebytes)
            {
                Com.Printf(s.name + " is too long: " + len + " bytes?! ignoring.\\n");
                return(null);
            }

            sc           = s.cache = new sfxcache_t(len);
            sc.length    = info.samples;
            sc.loopstart = info.loopstart;
            sc.speed     = info.rate;
            sc.width     = info.width;
            sc.stereo    = info.channels;
            ResampleSfx(s, sc.speed, sc.width, data, info.dataofs);
            data = null;
            return(sc);
        }
Example #3
0
        public static void ResampleSfx(sfx_t sfx, int inrate, int inwidth, byte[] data, int offset)
        {
            int        outcount;
            int        srcsample;
            int        i;
            int        sample, samplefrac, fracstep;
            sfxcache_t sc;

            sc = sfx.cache;
            if (sc == null)
            {
                return;
            }
            float stepscale;

            if (DONT_DO_A_RESAMPLING_FOR_JOAL_AND_LWJGL)
            {
                stepscale = 1;
            }
            else
            {
                stepscale = (float)inrate / S.GetDefaultSampleRate();
            }
            outcount  = (int)(sc.length / stepscale);
            sc.length = outcount;
            if (sc.loopstart != -1)
            {
                sc.loopstart = (int)(sc.loopstart / stepscale);
            }
            if (DONT_DO_A_RESAMPLING_FOR_JOAL_AND_LWJGL == false)
            {
                sc.speed = S.GetDefaultSampleRate();
            }
            sc.width   = inwidth;
            sc.stereo  = 0;
            samplefrac = 0;
            fracstep   = (int)(stepscale * 256);
            for (i = 0; i < outcount; i++)
            {
                srcsample   = samplefrac >> 8;
                samplefrac += fracstep;
                if (inwidth == 2)
                {
                    sample = (data[offset + srcsample * 2] & 0xff) + (data[offset + srcsample * 2 + 1] << 8);
                }
                else
                {
                    sample = ((data[offset + srcsample] & 0xff) - 128) << 8;
                }

                if (sc.width == 2)
                {
                    if (Defines.LITTLE_ENDIAN)
                    {
                        sc.data[i * 2]     = (byte)(sample & 0xff);
                        sc.data[i * 2 + 1] = (byte)((sample >> 8) & 0xff);
                    }
                    else
                    {
                        sc.data[i * 2]     = (byte)((sample >> 8) & 0xff);
                        sc.data[i * 2 + 1] = (byte)(sample & 0xff);
                    }
                }
                else
                {
                    sc.data[i] = (byte)(sample >> 8);
                }
            }
        }
Example #4
0
 public static void StartSound(Single[] origin, Int32 entnum, Int32 entchannel, sfx_t sfx, Single fvol, Single attenuation, Single timeofs)
 {
     impl.StartSound(origin, entnum, entchannel, sfx, fvol, attenuation, timeofs);
 }