Post Reply 
My first program on HP-50g - Music.
06-05-2021, 07:00 PM (This post was last modified: 06-05-2021 07:00 PM by matalog.)
Post: #1
My first program on HP-50g - Music.
I have recently taken a liking to programmable calculators, as I use a calculator a lot in work, and like a little bit of programming. I got myself a 50g a few days ago.

I must admit, that I am not taking very well or easily to the RPL way of programming, for example, I find the HP Prime language much more understandable, and usually use calculators in algebraic mode.

I wrote a little program, in RPN mode here, that takes the values of a list and uses them as frequencies in a series of BEEPs.

https://www.dropbox.com/s/6otu2jw4m7gjz0...6.mp4?dl=0

I'm sure it has been done before, but this is my first attempt at any program on the 50g, and although it is frustrating getting used to the calculator and language, it can BEEP!
Find all posts by this user
Quote this message in a reply
06-05-2021, 09:54 PM
Post: #2
RE: My first program on HP-50g - Music.
That is by far the most impressive User RPL music program I have heard on the 48/49/50. It almost has the polyphonic sound of some of the assembly language programs I've seen to do it.

Congratulations on your first program being so amazing! Any chance you might be willing to share the code?
Visit this user's website Find all posts by this user
Quote this message in a reply
06-06-2021, 06:49 AM
Post: #3
RE: My first program on HP-50g - Music.
Hello
If you rewrite the firmware to NewRPL you could have a much more powerful RPL language

newRPL:
https://sourceforge.net/projects/newrpl/
Find all posts by this user
Quote this message in a reply
06-06-2021, 07:02 AM (This post was last modified: 06-06-2021 07:15 AM by Stevetuc.)
Post: #4
RE: My first program on HP-50g - Music.
(06-06-2021 06:49 AM)compsystems Wrote:  Hello
If you rewrite the firmware to NewRPL you could have a much more powerful RPL language

newRPL:
https://sourceforge.net/projects/newrpl/

I'm curious as to how that improves the music program that's the topic of this thread?
Edit: did the 3 channel fm synth code mentioned by Claudio here make it to newrpl?
https://www.hpmuseum.org/forum/thread-97...l#pid98718
(06-04-2018 03:36 PM)Claudio L. Wrote:  Alarms are not buggy at all, but the buzzer doesn't have a driver yet... so it's a very quiet alarm for the time being. The good new is... I found my 3-channel FM-synthesizer code, as soon as I get some spare time I'll try to port it to newRPL so it will sound much better than the usual "beep".
Find all posts by this user
Quote this message in a reply
06-06-2021, 05:56 PM
Post: #5
RE: My first program on HP-50g - Music.
(06-05-2021 09:54 PM)Eric Rechlin Wrote:  That is by far the most impressive User RPL music program I have heard on the 48/49/50. It almost has the polyphonic sound of some of the assembly language programs I've seen to do it.

Congratulations on your first program being so amazing! Any chance you might be willing to share the code?

It's really as simple as it could be, the notes are all one length because of how the tune is written.

Code:
«
1 'N' STO
{392,33,65,349,33,33,330,65,262,33,65,330,33,33,392,65,349,41,330,82,247,41,82,8​2,41,41,82,82,41,41,82,82,440,27,55,494,27,27,523,55,330,27,55,349,27,27,392,55,​349,44,330,87,262,44,87,87,44,44,87,87,44,44,87,87,392,33,65,349,33,33,330,65,26​2,33,65,330,33,33,392,65,349,41,330,82,247,41,82,82,41,41,82,82,41,41,82,82,440,​55,110,494,55,55,523,110,330,55,110,330,55,55,392,110,440,44,392,87,392,44,87,87​,44,44,87,87,44,44,87,87,262,33,330,65,392,33,262,330,33,392,65,262,330,33,392,6​5,247,41,330,82,392,41,247,330,41,392,82,247,330,41,392,82,262,55,330,110,440,55​,262,330,55,440,110,262,330,55,440,110,262,44,349,87,440,44,262,349,44,440,87,26​2,349,44,440,87,262,33,330,65,392,33,262,330,33,392,65,262,330,33,392,65,247,41,​330,82,392,41,247,330,41,392,82,247,330,41,392,82,262,55,330,110,440,55,262,330,​55,440,110,262,330,55,440,110,262,44,349,87,440,44,262,349,44,440,87,262,349,44,​440,87}  'L1' STO
1 10 FOR A
1 256 FOR N
'L1' N GET 0.08 BEEP
NEXT
NEXT
»
Find all posts by this user
Quote this message in a reply
06-07-2021, 12:11 PM (This post was last modified: 06-07-2021 12:11 PM by Joe Horn.)
Post: #6
RE: My first program on HP-50g - Music.
(06-06-2021 05:56 PM)matalog Wrote:  It's really as simple as it could be, the notes are all one length because of how the tune is written.

Just a thought: In that case, the program might play smoother if you omit the inner loop, since the 50g supports list processing. Also, none of the variables are needed. Omit the 1 'N' STO, and replace everything after the end of the list with the following:

1 10 START DUP 0.08 BEEP NEXT DROP »

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
06-07-2021, 01:09 PM
Post: #7
RE: My first program on HP-50g - Music.
(06-06-2021 06:49 AM)compsystems Wrote:  Hello
If you rewrite the firmware to NewRPL you could have a much more powerful RPL language

newRPL:
https://sourceforge.net/projects/newrpl/
Is there a BEEP command on newRPL?

S.Korean / HP-50G | fx-570EX | fx-570CW | HP-200LX
Visit this user's website Find all posts by this user
Quote this message in a reply
06-07-2021, 03:24 PM
Post: #8
RE: My first program on HP-50g - Music.
On BEEP CMD, I don't think NewRPL team have done it yet, hopefully in an upcoming firmware release.
Find all posts by this user
Quote this message in a reply
06-07-2021, 09:29 PM (This post was last modified: 06-07-2021 09:33 PM by matalog.)
Post: #9
RE: My first program on HP-50g - Music.
(06-07-2021 12:11 PM)Joe Horn Wrote:  
(06-06-2021 05:56 PM)matalog Wrote:  It's really as simple as it could be, the notes are all one length because of how the tune is written.

Just a thought: In that case, the program might play smoother if you omit the inner loop, since the 50g supports list processing. Also, none of the variables are needed. Omit the 1 'N' STO, and replace everything after the end of the list with the following:

1 10 START DUP 0.08 BEEP NEXT DROP »

That makes it run quite a bit faster, it's now better to change the note length to 0.1 to slow it down a little. I guess it will leave less time between beeps, which has to help.

Thanks for sharing that trick.
Find all posts by this user
Quote this message in a reply
06-08-2021, 01:06 AM
Post: #10
RE: My first program on HP-50g - Music.
Hello!

In HP48 I used to do something like store all notes in vars and so recall it from a program.
I think that it also works in HP50.


I store all notes as a var, so recall it from a main program.

For example:

<<440 .1 BEEP>>
STO it in the var "LA"

and do the same for "Re", "Mi", "Fa", "Sol", "La", "Si", sharp, flat and so on.

Exemple of the main program:

<<LA DO DO RE MI FA FA SOL SOL SI SI>>
store it as MUSIC and and so run it.

This avoid you to type everytime the musical note time and frequency, makig the program shorter:-)

Kind regards,

Carlos




quote='matalog' pid='148834' dateline='1623101377']
(06-07-2021 12:11 PM)Joe Horn Wrote:  Just a thought: In that case, the program might play smoother if you omit the inner loop, since the 50g supports list processing. Also, none of the variables are needed. Omit the 1 'N' STO, and replace everything after the end of the list with the following:

1 10 START DUP 0.08 BEEP NEXT DROP »

That makes it run quite a bit faster, it's now better to change the note length to 0.1 to slow it down a little. I guess it will leave less time between beeps, which has to help.
hanks for sharing that trick.
[/quote]

Carlos - Brazil
Time Zone: GMT -3
http://area48.com
Visit this user's website Find all posts by this user
Quote this message in a reply
06-08-2021, 06:50 AM (This post was last modified: 06-08-2021 07:04 AM by Stevetuc.)
Post: #11
RE: My first program on HP-50g - Music.
(06-08-2021 01:06 AM)CMarangon Wrote:  Hello!

In HP48 I used to do something like store all notes in vars and so recall it from a program.
I think that it also works in HP50.


I store all notes as a var, so recall it from a main program.

For example:

<<440 .1 BEEP>>
STO it in the var "LA"

and do the same for "Re", "Mi", "Fa", "Sol", "La", "Si", sharp, flat and so on.

Exemple of the main program:

<<LA DO DO RE MI FA FA SOL SOL SI SI>>
store it as MUSIC and and so run it.

This avoid you to type everytime the musical note time and frequency, makig the program shorter:-)

Kind regards,

Carlos

[..]
The issue with this approach is it only covers 1 octave whereas the example tune is multi-octave.
It could be extended by <note name> eg A-G
<Accidental> sharp # or flat b
And <octave number> 0..8 where increasing octave number represents a doubling of freq.
Eg middle C is C4
But would need a bit more coding as there are up to 3 characters per note.
https://en.m.wikipedia.org/wiki/Scientif...h_notation    
Find all posts by this user
Quote this message in a reply
06-08-2021, 09:25 AM
Post: #12
RE: My first program on HP-50g - Music.
And you can't use # in 50g program name Smile

S.Korean / HP-50G | fx-570EX | fx-570CW | HP-200LX
Visit this user's website Find all posts by this user
Quote this message in a reply
06-08-2021, 12:17 PM
Post: #13
RE: My first program on HP-50g - Music.
(06-08-2021 09:25 AM)BINUBALL Wrote:  And you can't use # in 50g program name Smile
Ah well.. we could use the German system.
There is no »flat« or »sharp«, just the suffixes »-es« and »-is«. 
However there is also no B ..H is used instead.
Find all posts by this user
Quote this message in a reply
06-08-2021, 04:03 PM (This post was last modified: 06-08-2021 04:04 PM by 3298.)
Post: #14
RE: My first program on HP-50g - Music.
(06-08-2021 12:17 PM)Stevetuc Wrote:  However there is also no B ..H is used instead.
Yes there is, Americans call the German B a B-flat instead.
That's not even the only quirk of flats in the German nomenclature, the -es suffix gets shortened to -s on the vowels A and E, i.e. A-flat becomes As, E-flat becomes Es.
Things get even more arcane in the designations for octaves, and if you want to be really accurate with those, you would break the 50g var-name requirements too. It's likely possible to deal with the challenges in a way that would let any professional German musician understand them, but probably easier for others to mix notations and keep the American octaves.

Anyway, using dedicated programs to emit a single note with a BEEP command in each might save a small amount of storage space and/or some time typing, but it would definitely eliminate Joe Horn's speed boost, and probably slow it down beyond the original. If you insist on dedicated names for notes, store only the frequencies in them, and keep the durations and the BEEP command centralized. You may have to massage the list of notes with 1. \<< RCL \>> DOLIST to let BEEP see the frequencies instead of just variable names, but that's just a delay before the song starts, not between notes.
Find all posts by this user
Quote this message in a reply
06-08-2021, 06:46 PM
Post: #15
RE: My first program on HP-50g - Music.
(06-06-2021 07:02 AM)Stevetuc Wrote:  
(06-06-2021 06:49 AM)compsystems Wrote:  Hello
If you rewrite the firmware to NewRPL you could have a much more powerful RPL language

newRPL:
https://sourceforge.net/projects/newrpl/

I'm curious as to how that improves the music program that's the topic of this thread?
Edit: did the 3 channel fm synth code mentioned by Claudio here make it to newrpl?
https://www.hpmuseum.org/forum/thread-97...l#pid98718
(06-04-2018 03:36 PM)Claudio L. Wrote:  Alarms are not buggy at all, but the buzzer doesn't have a driver yet... so it's a very quiet alarm for the time being. The good new is... I found my 3-channel FM-synthesizer code, as soon as I get some spare time I'll try to port it to newRPL so it will sound much better than the usual "beep".

3 years later and it's still in the todo list, it's low priority as it's a fun thing only.
Find all posts by this user
Quote this message in a reply
06-09-2021, 02:51 PM
Post: #16
RE: My first program on HP-50g - Music.
Have you tried code like << { Hz1 Hz2 Hz3 ... } { time1 time2 time3 ... } BEEP >> ? IMO, this is much more efficient. This syntax was added to C. BASIC for CASIO FX by analogy with the hp-50g.
Find all posts by this user
Quote this message in a reply
06-10-2021, 01:08 AM
Post: #17
RE: My first program on HP-50g - Music.
(06-09-2021 02:51 PM)Hlib Wrote:  Have you tried code like << { Hz1 Hz2 Hz3 ... } { time1 time2 time3 ... } BEEP >> ? IMO, this is much more efficient. This syntax was added to C. BASIC for CASIO FX by analogy with the hp-50g.
That's great way to use list processing. I have wrote code like << { Hz1 Hz2 Hz3 ... } time BEEP >> But I haven't known that kind of code working.

And anyone can rewrite this code shorter?
Code:
<< 440 1 BEEP 1 WAIT 440 1 BEEP >>
If I can use WAIT in code more efficiently, then we can make better music

S.Korean / HP-50G | fx-570EX | fx-570CW | HP-200LX
Visit this user's website Find all posts by this user
Quote this message in a reply
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 




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