private void PlayButton_OnChecked(object sender, RoutedEventArgs e) { if (mResultSound != null) { const string filename = "~temp_sound.wav"; Sound resultTwoCh = new Sound(2,mResultSound.DiscretionRate,mResultSound.BitsPerSample); resultTwoCh.Add(mResultSound,0,0,0); resultTwoCh.Add(mResultSound, mResultSound.Channels > 1 ? 1 : 0, 1, 0); resultTwoCh.CreateWav(filename); File.SetAttributes(filename,File.GetAttributes(filename)|FileAttributes.Hidden); mPlayer = new SoundPlayer(filename); mPlayer.Load(); mPlayer.PlayLooping(); } }
public void PrimaryReflectionsComplexTest() { AS.Wall.Material mat = AS.Wall.Material.OakWoodCarpeted; AS.Room room = new AS.Room(); room.FloorMaterial = AS.Wall.Material.Brick; room.CeilingMaterial = AS.Wall.Material.OakWood; room.CeilingHeight = 2; room.AddWall(new AS.Wall(0, 0, 4, 0, mat)); room.AddWall(new AS.Wall(0, 0, 0, 10, mat)); room.AddWall(new AS.Wall(4, 0, 4, 10, mat)); room.AddWall(new AS.Wall(0, 10, 4, 10, mat)); AS.SoundPoint source = new AS.SoundPoint(2, 1); source.Sound = AS.Sound.GetSoundFromWav(@"D:\Whistling.wav"); room.AddSource(source); room.AddListener(new AS.ListenerPoint(1, 8,new AS.Line(0,0,-1,0),AS.ListenerPoint.Cardioid)); room.AddListener(new AS.ListenerPoint(3, 8, new AS.Line(0,0,1,0),AS.ListenerPoint.Cardioid )); room.CalculateSound(); AS.Sound sound = new AS.Sound(2,source.Sound.DiscretionRate,source.Sound.BitsPerSample); sound.Add(room.Listeners[1].Sound,0,0,0); sound.Add(room.Listeners[0].Sound,0,1,0); sound.AdjustVolume(0.75); //sound.SetVolume(0.6,0); //sound.SetVolume(0.6,1); sound.CreateWav(@"D:\Result.wav"); }
private void ConvolveButton_Click(object sender, RoutedEventArgs e) { BackgroundWorker worker =new BackgroundWorker(); ConvolutionStatusBlock.Text = "In progress..."; ConvolveButton.IsEnabled = false; OpenBaseSoundButton.IsEnabled = false; OpenKernelSoundButton.IsEnabled = false; SaveConvolvedButton.IsEnabled = false; worker.DoWork += delegate { if (mKernelSound.Channels < mConvolveBaseSound.Channels) { for (int i = 0; i < mConvolveBaseSound.Channels; i++) { mConvolveBaseSound.Convolve(mKernelSound, i, 0); } } else { if (mKernelSound.Channels > mConvolveBaseSound.Channels) { Sound TempSound = new Sound(mKernelSound.Channels,mConvolveBaseSound.DiscretionRate,mConvolveBaseSound.BitsPerSample); for (int i = 0; i < mKernelSound.Channels; i++) { TempSound.Add(mConvolveBaseSound,0,i,0); } mConvolveBaseSound = TempSound; } for (int i = 0; i < mConvolveBaseSound.Channels; i++) { mConvolveBaseSound.Convolve(mKernelSound, i, i); } } mConvolveResultSound = mConvolveBaseSound; mConvolveResultSound.AdjustVolume(0.8); mConvolveBaseSound = null; mKernelSound = null; }; worker.RunWorkerCompleted += delegate { BaseSoundBlock.Text = KernelSoundBlock.Text = "No file loaded"; ConvolutionStatusBlock.Text = "Convolution finished. Feel free to save result"; mConvolveBaseSound = null; mKernelSound = null; if (mConvolveResultSound == null) { ConvolutionStatusBlock.Foreground=Brushes.Red; ConvolutionStatusBlock.Text = "NMath library needs to be installed for convolution"; } OpenBaseSoundButton.IsEnabled = true; OpenKernelSoundButton.IsEnabled = true; SaveConvolvedButton.IsEnabled = true; }; worker.RunWorkerAsync(); }
public void PrimaryReflectionsHugeTest() { AS.Wall.Material mat = AS.Wall.Material.Brick; AS.Room room = new AS.Room(); room.FloorMaterial = AS.Wall.Material.Brick; room.CeilingMaterial = AS.Wall.Material.OakWood; room.CeilingHeight = 2; room.AddWall(new AS.Wall(0,5,10,0,mat)); room.AddWall(new AS.Wall(10,0,20,5,mat)); room.AddWall(new AS.Wall(20,5,20,45,mat)); room.AddWall(new AS.Wall(20,45,0,45,mat)); room.AddWall(new AS.Wall(0,45,0,5, mat)); AS.SoundPoint source = new AS.SoundPoint(10,40); source.Sound = AS.Sound.GetSoundFromWav(@"D:\dirac.wav"); room.AddSource(source); room.AddListener(new AS.ListenerPoint(9,4)); room.AddListener(new AS.ListenerPoint(11,4)); room.CalculateSound(); AS.Sound sound = new AS.Sound(2, source.Sound.DiscretionRate, source.Sound.BitsPerSample); sound.Add(room.Listeners[1].Sound, 0, 0, 0); sound.Add(room.Listeners[0].Sound, 0, 1, 0); sound.AdjustVolume(0.75); //sound.SetVolume(0.6, 0); //sound.SetVolume(0.6, 1); sound.CreateWav(@"D:\diracR.wav"); Console.WriteLine(GC.GetTotalMemory(false)/(1024*1024)+""); }