SOUND command for > 127 values

ncoplin

Member
Hi All,

I can find in the forum equations for the tone generation for values 0-127, but not for the noise function for values beyond this.

I've looked at the signals on a logic analyser and can see that the duty cycle seems to be "adjusted", more so than the frequency. Is this true? Is there a way for describing the generated signals by a function (or series functions). Looking to simulate the sounds generated with a PC program than to have to test on a real PICAXE every individual time I want to change something...

Cheers,
Nick
 

Technical

Technical Support
Staff member
The sound routine is the same for any note value 0-255, but the formula includes this (127 - note)
Therefore if you use a value greater than 127 you get mathematical byte overflow, which results in the command not functioning correctly and so it just makes various strange 'white noise' sounds. To emulate this you would need to emulate a PICAXE byte negative overflow to 255 at all points within your maths, where, as an example, a note value of 128 would give (127-128) = 255.
 

ncoplin

Member
Thanks Technical. I only seem able to find the Freq equation on the forum:
Frequency in Hz = 1 / ( (95exp-6) + ((127-note)x83exp-6) )

Wrapping the byte value sets the frequency correctly (you get a low "tone" , but there would appear to be a second aspect not described by frequency alone. Looking at the output of "sound 1, (128,10)" on an analyser there is something being done to the duty cycle as well? I cannot find a formula or logic for this...

Many thanks, Nick
 

ncoplin

Member
In the PICAXE manual under the Sound command, it states that values from 128 to 255 are 'white noises'.
yes, i read that. however the scope trace shows that the same value generates exactly the same wave form. There is no "noise" generator onboard the PIC, therefore I expect some equation (similar to how random numbers are generated) is used to produce a signal with modulations in the timebase. The same equation is started each time the SOUND command is issued. The modulations do not repeat (within reasonable time) as longer duration signals don't show it.

This I can tell from the scope traces. Short of doing an FFT or something beyond my math skill to 127 scope traces to synthesise a formula, I was kinda hoping for some info.

The wrapped tone equation still produces a tone - though they are of a frequncy which is low enough, their duty cylc is unmodified.

Hmmm?
 

Technical

Technical Support
Staff member
There is nothing special done to values 128-255, the resulting white noise waveforms are just a 'by product' of byte overflow mathematics on the sound command routine, which is only designed to work correctly for values of 1-127. It is purely the overflow in the firmware routines that give the strange effects, no special processing is done at all.
 

John West

Senior Member
Put in less technical terms, it's a cesspool, not a "hidden feature."

Unless, of course, you're looking for a cesspool. In which case, it's a hidden feature.
 
Last edited:

ncoplin

Member
There is nothing special done to values 128-255, the resulting white noise waveforms are just a 'by product' of byte overflow mathematics on the sound command routine, which is only designed to work correctly for values of 1-127. It is purely the overflow in the firmware routines that give the strange effects, no special processing is done at all.
Thanks Technical, clearly then the overflow is not in this equation Frequency in Hz = 1 / ( (95exp-6) + ((127-note)x83exp-6) ) which resolves fine to a lower frequency when the byte wrap considered. This equation only gives one answer - frequency.

Clearly for simulation/emulation it is the lower level firmware routine which does the timebased switching on/off which is overflowing. Is that routine able to be shared? Since the P.E. doesn't simulate the noise, one is left with the only option of repeatedly downloading variations to the chip to get the sound/noise they want.
 
Top