public void SwapBytes( ) { this.op = ( ushort )EndianHelper.LittleShort(( short )this.op); this.a = EndianHelper.LittleShort(this.a); this.b = EndianHelper.LittleShort(this.b); this.c = EndianHelper.LittleShort(this.c); }
// ResampleSfx private void ResampleSfx(SoundEffect_t sfx, int inrate, int inwidth, ByteArraySegment data) { var sc = ( SoundEffectCache_t )this.Host.Cache.Check(sfx.cache); if (sc == null) { return; } var stepscale = ( float )inrate / this._shm.speed; // this is usually 0.5, 1, or 2 var outcount = ( int )(sc.length / stepscale); sc.length = outcount; if (sc.loopstart != -1) { sc.loopstart = ( int )(sc.loopstart / stepscale); } sc.speed = this._shm.speed; if (this.Host.Cvars.LoadAs8bit.Get <bool>()) { 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 var src = data.Data; if (stepscale == 1 && inwidth == 1 && sc.width == 1) { // fast special case for (var i = 0; i < outcount; i++) { var 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 var samplefrac = 0; var fracstep = ( int )(stepscale * 256); int sample; var sa = new short[1]; for (var i = 0; i < outcount; i++) { var srcsample = samplefrac >> 8; samplefrac += fracstep; if (inwidth == 2) { Buffer.BlockCopy(src, data.StartIndex + srcsample * 2, sa, 0, 2); sample = EndianHelper.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; } } } }
public void SwapBytes( ) { this.type = ( ushort )EndianHelper.LittleShort(( short )this.type); this.ofs = ( ushort )EndianHelper.LittleShort(( short )this.ofs); this.s_name = EndianHelper.LittleLong(this.s_name); }