!SOUND

Discussions related to the extensions to the language available in LBB
User avatar
JackKelly
Posts: 63
Joined: Fri Apr 06, 2018 2:38 am
Location: Rome NY, USA

!SOUND

Post by JackKelly »

Is the BBC Basic command !SOUND available in LBB? If so, would you provide an example snippet.
guest
Site Admin
Posts: 198
Joined: Tue Apr 03, 2018 1:34 pm

Re: !SOUND

Post by guest »

JackKelly wrote: Sat Mar 02, 2019 5:16 am Is the BBC Basic command !SOUND available in LBB? If so, would you provide an example snippet.
I can't think of any reason why SOUND (and the associated ENVELOPE statement) would not work; the *TEMPO command is also relevant. But this 38-year-old functionality is primitive compared with what can be achieved using a MIDI file, for example.

Code: Select all

    !SOUND 1,-15,148,20
User avatar
JackKelly
Posts: 63
Joined: Fri Apr 06, 2018 2:38 am
Location: Rome NY, USA

Re: !SOUND

Post by JackKelly »

Thanks Richard. I tried everything and couldn't get it to work. After you said it should work, then 'presto', it worked! Amazing. Many things I will never understand. I have coded a Morse Code transmitter, and !SOUND was just the proper thing I needed.
[a] input "Enter a message --> "; Message$
if Message$="" then print "Program Complete.": end
call MorseCode Message$
goto [a]

sub MorseCode Message$
    DotLength=1
    DashLength=3
    DotDashInterval=1
    LetterInterval=3
    WordInterval=7
    Message$=upper$(trim$(Message$))
    for x=1 to len(Message$)
        x$=mid$(Message$, x, 1)
        select case x$
            case "A": LC$=".- "
            case "B": LC$="-... "
            case "C": LC$="-.-. "
            case "D": LC$="-.. "
            case "E": LC$=". "
            case "F": LC$="..-. "
            case "G": LC$="--. "
            case "H": LC$=".... "
            case "I": LC$=".. "
            case "J": LC$=".--- "
            case "K": LC$="-.- "
            case "L": LC$=".-.. "
            case "M": LC$="-- "
            case "N": LC$="-. "
            case "O": LC$="--- "
            case "P": LC$=".--. "
            case "Q": LC$="--.- "
            case "R": LC$=".-. "
            case "S": LC$="... "
            case "T": LC$="- "
            case "U": LC$="..- "
            case "V": LC$="...- "
            case "W": LC$=".-- "
            case "X": LC$="-..- "
            case "Y": LC$="-.-- "
            case "Z": LC$="--.. "
            case "1": LC$=".---- "
            case "2": LC$="..--- "
            case "3": LC$="...-- "
            case "4": LC$="....- "
            case "5": LC$="..... "
            case "6": LC$="-.... "
            case "7": LC$="--... "
            case "8": LC$="---.. "
            case "9": LC$="----. "
            case "0": LC$="----- "
            case " ": LC$="_"
            case else
                      LC$=""
        end select
        for y=1 to len(LC$)
            y$=mid$(LC$, y, 1)
            select case y$
                case "." 'dot + interval
                    !SOUND 1, -7, 200, DotLength*2
                    !SOUND 1, 0, 200, DotDashInterval*2
                case "-" 'dash + interval
                    !SOUND 1, -7, 200, DashLength*2
                    !SOUND 1, 0, 200, DotDashInterval*2
                case " " 'letter interval
                    !SOUND 1,0, 200,(LetterInterval-DotDashInterval)*2
                case "_" 'word interval
                    !SOUND 1, 0, 200,(WordInterval-DotDashInterval)*2
            end select
        next y
        print x$;                    
    next x
    print
end sub

'!SOUND 1,-7,200,2 'dot (one unit)
'!SOUND 1,-7,200,6 'dash (three units)
'!SOUND 1,0,200,2 'interval between dots & dashes (one unit) 
'!SOUND 1,0,200,6 'interval between letters (three units)
'!SOUND 1,0,200,14 'interval between words (seven units)