Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SoundDetector
- {
- public class Sound
- {
- bool soundDetected;
- //masse kode som tar opp lyd ...
- return soundDetected;
- void waveIn_DataAvailable(object sender, WaveInEventArgs e)
- {
- for (int index = 0; index < e.BytesRecorded; index += 2)
- {
- short sample = (short)((e.Buffer[index + 1] << 8) |
- e.Buffer[index + 0]);
- float sample32 = sample / 32768f;
- if (bigValue < sample32)
- {
- bigValue = sample32;
- waveIn.StopRecording(); //her slutter den å ta opp
- if (bigValue > maxValue) //if sound
- {
- Console.WriteLine("detected");
- soundDetected = true;
- return;
- }
- else //no sound
- {
- Console.WriteLine("nosound");
- soundDetected = false;
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement