public TrackGain(int sampleRate, int sampleSize) { if(!ReplayGain.IsSupportedFormat(sampleRate, sampleSize)) { throw new NotSupportedException("Unsupported format. Supported sample sizes are 16, 24."); } this.freqIndex = ReplayGain.FreqInfos.IndexOf(i => i.SampleRate == sampleRate); this.sampleSize = sampleSize; this.gainData = new GainData(); this.lInPreBuf = new double[ReplayGain.MAX_ORDER * 2]; this.lStepBuf = new double[ReplayGain.MAX_SAMPLES_PER_WINDOW + ReplayGain.MAX_ORDER]; this.lOutBuf = new double[ReplayGain.MAX_SAMPLES_PER_WINDOW + ReplayGain.MAX_ORDER]; this.rInPreBuf = new double[ReplayGain.MAX_ORDER * 2]; this.rStepBuf = new double[ReplayGain.MAX_SAMPLES_PER_WINDOW + ReplayGain.MAX_ORDER]; this.rOutBuf = new double[ReplayGain.MAX_SAMPLES_PER_WINDOW + ReplayGain.MAX_ORDER]; this.sampleWindow = (int)Math.Ceiling(sampleRate * ReplayGain.RMS_WINDOW_TIME); this.lInPre = new CPtr<double>(lInPreBuf, ReplayGain.MAX_ORDER); this.lStep = new CPtr<double>(lStepBuf, ReplayGain.MAX_ORDER); this.lOut = new CPtr<double>(lOutBuf, ReplayGain.MAX_ORDER); this.rInPre = new CPtr<double>(rInPreBuf, ReplayGain.MAX_ORDER); this.rStep = new CPtr<double>(rStepBuf, ReplayGain.MAX_ORDER); this.rOut = new CPtr<double>(rOutBuf, ReplayGain.MAX_ORDER); }
public CR2WChunk(CR2WFile cr2w) { this.cr2w = cr2w; parentPtr = new CPtr(cr2w); parentPtr.Name = nameof(Parent); flags = new CUInt16(cr2w); flags.Name = nameof(Flags); typeName = new CName(cr2w); typeName.Name = nameof(Type); Flags = 8192; }
public CPtr CreatePtr(string type, CR2WChunk tochunk, string varname = "") { var cptr = new CPtr(this); cptr.Name = varname; cptr.Type = type; if (tochunk != null) { cptr.val = chunks.IndexOf(tochunk) + 1; } return(cptr); }
public CPtr CreatePtr(string type, CR2WExportWrapper tochunk, string varname = "") { var ptr = new CPtr(this); ptr.Name = varname; ptr.Type = type; if (tochunk != null) { ptr.val = chunks.IndexOf(tochunk) + 1; } return(ptr); }
private void getQuestRootNodes(List <CR2WExportWrapper> rootNodes) { CQuest quest = (CQuest)File.chunks[0].data; CPtr <CQuestGraph> graphObj = quest.Graph; if (graphObj != null) { CArray <CPtr <CGraphBlock> > graphBlocks = (graphObj.Reference.data as CQuestGraph).GraphBlocks; if (graphBlocks != null) { rootNodes.AddRange(from part in graphBlocks.Elements.OfType <CPtr <CGraphBlock> >() where part != null && part.GetPtrTargetType() == "CQuestStartBlock" select part.Reference); } } }
private void getQuestPhaseRootNodes(List <CR2WExportWrapper> rootNodes) { CQuestPhase resource = (CQuestPhase)File.Chunks[0].data; CPtr <CQuestGraph> graphObj = resource.Graph; if (graphObj != null) { var graphBlocks = (graphObj.Reference.data as CQuestGraph).GraphBlocks; if (graphBlocks != null) { rootNodes.AddRange(from part in graphBlocks.Elements.OfType <CPtr <CGraphBlock> >() where part != null && part.GetPtrTargetType() == "CQuestPhaseInputBlock" select part.Reference); } } }
public CR2WChunk(CR2WFile cr2w) { this.cr2w = cr2w; parentPtr = new CPtr(cr2w); parentPtr.Name = "Parent"; flags = new CUInt16(cr2w); flags.Name = "Flags"; typeName = new CName(cr2w); typeName.Name = "Type"; Flags = 8192; }
public override List <IPtrAccessor> GetConnections() { var list = new List <IPtrAccessor>(); if (Chunk.data is CQuestGraphBlock graphBlock) { CArray <SCachedConnections> cachedConnections = graphBlock.CachedConnections; if (cachedConnections != null) { foreach (SCachedConnections conn in cachedConnections.Elements) { CName socketId = conn.SocketId; CArray <SBlockDesc> blocks = conn.Blocks; if (blocks != null) { foreach (SBlockDesc block in blocks.Elements) { CPtr <CQuestGraphBlock> graphpointer = block.Ock; if (graphpointer.Reference != null) { list.Add(graphpointer); } } } } } } else if (Chunk.data is CStorySceneLinkElement linkElement) { CPtr <CStorySceneLinkElement> nextLinkElementPtr = linkElement.NextLinkElement; if (nextLinkElementPtr != null) { if (nextLinkElementPtr.Reference != null) { list.Add(nextLinkElementPtr); } } } else { } return(list); }
public override List <IPtrAccessor> GetConnections() { var connections = new List <IPtrAccessor>(); CQuestPhaseBlock phaseBlock = (CQuestPhaseBlock)Chunk.data; CPtr <CQuestGraph> graphObj = phaseBlock.EmbeddedGraph; if (graphObj != null && graphObj.Reference != null) { CArray <CPtr <CGraphBlock> > graphBlocks = (graphObj.Reference.data as CQuestGraph).GraphBlocks; if (graphBlocks != null) { connections.AddRange(graphBlocks.Elements.Where(_ => _.GetPtrTargetType() == "CQuestPhaseInputBlock")); } } return(connections); }
public override void UpdateView() { var height = Height; base.UpdateView(); Height = height; lblCondition.Text = ""; CStorySceneFlowCondition resource = (CStorySceneFlowCondition)Chunk.data; CPtr <IQuestCondition> questCondition = resource.QuestCondition; if (questCondition != null) { if (questCondition.Reference != null) { lblCondition.Click += delegate { FireSelectEvent(questCondition.Reference); }; // put something in the tex field: dynamic IQuestCondition = questCondition.Reference.data; //FIXME dynamic try { var factIdObj = IQuestCondition.FactId; if (factIdObj != null && factIdObj is CString) { lblCondition.Text = ((CString)factIdObj).val; } } catch (Exception) { lblCondition.Text = questCondition.Reference.REDName; } } } var commentObj = resource.Comment; if (commentObj != null && commentObj is CString) { lblCondition.Text = ((CString)commentObj).val; } }
private void frmChunkFlowDiagram_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (Form.ModifierKeys != Keys.Control) { foreach (var c in ChunkEditors.Values) { var conns = c.GetConnections(); if (conns != null) { for (var i = 0; i < conns.Count; i++) { var sp = c.GetConnectionLocation(i); var rect = new Rectangle(c.Location.X + c.Width, c.Location.Y + sp.Y - connectionPointSize / 2, connectionPointSize, connectionPointSize); if (rect.Contains(e.Location)) { connectingSource = conns[i]; connectingSourceEditor = c; connectingSourceIndex = i; isConnecting = true; return; } } } } selectionStart = e.Location; isSelecting = true; } else { prevMousePos = e.Location; isMoving = true; } } }
public CR2WExportWrapper(CR2WFile file) { this.cr2w = file; parentPtr = new CPtr(file) { Name = "Parent" }; flags = new CUInt16(file) { Name = "Flags" }; typeName = new CName(file) { Name = "Type" }; Flags = 8192; _export.objectFlags = 8192; }
public CR2WExportWrapper(CR2WFile file, CR2WExport export) { this.cr2w = file; _export = export; parentPtr = new CPtr(file) { Name = "Parent" }; ParentChunkId = export.parentID; flags = new CUInt16(file) { Name = "Flags", val = export.objectFlags }; typeName = new CName(file) { Name = "Type", val = export.className }; }
public void VisitPtr(CPtr ptr) { _val = " p" + _val; }
private void FilterButter(CPtr<double> input, CPtr<double> output, long nSamples, double[] aKernel, double[] bKernel) { while (nSamples-- != 0) { output[0] = input[0] * bKernel[0] - output[-1] * aKernel[1] + input[-1] * bKernel[1] - output[-2] * aKernel[2] + input[-2] * bKernel[2]; ++output; ++input; } }
public void ParseJournalType(CPtr <CJournalBase> pointer) { CR2WExportWrapper typenode = pointer.Reference; CVariable target = typenode.data; if (target is CJournalCreature creature) { vulnerable_treview.Show(); var name = creature.BaseName; this.Text = $@"Creature editor [{name}]"; descriptiontext += (name + "<br>"); ParseUsedAgainst(creature.ItemsUsedAgainstCreature); ParseImageAndPreview(creature); ParseCJournalCreatureChildren(creature.Children); } else if (target is CJournalCharacter character) { var name = character.BaseName; ParseImageAndPreview(character); this.Text = $@"Character editor [{name}]"; descriptiontext += (name + "<br>"); vulnerable_treview.Hide(); ParseChildDescription(character.Children); } else if (target is CJournalGlossary) { var name = (target as CJournalGlossary).BaseName; this.Text = $@"Glossary editor [{name}]"; descriptiontext += (name + "<br>"); vulnerable_treview.Hide(); ParseChildDescription((target as CJournalGlossary).Children); } else if (target is CJournalTutorial) { var name = (target as CJournalTutorial).BaseName; descriptiontext += (target as CJournalTutorial).Description.ToString(); vulnerable_treview.Hide(); entityImage.Hide(); this.Text = $@"Tutorial editor [{name}]"; } else if (target is CJournalStoryBookChapter) { var name = (target as CJournalStoryBookChapter).BaseName; vulnerable_treview.Hide(); entityImage.Hide(); this.Text = $@"Story book editor [{name}]"; } else if (target is CJournalStoryBookPage) { var name = (target as CJournalStoryBookPage).BaseName; descriptiontext += "<h3>" + (target as CJournalStoryBookPage).Title + "</h3>"; ParseChildDescription((target as CJournalStoryBookPage).Children); vulnerable_treview.Hide(); entityImage.Hide(); this.Text = $@"Story book editor [{name}]"; } else if (target is CJournalQuest) { textRender.Hide(); vulnerable_treview.Hide(); QuestView = new TreeView(); splitContainer1.Panel2.Controls.Add(QuestView); QuestView.Dock = DockStyle.Fill; var name = (target as CJournalQuest).Title + " " + (target as CJournalQuest).Type; this.Text = $@"Quest editor [{name}]"; ParseCJournalQuestChild((target as CJournalQuest).Children); } else { vulnerable_treview.Hide(); var name = (target as CJournalBase).BaseName; this.Text = $@"{typenode.REDType} editor [{name}]"; } }
/// <summary> /// Disposes the resources used to calculate ReplayGain, but doesn't clear the result of the analysis. /// </summary> public void Dispose() { this.lInPreBuf = null; this.lStepBuf = null; this.lOutBuf = null; this.rInPreBuf = null; this.rStepBuf = null; this.rOutBuf = null; this.lInPre = new CPtr<double>(); this.lStep = new CPtr<double>(); this.lOut = new CPtr<double>(); this.rInPre = new CPtr<double>(); this.rStep = new CPtr<double>(); this.rOut = new CPtr<double>(); }
private void FilterYule(CPtr<double> input, CPtr<double> output, long nSamples, double[] aKernel, double[] bKernel) { while (nSamples-- != 0) { output[0] = 1e-10 /* 1e-10 is a hack to avoid slowdown because of denormals */ + input[0] * bKernel[0] - output[-1] * aKernel[1] + input[-1] * bKernel[1] - output[-2] * aKernel[2] + input[-2] * bKernel[2] - output[-3] * aKernel[3] + input[-3] * bKernel[3] - output[-4] * aKernel[4] + input[-4] * bKernel[4] - output[-5] * aKernel[5] + input[-5] * bKernel[5] - output[-6] * aKernel[6] + input[-6] * bKernel[6] - output[-7] * aKernel[7] + input[-7] * bKernel[7] - output[-8] * aKernel[8] + input[-8] * bKernel[8] - output[-9] * aKernel[9] + input[-9] * bKernel[9] - output[-10] * aKernel[10] + input[-10] * bKernel[10]; ++output; ++input; } }
public void ParseJournalType(CPtr pointer) { var typenode = pointer.PtrTarget; switch (pointer.PtrTargetType) { case "CJournalCreature": { vulnerable_treview.Show(); var name = typenode.GetVariableByName("baseName"); indeximage_label.Text = typenode.GetVariableByName("image").ToString(); this.Text = $@"Creature editor [{name}]"; descriptiontext += (name + "\n\n"); ParseUsedAgainst((CArray)typenode.GetVariableByName("itemsUsedAgainstCreature")); ParseCJournalCreatureChildren((CArray)typenode.GetVariableByName("children")); break; } case "CJournalCharacter": { var name = typenode.GetVariableByName("baseName"); indeximage_label.Text = typenode.GetVariableByName("image").ToString(); this.Text = $@"Character editor [{name}]"; descriptiontext += (name + "\n\n"); vulnerable_treview.Hide(); ParseCJournalCharacterChildren((CArray)typenode.GetVariableByName("children")); break; } case "CJournalGlossary": { var name = typenode.GetVariableByName("baseName"); this.Text = $@"Glossary editor [{name}]"; descriptiontext += (name + "\n\n"); vulnerable_treview.Hide(); ParseCJournalGlossaryChildren((CArray)typenode.GetVariableByName("children")); break; } case "CJournalTutorial": { var name = typenode.GetVariableByName("baseName"); indeximage_label.Text = name.ToString(); descriptiontext += typenode.GetVariableByName("description").ToString(); vulnerable_treview.Hide(); this.Text = $@"Tutorial editor [{name}]"; break; } case "CJournalStoryBookChapter": { var name = typenode.GetVariableByName("baseName"); indeximage_label.Text = name.ToString(); vulnerable_treview.Hide(); this.Text = $@"Story book editor [{name}]"; break; } case "CJournalQuest": { textRender.Hide(); vulnerable_treview.Hide(); QuestView = new TreeView(); splitContainer1.Panel2.Controls.Add(QuestView); QuestView.Dock = DockStyle.Fill; var name = typenode.GetVariableByName("title") + " " + typenode.GetVariableByName("type"); indeximage_label.Text = name; this.Text = $@"Quest editor [{name}]"; ParseCJournalQuestChild((CArray)typenode.GetVariableByName("children")); break; } default: { vulnerable_treview.Hide(); var name = typenode.GetVariableByName("baseName"); indeximage_label.Text = name.ToString(); this.Text = $@"{typenode.Type} editor [{name}]"; break; } } }
private void AnalyzeSamples(CPtr<double> leftSamples, CPtr<double> rightSamples) { int numSamples = leftSamples.Length; CPtr<double> curLeft; CPtr<double> curRight; long batchSamples = numSamples; long curSamples; long curSamplePos = 0; if (numSamples < ReplayGain.MAX_ORDER) { Array.Copy(leftSamples.Array, 0, this.lInPreBuf, ReplayGain.MAX_ORDER, numSamples); Array.Copy(rightSamples.Array, 0, this.rInPreBuf, ReplayGain.MAX_ORDER, numSamples); } else { Array.Copy(leftSamples.Array, 0, this.lInPreBuf, ReplayGain.MAX_ORDER, ReplayGain.MAX_ORDER); Array.Copy(rightSamples.Array, 0, this.rInPreBuf, ReplayGain.MAX_ORDER, ReplayGain.MAX_ORDER); } while (batchSamples > 0) { curSamples = batchSamples > this.sampleWindow - this.totSamp ? this.sampleWindow - this.totSamp : batchSamples; if (curSamplePos < ReplayGain.MAX_ORDER) { curLeft = this.lInPre + curSamplePos; curRight = this.rInPre + curSamplePos; if (curSamples > ReplayGain.MAX_ORDER - curSamplePos) curSamples = ReplayGain.MAX_ORDER - curSamplePos; } else { curLeft = leftSamples + curSamplePos; curRight = rightSamples + curSamplePos; } FilterYule(curLeft, this.lStep + this.totSamp, curSamples, ReplayGain.FreqInfos[this.freqIndex].AYule, ReplayGain.FreqInfos[this.freqIndex].BYule); FilterYule(curRight, this.rStep + this.totSamp, curSamples, ReplayGain.FreqInfos[this.freqIndex].AYule, ReplayGain.FreqInfos[this.freqIndex].BYule); FilterButter(this.lStep + this.totSamp, this.lOut + this.totSamp, curSamples, ReplayGain.FreqInfos[this.freqIndex].AButter, ReplayGain.FreqInfos[this.freqIndex].BButter); FilterButter(this.rStep + this.totSamp, this.rOut + this.totSamp, curSamples, ReplayGain.FreqInfos[this.freqIndex].AButter, ReplayGain.FreqInfos[this.freqIndex].BButter); curLeft = this.lOut + this.totSamp; // Get the squared values curRight = this.rOut + this.totSamp; for (long i = curSamples % 16; i-- != 0; ) { this.lSum += Sqr(curLeft[0]); ++curLeft; this.rSum += Sqr(curRight[0]); ++curRight; } for (long i = curSamples / 16; i-- != 0; ) { this.lSum += Sqr(curLeft[0]) + Sqr(curLeft[1]) + Sqr(curLeft[2]) + Sqr(curLeft[3]) + Sqr(curLeft[4]) + Sqr(curLeft[5]) + Sqr(curLeft[6]) + Sqr(curLeft[7]) + Sqr(curLeft[8]) + Sqr(curLeft[9]) + Sqr(curLeft[10]) + Sqr(curLeft[11]) + Sqr(curLeft[12]) + Sqr(curLeft[13]) + Sqr(curLeft[14]) + Sqr(curLeft[15]); curLeft += 16; this.rSum += Sqr(curRight[0]) + Sqr(curRight[1]) + Sqr(curRight[2]) + Sqr(curRight[3]) + Sqr(curRight[4]) + Sqr(curRight[5]) + Sqr(curRight[6]) + Sqr(curRight[7]) + Sqr(curRight[8]) + Sqr(curRight[9]) + Sqr(curRight[10]) + Sqr(curRight[11]) + Sqr(curRight[12]) + Sqr(curRight[13]) + Sqr(curRight[14]) + Sqr(curRight[15]); curRight += 16; } batchSamples -= curSamples; curSamplePos += curSamples; this.totSamp += curSamples; if (this.totSamp == this.sampleWindow) { // Get the Root Mean Square (RMS) for this set of samples double val = ReplayGain.STEPS_PER_DB * 10.0 * Math.Log10((this.lSum + this.rSum) / this.totSamp * 0.5 + 1.0e-37); int ival = (int)val; if (ival < 0) ival = 0; if (ival >= this.gainData.Accum.Length) ival = this.gainData.Accum.Length - 1; this.gainData.Accum[ival]++; this.lSum = this.rSum = 0.0; if (this.totSamp > int.MaxValue) { throw new OverflowException("Too many samples! Change to long and recompile!"); } Array.Copy(this.lOutBuf, (int)this.totSamp, this.lOutBuf, 0, ReplayGain.MAX_ORDER); Array.Copy(this.rOutBuf, (int)this.totSamp, this.rOutBuf, 0, ReplayGain.MAX_ORDER); Array.Copy(this.lStepBuf, (int)this.totSamp, this.lStepBuf, 0, ReplayGain.MAX_ORDER); Array.Copy(this.rStepBuf, (int)this.totSamp, this.rStepBuf, 0, ReplayGain.MAX_ORDER); this.totSamp = 0; } if (this.totSamp > this.sampleWindow) { // somehow I really screwed up: Error in programming! Contact author about totsamp > sampleWindow throw new Exception("Gain analysis error!"); } } if (numSamples < ReplayGain.MAX_ORDER) { Array.Copy(this.lInPreBuf, numSamples, this.lInPreBuf, 0, ReplayGain.MAX_ORDER - numSamples); Array.Copy(this.rInPreBuf, numSamples, this.rInPreBuf, 0, ReplayGain.MAX_ORDER - numSamples); Array.Copy(leftSamples.Array, leftSamples.Index, this.lInPreBuf, ReplayGain.MAX_ORDER - numSamples, numSamples); Array.Copy(rightSamples.Array, rightSamples.Index, this.rInPreBuf, ReplayGain.MAX_ORDER - numSamples, numSamples); } else { Array.Copy(leftSamples.Array, leftSamples.Index + numSamples - ReplayGain.MAX_ORDER, this.lInPreBuf, 0, ReplayGain.MAX_ORDER); Array.Copy(rightSamples.Array, rightSamples.Index + numSamples - ReplayGain.MAX_ORDER, this.rInPreBuf, 0, ReplayGain.MAX_ORDER); } }