just stabbing in the dark in case nobody else gives a more useful response but...
#1 - what is the format of your output? If it's low in bitcount that could make the signal more dirty i believe (less resolution to make a more perfect sine wave) #2 - have you tried calculating via doubles? #3 - what is data->amplitude... does that ever change or is it just a one time set volume adjustment for the left and right channels? On Tue, Apr 26, 2011 at 12:57 PM, <eu...@lavabit.com> wrote: > Hello, > > I want to generate two different frequency sinewaves on LineOut - > Left&Right. For audio IO I'm using Portaudio(Linux, PortAudio V19-devel > (built Apr 17 2011 22:00:29)), and the callback code is: > > static int paCallback( const void* inBuff, void* outBuff, > unsigned long frpBuff, > const > PaStreamCallbackTimeInfo* tInf, > PaStreamCallbackFlags flags, > void* userData ) > { > int16_t i; > audioData* data = (audioData*) userData; > float* out = (float*) outBuff; > > /* Prevent warnings */ > (void) tInf; > (void) flags; > > for( i=0; i<frpBuff; i++ ) > { > *out++ = data->amplitude[0] * sinf( (2.0f * M_PI) * > data->phase[0] ); > *out++ = data->amplitude[1] * sinf( (2.0f * M_PI) * > data->phase[1] ); > > /* Update phase, rollover at 1.0 */ > data->phase[0] += (data->frequency[0] / SAMPLE_RATE); > if(data->phase[0] > 1.0f) data->phase[0] -= 2.0f; > data->phase[1] += (data->frequency[1] / SAMPLE_RATE); > if(data->phase[1] > 1.0f) data->phase[1] -= 2.0f; > } > > return paContinue; > } > > When I checked the output spectrum for a 10kHz frequency using baudline > (running on another PC), I got this http://images.cjb.net/80af2.png . The > spectrum is clean only for output frequencies below 2-3 kHz. > > The tone generator inside baudline gives a clean spectrum at 10 kHz: > http://images.cjb.net/b943b.png . > > What method would you recommend for generating a clean sinewave at 5-12 kHz? > I think there is a bug somewhere, because the sine is computed in float > for each sample and should be precise enough... > > Thanks > > > > -- > dupswapdrop -- the music-dsp mailing list and website: > subscription info, FAQ, source code archive, list archive, book reviews, dsp > links > http://music.columbia.edu/cmc/music-dsp > http://music.columbia.edu/mailman/listinfo/music-dsp > -- dupswapdrop -- the music-dsp mailing list and website: subscription info, FAQ, source code archive, list archive, book reviews, dsp links http://music.columbia.edu/cmc/music-dsp http://music.columbia.edu/mailman/listinfo/music-dsp