Troubleshooting Wavefile Tones: Fixing Unwanted Low Tone Beats in Your Code

  • Thread starter Thread starter btb4198
  • Start date Start date
AI Thread Summary
The discussion centers on issues with a tone file being generated through code, where an unintended low tone beat is present. The user shares their code, which involves writing audio samples using a sine wave based on specified frequency, amplitude, and beat. A key point of confusion arises regarding why samples are written twice in certain sections of the code, potentially leading to the unexpected sound. The user specifies their parameters: a frequency of 180 Hz, an amplitude of 0.05 dB, and a beat of 10 Hz. There is a suggestion that the sound may result from the transition between the end of the silence (zero samples) and the beginning of the tone, indicating a possible overlap or timing issue in the sample writing process. The discussion highlights the importance of understanding how audio samples are generated and the impact of timing on the final output.
btb4198
Messages
570
Reaction score
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.. here is my code:

Code:
   wavefile = new WaveFileWriter(save1.FileName, tone.WaveFormat);
   double counter2 = 0;
   double Frequency3 = Convert.ToDouble(FREtx3.Text);
   double Amplitude3 = Convert.ToDouble(PeakTXT3.Text);
   Beat = Convert.ToDouble(isochronictxt.Text);
   if (Beat != 0)
   {
      Beat = (1 / Beat);
   }
   else
  {
      Beat = 0;
  }
  for (int n = 0; n < time; n++)
  {
      if (counter2 >= Beat)
     {
          for (int t = 0; t < 10000; t++)
          {
               wavefile.WriteSample(0F);
               wavefile.WriteSample(0F);
                                    
          }

          counter2 = 0;
     }
     else
     {
          wavefile.WriteSample((float)Math.Abs((Amplitude3 * Math.Sin((2 * Math.PI * n * Frequency3) / 44100))));
          wavefile.WriteSample((float)Math.Abs((Amplitude3 * Math.Sin((2 * Math.PI * n * Frequency3) / 44100))));
          counter2 = counter2 + (1D / 44100D);     
     }
  }
  wavefile.Flush();
  wavefile.Dispose();
  file.Add(save1.FileName);
 }
where is that tone coming from ?
https://onedrive.live.com/redir?resid=CC8AF223519E2440!114&authkey=!ADGTKdZEpF4F4Q4&ithint=file,.wav

you can download the song file there...
where is that lost tone coming from ??
 
Last edited by a moderator:
Technology news on Phys.org
btb4198 said:
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.. here is my code:

Code:
   wavefile = new WaveFileWriter(save1.FileName, tone.WaveFormat);
   double counter2 = 0;
   double Frequency3 = Convert.ToDouble(FREtx3.Text);
   double Amplitude3 = Convert.ToDouble(PeakTXT3.Text);
   Beat = Convert.ToDouble(isochronictxt.Text);
   if (Beat != 0)
   {
      Beat = (1 / Beat);
   }
   else
  {
      Beat = 0;
  }
  for (int n = 0; n < time; n++)
  {
      if (counter2 >= Beat)
     {
          for (int t = 0; t < 10000; t++)
          {
               wavefile.WriteSample(0F);
               wavefile.WriteSample(0F);
                                    
          }

          counter2 = 0;
     }
       }else
     {
          wavefile.WriteSample((float)Math.Abs((Amplitude3 * Math.Sin((2 * Math.PI * n * Frequency3) / 44100))));
          wavefile.WriteSample((float)Math.Abs((Amplitude3 * Math.Sin((2 * Math.PI * n * Frequency3) / 44100))));
          counter2 = counter2 + (1D / 44100D);     
     }

  wavefile.Flush();
  wavefile.Dispose();
  file.Add(save1.FileName);
 }


where is that tone coming from ?
https://onedrive.live.com/redir?resid=CC8AF223519E2440!114&authkey=!ADGTKdZEpF4F4Q4&ithint=file,.wav

you can download the song file there...
where is that lost tone coming from ??

Why are you writing the sample twice (in two places)? The places I'm referring to are here
Code:
for (int t = 0; t < 10000; t++)
          {
               wavefile.WriteSample(0F);
               wavefile.WriteSample(0F);
                                    
          }
and here
Code:
else
     {
          wavefile.WriteSample((float)Math.Abs((Amplitude3 * Math.Sin((2 * Math.PI * n * Frequency3) / 44100))));
          wavefile.WriteSample((float)Math.Abs((Amplitude3 * Math.Sin((2 * Math.PI * n * Frequency3) / 44100))));
          counter2 = counter2 + (1D / 44100D);     
     }
Just a guess, but the sound you're hearing might be the part of the audio at the end of the first write and at the beginning of the next.

Also, it might be informative to know what frequency, amplitude, and beat you're using, all of which apparently come from some text files.
 
I am using two channels, so i want both changes to play the same points and the same time. so the even indices are like the right channel and the old indices are the left channel.

Also I do not understand what you mean by "Just a guess, but the sound you're hearing might be the part of the audio at the end of the first write and at the beginning of the next."Frequency is 180 Hz
amplitude is 0.05 db
and beat is 10 Hz
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top