help oscillator pitch problem

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Hi folks, I get a big trouble which make me sad :help: !
this is my situation,
I have an oscillator see www.musicdsp.com "quick and dirty" than I've a good and working routine which give me a envelope, so I put envelope result into freq var and the result it's a no sense wave.

Can U help me?


Thanks

Post

Have you tested the oscillator code without modulation the frequency value? What values is your envelope putting out and what values is the oscillator expecting? You've got three potential problems (the oscillator code may not work, the envelope code may not work, and the envelope output may not make sense as a frequency input) - so isolate your problem first.

Post

Thank 4 Ur answer,
yep I've tested all the 3 point, oscillator work, emvelope work, and output of envelope get richt sense... this problem make me crazy, U know if there is a source of an effect like bdrum synth or so on

thanks Again :)

Post

Try this for the oscillator instead:

Code: Select all

const double PI = 3.1415926535897932384626433832795;
const double TWO_PI = PI * 2;

class Osc
{
public:
	Osc() : amp_(1.0), phs_(0.0), pinc_(0.0) { }

	inline void setAmp(double amp) { amp_ = amp; }
	inline void setFrequency(double f, double sr) { pinc_ = f * PI / sr; }

	inline double dirtySine();

private:
	double amp_;
	double phs_;
	double pinc_;
};

inline double 
Osc::dirtySine()
{
	double p = phs_ + pinc_;

	if (p > TWO_PI) {
		p -= TWO_PI;
	}
	
	phs_ = p;
	return (amp_ * sin(p));
}
Also not a great way of producing a sine. It works well, but could be much faster.
The frequency should be supplied in whatever units the samplerate is in, so if you've got this from a vsttimeinfo struct, you'll want it to be in Hz.
You could get rid of the PI/sr in the frequency calculation by precalculating it.

Post

you great thanks I will try it soon as possible...
just a question which kind of site is yours? I don't understand, self music promotion or music shop

You keep my curiosity :)

Paul :P

Post

The site is basically for promoting music, although itreally needs sorting out. Some of the tracks have been signed, so we've had to take down the audio from the site. There are demos at the bitboutique site and at the iron box site though.

Post

texture U R GREAT! seems to work...

thanks again :)

Post

I guess this was the old accumating problem?

doing phase = time*freq instead of phase += deltaTime*freq.
Stefan H Singer
Musician, coder and co-founder of We made you look Web agency

Post

stefancrs wrote:I guess this was the old accumating problem?

doing phase = time*freq instead of phase += deltaTime*freq.
Looked like it was both!

There appeared to be an array of integer accumulators (for multiple channels?). These then got converted to doubles on every iteration and divided by the samplerate (also converted from int to double). This gave the time of one cycle.

The phase was then calculated from the cycle time, in radians and added to a phase variable before applying the sin() function.

Obviously using sin() to calculate the waveform is pretty unneccesary, as a self oscillating IIR would be far more efficient.

Post

couriervst wrote:texture U R GREAT! seems to work...

thanks again :)
glad it works :D

Post Reply

Return to “DSP and Plugin Development”