Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ?using System;
- namespace ConsoleApp1
- {
- class Program
- {
- const int offsetstart = 0x2c;
- const int expecteddatasize = 4032000; //4032000; // original task:4032000, Assignment1=2293200
- const int numsamples = expecteddatasize >> 2; // 4 bytes per sample (2 left, 2 right)
- struct sampleLR
- {
- public Int16 left;
- public Int16 right;
- };
- static void FindText(int type, sampleLR[] s, int startoffset, int distance)
- {
- Console.WriteLine();
- Console.WriteLine("FindText-type=" + type.ToString() + ", offset=" + startoffset.ToString() + ", distance=" + distance.ToString());
- byte assembledbyte = 0;
- int numbitsgot = 0;
- for(int i = startoffset; i < numsamples; i += distance)
- {
- if (i >= numsamples)
- break;
- byte l = (byte)(UInt16)((UInt16)s[i].left & (UInt16)0x01);
- byte r = (byte)(UInt16)((UInt16)s[i].right & (UInt16)0x01);
- if (type == 1)
- {
- assembledbyte = (byte)((byte)(assembledbyte << 1) | l);
- assembledbyte = (byte)((byte)(assembledbyte << 1) | r);
- numbitsgot += 2;
- }
- if (type == 2)
- {
- assembledbyte = (byte)((byte)(assembledbyte << 1) | r);
- assembledbyte = (byte)((byte)(assembledbyte << 1) | l);
- numbitsgot += 2;
- }
- if (type == 3)
- {
- assembledbyte = (byte)((byte)(assembledbyte << 1) | l);
- numbitsgot++;
- }
- if (type == 4)
- {
- assembledbyte = (byte)((byte)(assembledbyte << 1) | r);
- numbitsgot++;
- }
- if (type == 5)
- {
- assembledbyte = (byte)((byte)(assembledbyte >> 1) | (byte)(l<<7));
- assembledbyte = (byte)((byte)(assembledbyte >> 1) | (byte)(r<<7));
- numbitsgot += 2;
- }
- if (type == 6)
- {
- assembledbyte = (byte)((byte)(assembledbyte >> 1) | (byte)(r << 7));
- assembledbyte = (byte)((byte)(assembledbyte >> 1) | (byte)(l << 7));
- numbitsgot += 2;
- }
- if (type == 7)
- {
- assembledbyte = (byte)((byte)(assembledbyte >> 1) | (byte)(l << 7));
- numbitsgot++;
- }
- if (type == 8)
- {
- assembledbyte = (byte)((byte)(assembledbyte >> 1) | (byte)(r << 7));
- numbitsgot++;
- }
- if (numbitsgot > 8)
- throw new Exception("more than 8 bits!");
- if (numbitsgot >= 8)
- {
- //if(assembledbyte>=32&&assembledbyte<=126)
- Console.Write((char)assembledbyte);
- assembledbyte = 0;
- numbitsgot = 0;
- }
- }
- }
- static void Main(string[] args)
- {
- System.IO.FileStream fs = new System.IO.FileStream("C:\\TEMP\\CTF_moocfi_2019\\SomethingSoundsOff\\woods_a.wav", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
- byte[] b=new byte[expecteddatasize];
- long sr = fs.Seek(offsetstart, System.IO.SeekOrigin.Begin);
- int readresult=fs.Read(b, 0, expecteddatasize);
- fs.Close();
- if(readresult== expecteddatasize)
- {
- Console.WriteLine("File read successfully.");
- sampleLR[] s = new sampleLR[numsamples];
- for(int i = 0; i < numsamples; i++)
- {
- byte b0 = b[4 * i];
- byte b1 = b[4 * i + 1];
- byte b2 = b[4 * i + 2];
- byte b3 = b[4 * i + 3];
- Int16 left = (Int16)((UInt16)b1 << 8 | (UInt16)b0);
- Int16 right= (Int16)((UInt16)b3 << 8 | (UInt16)b2);
- s[i].left = left;
- s[i].right = right;
- }
- Console.WriteLine("Copied samples successfully.");
- int startoffset = 0;
- int distance = 1;
- FindText(1, s, startoffset, distance); // 1=left, right, bits 0...7
- //FindText(2, s, startoffset, distance); // 2=right, left, bits 0...7
- //FindText(3, s, startoffset, distance); // 3=left only, bits 0...7
- //FindText(4, s, startoffset, distance); // 3=right only, bits 0...7
- //FindText(5, s, startoffset, distance); // 1=left, right, bits 7...0
- //FindText(6, s, startoffset, distance); // 2=right, left, bits 7...0
- //FindText(7, s, startoffset, distance); // 3=left only, bits 7...0
- //FindText(8, s, startoffset, distance); // 3=right only, bits 7...0
- //startoffset = 1;
- //FindText(1, s, startoffset, distance); // 1=left, right, bits 0...7
- //FindText(2, s, startoffset, distance); // 2=right, left, bits 0...7
- //FindText(3, s, startoffset, distance); // 3=left only, bits 0...7
- //FindText(4, s, startoffset, distance); // 3=right only, bits 0...7
- //FindText(5, s, startoffset, distance); // 1=left, right, bits 7...0
- //FindText(6, s, startoffset, distance); // 2=right, left, bits 7...0
- //FindText(7, s, startoffset, distance); // 3=left only, bits 7...0
- //FindText(8, s, startoffset, distance); // 3=right only, bits 7...0
- //startoffset = 2;
- //FindText(1, s, startoffset, distance); // 1=left, right, bits 0...7
- //FindText(2, s, startoffset, distance); // 2=right, left, bits 0...7
- //FindText(3, s, startoffset, distance); // 3=left only, bits 0...7
- //FindText(4, s, startoffset, distance); // 3=right only, bits 0...7
- //FindText(5, s, startoffset, distance); // 1=left, right, bits 7...0
- //FindText(6, s, startoffset, distance); // 2=right, left, bits 7...0
- //FindText(7, s, startoffset, distance); // 3=left only, bits 7...0
- //FindText(8, s, startoffset, distance); // 3=right only, bits 7...0
- //startoffset = 3;
- //FindText(1, s, startoffset, distance); // 1=left, right, bits 0...7
- //FindText(2, s, startoffset, distance); // 2=right, left, bits 0...7
- //FindText(3, s, startoffset, distance); // 3=left only, bits 0...7
- //FindText(4, s, startoffset, distance); // 3=right only, bits 0...7
- //FindText(5, s, startoffset, distance); // 1=left, right, bits 7...0
- //FindText(6, s, startoffset, distance); // 2=right, left, bits 7...0
- //FindText(7, s, startoffset, distance); // 3=left only, bits 7...0
- //FindText(8, s, startoffset, distance); // 3=right only, bits 7...0
- //startoffset = 4;
- //FindText(1, s, startoffset, distance); // 1=left, right, bits 0...7
- //FindText(2, s, startoffset, distance); // 2=right, left, bits 0...7
- //FindText(3, s, startoffset, distance); // 3=left only, bits 0...7
- //FindText(4, s, startoffset, distance); // 3=right only, bits 0...7
- //FindText(5, s, startoffset, distance); // 1=left, right, bits 7...0
- //FindText(6, s, startoffset, distance); // 2=right, left, bits 7...0
- //FindText(7, s, startoffset, distance); // 3=left only, bits 7...0
- //FindText(8, s, startoffset, distance); // 3=right only, bits 7...0
- //startoffset = 5;
- //FindText(1, s, startoffset, distance); // 1=left, right, bits 0...7
- //FindText(2, s, startoffset, distance); // 2=right, left, bits 0...7
- //FindText(3, s, startoffset, distance); // 3=left only, bits 0...7
- //FindText(4, s, startoffset, distance); // 3=right only, bits 0...7
- //FindText(5, s, startoffset, distance); // 1=left, right, bits 7...0
- //FindText(6, s, startoffset, distance); // 2=right, left, bits 7...0
- //FindText(7, s, startoffset, distance); // 3=left only, bits 7...0
- //FindText(8, s, startoffset, distance); // 3=right only, bits 7...0
- //startoffset = 6;
- //FindText(1, s, startoffset, distance); // 1=left, right, bits 0...7
- //FindText(2, s, startoffset, distance); // 2=right, left, bits 0...7
- //FindText(3, s, startoffset, distance); // 3=left only, bits 0...7
- //FindText(4, s, startoffset, distance); // 3=right only, bits 0...7
- //FindText(5, s, startoffset, distance); // 1=left, right, bits 7...0
- //FindText(6, s, startoffset, distance); // 2=right, left, bits 7...0
- //FindText(7, s, startoffset, distance); // 3=left only, bits 7...0
- //FindText(8, s, startoffset, distance); // 3=right only, bits 7...0
- //startoffset = 7;
- //FindText(1, s, startoffset, distance); // 1=left, right, bits 0...7
- //FindText(2, s, startoffset, distance); // 2=right, left, bits 0...7
- //FindText(3, s, startoffset, distance); // 3=left only, bits 0...7
- //FindText(4, s, startoffset, distance); // 3=right only, bits 0...7
- //FindText(5, s, startoffset, distance); // 1=left, right, bits 7...0
- //FindText(6, s, startoffset, distance); // 2=right, left, bits 7...0
- //FindText(7, s, startoffset, distance); // 3=left only, bits 7...0
- //FindText(8, s, startoffset, distance); // 3=right only, bits 7...0
- }
- else
- {
- Console.WriteLine("Error reading file.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement