Understanding a C64 program on the melody of a song as math equations

  • Thread starter tade
  • Start date
In summary, the article explores how programming on the Commodore 64 (C64) can be likened to understanding melodies through mathematical equations. It discusses the process of translating musical notes into numerical representations, highlighting the relationship between programming logic and musical composition. By breaking down the melody into its mathematical components, the piece illustrates how both disciplines share a fundamental structure, allowing for a deeper appreciation of music through the lens of programming.
  • #36
tade said:
i'm wondering what the math and logical formulas by which each note, which note to play next, is generated are
and just for the melody part
Oh, okay, so you're looking at a sequence of bytes in the "I'll get around to explaining the guts of the code (but never actually getting around to it)" section.

Have you looked up how the LSFR works ? Not counting the bass line, how many different notes (+rest) are there ?
 
Last edited:
Technology news on Phys.org
  • #37
hmmm27 said:
Oh, okay, so you're looking at a sequence of bytes in the "I'll get around to explaining the guts of the code (but never actually getting around to it)" section.
What do you mean? The author does explain all of the code in the linked article.

hmmm27 said:
Have you looked up how the LSFR works ? Not counting the bass line, how many different notes (+rest) are there ?
This has been completely covered already in this thread.
 
  • #38
tade said:
and if your code has an error
There is no error in my code (well there is a tiny one: it stops one note too early and doesn't output the last note, an "e" in the key of the piano score). And the error in @willem2's code was tiny too, although it stopped it working as written:
Python:
# The last line:
print(notes[n], end = ' ')
# should be
print(notes[seed & 7], end = ' ')
Note that both my code and @willem2's print the same notes as are written in the piano score except for (i) the 'jittering' due to repeatedly starting the sequence at the beginning and (ii) the difference in the middle section due to overlaying an effect as mentioned in the original article (which is a feature of the C64's SID hardware so impossible to emulate here).

tade said:
i was wondering if there might be an interesting mathematical property behind how it still sounds like a hashed version of the actual song
I don't know why you think is sounds like a 'hashed version', these are the notes generated by @willem2's code (fixed as above): compare them to the piano score in the YouTube video and you will see they are the same (except for the last beat of bar 49 where the piano version has an incorrect A instead of a rest):
Code:
32
                |           _ B C | a e _ _ _ B C A | a b c b c b c b | C A A A a e B c |

36
b c e _ _ B c e | B C A A A A A A | a e _ _ B c b C | A A a e _ B C a | b c e _ _ _ _ _ |
41
B c e _ B C A a | e _ B c e B c b | C A a e _ _ _ _ | B C a e B c e B |
45
c e B C a b C A | a e B c e _ _ _ | B c b c b C a b | C a b c b C a e |

49
B c b C a e _ _ | B C A A A a b C | a b C A A a b c | b C A a b c e _ |
53
B c e _ _ B C a | b C a e _ B C A | A a e B C A a e | B C a e _ B c b |

57
C a b c e B c e | _ B c b c e B c | b c b c e B C A | a b C A a b C a |
61
e B C A A a b C | A A A A a b c e | B C a e B C a b | c b c e _
 

Similar threads

Back
Top