public GameActor(GameSample gs, string name) : base(name) { this.gs = gs; }
public GameSamples() { sample[0] = new GameSample(1); }
static GameSample read_wav_sample(object f) { uint offset = 0; uint length=0, rate=0, filesize, temp32; ushort bits=0, temp16=0; byte[] buf = new byte[32]; GameSample result; /* read the core header and make sure it's a WAVE file */ offset += (uint)osd_fread(f, buf, 4); if (offset < 4) return null; if (!Encoding.Default.GetString(buf).StartsWith("RIFF")) return null; /* get the total size */ offset += (uint)osd_fread(f, buf, 4); if (offset < 8) return null; filesize = (uint)BitConverter.ToInt32(buf, 0); /* read the RIFF file type and make sure it's a WAVE file */ offset += (uint)osd_fread(f, buf, 4); if (offset < 12) return null; if (!Encoding.Default.GetString(buf).StartsWith("WAVE")) return null; /* seek until we find a format tag */ while (true) { offset += (uint)osd_fread(f, buf, 4); offset += (uint)osd_fread(f, ref length, 4); //length = intelLong(length); if (Encoding.Default.GetString(buf).StartsWith("fmt ")) break; /* seek to the next block */ osd_fseek(f, (int)length, SEEK_CUR); offset += length; if (offset >= filesize) return null; } /* read the format -- make sure it is PCM */ offset +=(uint) osd_fread_lsbfirst(f, ref temp16, 2); if (temp16 != 1) return null; /* number of channels -- only mono is supported */ offset += (uint)osd_fread_lsbfirst(f, ref temp16, 2); if (temp16 != 1) return null; /* sample rate */ offset += (uint)osd_fread(f, ref rate, 4); //rate = intelLong(rate); /* bytes/second and block alignment are ignored */ offset += (uint)osd_fread(f, buf, 6); /* bits/sample */ offset += (uint)osd_fread_lsbfirst(f, ref bits, 2); if (bits != 8 && bits != 16) return null; /* seek past any extra data */ osd_fseek(f,(int) length - 16, SEEK_CUR); offset += length - 16; /* seek until we find a data tag */ while (true) { offset += (uint)osd_fread(f, buf, 4); offset += (uint)osd_fread(f, ref length, 4); //length = intelLong(length); if (Encoding.Default.GetString(buf).StartsWith("data")) break; /* seek to the next block */ osd_fseek(f, (int)length, SEEK_CUR); offset += length; if (offset >= filesize) return null; } /* allocate the game sample */ result = new GameSample((int)length); /* fill in the sample data */ result.length = (int)length; result.smpfreq = (int)rate; result.resolution = bits; /* read the data in */ if (bits == 8) { osd_fread(f, result.data, (int)length); /* convert 8-bit data to signed samples */ for (temp32 = 0; temp32 < length; temp32++) { //sbyte b = (sbyte)result.data[temp32]; //b ^= unchecked((sbyte)0x80); //result.data[temp32] = (byte)b; result.data[temp32] ^= 0x80; } } else { /* 16-bit data is fine as-is */ osd_fread_lsbfirst(f, result.data, (int)length); } return result; }
public GameSamples(int size) { sample = new GameSample[size]; for (int i = 0; i < size; i++) sample[i] = new GameSample(1); }