How do I compute a sine wave

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xanax

    How do I compute a sine wave

    Hi all,
    I need to produce a sine wave and use the WaveOut APi to sound it on my
    sound card.
    I also need to compute Fast Fourier Transform to modify the Sine wave.

    Any ideas on where to start or get some info on this??
    Cheers,
    Xanax.


  • Gianni Mariani

    #2
    Re: How do I compute a sine wave

    Xanax wrote:[color=blue]
    > Hi all,
    > I need to produce a sine wave and use the WaveOut APi to sound it on my
    > sound card.
    > I also need to compute Fast Fourier Transform to modify the Sine wave.
    >
    > Any ideas on where to start or get some info on this??[/color]

    This NG is about the C++ language.

    You'll need to look elsewhere for help on FFT's and sound API's.


    Comment

    • Bruce

      #3
      Re: How do I compute a sine wave

      In comp.lang.c++
      Gianni Mariani <gi2nospam@mari ani.ws> wrote:
      [color=blue]
      >Xanax wrote:[color=green]
      >> Hi all,
      >> I need to produce a sine wave and use the WaveOut APi to sound it on my
      >> sound card.
      >> I also need to compute Fast Fourier Transform to modify the Sine wave.
      >>
      >> Any ideas on where to start or get some info on this??[/color]
      >
      >This NG is about the C++ language.[/color]

      So why don't you give him an example in C++?
      #include <iostream>
      #include <math.h>

      using namespace std;

      const double DegreesPerWave = 360.0;
      const double Pi = 3.1415926535897 932384626433832 795;

      class SineWave
      {
      public:
      SineWave(){Ampl itude = 2.0; Resolution = 256; Wave = new double[256];};
      SineWave(double Amp, int Res){Amplitude = Amp; Resolution = Res; Wave =
      new double[Res]; };
      ~SineWave(){del ete Wave;};

      void MakeSinWave();
      void DumpSinWave();
      double Deg2Rad( double x) {return x * Pi/180.0;};

      private:
      double Amplitude;
      int Resolution;
      double *Wave;
      };


      int main(int argc, char **argv)
      {
      SineWave s;

      s.MakeSinWave() ;
      s.DumpSinWave() ;
      return 0;
      }

      void SineWave::MakeS inWave()
      {
      double cnt = 0.0, step = DegreesPerWave / Resolution;

      for ( int i = 0; i < Resolution; i++, cnt += step)
      {
      Wave[i] = Amplitude * sin(Deg2Rad(cnt ));
      }

      }

      void SineWave::DumpS inWave()
      {
      for ( int i = 0; i < Resolution; i++)
      {
      cout << Wave[i] << endl;
      }
      }

      Comment

      • Jerry Coffin

        #4
        Re: How do I compute a sine wave

        In article <jECfb.150$1Q3. 760@news.indigo .ie>, jo@fo.mo says...[color=blue]
        > Hi all,
        > I need to produce a sine wave and use the WaveOut APi to sound it on my
        > sound card.[/color]

        std::sin would be the obvious way.
        [color=blue]
        > I also need to compute Fast Fourier Transform to modify the Sine wave.[/color]

        If you're starting with a sine wave, the result of an FFT is a foregone
        conclusion -- a sine wave is a pure fundamental, so you basically get a
        spike to 100% at the fundamental, and above that you'll get a tiny bit
        of "noise" that's basically just an artifact of the sampling.

        If you want to add overtones, you don't need to apply an FFT to a sine
        wave to start with -- you can just put in the overtones you want, and
        then do an inverse FFT to get your waveform.

        --
        Later,
        Jerry.

        The universe is a figment of its own imagination.

        Comment

        • Xanax

          #5
          Re: How do I compute a sine wave

          Thanks all that's great!!
          "Jerry Coffin" <jcoffin@taeus. com> wrote in message
          news:MPG.19e956 9167fc7214989b4 b@news.clspco.a delphia.net...[color=blue]
          > In article <jECfb.150$1Q3. 760@news.indigo .ie>, jo@fo.mo says...[color=green]
          > > Hi all,
          > > I need to produce a sine wave and use the WaveOut APi to sound it on my
          > > sound card.[/color]
          >
          > std::sin would be the obvious way.
          >[color=green]
          > > I also need to compute Fast Fourier Transform to modify the Sine wave.[/color]
          >
          > If you're starting with a sine wave, the result of an FFT is a foregone
          > conclusion -- a sine wave is a pure fundamental, so you basically get a
          > spike to 100% at the fundamental, and above that you'll get a tiny bit
          > of "noise" that's basically just an artifact of the sampling.
          >
          > If you want to add overtones, you don't need to apply an FFT to a sine
          > wave to start with -- you can just put in the overtones you want, and
          > then do an inverse FFT to get your waveform.
          >
          > --
          > Later,
          > Jerry.
          >
          > The universe is a figment of its own imagination.[/color]


          Comment

          • Ashish

            #6
            Re: How do I compute a sine wave


            "Xanax" <jo@fo.mo> wrote in message news:jECfb.150$ 1Q3.760@news.in digo.ie...[color=blue]
            > Hi all,
            > I need to produce a sine wave and use the WaveOut APi to sound it on my
            > sound card.
            > I also need to compute Fast Fourier Transform to modify the Sine wave.
            >
            > Any ideas on where to start or get some info on this??
            > Cheers,
            > Xanax.
            >
            >[/color]

            Ask this question in a mathematics newsgroup (Sorry, I am too lazy to look
            up newsgroup names for you)


            Comment

            • Ashish

              #7
              Re: How do I compute a sine wave


              "Jerry Coffin" <jcoffin@taeus. com> wrote in message
              news:MPG.19e956 9167fc7214989b4 b@news.clspco.a delphia.net...[color=blue]
              > In article <jECfb.150$1Q3. 760@news.indigo .ie>, jo@fo.mo says...[color=green]
              > > Hi all,
              > > I need to produce a sine wave and use the WaveOut APi to sound it on my
              > > sound card.[/color]
              >
              > std::sin would be the obvious way.
              >[color=green]
              > > I also need to compute Fast Fourier Transform to modify the Sine wave.[/color]
              >
              > If you're starting with a sine wave, the result of an FFT is a foregone
              > conclusion -- a sine wave is a pure fundamental, so you basically get a
              > spike to 100% at the fundamental, and above that you'll get a tiny bit
              > of "noise" that's basically just an artifact of the sampling.
              >
              > If you want to add overtones, you don't need to apply an FFT to a sine
              > wave to start with -- you can just put in the overtones you want, and
              > then do an inverse FFT to get your waveform.
              >[/color]

              Dont confuse the newbie.


              Comment

              Working...