Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
square waves (or pulse waves) 8 Hz duty cycle?
#7
And here's something from me too 

Code: (Select All)

FREQ = 8
Pi2 = 8 * Atn(1)
Amplitude = .3
SampleRate = _SndRate
FRate = FREQ / SampleRate

Screen _NewImage(640, 480, 32)

Cls
Color _RGB32(255)
Locate 1
Print "Press + or - to change frequency, ESC to exit"
Locate 2
Print "Frequency: "; FREQ; " Hz"

x = 0
oldY = 240
PSet (0, 240)
ox = 0
oy = 240
Do
    duration = duration + 1
    sample = Amplitude * Sgn(Sin(Pi2 * duration * FRate))
    _SndRaw sample

    y = 240 - sample * 200
    Line (x + 1, y - 130)-(x + 1, y + 130), _RGB32(0)
    PSet (ox, oy)
    Line -(x, y), _RGB32(0, 200, 0)
    ox = x
    oy = y
    oldY = y
    x = x + .05
    If x > 639 Then
        Color _RGB32(255)
        Locate 1
        Print "Press + or - to change frequency, ESC to exit"
        Locate 2
        Print "Frequency: "; FREQ; " Hz"
        x = 0
        Line (0, y - 130)-(0, y + 130), _RGB32(0)
        PSet (0, 240)
    End If

    Do

        i$ = InKey$
        Select Case i$
            Case "+"
                FREQ = FREQ + 1
                If FREQ > 20000 Then FREQ = 20000
                FRate = FREQ / SampleRate
                Locate 2
                Print "Frequency: "; FREQ; " Hz  "

            Case "-"
                FREQ = FREQ - 1
                If FREQ < 1 Then FREQ = 1
                FRate = FREQ / SampleRate
                Locate 2
                Print "Frequency: "; FREQ; " Hz  "
        End Select

    Loop Until _SndRawLen < .1
Loop Until _KeyDown(27)
End


Reply


Messages In This Thread
RE: square waves (or pulse waves) 8 Hz duty cycle? - by Petr - 11-12-2025, 04:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a square monospace font PhilOfPerth 9 1,722 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)