From: gpinzone@george.poly.edu (Gerard Pinzone)
Newsgroups: comp.sources.hp48
Subject: v03i008:  song - HP28 music maker v1.0, Part01/01
Summary: SONG, SONG2
Date: 2 Dec 91 02:30:33 GMT
Followup-To: comp.sys.hp48
Organization: Polytechnic Univ., Farmingdale NY and East Coast Anime

Checksum: 1448444625 (verify with brik -cv)
Submitted-by: Gerard Pinzone <gpinzone@george.poly.edu>
Posting-number: Volume 3, Issue 8
Archive-name: song/part01

BEGIN_DOC song.doc
Here is a partial repost of an EXTREMELY simple music program for the HP28.
I couldn't get the original code to work, so I re-wrote the program.  This
is my first attempt at programming on the HP28, so bear with me...this is
all really fascinating!  I think my revision actually works more
efficiently but I'll leave it to the experts.  I also included some songs
I transposed from musical notes.

Here is a table of most used notes.  Along side of the notes are the
frequencies of the notes to put in the matrix:

                                                         E3  2707
                                                       D3  2408
                                                     C3  2145
                                                   B2  2025
                                                 A2  1804
                                               G2  1607
      ---------------------------------------F2  1432------------------
                                           E2  1351
      -----------------------------------D2  1204----------------------
                                       C2  1072
      -------------------------------B1  1012--------------------------
                                   A1  902
      ---------------------------G1  803-------------------------------
                               F1  716
      -----------------------E1  675-----------------------------------
                           D1  602
                         C1  536
                       B0  506
                     A0  451
                   G0  401
                 F0  358

The original author's table is more complete (sharps and flats), but this
is easier to use when transcribing notes from sheet music.  If you need a
flat (say E flat) use the note below, but sharped (D sharp) and look it up
on the original author's table.

One VERY important fact:  When entering notes, enter them in REVERSE order.
In other words, start from the last note of the song and work backwards!

I found that a duration of .125 for 16th notes, .25 for quarter notes,
.5 for half notes, and 1 for whole notes work fine (seems logical eh?).
If the song has a slow tempo (like the Godfather theme), the times are
doubled.

=============================original message=============================
Date:         Thu, 4 May 89 22:52:15 EST
Reply-To:     HP-28 -  HP-28C and HP-28S Calculators <HP-28@NDSUVM1>
Sender:       HP-28 -  HP-28C and HP-28S Calculators <HP-28@NDSUVM1>
From:         GRIK@MTUS5
Subject:      Music program
 
Greetings!
 
Here is a simple, but adequate program to process music.  It requires a
matrix to be on the stack, in the following format:
 
[[ Firstnote's frequency, firstnote's length]
 [           .                    .         ]
 [           .                    .         ]
 [           .                    .         ]
 [           .                    .         ]
 [           .                    .         ]
 [ lastnote's frequency, lastnote's lenght  ]]
 
This program can also make use of rests, as follows:
make the notes frequency column the lenght of the rest and the notes length
column equal to 0. So a rest would look like so:  [ restlength, 0]
END_DOC
--------------------------------old code!---------------------------------
SONG
 
BEGIN_SRC song.28
<< MEM DROP                    | garbage cleanup so max ram is available
   DUP SIZE 1 SWAP             | set up bounds for the FOR-NEXT
   FOR x                       |
      DUP x GET ARRY-> DROP    | get x'th element
      IF DUP NOT THEN          | check to see if a rest
         DROP WAIT             | if so wait
      ELSE                     |
         BEEP                  | else beep
      END                      |
   NEXT                        | continue loop
   DROP                        |
 >>
END_SRC
--------------------------------old code!---------------------------------

BEGIN_DOC notes.doc
Now in order to make music you have to have notes, and to do this you have to
have the corresponding frequencies.
  O =  N ,  S
-|----------------------------------------------------------------------------|
C|0 = 268, 284  |1 = 536, 568  |2 = 1072, 1136  |3 = 2145, 2273  |4 = 4291, U |
-|----------------------------------------------------------------------------|
D|    301, 318  |    602, 637  |    1204, 1275  |    2408, 2551  |     U, U   |
-|----------------------------------------------------------------------------|
E|    337, ---  |    675, ---  |    1351, ----  |    2703, ----  |     U, U   |
-|----------------------------------------------------------------------------|
F|    358, 379  |    716, 758  |    1432, 1517  |    2864, 3034  |     U, U   |
-|----------------------------------------------------------------------------|
G|    401, 425  |    803, 851  |    1607, 1703  |    3215, 3406  |     U, U   |
-|----------------------------------------------------------------------------|
A|    451, 477  |    902, 955  |    1804, 1911  |    3608, 3823  |     U, U   |
-|----------------------------------------------------------------------------|
B|    506, ---  |   1012, ---  |    2025, ----  |    4050, ----  |     U, U   |
-|----------------------------------------------------------------------------|


The chart is fairly easy to read:  the O signifies the octave, the N represents
the frequencies of the natural notes, and the S represents the frequencies of
the Sharp of that note.   A U signifies that the note is not available.
I believe that the C octave 1 is middle C...


Any questions, comments, improvements welcome....



Eric J. Zmyslowski
Grik@mtus5.bitnet
END_DOC
==========================end of original message=========================

SONG2

BEGIN_SRC song2.28
<<
      MEM DROP                      | Garbage cleanup so max ram available
      DUP ARRY->                    | Take apart matrix
      LIST-> DROP DROP              | Get number of notes
      1 SWAP                        | Set up bounds for FOR-NEXT
            FOR x
                  IF DUP NOT THEN   | Check for rest
                        DROP WAIT   | If so, wait
                  ELSE
                        BEEP        | Otherwise play note
                  END
            NEXT                    | Continue loop
>>
END_SRC

TEMPO

BEGIN_SRC tempo.28
<<
 -> x
      <<
            TRN ARRY->              | Take apart matrix
            LIST-> DROP SWAP 1 SWAP | Seperate duration
            ->LIST ->ARRY x *       | Change tempo by a factor of 'x'
            ARRY-> LIST->           | Put durations back with notes
            DROP DROP 2 SWAP 2
            ->LIST ->ARRY TRN       | Restore orignial matrix
      >>
>>
END_SRC


BEGIN_MISC songs
Here are some songs.  Follow the columns from top to bottom; don't read
across the page for multi-column listings.


                                The Blue Danube
                                ---------------

         [[536   .8 ]     [1072  .25]     [1804  .25]     [.25   0  ]
          [803   .25]     [803   .25]     [.25   0  ]     [1607  .25]
          [902   .5 ]     [675   .25]     [902   .25]     [1607  .25]
          [602   .25]     [536   .25]     [902   .25]     [.25   0  ]
          [675   .5 ]     [536   .25]     [602   .25]     [803   .25]
          [675   .25]     [.25   0  ]     [506   .25]     [803   .25]
          [1072  .25]     [1607  .25]     [506   .25]     [675   .25]
          [1351  .8 ]     [1607  .25]     [.25   0  ]     [536   .25]
          [803   .25]     [.25   0  ]     [1432  .25]     [536   .25]
          [758   .25]     [2145  .25]     [1432  .25]     [.25   0  ]
          [902   .8 ]     [2145  .25]     [.25   0  ]     [1351  .25]
          [902   .25]     [.25   0  ]     [1804  .25]     [1351  .25]
          [716   .25]     [1072  .25]     [1804  .25]     [.25   0  ]
          [602   .25]     [803   .25]     [.25   0  ]     [1607  .25]
          [602   .25]     [675   .25]     [902   .25]     [1607  .25]
          [.25   0  ]     [536   .25]     [902   .25]     [.25   0  ]
          [1804  .25]     [536   .25]     [602   .25]     [803   .25]
          [1804  .25]     [.25   0  ]     [506   .25]     [803   .25]
          [.25   0  ]     [1351  .25]     [506   .25]     [675   .25]
          [2145  .25]     [1351  .25]     [.25   0  ]     [536   .25]
          [2145  .25]     [.25   0  ]     [1432  .25]     [536   .25]]
          [.25   0  ]     [1804  .25]     [1432  .25]


                  Hava Nagila                      Dixie
                  -----------                      -----

                 [[851   1   ]                 [[675   .25 ]
                  [716   .125]                  [803   .25 ]
                  [6.75  .125]                  [803   .25 ]
                  [716   .25 ]                  [803   .25 ]
                  [851   .5  ]                  [716   .125]
                  [902   .25 ]                  [675   .125]
                  [1012  .25 ]                  [602   .125]
                  [1072  .25 ]                  [536   .125]
                  [902   .75 ]                  [536   .25 ]
                  [902   .5  ]                  [536   .25 ]
                  [851   .25 ]                  [675   .125]
                  [902   .25 ]                  [803   .125]]
                  [1012  .25 ]
                  [851   .75 ]
                  [851   .5  ]
                  [675   .25 ]
                  [716   .25 ]
                  [851   .25 ]
                  [675   .75 ]
                  [675   .5  ]]


                           Theme from THE GODFATHER
                           ------------------------


         [[451   1  ]     [803   .5 ]     [675   .25]     [803   .25]
          [536   .25]     [902   1  ]     [902   .25]     [716   .25]
          [675   .25]     [851   .25]     [1012  .25]     [902   .25]
          [675   .25]     [716   .25]     [902   .25]     [1012  .25]
          [716   .25]     [602   .5 ]     [1072  .25]     [902   .25]
          [716   .25]     [1012  1  ]     [902   .25]     [1072  .25]
          [803   .25]     [851   .25]     [1012  .25]     [902   .25]
          [675   .25]     [716   .25]     [1072  .25]     [1012  .25]
          [716   .25]     [602   .5 ]     [902   .25]     [1072  .25]
          [716   .25]     [602   1  ]     [675   .5 ]     [902   .25]
          [803   .25]     [637   .25]     [675   1  ]     [675   .5 ]]

                                     All music transcribed by
                                                        Gerard Pinzone
                                                   gpinzone@george.poly.edu


END_MISC
Yours truly,
                      ___                          ___
                     /   )                  /)     /  )
                    / ___  _  __  __  __  _//     /__/    _      _   _   _
                    \___/_</_/ (_(_/_/ (_(_/__   /    _/_/ )_/)_(_)_/ )_</__
                                                              )
                                                             ()

}>:+:<{([ Gerard Pinzone ])}>:+:<{([I])}>:+:<{([ gpinzone@george.poly.edu ])}>:
    _______   ________   ________    Just on the border of your waking mind
   /   ___/\ /  _____/\ /  __   /\   There lies another time
  /   ___/\//  /____ \//  __   / /   Where darkness and light are one
 /______/\//_______/\ /__/ /__/ /    And as you tread the halls of sanity
 \______\/ \_______\/ \__\/\__\/     You feel so glad to be unable to go beyond
   (everything 'cept anchovies!)     I have a message from another time...
-=:)>}]  EAST COAST ANIME  [{<(:=-   ELO: "Prologue"  -=-  Daicon IV

