' Program to play sound that resembles security alarm.
' This program is free software: released under Creative Commons Zero (CC0) license
' by Svjatoslav Agejenko.
' Email: svjatoslav@svjatoslav.eu
' Homepage: http://www.svjatoslav.eu
'
' Changelog:
' ?, Initial version
' 2024 - 2025, Enhanced program readability

SCREEN 1
CLS

' Initialize main frequency control variable
' This will create the oscillating siren effect by increasing/decreasing value
currentFrequency = 40

StartLoop:
    ' Play primary oscillating tone (main siren component)
    ' Frequency sweeps up and down between thresholds
    SOUND currentFrequency, .3

    ' Add secondary fixed-frequency component (200Hz for 1 duration unit)
    ' Creates layered audio effect that makes alarm more realistic
    ' Duration parameter uses QBasic's time units (1 ≈ 0.05 seconds)
    SOUND 200, 1

    ' Rapidly increase frequency for ascending siren sweep
    ' Jump amount (100) creates dramatic pitch jumps
    currentFrequency = currentFrequency + 100

    ' Check if we've exceeded upper frequency threshold (1000Hz)
    ' If yes, switch to descending phase
    IF currentFrequency > 1000 THEN GoTo DecreaseFrequency

    ' Repeat ascending sweep until reaching maximum threshold
    GOTO StartLoop

DecreaseFrequency:
    ' Continue playing oscillating tone during descending phase
    SOUND currentFrequency, .3

    ' Add high-pitched pulse (500Hz for short duration)
    ' Creates distinctive alarm "warble" pattern
    ' Shorter duration (.2) adds rhythmic pulsing
    SOUND 500, .2

    ' Gradually decrease frequency for descending sweep
    ' Smaller decrement (10) creates slower descent than ascent
    currentFrequency = currentFrequency - 10

    ' Check if we've dropped below lower threshold (200Hz)
    ' If yes, restart ascending phase to complete siren cycle
    IF currentFrequency < 200 THEN GoTo StartLoop

    ' Continue descending sweep until reaching minimum threshold
    GOTO DecreaseFrequency
