Asked by:
C# ticking in my wav file
Question

I am trying to make a tone file and it is working. but it is not sounding the way I want it to sound. There is a low tone beat in the file. that I did not add to it. And I do not know why it is there..
Someone told me to try fading out / fade in and not just going down to 0 and I did but it did not work.
can anyone help me ?
I just need to remove the ticking and output the right Frequency
here is my code:
double time = Convert.ToDouble(time2.Text) / 2.2675; time = time * 50000D; double Amplitude = Convert.ToDouble(Peaktxt.Text); SaveFileDialog save1 = new SaveFileDialog(); save1.Filter = "Wave file (*.wav)*.wav;"; if (save1.ShowDialog() != DialogResult.OK) return; WaveFileWriter wavefile; wavefile = new WaveFileWriter(save1.FileName, tone.WaveFormat); double counter3 = 0; double tenp = 0; double Ptemp = Peak3  0.001D; int newcounter = 0; if (Beat3 != 0) { Beat3 = (1 / Beat3); tenp = Beat3/(1D / 44100D); } else { Beat3 = 0; } for (int n = 0; n < time; n++) { if (counter3 >= Beat3 && Beat3 != 0) { for (int t = 0; t < tenp; t++) { if (Ptemp > 0.000005) { float temo = (float)(Ptemp * Math.Sin((((Math.PI * n * (Frequency3))/2) / 44100D))); wavefile.WriteSample(Math.Abs(temo)); wavefile.WriteSample(Math.Abs(temo)); n++; Ptemp = Ptemp  0.001D; newcounter++; } else if ((tenp  newcounter) <= 0 ) { float temo = (float)(Ptemp * Math.Sin((((Math.PI * n * (Frequency3))/2) / 44100D))); wavefile.WriteSample(temo); wavefile.WriteSample(temo); n++; Ptemp = Ptemp + 0.001D; } else { wavefile.WriteSample(0F); wavefile.WriteSample(0F); n++; } } counter3 = 0; } else { float temo = (float)(Peak3 * Math.Sin(((( Math.PI * n * (Frequency3))/2)/44100D))); wavefile.WriteSample(Math.Abs(temo)); wavefile.WriteSample(Math.Abs(temo)); counter3 = counter3 + (1D / 44100D); Ptemp = Peak3  0.001D; } } wavefile.Flush(); wavefile.Dispose(); if (waveout == null) { waveout = new WaveOut(); waveout.PlaybackStopped += onPlaybackStopped; } MixingSampleProvider mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100,2)); audioFileReader = new AudioFileReader(save1.FileName); mixer.AddMixerInput((ISampleProvider)audioFileReader); SampleToWaveProvider mixer3 = new SampleToWaveProvider(mixer); try { waveout.Init(mixer3); waveout.Play(); timer1.Start(); } catch { MessageBox.Show(" Error retry"); waveout.Stop(); waveout.Dispose(); waveout = null; return; }
 Moved by Anne Jing Monday, May 26, 2014 5:34 AM
Sunday, May 25, 2014 10:19 AM
All replies

I am trying to make a tone file and it is working. but it is not sounding the way I want it to sound. There is a low tone beat in the file. that I did not add to it. And I do not know why it is there..
Someone told me to try fading out / fade in and not just going down to 0 and I did but it did not work.
can anyone help me ?
I just need to remove the ticking and output the right Frequency
here is my code:
tone = new isochronicTone(); tone.SetWaveFormat(44100, 2); double time = Convert.ToDouble(time2.Text) / 2.2675; time = time * 50000D; double Amplitude = Convert.ToDouble(Peaktxt.Text); SaveFileDialog save1 = new SaveFileDialog(); save1.Filter = "Wave file (*.wav)*.wav;"; if (save1.ShowDialog() != DialogResult.OK) return; WaveFileWriter wavefile; wavefile = new WaveFileWriter(save1.FileName, tone.WaveFormat); double counter3 = 0; double tenp = 0; double Ptemp = Peak3  0.001D; int newcounter = 0; if (Beat3 != 0) { Beat3 = (1 / Beat3); tenp = Beat3/(1D / 44100D); } else { Beat3 = 0; } for (int n = 0; n < time; n++) { if (counter3 >= Beat3 && Beat3 != 0) { for (int t = 0; t < tenp; t++) { if (Ptemp > 0.000005) { float temo = (float)(Ptemp * Math.Sin((((Math.PI * n * (Frequency3))/2) / 44100D))); wavefile.WriteSample(temo); wavefile.WriteSample(temo); n++; Ptemp = Ptemp  0.001D; newcounter++; } else if ((tenp  newcounter) <= 0 ) { float temo = (float)(Ptemp * Math.Sin((((Math.PI * n * (Frequency3))/2) / 44100D))); wavefile.WriteSample(temo); wavefile.WriteSample(temo); n++; Ptemp = Ptemp + 0.001D; } else { wavefile.WriteSample(0F); wavefile.WriteSample(0F); n++; } } counter3 = 0; } else { float temo = (float)(Peak3 * Math.Sin(((( Math.PI * n * (Frequency3))/2)/44100D))); wavefile.WriteSample(temo); wavefile.WriteSample(temo); counter3 = counter3 + (1D / 44100D); Ptemp = Peak3  0.001D; newcounter = 0; } } wavefile.Flush(); wavefile.Dispose(); if (waveout == null) { waveout = new WaveOut(); waveout.PlaybackStopped += onPlaybackStopped; } MixingSampleProvider mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100,2)); audioFileReader = new AudioFileReader(save1.FileName); mixer.AddMixerInput((ISampleProvider)audioFileReader); SampleToWaveProvider mixer3 = new SampleToWaveProvider(mixer); try { waveout.Init(mixer3); waveout.Play(); timer1.Start(); } catch { MessageBox.Show(" Error retry"); waveout.Stop(); waveout.Dispose(); waveout = null; return; }
What am i doing wrong ?
here is how it sounds: https://onedrive.live.com/redir?resid=CC8AF223519E2440!119&authkey=!AAFtwo79tic33IA&ithint=file%2c.wav
Sunday, May 25, 2014 10:32 AM 
Hi,
According to yout description, I am afraid your problem is out of support in C# forum. Because NAudio is the 3rd part product. You can post your thread in the below link:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Monday, May 26, 2014 5:34 AM