Check() public static method

Cache_Check Returns value of c.data if still cached or null
public static Check ( cache_user_t c ) : object
c cache_user_t
return object
コード例 #1
0
        // S_SoundList
        private static void SoundList()
        {
            int total = 0;

            for (int i = 0; i < _NumSfx; 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.Print("L");
                }
                else
                {
                    Con.Print(" ");
                }
                Con.Print("({0:d2}b) {1:g6} : {2}\n", sc.width * 8, size, sfx.name);
            }
            Con.Print("Total resident: {0}\n", total);
        }
コード例 #2
0
        // S_TouchSound (char *sample)
        public static void TouchSound(string sample)
        {
            if (!_Controller.IsInitialized)
            {
                return;
            }

            sfx_t sfx = FindName(sample);

            Cache.Check(sfx.cache);
        }
コード例 #3
0
        // S_LoadSound
        private static sfxcache_t 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 = common.LoadFile(namebuffer);
            if (data == null)
            {
                Con.Print("Couldn't load {0}\n", namebuffer);
                return(null);
            }

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

            if (info.channels != 1)
            {
                Con.Print("{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);
        }
コード例 #4
0
        // ResampleSfx
        private 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;
                    }
                }
            }
        }