Velocity Reviews > C++ > How do I compute a sine wave

# How do I compute a sine wave

Xanax
Guest
Posts: n/a

 10-04-2003
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
Guest
Posts: n/a

 10-04-2003
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.

Bruce
Guest
Posts: n/a

 10-04-2003
In comp.lang.c++
Gianni Mariani <(E-Mail Removed)> 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)
{
}

}

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

Jerry Coffin
Guest
Posts: n/a

 10-05-2003
In article <jECfb.150\$(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed) 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
Guest
Posts: n/a

 10-05-2003
Thanks all that's great!!
"Jerry Coffin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ia.net...
> In article <jECfb.150\$(E-Mail Removed)>, (E-Mail Removed) 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.

Ashish
Guest
Posts: n/a

 10-06-2003

"Xanax" <(E-Mail Removed)> wrote in message news:jECfb.150\$(E-Mail Removed)...
> 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
Guest
Posts: n/a

 10-06-2003

"Jerry Coffin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ia.net...
> In article <jECfb.150\$(E-Mail Removed)>, (E-Mail Removed) 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.