We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Sonia - glitchy sine wave
Page Index Toggle Pages: 1
Sonia - glitchy sine wave (Read 689 times)
Sonia - glitchy sine wave
Feb 2nd, 2010, 6:40am
 
Hi all,

I'm trying to generate a simple sine wave using the Sonia library, and can't seem to get it right.  There is a glitch in the wave that gives a nasty click, but I can't for the life of me work out what is causing it or how to resolve it!

Using the below code the n key will stop the wave, and m will restart it.  There seems to be a few regular patterns of click that re-occur on different restarts, and occasionally it will run OK, but that is rare.

Can anyone help?

Cheers
Phil

import pitaru.sonia_v2_9.*;

int bufSize = 2048;
float SR = 44100;
float oneHertz = TWO_PI / SR;
float freq = 440 * oneHertz;
float amp = 0.5;
float phs = 0;

void setup()
{
 size(512,512);
 Sonia.start(this,44100);
 LiveOutput.start(bufSize, bufSize * 2);
 LiveOutput.startStream();
 stroke(255);
 strokeWeight(4);
}

void liveOutputEvent()
{
 for (int n = 0; n < bufSize; n++)
   LiveOutput.data[n] = amp * sin (freq * n + phs);
 phs+=freq * bufSize;
}

void draw()
{
 background(0);
 for(int n = 0; n < min(width, bufSize); n++)
   point(n, height*(0.5-0.5*LiveOutput.data[n]));
}

void keyTyped()
{
if (key=='m')
  LiveOutput.stopStream();
 
if (key=='n')
  LiveOutput.startStream();
}
Page Index Toggle Pages: 1