Ticking in my wav file

  1. 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 (Text):

    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
     
  2. jcsd
  3. NascentOxygen

    Staff: Mentor

    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?
     
  4. AlephZero

    AlephZero 7,298
    Science Advisor
    Homework Helper

    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: May 25, 2014
  5. Windows
    the code is C#
    kind of
    this is how is should look
    http://en.wikipedia.org/wiki/File:Isochronic-toes.svg
     
  6. AlephZero

    AlephZero 7,298
    Science Advisor
    Homework Helper

    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.
     
  7. 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 fundemental 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.
     
  8. 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 (Text):
    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;                                          

    }
     
  9. 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?
     
  10. Yes. you only need

    Code (Text):


    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.
     

  11. Dude it Works!!!
    I do not understand...
    what are you doing that I am not???
    why is there no ticking ??
     
  12. 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 wich 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.
     
  13. 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 ?
     
  14. willem2,
    Can you explain to me how function know when to be 0? and how to long to stay 0?
     
  15. You really have to try to express yourself a bit clearer. What function do you mean here?
     
  16. this one

    Code (Text):

    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;                                          

    }
     
     
  17. 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)) ?
     
  18. 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.
     
  19. 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
     
  20. 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 ?
     
Know someone interested in this topic? Share a link to this question via email, Google+, Twitter, or Facebook

0
Draft saved Draft deleted