public static void WriteEepromCommand(string outfile, UInt32 address, byte value)
        {
            List <short> EepromData = new List <short>();

            WriteEeprom(EepromData, address, value);
            WaveGenerator W3 = new WaveGenerator(EepromData);

            W3.Save(outfile);
        }
        public static void WriteRebootWav(string outputfilename)
        {
            List <short> RebootData = new List <short>();

            WriteReboot(RebootData);
            WaveGenerator W3 = new WaveGenerator(RebootData);

            W3.Save(outputfilename);
        }
        public static void WriteDACCommand(string outfile, uint value1, uint value2)
        {
            List <short> DACData = new List <short>();

            WriteDAC(DACData, value1, value2);
            WaveGenerator W3 = new WaveGenerator(DACData);

            W3.Save(outfile);
        }
Esempio n. 4
0
        private void GenerateMultipleWaves_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            string        filePath = filepathTextBox2.Text;
            WaveGenerator wave;
            int           samples;
            float         fDiff, vDiff, dDiff;

            if (!Int32.TryParse(numberOfSamples.Text, out samples))
            {
                MessageBox.Show("You must enter a number for the number of samples.");
                return;
            }

            else if (!float.TryParse(freqDiff.Text, out fDiff))
            {
                MessageBox.Show("You must enter a number for the difference in frequency.");
                return;
            }
            else if (!float.TryParse(volDiff.Text, out vDiff))
            {
                MessageBox.Show("You must enter a number for the difference in volume.");
                return;
            }
            else if (!float.TryParse(durDiff.Text, out dDiff))
            {
                MessageBox.Show("You must enter a number for the difference in duration.");
                return;
            }

            for (int i = 0; i < samples; ++i)
            {
                wave = new WaveGenerator(WaveExampleType.Sine, frequency_many + ((i - 1) * fDiff), volume_many + ((i - 1) * vDiff), duration_many + ((i - 1) * dDiff));
                if (prefixRadioButton.Checked)
                {
                    wave.Save(filePath + namingConvention.Text + i.ToString() + ".wav");
                }
                else
                {
                    wave.Save(filePath + i.ToString() + namingConvention.Text + ".wav");
                }
            }
            Cursor = Cursors.Default;
        }
Esempio n. 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        filePath = filepathTextBox1.Text;
            WaveGenerator wave     = new WaveGenerator(WaveExampleType.Sine, frequency_single, volume_single, duration_single);

            wave.Save(filePath);
            SoundPlayer player = new SoundPlayer(filePath);

            player.Play();
        }
Esempio n. 6
0
        private static void PlayNotes(List <Note> notes)
        {
            using (var stream = new MemoryStream())
            {
                WaveGenerator wave = new WaveGenerator(notes);
                wave.Save(stream);

                stream.Seek(0, SeekOrigin.Begin);
                SoundPlayer player = new SoundPlayer(stream);
                player.Play();
            }
        }
Esempio n. 7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Vector v1 = new Vector(0, -1);
            Vector v2 = new Vector(-.95f, -.35f);
            Vector v3 = new Vector(-.59f, .81f);
            Vector v4 = new Vector(.59f, .81f);
            Vector v5 = new Vector(.95f, -.35f);

            WaveGenerator wg = new WaveGenerator();

            wg.SetWaveShape(new Vector[] { v1, v3, v5, v2, v4 });
            wg.Generate();
            wg.Save("C:\\Users\\theen\\Desktop\\wawawaw\\test.wav");
        }
        public void playSound(WaveExampleType waveType)
        {
            // Set filepath
            string filePath = this.GetHashCode().ToString();

            // Instantiate wave generator
            WaveGenerator wave = new WaveGenerator(waveType, getFrequency(), 0.1);

            // Save to filepath
            wave.Save(filePath);

            // Play the sound
            player = new SoundPlayer(filePath);
            player.PlayLooping();
        }
Esempio n. 9
0
        public void saveAsWav()
        {
            if (wav == null)
            {
                return;
            }
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Filter = "WAV|*.wav";
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                WaveGenerator wave = new WaveGenerator(samples);
                wave.Save(saveDialog.FileName);
            }
        }
Esempio n. 10
0
        private void btnCreateFile_Click(object sender, EventArgs e)
        {
            CalculateSampleCount();

            // Displays a SaveFileDialog so the user can save the Image
            // assigned to Button2.
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            string         beatDuration    = "";

            switch (cbNoteDuration.SelectedItem.ToString())
            {
            case "1/2":
                beatDuration = "half-note";
                break;

            case "1/4":
                beatDuration = "quarter-note";
                break;

            case "1/8":
                beatDuration = "eighth-note";
                break;
            }
            string description = nudBpm.Value.ToString() + "bpm_" + nudNumberBars.Value.ToString()
                                 + "bars_" + nudTimeSigTop.Value.ToString() + "-" + cbTimeSigBottom.SelectedItem + "_" + beatDuration + "-beat";

            saveFileDialog1.FileName = description + ".wav";
            saveFileDialog1.Filter   = "Wav file|*.wav";
            saveFileDialog1.Title    = "Save empty mono loop";
            saveFileDialog1.ShowDialog();

            // If the file name is not an empty string open it for saving.
            if (saveFileDialog1.FileName != "")
            {
                // Saves the Image via a FileStream created by the OpenFile method.
                //System.IO.FileStream fs =
                //   (System.IO.FileStream)saveFileDialog1.OpenFile();

                WaveGenerator wave = new WaveGenerator(nbrSamples, programName + " " + programVersion + ": " + description);
                wave.Save(saveFileDialog1.FileName);

                //fs.Close();
            }
        }
Esempio n. 11
0
        public static void WriteDACCommandFile(string outfile)
        {
            List <short> DACData = new List <short>();

            WriteSecond(DACData);
            WriteLeadIn(DACData);
            for (int j = 0; j < 10; j++)
            {
                for (uint i = 0; i < 2048; i += 30)
                {
                    WriteDAC(DACData, 2047 - i, i);
                }
                for (uint i = 0; i < 2048; i += 30)
                {
                    WriteDAC(DACData, i, 2047 - i);
                }
            }
            WriteLeadOut(DACData);
            WriteSecond(DACData);
            WaveGenerator W3 = new WaveGenerator(DACData);

            W3.Save(outfile);
        }
Esempio n. 12
0
        public static void ConvertHexToWav(string sourcehexfile, string targetwavfile)
        {
            IHex.IHex H        = new IHex.IHex(sourcehexfile);
            var       allbytes = H.Collapse();

            Console.WriteLine("0x{0:X} bytes read from {1}", allbytes.Count, sourcehexfile);

            int BootLoaderOffset = 0;

            BootLoaderOffset = FindOffset(allbytes);
            Console.WriteLine("Bootloader sits 0x{0:X} from start", BootLoaderOffset);

            int         count = Math.Max(0, allbytes.Count - BootLoaderOffset);
            List <byte> bytes = new List <byte>();

            for (int i = 0; i < count; i++)
            {
                bytes.Add(allbytes[i + BootLoaderOffset]);
            }

            int bcount = (bytes.Count() % 1024);

            if (bcount > 0)
            {
                for (int i = 0; i < 1024 - bcount; i++)
                {
                    bytes.Add(0);
                }
            }

            List <short> Data2      = new List <short>();
            byte         idx        = 0;
            UInt32       blockwrite = 0;
            List <byte>  thebytes   = new List <byte>();
            int          blockchunk = 0;

            uint BlocksToWrite = (uint)Math.Ceiling(bytes.Count() / 1024.0f);

            Console.WriteLine("Writing {0} chunks of 1024 bytes each", BlocksToWrite);
            for (uint i = 0; i < 4000; i += 100)
            {
                WriteDAC(Data2, i, 4000 - i);
            }
            WriteLeadIn(Data2);
            Write4Byte(Data2, (byte)'K', (byte)'I', (byte)'L', (byte)'L');
            WriteInt(Data2, 1337);// 1337
            WriteLeadOut(Data2, true);
            WriteSecond(Data2);
            WriteSecond(Data2);
            WriteSecond(Data2);
            WriteSecond(Data2);

            WriteLeadIn(Data2);
            Write4Byte(Data2, (byte)'D', (byte)'O', (byte)'I', (byte)'T');
            WriteInt(Data2, BlocksToWrite);// blocks
            WriteLeadOut(Data2, true);
            WriteSecond(Data2);

            while ((bytes.Count() / 1024) * 1024 < bytes.Count())
            {
                bytes.Add(0);
            }

            for (int i = 0; i < bytes.Count(); i += MAXCHUNK)
            {
                int bytecount = Math.Min(MAXCHUNK, bytes.Count() - i);
                if (Verbose)
                {
                    Console.WriteLine("writing chunk {0}", blockchunk);
                }

                WriteLeadIn(Data2);
                Write4Byte(Data2, (byte)'B', (byte)'L', (byte)'O', idx);
                blockchunk++;
                List <byte> chunkbytes = new List <byte>();

                for (int j = 0; j < bytecount; j++)
                {
                    chunkbytes.Add(bytes[i + j]);
                    thebytes.Add(bytes[i + j]);
                }

                for (int j = bytecount; j < MAXCHUNK; j++)
                {
                    chunkbytes.Add(0);

                    thebytes.Add(0);
                }

                UInt32 CRC = crc32c(0, chunkbytes, MAXCHUNK);
                if (Verbose)
                {
                    Console.Write("CRC: ");
                }
                WriteInt(Data2, CRC);
                if (Verbose)
                {
                    Console.WriteLine("");
                }
                writecount = 0;

                for (int ii = 0; ii < MAXCHUNK; ii++)
                {
                    WriteByte(Data2, chunkbytes[ii]);
                }

                WriteLeadOut(Data2, true);

                idx++;
                if (idx == 1024 / MAXCHUNK)
                {
                    WriteFlashCommand(blockwrite, thebytes, Data2);

                    blockwrite += 1024;
                    thebytes.Clear();
                    idx = 0;
                }
            }

            if (idx != 0)
            {
                while (thebytes.Count < 1024)
                {
                    thebytes.Add(0);
                }
                WriteFlashCommand(blockwrite, thebytes, Data2);
            }

            for (int i = 0; i < 11; i++)
            {
                WriteEmptyLongPulse(Data2);
                WriteEmptyLongPulse(Data2);
            }

            WriteReboot(Data2);
            WriteReboot(Data2);
            WriteReboot(Data2);

            WaveGenerator W2 = new WaveGenerator(Data2);

            W2.Save(targetwavfile);
        }