Adilol

Most useless piece of code ever?

Aug 21st, 2011
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1.     using System.IO;
  2.     using System.Media;
  3.  
  4.     public class Beeper
  5.     {
  6.         public static void Beep(int Amplitude, int Frequency, int Duration)
  7.         {
  8.             double A = ((Amplitude * 32768.0) / 1000.0) - 1.0;
  9.             double DeltaFT = (2 * Math.PI * Frequency) / 44100.0;
  10.             int Samples = (44100 * Duration) / 1000;
  11.  
  12.             Console.WriteLine(Samples);
  13.  
  14.             int Bytes = Samples * 4;
  15.             int[] Hdr = new int[] { 0x46464952, 0x24 + Bytes, 0x45564157, 0x20746d66, 0x10, 0x20001, 0xac44, 0x2b110, 0x100004, 0x61746164, Bytes };
  16.            
  17.            using ( MemoryStream MS = new MemoryStream(0x24 + Bytes) )
  18.             {
  19.                 using ( BinaryWriter BW = new BinaryWriter(MS) )
  20.                 {
  21.                     int length = Hdr.Length - 1;
  22.  
  23.                     for ( int I = 0; I <= length; I++ )
  24.                     {
  25.                         BW.Write(Hdr[I]);
  26.                     }
  27.                     int sample = Samples - 1;
  28.  
  29.                     for ( int T = 0; T <= sample; T++ )
  30.                     {
  31.                         short Sample = (short)Math.Round((double)(A * Math.Sin(DeltaFT * T)));
  32.                         BW.Write(Sample);
  33.                         BW.Write(Sample);
  34.                     }
  35.  
  36.                     BW.Flush();
  37.                     MS.Seek(0L, SeekOrigin.Begin);
  38.  
  39.                     using ( SoundPlayer SP = new SoundPlayer(MS) )
  40.                     {
  41.                         SP.PlaySync();
  42.                     {
  43.                 }
  44.             }
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment