public Dump(DataChunk Chunk, Image Image = null, string Text = null) { if (Chunk == null) throw new ArgumentNullException(); this.chunk = Chunk; this.image = Image; this.text = Text; }
public void DataChunk_WithEmptyEnumearation_ShouldReturnCountAsZero() { //Arrange //Act var actual = new DataChunk<string>(Enumerable.Empty<string>(), isEnd: true); //Assert Assert.AreEqual(0, actual.Count, "DataChunk was constructed with an empty array, but had a count that was not 0"); }
public void DataChunk_WhenEndOfData_SetsIsEndToTrue() { //Arrange //Act var actual = new DataChunk<string>(new[] { @"don't care" }, isEnd: true); //Assert Assert.IsTrue(actual.IsEnd, "Failed to set IsEnd property of enumeration."); }
public void DataChunk_WithTwoItems_ShouldMatchEnnumerationCount() { //Arrange //Act var actual = new DataChunk<string>(new[] { "1", "2" }, isEnd: true); //Assert Assert.AreEqual(2, actual.Count, "Failed to match count of enumeration."); }
public void DataChunk_WithTwoItems_SetsLastItem() { //Arrange var input = new[] { "Johnson", "Controls" }; //Act var actual = new DataChunk<string>(input, isEnd: true); //Assert Assert.AreEqual(input.Last(), actual.LastElement, "Failed to set last item of enumeration."); }
public void Parse(DataChunk dataChunk, IObserver<string> observer) { ParameterValidator.ParameterValidator.EnsureParametersAreValid(new NullValidatorWithValue<DataChunk>(() => dataChunk, dataChunk), new NullValidatorWithValue<IObserver<string>>(() => observer, observer)); var exactSizedByteData = GetExactSizedByteData(dataChunk.Chunk, dataChunk.Size); var exactSizedByteDataAsString = ConvertBytesToString(exactSizedByteData); LookForMessageAndNotifyObserver(exactSizedByteDataAsString, observer); }
private void WriteWavHeader(int length) { FMOD.SOUND_TYPE type = FMOD.SOUND_TYPE.UNKNOWN; FMOD.SOUND_FORMAT format = FMOD.SOUND_FORMAT.NONE; int channels = 0, bits = 0, temp1 = 0; float rate = 0.0f; float temp = 0.0f; if (sound == null) { return; } sound.getFormat(ref type, ref format, ref channels, ref bits); sound.getDefaults(ref rate, ref temp, ref temp, ref temp1); fs.Seek(0, SeekOrigin.Begin); FmtChunk fmtChunk = new FmtChunk(); DataChunk dataChunk = new DataChunk(); WavHeader wavHeader = new WavHeader(); RiffChunk riffChunk = new RiffChunk(); fmtChunk.chunk = new RiffChunk(); fmtChunk.chunk.id = new char[4]; fmtChunk.chunk.id[0] = 'f'; fmtChunk.chunk.id[1] = 'm'; fmtChunk.chunk.id[2] = 't'; fmtChunk.chunk.id[3] = ' '; fmtChunk.chunk.size = Marshal.SizeOf(fmtChunk) - Marshal.SizeOf(riffChunk); fmtChunk.wFormatTag = 1; fmtChunk.nChannels = (ushort)channels; fmtChunk.nSamplesPerSec = (uint)rate; fmtChunk.nAvgBytesPerSec = (uint)(rate * channels * bits / 8); fmtChunk.nBlockAlign = (ushort)(1 * channels * bits / 8); fmtChunk.wBitsPerSample = (ushort)bits; dataChunk.chunk = new RiffChunk(); dataChunk.chunk.id = new char[4]; dataChunk.chunk.id[0] = 'd'; dataChunk.chunk.id[1] = 'a'; dataChunk.chunk.id[2] = 't'; dataChunk.chunk.id[3] = 'a'; dataChunk.chunk.size = (int)length; wavHeader.chunk = new RiffChunk(); wavHeader.chunk.id = new char[4]; wavHeader.chunk.id[0] = 'R'; wavHeader.chunk.id[1] = 'I'; wavHeader.chunk.id[2] = 'F'; wavHeader.chunk.id[3] = 'F'; wavHeader.chunk.size = (int)(Marshal.SizeOf(fmtChunk) + Marshal.SizeOf(riffChunk) + length); wavHeader.rifftype = new char[4]; wavHeader.rifftype[0] = 'W'; wavHeader.rifftype[1] = 'A'; wavHeader.rifftype[2] = 'V'; wavHeader.rifftype[3] = 'E'; /* Write out the WAV header. */ IntPtr wavHeaderPtr = Marshal.AllocHGlobal(Marshal.SizeOf(wavHeader)); IntPtr fmtChunkPtr = Marshal.AllocHGlobal(Marshal.SizeOf(fmtChunk)); IntPtr dataChunkPtr = Marshal.AllocHGlobal(Marshal.SizeOf(dataChunk)); byte []wavHeaderBytes = new byte[Marshal.SizeOf(wavHeader)]; byte []fmtChunkBytes = new byte[Marshal.SizeOf(fmtChunk)]; byte []dataChunkBytes = new byte[Marshal.SizeOf(dataChunk)]; Marshal.StructureToPtr(wavHeader, wavHeaderPtr, false); Marshal.Copy(wavHeaderPtr, wavHeaderBytes, 0, Marshal.SizeOf(wavHeader)); Marshal.StructureToPtr(fmtChunk, fmtChunkPtr, false); Marshal.Copy(fmtChunkPtr, fmtChunkBytes, 0, Marshal.SizeOf(fmtChunk)); Marshal.StructureToPtr(dataChunk, dataChunkPtr, false); Marshal.Copy(dataChunkPtr, dataChunkBytes, 0, Marshal.SizeOf(dataChunk)); fs.Write(wavHeaderBytes, 0, Marshal.SizeOf(wavHeader)); fs.Write(fmtChunkBytes, 0, Marshal.SizeOf(fmtChunk)); fs.Write(dataChunkBytes, 0, Marshal.SizeOf(dataChunk)); }
//--Public Methods public WaveFile(IChunk[] WaveChunks) { this.waveChunks = WaveChunks; this.dataChunk = (DataChunk)GetChunk(WaveHelper.WaveChunkType.Data); this.fmtChunk = (FormatChunk)GetChunk(WaveHelper.WaveChunkType.Format); }
private void SaveToWav() { FileStream fs = null; int channels = 0, bits = 0; float rate = 0; IntPtr ptr1 = new IntPtr(), ptr2 = new IntPtr(); uint lenbytes = 0, len1 = 0, len2 = 0; FMOD.SOUND_TYPE type = FMOD.SOUND_TYPE.WAV; FMOD.SOUND_FORMAT format = FMOD.SOUND_FORMAT.NONE; int temp1 = 0; float temp3 = 0; if (sound == null) { return; } sound.getFormat (ref type, ref format, ref channels, ref bits); sound.getDefaults(ref rate, ref temp3, ref temp3, ref temp1); sound.getLength (ref lenbytes, FMOD.TIMEUNIT.PCMBYTES); FmtChunk fmtChunk = new FmtChunk(); DataChunk dataChunk = new DataChunk(); WavHeader wavHeader = new WavHeader(); RiffChunk riffChunk = new RiffChunk(); fmtChunk.chunk = new RiffChunk(); fmtChunk.chunk.id = new char[4]; fmtChunk.chunk.id[0] = 'f'; fmtChunk.chunk.id[1] = 'm'; fmtChunk.chunk.id[2] = 't'; fmtChunk.chunk.id[3] = ' '; fmtChunk.chunk.size = Marshal.SizeOf(fmtChunk) - Marshal.SizeOf(riffChunk); fmtChunk.wFormatTag = 1; fmtChunk.nChannels = (ushort)channels; fmtChunk.nSamplesPerSec = (uint)rate; fmtChunk.nAvgBytesPerSec = (uint)(rate * channels * bits / 8); fmtChunk.nBlockAlign = (ushort)(1 * channels * bits / 8); fmtChunk.wBitsPerSample = (ushort)bits; dataChunk.chunk = new RiffChunk(); dataChunk.chunk.id = new char[4]; dataChunk.chunk.id[0] = 'd'; dataChunk.chunk.id[1] = 'a'; dataChunk.chunk.id[2] = 't'; dataChunk.chunk.id[3] = 'a'; dataChunk.chunk.size = (int)lenbytes; wavHeader.chunk = new RiffChunk(); wavHeader.chunk.id = new char[4]; wavHeader.chunk.id[0] = 'R'; wavHeader.chunk.id[1] = 'I'; wavHeader.chunk.id[2] = 'F'; wavHeader.chunk.id[3] = 'F'; wavHeader.chunk.size = (int)(Marshal.SizeOf(fmtChunk) + Marshal.SizeOf(riffChunk) + lenbytes); wavHeader.rifftype = new char[4]; wavHeader.rifftype[0] = 'W'; wavHeader.rifftype[1] = 'A'; wavHeader.rifftype[2] = 'V'; wavHeader.rifftype[3] = 'E'; fs = new FileStream("record.wav", FileMode.Create, FileAccess.Write); /* Write out the WAV header. */ IntPtr wavHeaderPtr = Marshal.AllocHGlobal(Marshal.SizeOf(wavHeader)); IntPtr fmtChunkPtr = Marshal.AllocHGlobal(Marshal.SizeOf(fmtChunk)); IntPtr dataChunkPtr = Marshal.AllocHGlobal(Marshal.SizeOf(dataChunk)); byte []wavHeaderBytes = new byte[Marshal.SizeOf(wavHeader)]; byte []fmtChunkBytes = new byte[Marshal.SizeOf(fmtChunk)]; byte []dataChunkBytes = new byte[Marshal.SizeOf(dataChunk)]; Marshal.StructureToPtr(wavHeader, wavHeaderPtr, false); Marshal.Copy(wavHeaderPtr, wavHeaderBytes, 0, Marshal.SizeOf(wavHeader)); Marshal.StructureToPtr(fmtChunk, fmtChunkPtr, false); Marshal.Copy(fmtChunkPtr, fmtChunkBytes, 0, Marshal.SizeOf(fmtChunk)); Marshal.StructureToPtr(dataChunk, dataChunkPtr, false); Marshal.Copy(dataChunkPtr, dataChunkBytes, 0, Marshal.SizeOf(dataChunk)); fs.Write(wavHeaderBytes, 0, Marshal.SizeOf(wavHeader)); fs.Write(fmtChunkBytes, 0, Marshal.SizeOf(fmtChunk)); fs.Write(dataChunkBytes, 0, Marshal.SizeOf(dataChunk)); /* Lock the sound to get access to the raw data. */ sound.@lock(0, lenbytes, ref ptr1, ref ptr2, ref len1, ref len2); /* Write it to disk. */ byte []rawdata = new byte[len1]; Marshal.Copy(ptr1, rawdata, 0, (int)len1); fs.Write(rawdata, 0, (int)len1); /* Unlock the sound to allow FMOD to use it again. */ sound.unlock(ptr1, ptr2, len1, len2); fs.Close(); MessageBox.Show("Written to record.wav"); }
private void LoadData(DataChunk chunk, long startTime, long endTime) // startTime and endTime are unused... { long pointer; if (chunk.Start < 0) { pointer = currentRow + 1; } else { pointer = currentRow + chunk.Start + 1; } db.rrdFile.Seek(dataOffset + (pointer*8), SeekOrigin.Begin); //cat.debug("Archive Base: " + dataOffset + " Archive Pointer: " + pointer); //cat.debug("Start Offset: " + chunk.start + " End Offset: " // + (rowCount - chunk.end)); double[][] data = chunk.Data; /* * This is also terrible - cleanup - CT */ int row = 0; for (int i = chunk.Start; i < RowCount - chunk.End; i++, row++) { if (i < 0) { // no valid data yet for (int ii = 0; ii < chunk.DsCount; ii++) { data[row][ii] = Double.NaN; } } else if (i >= RowCount) { // past valid data area for (int ii = 0; ii < chunk.DsCount; ii++) { data[row][ii] = Double.NaN; } } else { // inside the valid are but the pointer has to be wrapped if (pointer >= RowCount) { pointer -= RowCount; db.rrdFile.Seek(dataOffset + (pointer*8), SeekOrigin.Begin); } for (int ii = 0; ii < chunk.DsCount; ii++) { data[row][ii] = db.rrdFile.ReadDouble(); } pointer++; } } }
internal DataChunk LoadData(DataChunk chunk) { DateTime end = DateTime.UtcNow; DateTime start = end.AddDays(-1); LoadData(chunk, start.GetTimestamp(), end.GetTimestamp()); return chunk; }
/// <summary> /// Loads a chunk of data, applies any extra settings, calls UpdateOutput /// </summary> /// <param name="Entry"></param> public async Task LoadChunk(IChunkInfo Entry) { if (Entry == null) return; this.CurrentChunk = this.Image.GetChunk(Entry); this.strip_txtStart.Text = this.CurrentChunk.Info.Addr.StartOffset.ToString("X"); if (this.UseLength) this.strip_txtEnd.Text = this.CurrentChunk.Info.Addr.Length.ToString("X"); else this.strip_txtEnd.Text = this.CurrentChunk.Info.Addr.EndOffset.ToString("X"); if (Entry is TextChunkInfo) this.OutMode = DumpTypes.Text; else if (Entry is GfxChunkInfo) this.OutMode = DumpTypes.Gfx; //else this.OutMode = DumpTypes.Raw; await this.UpdateOutput(); }
public void Save(string continent) { var hasWdt = FileManager.Instance.Provider.Exists(string.Format(@"World\Maps\{0}\{0}.wdt", continent)); var chunks = new Dictionary<uint, DataChunk>(); if(hasWdt) { using(var inFile = FileManager.Instance.Provider.OpenFile(string.Format(@"World\Maps\{0}\{0}.wdt", continent))) { var reader = new BinaryReader(inFile); while(reader.BaseStream.Position + 8 < reader.BaseStream.Length) { var signature = reader.ReadUInt32(); var size = reader.ReadInt32(); if (reader.BaseStream.Position + size > reader.BaseStream.Length) break; var data = reader.ReadBytes(size); if(chunks.ContainsKey(signature)) { Log.Warning("Duplicate chunk in WDT file, this is unexpected!"); continue; } chunks.Add(signature, new DataChunk { Data = data, Signature = signature, Size = size }); } } } using(var outStream = FileManager.Instance.GetOutputStream(string.Format(@"World\Maps\{0}\{0}.wdt", continent))) { var writer = new BinaryWriter(outStream); if (hasWdt == false) CreateEmptyWdt(writer, continent); else { if(chunks.ContainsKey(0x4D504844) == false) { var dch = new DataChunk { Signature = 0x4D504844, Size = 32, Data = BitConverter.GetBytes(Flags) .Concat(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) .ToArray() }; chunks.Add(dch.Signature, dch); } else { var cnk = chunks[0x4D504844]; Buffer.BlockCopy(BitConverter.GetBytes(Flags), 0, cnk.Data, 0, 4); } foreach(var pair in chunks) { writer.Write(pair.Value.Signature); writer.Write(pair.Value.Size); writer.Write(pair.Value.Data); } } } }
//--Public Methods public WaveFile(IChunk[] WaveChunks) { this.waveChunks = WaveChunks; this.dataChunk = (DataChunk)GetChunk(WaveHelper.WaveChunkType.Data); this.fmtChunk = (FormatChunk)GetChunk(WaveHelper.WaveChunkType.Format); }
/// <summary> /// Build references for moon phases and anything that they may affects /// </summary> /// <param name="dataOvlReference"></param> public MoonPhaseReferences(DataOvlReference dataOvlReference) { this._moonPhaseChunk = dataOvlReference.GetDataChunk(DataOvlReference.DataChunkName.MOON_PHASES); }