During a talent show at school I tried my hand at rapping and during a speed rap section the camera sampling rate blended words and an innocent and rather clever phrase was picked up as something entirely different(Yes I rapped).
Having another recording from an alternate source I set out to prove that there was a significant difference between the two recordings the reason however I would leave up to them, though in a coming post I think I'll make a digital forensics package(for files that is). Anywho lets get to it:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AudioAnalysis
{
public partial class Form1 : Form
{
public Form1()
{
// reader2.Text = track0.Value.ToString();
InitializeComponent();
}
private void openWaveToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Wave File (*.wav)|*.wav;";
if (open.ShowDialog() != DialogResult.OK) return;
waveViewer1.SamplesPerPixel = 450;
waveViewer1.WaveStream = new NAudio.Wave.WaveFileReader(open.FileName);
chart1.Series.Add("wave");
chart1.Series["wave"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
chart1.Series["wave"].ChartArea = "ChartArea1";
NAudio.Wave.WaveChannel32 wave = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName));
byte[] buffer = new byte[track.Value];
int read = 0;
while (wave.Position < track.Value)
{
read = wave.Read(buffer, 0, track.Value);
for (int i = track0.Value; i < read / 4; i++)
{
chart1.Series["wave"].Points.Add(BitConverter.ToSingle(buffer, i * 4));
string stringy = (10*BitConverter.ToSingle(buffer, i * 4)).ToString();
outsalot.AppendText(stringy + "\n");
bar.Value = i;
if (bar.Value == bar.Maximum-1) { bar.Value = 0; }
}
}
}
private void readout_TextChanged(object sender, EventArgs e)
{
track.Value = Int32.Parse(readout.Text);
}
private void track_Scroll(object sender, EventArgs e)
{
readout.Text = track.Value.ToString();
bar.Maximum = track.Value/4;
}
private void chart1_Click(object sender, EventArgs e)
{
}
private void logToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void track0_Scroll(object sender, EventArgs e)
{
reader2.Text = track0.Value.ToString();
}
private void reader2_TextChanged(object sender, EventArgs e)
{
track0.Value = Int32.Parse(reader2.Text);
}
private void hAMToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int vxl = 0; vxl < outsalot.Lines.Length-5; vxl = vxl + 1)
{
string hamm = (float.Parse(outsalot.Lines[vxl]) - float.Parse(outsytwo.Lines[vxl])).ToString();
hamming.Text = hamming.Text + hamm+"\n";
bar.Maximum = outsalot.Lines.Length - 5;
bar.Value = vxl;
if (bar.Value == outsalot.Lines.Length - 10) { bar.Value = 0; }
}
}
private void move_Click(object sender, EventArgs e)
{
outsytwo.Text = outsalot.Text;
outsalot.ResetText();
chart1.Series.Clear();
}
private void diracΔToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int vxl = 0; vxl < outsalot.Lines.Length ; vxl = vxl + 1)
{
string hamm = ((float.Parse(outsalot.Lines[vxl]) - Int32.Parse(outsytwo.Lines[vxl]))/Math.Abs((float.Parse(outsalot.Lines[vxl]) - Int32.Parse(outsytwo.Lines[vxl])))).ToString();
hamming.Text = hamming.Text + hamm + "\n";
bar.Maximum = outsalot.Lines.Length;
bar.Value = vxl;
if (bar.Value == outsalot.Lines.Length - 10) { bar.Value = 0; }
}
}
private void differenceToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int vxl = 0; vxl < outsalot.Lines.Length-1; vxl = vxl + 1)
{
string one = ((float.Parse(outsalot.Lines[vxl]) - float.Parse(outsalot.Lines[vxl+1]))) .ToString();
hamming.Text = hamming.Text + one + "\n";
bar.Maximum = outsalot.Lines.Length;
bar.Value = vxl;
if (bar.Value == outsalot.Lines.Length - 10) { bar.Value = 0; }
}
outsalot.Text=hamming.Text;
hamming.Text="";
for (int vxl = 0; vxl < outsalot.Lines.Length-1; vxl = vxl + 1)
{
string two = ((float.Parse(outsytwo.Lines[vxl]) - float.Parse(outsytwo.Lines[vxl + 1]))).ToString();
hamming.Text = hamming.Text + two+ "\n";
bar.Maximum = outsytwo.Lines.Length;
bar.Value = vxl;
if (bar.Value == outsalot.Lines.Length - 10) { bar.Value = 0; }
}
outsytwo.Text=hamming.Text;
hamming.Text = "";
}
private void hamming_TextChanged(object sender, EventArgs e)
{
hamming.Text = hamming.Text.Replace("NaN", "0");
}
}
}
So the basic idea was to load the audio, split db and pitch into to sections(which is why I switched to the MS Studio C# collection as it has this lib function built in. Simple from here, we just break this down into text and output to two textboxes:
Sure, yeah, I could easily have used two strings to hold the data but the text box will come in handy later and it is useful for later running through the data and selecting rows. So we want to calculate the Hamming Distance so, made a File>HAM, option:
private void hAMToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int vxl = 0; vxl < outsalot.Lines.Length-5; vxl = vxl + 1)
{
string hamm = (float.Parse(outsalot.Lines[vxl]) - float.Parse(outsytwo.Lines[vxl])).ToString();
hamming.Text = hamming.Text + hamm+"\n";
bar.Maximum = outsalot.Lines.Length - 5;
bar.Value = vxl;
if (bar.Value == outsalot.Lines.Length - 10) { bar.Value = 0; }
}
}
which really just subtracts the two waveforms. How? well you need to open the two separate waveforms which is where the empty white textbox and the [Move] <button> come into play. Press the move button, open the second wave form and calculate the HAM.(Again File>HAM though hopefully you recall).
Also I should point out, I did not take the time to fix the scrolling bars at the top(these select how much of the WaveForm(.wav) files you wish to analyse. So what you need to do before even opening the first WAV is to move these around until numbers appear in the text box(I recommend 0 left and 16384 right, and just cut the audio so that they are in the same place on something like audacity). Now about what I just said about cutting them to the same place. You don't really need to. To check for changes that are not Amplitudinal(new word) then this is just a quick mathematical operation on the Hammed functions(not the difference of the WAV's). If the difference between each can be attributed to a multiplicative factor ie our strings are:
363693639
121231213
Then we can say that the only difference is caused by an audio gain function, whose multiplier is 3.
The DiracΔ function starts to hit on that:
private void diracΔToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int vxl = 0; vxl < outsalot.Lines.Length ; vxl = vxl + 1)
{
string hamm = ((float.Parse(outsalot.Lines[vxl]) - Int32.Parse(outsytwo.Lines[vxl]))/Math.Abs((float.Parse(outsalot.Lines[vxl]) - Int32.Parse(outsytwo.Lines[vxl])))).ToString();
hamming.Text = hamming.Text + hamm + "\n";
bar.Maximum = outsalot.Lines.Length;
bar.Value = vxl;
if (bar.Value == outsalot.Lines.Length - 10) { bar.Value = 0; }
}
}
It takes the vals, subtracts and divides by the absolute in order to work with multiplicatives. Does this have anything to do with DiracΔ functions. Not really I was just playing on the fact that the entire issue(dispute) is probably due to the lower sampling rate of the microphones used by the aggressors.
Now the difference function( FILE>Difference), wait hold up, here is a pic of the menu for refs:
Right, and here is the code for Difference:
private void differenceToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int vxl = 0; vxl < outsalot.Lines.Length-1; vxl = vxl + 1)
{
string one = ((float.Parse(outsalot.Lines[vxl]) - float.Parse(outsalot.Lines[vxl+1]))) .ToString();
hamming.Text = hamming.Text + one + "\n";
bar.Maximum = outsalot.Lines.Length;
bar.Value = vxl;
if (bar.Value == outsalot.Lines.Length - 10) { bar.Value = 0; }
}
outsalot.Text=hamming.Text;
hamming.Text="";
for (int vxl = 0; vxl < outsalot.Lines.Length-1; vxl = vxl + 1)
{
string two = ((float.Parse(outsytwo.Lines[vxl]) - float.Parse(outsytwo.Lines[vxl + 1]))).ToString();
hamming.Text = hamming.Text + two+ "\n";
bar.Maximum = outsytwo.Lines.Length;
bar.Value = vxl;
if (bar.Value == outsalot.Lines.Length - 10) { bar.Value = 0; }
}
outsytwo.Text=hamming.Text;
hamming.Text = "";
}
Difference differs(ha) from the other functions in that it works or acts upon only one waveform(at a time and we could run Difference on the Hamming distance function of the two waveforms). It subtracts element [x] from element [x+1] all the way to [(max(x)-1)-(max(x)-2)], the reason being that the differences between successive elements should be the same in each waveform if they have not been tampered with and there is not too many confounding variables from outside sources(audience etc).
Now I ussually do not write up the code for the visuals but in this case it is useful as I did utilize a split container to hold everything. You can delete the db graph(top one) as it does nothing for us(volume is not entirely useful when we are talking about vocal modification, although we can sort of use it to mess with the difference functions we talked about earlier as I described them in terms of db and not pitch though they are currently programmed to work on pitch. To work on db you need to convert arrays to txt \n format).
namespace AudioAnalysis
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openWaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.hAMToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.diracΔToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.differenceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.logToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.move = new System.Windows.Forms.Button();
this.outsalot = new System.Windows.Forms.RichTextBox();
this.waveViewer1 = new NAudio.Gui.WaveViewer();
this.hamming = new System.Windows.Forms.RichTextBox();
this.outsytwo = new System.Windows.Forms.RichTextBox();
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components);
this.track = new System.Windows.Forms.TrackBar();
this.readout = new System.Windows.Forms.TextBox();
this.bar = new System.Windows.Forms.ProgressBar();
this.track0 = new System.Windows.Forms.TrackBar();
this.reader2 = new System.Windows.Forms.TextBox();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.track)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.track0)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.BackColor = System.Drawing.Color.WhiteSmoke;
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.logToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1091, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openWaveToolStripMenuItem,
this.hAMToolStripMenuItem,
this.diracΔToolStripMenuItem,
this.differenceToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "File";
//
// openWaveToolStripMenuItem
//
this.openWaveToolStripMenuItem.Name = "openWaveToolStripMenuItem";
this.openWaveToolStripMenuItem.Size = new System.Drawing.Size(135, 22);
this.openWaveToolStripMenuItem.Text = "Open Wave";
this.openWaveToolStripMenuItem.Click += new System.EventHandler(this.openWaveToolStripMenuItem_Click);
//
// hAMToolStripMenuItem
//
this.hAMToolStripMenuItem.Name = "hAMToolStripMenuItem";
this.hAMToolStripMenuItem.Size = new System.Drawing.Size(135, 22);
this.hAMToolStripMenuItem.Text = "HAM";
this.hAMToolStripMenuItem.Click += new System.EventHandler(this.hAMToolStripMenuItem_Click);
//
// diracΔToolStripMenuItem
//
this.diracΔToolStripMenuItem.Name = "diracΔToolStripMenuItem";
this.diracΔToolStripMenuItem.Size = new System.Drawing.Size(135, 22);
this.diracΔToolStripMenuItem.Text = "DiracΔ";
this.diracΔToolStripMenuItem.Click += new System.EventHandler(this.diracΔToolStripMenuItem_Click);
//
// differenceToolStripMenuItem
//
this.differenceToolStripMenuItem.Name = "differenceToolStripMenuItem";
this.differenceToolStripMenuItem.Size = new System.Drawing.Size(135, 22);
this.differenceToolStripMenuItem.Text = "Difference";
this.differenceToolStripMenuItem.Click += new System.EventHandler(this.differenceToolStripMenuItem_Click);
//
// logToolStripMenuItem
//
this.logToolStripMenuItem.Name = "logToolStripMenuItem";
this.logToolStripMenuItem.Size = new System.Drawing.Size(39, 20);
this.logToolStripMenuItem.Text = "Log";
this.logToolStripMenuItem.Click += new System.EventHandler(this.logToolStripMenuItem_Click);
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 24);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.move);
this.splitContainer1.Panel1.Controls.Add(this.outsalot);
this.splitContainer1.Panel1.Controls.Add(this.waveViewer1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.hamming);
this.splitContainer1.Panel2.Controls.Add(this.outsytwo);
this.splitContainer1.Panel2.Controls.Add(this.chart1);
this.splitContainer1.Size = new System.Drawing.Size(1091, 461);
this.splitContainer1.SplitterDistance = 227;
this.splitContainer1.TabIndex = 1;
//
// move
//
this.move.Location = new System.Drawing.Point(926, 180);
this.move.Name = "move";
this.move.Size = new System.Drawing.Size(153, 23);
this.move.TabIndex = 2;
this.move.Text = "Move";
this.move.UseVisualStyleBackColor = true;
this.move.Click += new System.EventHandler(this.move_Click);
//
// outsalot
//
this.outsalot.Location = new System.Drawing.Point(926, 3);
this.outsalot.Name = "outsalot";
this.outsalot.Size = new System.Drawing.Size(153, 174);
this.outsalot.TabIndex = 1;
this.outsalot.Text = "";
//
// waveViewer1
//
this.waveViewer1.Location = new System.Drawing.Point(0, 6);
this.waveViewer1.Name = "waveViewer1";
this.waveViewer1.SamplesPerPixel = 128;
this.waveViewer1.Size = new System.Drawing.Size(920, 195);
this.waveViewer1.StartPosition = ((long)(0));
this.waveViewer1.TabIndex = 0;
this.waveViewer1.WaveStream = null;
//
// hamming
//
this.hamming.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
this.hamming.ForeColor = System.Drawing.SystemColors.Menu;
this.hamming.Location = new System.Drawing.Point(788, 4);
this.hamming.Name = "hamming";
this.hamming.Size = new System.Drawing.Size(132, 213);
this.hamming.TabIndex = 2;
this.hamming.Text = "";
this.hamming.TextChanged += new System.EventHandler(this.hamming_TextChanged);
//
// outsytwo
//
this.outsytwo.Location = new System.Drawing.Point(926, 4);
this.outsytwo.Name = "outsytwo";
this.outsytwo.Size = new System.Drawing.Size(162, 213);
this.outsytwo.TabIndex = 1;
this.outsytwo.Text = "";
//
// chart1
//
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Location = new System.Drawing.Point(0, 0);
this.chart1.Name = "chart1";
this.chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.EarthTones;
this.chart1.Size = new System.Drawing.Size(782, 201);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";
this.chart1.Click += new System.EventHandler(this.chart1_Click);
//
// track
//
this.track.Location = new System.Drawing.Point(519, 0);
this.track.Maximum = 16384;
this.track.Name = "track";
this.track.Size = new System.Drawing.Size(303, 45);
this.track.TabIndex = 1;
this.track.Value = 16384;
this.track.Scroll += new System.EventHandler(this.track_Scroll);
//
// readout
//
this.readout.BackColor = System.Drawing.SystemColors.HotTrack;
this.readout.ForeColor = System.Drawing.SystemColors.Menu;
this.readout.Location = new System.Drawing.Point(464, 4);
this.readout.Name = "readout";
this.readout.Size = new System.Drawing.Size(49, 20);
this.readout.TabIndex = 2;
this.readout.TextChanged += new System.EventHandler(this.readout_TextChanged);
//
// bar
//
this.bar.Location = new System.Drawing.Point(816, 0);
this.bar.Name = "bar";
this.bar.Size = new System.Drawing.Size(272, 23);
this.bar.TabIndex = 3;
//
// track0
//
this.track0.BackColor = System.Drawing.SystemColors.Control;
this.track0.Location = new System.Drawing.Point(82, -2);
this.track0.Maximum = 16384;
this.track0.Name = "track0";
this.track0.Size = new System.Drawing.Size(303, 45);
this.track0.TabIndex = 4;
this.track0.Scroll += new System.EventHandler(this.track0_Scroll);
//
// reader2
//
this.reader2.BackColor = System.Drawing.Color.Maroon;
this.reader2.ForeColor = System.Drawing.SystemColors.Menu;
this.reader2.Location = new System.Drawing.Point(388, 4);
this.reader2.Name = "reader2";
this.reader2.Size = new System.Drawing.Size(49, 20);
this.reader2.TabIndex = 5;
this.reader2.TextChanged += new System.EventHandler(this.reader2_TextChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1091, 485);
this.Controls.Add(this.reader2);
this.Controls.Add(this.track0);
this.Controls.Add(this.bar);
this.Controls.Add(this.readout);
this.Controls.Add(this.track);
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "AudioAnalysis";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.track)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.track0)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem openWaveToolStripMenuItem;
private System.Windows.Forms.SplitContainer splitContainer1;
private NAudio.Gui.WaveViewer waveViewer1;
private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
private System.Windows.Forms.ToolStripMenuItem logToolStripMenuItem;
private System.Windows.Forms.BindingSource bindingSource1;
private System.Windows.Forms.TrackBar track;
private System.Windows.Forms.TextBox readout;
private System.Windows.Forms.RichTextBox outsalot;
private System.Windows.Forms.ProgressBar bar;
private System.Windows.Forms.RichTextBox outsytwo;
private System.Windows.Forms.TrackBar track0;
private System.Windows.Forms.TextBox reader2;
private System.Windows.Forms.ToolStripMenuItem hAMToolStripMenuItem;
private System.Windows.Forms.RichTextBox hamming;
private System.Windows.Forms.Button move;
private System.Windows.Forms.ToolStripMenuItem diracΔToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem differenceToolStripMenuItem;
}
}