11-12-2025, 10:31 AM
Hello everyone,
I'm still busy testing QB64PE.
For a later experiment, I want to use the PC as a square wave generator (or pulse generator).
One of the low frequencies I need is 8 Hz.
This isn't possible using the Sound statement (cfr frequency lower then 30Hz...)
But via F1 help on the _SNDRAW item, I discovered the QB64PE example for sine and square waves.
To my great surprise, this works on my old Lenovo ThinkCentre PC from 1 Hz!
Okay, I'm very happy with that.
But.... Does anyone know if it is possible to regulate the duty cycle with this _SNDRAW statement?
I'm still busy testing QB64PE.
For a later experiment, I want to use the PC as a square wave generator (or pulse generator).
One of the low frequencies I need is 8 Hz.
This isn't possible using the Sound statement (cfr frequency lower then 30Hz...)
But via F1 help on the _SNDRAW item, I discovered the QB64PE example for sine and square waves.
To my great surprise, this works on my old Lenovo ThinkCentre PC from 1 Hz!
Okay, I'm very happy with that.
But.... Does anyone know if it is possible to regulate the duty cycle with this _SNDRAW statement?
Code: (Select All)
'Source: QB64PE (_SNDRAW + F1)
'Sound using a sine wave with _SNDRAW Amplitude * SIN(8 * ATN(1) * Duration * (Frequency / _SNDRATE))
'Explanation: The loop Duration is determined
' by the number of seconds times the _SNDRATE number of samples per second.
'Square waves can use the same formula with:
' Amplitude * SGN(SIN(8 * ATN(1) * Duration * (Frequency/_SNDRATE))).
'any frequency desired from 36 to 10,000
'FREQ = 1 'Test Rudy (works on my PC)
FREQ = 8 'Test Rudy (works on my PC)
'FREQ = 10000
Pi2 = 8 * ATN(1) '2 * pi
Amplitude = .3 'amplitude of the signal from -1.0 to 1.0
SampleRate = _SNDRATE 'sets the sample rate
FRate = FREQ / SampleRate '
FOR Duration = 0 TO 5 * SampleRate 'play 5 seconds
'_SNDRAW Amplitude * SIN(Pi2 * Duration * FRate) 'sine wave
_SNDRAW Amplitude * SGN(SIN(Pi2 * Duration * FRate)) 'square wave
' Works for a frequences starting from 1 Hertz (old Lenovo ThinkCentre, Linux Mint 22)
NEXT
DO: LOOP WHILE _SNDRAWLEN
END

