Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string path         = @"C:\Users\kielbkam\Desktop\semestr 6\emedia\emedia\emedia\";
            string originalFIle = "Yamaha-V50-Rock-Beat-120bpm.wav";
            string encodedFile  = "encodedWAVFile.wav";
            string decodedFile  = "decodedWAVFile.wav";

            WAVFile wavFile = new WAVReader(path + originalFIle).ReadWAVFile(false);

            wavFile.DisplayHeader();

            WAVFile cipheredWavFile = wavFile;
            Cipher  cipher          = new Cipher();

            double[] encoded       = cipher.getCipheredData(cipheredWavFile.Data);
            Data     dataModifiyer = new Data();

            cipheredWavFile.Data = dataModifiyer.Normalize(encoded);
            WAVWriter wavWriter = new WAVWriter(path + encodedFile);

            wavWriter.WriteWAVFile(cipheredWavFile);

            WAVFile decipheredWavFile = new WAVReader(path + encodedFile).ReadWAVFile(true);

            double[] decipheredFloats = dataModifiyer.Denormalize(decipheredWavFile.Data);
            decipheredWavFile.Data = cipher.getDecipheredData(decipheredFloats);

            WAVWriter wavWriterForDecoded = new WAVWriter(path + decodedFile);

            wavWriterForDecoded.WriteWAVFile(decipheredWavFile);

            Console.WriteLine("Finished");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public WAVFile ReadWAVFile(bool isEncoded)
        {
            WAVFile wavFile = new WAVFile();

            using (FileStream fs = new FileStream(this.pathToWAVFile, FileMode.Open))
            {
                BinaryReader binaryReader = new BinaryReader(fs);

                wavFile.ChunkId       = ConvertIntToString(ReverseEndianness(binaryReader.ReadInt32()));
                wavFile.ChunkSize     = binaryReader.ReadUInt32();
                wavFile.Format        = ConvertIntToString(ReverseEndianness(binaryReader.ReadInt32()));
                wavFile.Subchunk1ID   = ConvertIntToString(ReverseEndianness(binaryReader.ReadInt32()));
                wavFile.Subchunk1Size = binaryReader.ReadUInt32();
                wavFile.AudioFormat   = binaryReader.ReadUInt16();
                wavFile.NumChannels   = binaryReader.ReadUInt16();
                wavFile.SampleRate    = binaryReader.ReadUInt32();
                wavFile.ByteRate      = binaryReader.ReadUInt32();
                wavFile.BlockAlign    = binaryReader.ReadInt16();
                wavFile.BitsPerSample = binaryReader.ReadUInt16();
                wavFile.Subchunk2ID   = ConvertIntToString(ReverseEndianness(binaryReader.ReadInt32()));
                wavFile.Subchunk2Size = binaryReader.ReadUInt32();
                // jesli enkodujemy to musimy zwiekszyc rozmiar ramki danych samego pliku WAVE.
                // W naszym przypadku jest to double (8 bajtow) dlatego sam rozmiar mnozymi razy sizeof(double).
                wavFile.Data = isEncoded == true?
                               binaryReader.ReadBytes((int)wavFile.Subchunk2Size * 8) :
                                   binaryReader.ReadBytes((int)wavFile.Subchunk2Size);
            }

            return(wavFile);
        }
Ejemplo n.º 3
0
        public void WriteWAVFile(WAVFile wavFile)
        {
            using (FileStream fs = new FileStream(this.pathToWAVFile, FileMode.OpenOrCreate))
            {
                BinaryWriter binaryWriter = new BinaryWriter(fs);

                binaryWriter.Write(ReverseEndianness(ConvertStringToInt(wavFile.ChunkId)));
                binaryWriter.Write(wavFile.ChunkSize);
                binaryWriter.Write(ReverseEndianness(ConvertStringToInt(wavFile.Format)));
                binaryWriter.Write(ReverseEndianness(ConvertStringToInt(wavFile.Subchunk1ID)));
                binaryWriter.Write(wavFile.Subchunk1Size);
                binaryWriter.Write((UInt16)wavFile.AudioFormat);
                binaryWriter.Write((UInt16)wavFile.NumChannels);
                binaryWriter.Write(wavFile.SampleRate);
                binaryWriter.Write(wavFile.ByteRate);
                binaryWriter.Write((Int16)wavFile.BlockAlign);
                binaryWriter.Write((UInt16)wavFile.BitsPerSample);
                binaryWriter.Write(ReverseEndianness(ConvertStringToInt(wavFile.Subchunk2ID)));
                binaryWriter.Write(wavFile.Subchunk2Size);
                binaryWriter.Write(wavFile.Data);
            }
        }