Post Reply 
My first program on HP-50g - Music.
06-10-2021, 12:17 PM
Post: #18
RE: My first program on HP-50g - Music.
(06-10-2021 01:08 AM)BINUBALL Wrote:  If I can use WAIT in code more efficiently, then we can make better music

My first thought upon reading this was: "what happens if BEEP is given an invalid frequency to play -- might it simply produce silence for the given duration?"

Unfortunately, the answer is no. When I tested this with 0 for the frequency, BEEP simply ignored the input and the next note started playing immediately (ie. no pause at all).

So I then thought a simple conditional test might work to either perform a BEEP for non-zero frequencies or a WAIT if given 0. This version uses DOLIST to take corresponding entries from two input lists (the first has the frequencies, the second has the durations). If the frequency is 0, it is simply dropped and WAIT is used with the given duration. Otherwise BEEP is used with the given arguments:
Code:
\<<
   { 440  0  440 }
   {  1   1   1  }
   2.
   \<<
      IF
         OVER
      THEN
         BEEP
      ELSE
         NIP
         WAIT
      END
   \>>
   DOLIST
\>>

The same logic applies to this version, which is a bit smaller at the expense of readability:
Code:
\<<
   { 440  0  440 }
   {  1   1   1  }
   2.
   \<<
      OVER
      ::BEEP
      { NIP WAIT }
      IFTE
   \>>
   DOLIST
\>>

I'm sure there's other ways to do this, but this was what came to mind when reading your question.

- David
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: My first program on HP-50g - Music. - DavidM - 06-10-2021 12:17 PM



User(s) browsing this thread: 2 Guest(s)