Removing Ticking from WAV File & Outputting Correct Frequency

  • Thread starter btb4198
  • Start date
  • Tags
    File
In summary: Close(); }In summary, someone told me to try fading out / fade in and not just going down to 0 and I did but it did not work.
  • #1
btb4198
572
10
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:
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,.wav
 
Engineering news on Phys.org
  • #2
I haven't looked at what you are doing, but I'm wondering if you are "generating" a stepwise waveform in real time? Maybe the "time sharing" of the processor is causing the result to not be what you expected? There will be regular dwells. Are you using a windows or linux platform?
 
  • #3
Even if he is generating a wave in real time, that shouldn't be a problem.

If the clock speed is say 2 GHz, and you are generating 41,000 samples per second, then even with a single core CPU you have about 50,000 clock cycles available to generate each sample.

Generating several hundred audio streams simultaneously in real time and merging them together isn't a problem on a typical modern PC (e.g. 4 CPU cores and a clock speed a bit more than 2 GHz), if you do it right.

If you use the standard operating system functions in Windows (e.g. the audio options in DirectX) they will collect up about 0.1sec worth of audio data before they start generating any sound, to deal with badly behaved multitasking.
 
Last edited:
  • #4
NascentOxygen said:
I haven't looked at what you are doing, but I'm wondering if you are "generating" a stepwise waveform in real time? Maybe the "time sharing" of the processor is causing the result to not be what you expected? There will be regular dwells. Are you using a windows or linux platform?

Windows
the code is C#
kind of
this is how is should look
http://en.wikipedia.org/wiki/File:Isochronic-toes.svg
 
  • #5
You could probably start a new genre of techno dance music based on that "ticking" :smile:.

One way to minimize this is to start and end your blocks of zeros when the sine wave is passing through zero. You can either figure out when that will happen knowing the frequency and the sample rate, or just test for when two consecutive samples of the sine wave have opposite signs.
 
  • #6
How is that "ticking"? Sounds like a buzz to me. Post a wave form. Do some basic troubleshooting. You always come and ask questions without doing the basics first. We are not going to debug your code at that fundamental level.

Can you get it to put out a steady tone? Can you then increase the modulation? Do the basics, one step at a time. No one can do that for you.
 
  • #7
btb4198 said:
Windows
the code is C#
kind of
this is how is should look
http://en.wikipedia.org/wiki/File:Isochronic-toes.svg

It seems you want an interval of full volume, than in interval where the volume reduces, than in interval of 0 volume, and than an interval where the volume increases. Than keep on repeating these 4 intervals?

I believe the problem is that the volume ptemp never goes back up to 1, but keeps hovering near 0, because 0.001 is subtracted and than added to it. Finally when the ( t = 0; t < tenp; t++) ends, the volume goes immediately back to 1, producing a click.

A better idea than all those counters and if, is to define a custom function of the volume during 1 beat.

You can then use a single loop where you output volfunc(beatfrequency * n /44100D) * math.sin(2 * math.pi * frequency * n /44100D)

the customfunction can be

Code:
double volfunc(double t) 
{ 
	double rem = t % 1;

	if (rem<0.1) return rem * 10;            
	if (rem<0.5) return 1;                       
	if (rem<0.6) return (0.6 - rem) *10;  
	return 0;                                           

}
 
  • #8
willem2 said:
It seems you want an interval of full volume, than in interval where the volume reduces, than in interval of 0 volume, and than an interval where the volume increases. Than keep on repeating these 4 intervals?

I believe the problem is that the volume ptemp never goes back up to 1, but keeps hovering near 0, because 0.001 is subtracted and than added to it. Finally when the ( t = 0; t < tenp; t++) ends, the volume goes immediately back to 1, producing a click.

A better idea than all those counters and if, is to define a custom function of the volume during 1 beat.

You can then use a single loop where you output volfunc(beatfrequency * n /44100D) * math.sin(2 * math.pi * frequency * n /44100D)

the customfunction can be

Code:
double volfunc(double t) 
{ 
	double rem = t % 1;

	if (rem<0.1) return rem * 10;            
	if (rem<0.5) return 1;                       
	if (rem<0.6) return (0.6 - rem) *10;  
	return 0;                                           

}
I do not understand how this code should work?
Where would I put it at ?
should it go here
}
for (int n = 0; n < time; n++)
{
if (counter3 >= Beat3 && Beat3 != 0)
{
...



or does that function replace the need for the Beat counter?
 
  • #9
btb4198 said:
I do not understand how this code should work?
Where would I put it at ?
should it go here
}
for (int n = 0; n < time; n++)
{
if (counter3 >= Beat3 && Beat3 != 0)
{

or does that function replace the need for the Beat counter?

Yes. you only need

Code:
for (int n = 0; n < time; n++) {
       float temp = volfunc(beatfrequency * n /44100D) * math.sin(2 * math.pi * frequency * n /44100D) 
       wavefile.writesample(temp);
       wavefile.writesample(temp);
}

frequency and beatfrequency must be declared as doubles and initialized of course.

try to graph volfunc in the interval (0,1) to see what's going on.
 
  • #10
willem2 said:
Yes. you only need

Code:
for (int n = 0; n < time; n++) {
       float temp = volfunc(beatfrequency * n /44100D) * math.sin(2 * math.pi * frequency * n /44100D) 
       wavefile.writesample(temp);
       wavefile.writesample(temp);
}

frequency and beatfrequency must be declared as doubles and initialized of course.

try to graph volfunc in the interval (0,1) to see what's going on.


Dude it Works!
I do not understand...
what are you doing that I am not?
why is there no ticking ??
 
  • #11
btb4198 said:
Dude it Works!
I do not understand...
what are you doing that I am not?
why is there no ticking ??

If you plot volfunc from 0 to 1 you get this:

volfunc.png


because of the remainder, the function repeats over and over.

volfunc (beatfrequency * n /44100D) will have a period of 1/beatfrequency (in seconds)

By multiplying the two functions you use amplitude modulation. You get a sinewave of which the volume is modulated by the result of volfunc(). It's essential that volfunc() has no jumps.


double volfunc(double t)
{
double rem = t % 1;

if (rem<0.5) return 1;
return 0;
}

A volfunc() like this will produce ticks. The modulating signal is a square wave.
 
  • #12
willem2 said:
If you plot volfunc from 0 to 1 you get this:

View attachment 70067

because of the remainder, the function repeats over and over.

volfunc (beatfrequency * n /44100D) will have a period of 1/beatfrequency (in seconds)

By multiplying the two functions you use amplitude modulation. You get a sinewave of which the volume is modulated by the result of volfunc(). It's essential that volfunc() has no jumps.


double volfunc(double t)
{
double rem = t % 1;

if (rem<0.5) return 1;
return 0;
}

A volfunc() like this will produce ticks. The modulating signal is a square wave.
I was at this site:
http://mynoise.net/NoiseMachines/isochronicBrainwaveGenerator.php

and I was trying to match you they have, but sometimes i get a tick and they do not?
like for
32 Hz @ 14,080 Hz - Beta | Fear /!\

why is that ?
are they doing something different ?
 
  • #13
willem2,
Can you explain to me how function know when to be 0? and how to long to stay 0?
 
  • #14
btb4198 said:
willem2,
Can you explain to me how function know when to be 0? and how to long to stay 0?

You really have to try to express yourself a bit clearer. What function do you mean here?
 
  • #15
this one

Code:
double volfunc(double t) 
{ 
	double rem = t % 1;

	if (rem<0.1) return rem * 10;            
	if (rem<0.5) return 1;                       
	if (rem<0.6) return (0.6 - rem) *10;  
	return 0;                                           

}
 
  • #16
1) how do you know it is putting 0s at the right spots ?
2) why is it volfunc (beatfrequency * n /44100D) and not volfunc (Sin.Math(beatfrequency * n /44100D)) ?
 
  • #17
Do you know anything about Fourier tranforms, convolutions, unit steps, and impulses? If you do there is a very mathy explanation for your tick.

The simple act of turning things on and off causes vibrations. It's the tick that your hearing. The vibrations have a spectrum that can be calculated using Fourier transforms.

The simple answer to your problem is do not turn the volume of a tone up or down too quickly. It will cause unintended frequencies.
 
  • #18
hi,
I do know about Fourier transforms, convolutions, unit steps, and impulses. So turning it off and on too fast made a tricking frequencies ?
but how does the functions: volfunc(double t) work?
like I know what it is doing... I can follow the code in that way, but what i do not know is how it know when to add 0s and how many to add?
I think it make be off ? too fast

I set beatfrequency to 10 and it think it was too fast.
so I tried to do :

buffer[n + offset] = (float)(volfunc(( (Beat/2D) * n / 44100D)) * Amplitude * Math.Sin(Math.PI * Frequency * n / 44100D));

I am comparing it to this site:
http://mynoise.net/NoiseMachines/isochronicBrainwaveGenerator.php
 
  • #19
if a beat is 10 Hz?

the 0.1 s

and if I am sampling at a rate of 44100 ?

then one sample in my is 2.2675736961451247165532879818594e-5s

so if I do a for statement, the 0s should start at idex 4410?
is that right ?

there should be a beat every 0.1 s
so ever 4410 samples ?
 

1. How do you remove ticking from a WAV file?

Removing ticking from a WAV file can be done by using audio editing software or programming tools specifically designed for audio processing. These tools use algorithms to identify and remove the ticking sounds from the file.

2. Is it possible to remove ticking without affecting the quality of the original file?

Yes, it is possible to remove ticking without significantly affecting the quality of the original file. However, the effectiveness of the removal process may vary depending on the severity of the ticking and the quality of the audio editing tools used.

3. Can removing ticking alter the frequency of the WAV file?

Yes, removing ticking can alter the frequency of the WAV file. This is because ticking can disrupt the original frequency of the audio, and removing it may result in slight changes to the overall frequency of the file.

4. How can I ensure that the output frequency is correct after removing ticking?

To ensure that the output frequency is correct, it is important to use high-quality audio editing software or programming tools. These tools have features that allow you to analyze and adjust the frequency of the file to ensure accuracy.

5. Can removing ticking be done automatically or does it require manual intervention?

Removing ticking can be done automatically using audio editing software or programming tools. However, for more complex or severe ticking, manual intervention may be necessary to achieve the best results.

Similar threads

Replies
2
Views
1K
Back
Top