Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
square waves (or pulse waves) 8 Hz duty cycle?
#1
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?

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
Reply


Messages In This Thread
square waves (or pulse waves) 8 Hz duty cycle? - by Rudy M - 11-12-2025, 10:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a square monospace font PhilOfPerth 9 1,716 03-08-2025, 12:26 AM
Last Post: madscijr
  where my square pixels at? James D Jarvis 5 1,186 03-09-2023, 07:04 PM
Last Post: James D Jarvis

Forum Jump:


Users browsing this thread: 1 Guest(s)