[sdiy] Harmonic bandwidth

Eric Brombaugh ebrombaugh at earthlink.net
Wed Jan 9 16:47:31 CET 2008


Scott Gravenhorst wrote:
> music.maker at gte.net wrote:
>> Ok, now I've done it.  I wrote a C program to generate 3 .wav files using double float,
>> one with zero starting phase values and 2 more each with different random, but constant
>> phase values.  The program uses 32 harmonics in the series that produces a sawtooth.  I
>> was careful to limit clipping and applied the same worst case attenuation value to all
>> three.  Each sample is several seconds long.

Post source somewhere so others can try?

>> I most definately hear a difference in timbre.
>>
>> The question is "why?".  
>>
>> Surely, there is something about digital generation of waveforms.

The flip answer would be "Because math doesn't really work." :)

Seriously, there are a host of reasons why you're hearing a difference 
that may be caused by other things you didn't control in your 
experiment, for example

* Attack transient - different phases will result in different 
waveshapes, and while the assertion that 'the human ear is insensitive 
to phase' may be true, the startup transient of the different waveforms 
may well influence how you perceive them. Putting a nice 50ms raised 
cosine attack & decay with about on your trial waves might mitigate this.

* Audio signal chain in your PC. Let's just be kind and say that the 
design criteria in many PCs aren't what they could be. You may have an 
excellent audio output, but if not it could influence the sound. I know 
one of my PC's has crappy audio drivers and I can hear a difference 
between it and my others.

* You're ears are better than average? Remember that most 
psychoacoustics are based on general perceptions, but everyone is 
slightly different.

* Others?

> One thing I just noticed, in the documentation for the sin() function for C, it says "The sin()
> function may lose accuracy when its argument is far from 0.0".  
> 
> My particular program checks the value before handing it to the sin() function, but I have two
> questions:
> 
> 1) No computer value for pi is exactly accurate, so to monitor the current angle value and subtract
> 2*pi when it goes over 2*pi is also an inaccurate value.
> 
> 2) how far from 0.0 does one have to go to get an inaccurate _enough_ sin() value?
> 
> Is it possible that these reasons are all it takes?  I would have to assume that these problems
> exist in any digital approximation of this.

That depends on the implementation of the transcendental functions in 
your math library - my experience is that you have to be pretty far away 
from 0.0 to make any difference. I'm not talking a few multiples of pi, 
but billions. If you think it's an issue however taking your phase value 
mod 2*pi before the sin/cos function can help.

Note - to get a precise value of 2*pi, use 8.0*atan(1.0) - that will 
give it to the best precision your library allows.

Eric



More information about the Synth-diy mailing list