How do I compute a sine wave

Discussion in 'C++' started by Xanax, Oct 4, 2003.

  1. Xanax

    Xanax Guest

    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.
     
    Xanax, Oct 4, 2003
    #1
    1. Advertising

  2. Xanax wrote:
    > 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??


    This NG is about the C++ language.

    You'll need to look elsewhere for help on FFT's and sound API's.
     
    Gianni Mariani, Oct 4, 2003
    #2
    1. Advertising

  3. Xanax

    Bruce Guest

    In comp.lang.c++
    Gianni Mariani <> wrote:

    >Xanax wrote:
    >> 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??

    >
    >This NG is about the C++ language.


    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.1415926535897932384626433832795;

    class SineWave
    {
    public:
    SineWave(){Amplitude = 2.0; Resolution = 256; Wave = new double[256];};
    SineWave(double Amp, int Res){Amplitude = Amp; Resolution = Res; Wave =
    new double[Res]; };
    ~SineWave(){delete 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::MakeSinWave()
    {
    double cnt = 0.0, step = DegreesPerWave / Resolution;

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

    }

    void SineWave::DumpSinWave()
    {
    for ( int i = 0; i < Resolution; i++)
    {
    cout << Wave << endl;
    }
    }
     
    Bruce, Oct 4, 2003
    #3
  4. Xanax

    Jerry Coffin Guest

    In article <jECfb.150$>, says...
    > Hi all,
    > I need to produce a sine wave and use the WaveOut APi to sound it on my
    > sound card.


    std::sin would be the obvious way.

    > I also need to compute Fast Fourier Transform to modify the Sine wave.


    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.
     
    Jerry Coffin, Oct 5, 2003
    #4
  5. Xanax

    Xanax Guest

    Thanks all that's great!!
    "Jerry Coffin" <> wrote in message
    news:...
    > In article <jECfb.150$>, says...
    > > Hi all,
    > > I need to produce a sine wave and use the WaveOut APi to sound it on my
    > > sound card.

    >
    > std::sin would be the obvious way.
    >
    > > I also need to compute Fast Fourier Transform to modify the Sine wave.

    >
    > 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.
     
    Xanax, Oct 5, 2003
    #5
  6. Xanax

    Ashish Guest

    "Xanax" <> wrote in message news:jECfb.150$...
    > 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.
    >
    >


    Ask this question in a mathematics newsgroup (Sorry, I am too lazy to look
    up newsgroup names for you)
     
    Ashish, Oct 6, 2003
    #6
  7. Xanax

    Ashish Guest

    "Jerry Coffin" <> wrote in message
    news:...
    > In article <jECfb.150$>, says...
    > > Hi all,
    > > I need to produce a sine wave and use the WaveOut APi to sound it on my
    > > sound card.

    >
    > std::sin would be the obvious way.
    >
    > > I also need to compute Fast Fourier Transform to modify the Sine wave.

    >
    > 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.
    >


    Dont confuse the newbie.
     
    Ashish, Oct 6, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    4,710
    Jim Lewis
    Nov 28, 2005
  2. Phil Newman

    Simple Sine Wave Array

    Phil Newman, Nov 2, 2005, in forum: C++
    Replies:
    11
    Views:
    728
  3. red floyd
    Replies:
    5
    Views:
    1,095
    Nathan Wijnia
    Jun 21, 2007
  4. rara10
    Replies:
    0
    Views:
    965
    rara10
    Jan 30, 2009
  5. Shiva
    Replies:
    2
    Views:
    1,697
    Chris Maryan
    Feb 2, 2009
Loading...

Share This Page