Advertisement
Guest User

Untitled

a guest
Jul 12th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. namespace SoundDetector
  2. {
  3.     public class Sound
  4.     {
  5.         bool soundDetected;        
  6.      //masse kode som tar opp lyd ...
  7.             return soundDetected;
  8.  
  9.            
  10.         void waveIn_DataAvailable(object sender, WaveInEventArgs e)
  11.         {
  12.             for (int index = 0; index < e.BytesRecorded; index += 2)
  13.             {
  14.                 short sample = (short)((e.Buffer[index + 1] << 8) |
  15.                                         e.Buffer[index + 0]);
  16.                 float sample32 = sample / 32768f;
  17.                 if (bigValue < sample32)
  18.                 {
  19.                     bigValue = sample32;
  20.                     waveIn.StopRecording();          //her slutter den å ta opp   
  21.  
  22.                     if (bigValue > maxValue)        //if sound
  23.                     {  
  24.                         Console.WriteLine("detected");
  25.                         soundDetected = true;
  26.                         return;
  27.                     }
  28.                     else                //no sound
  29.                     {
  30.                         Console.WriteLine("nosound");
  31.                         soundDetected = false;
  32.                         return;
  33.                     }
  34.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement