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

  • Thread starter Thread starter tade
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
37 replies · 7K views
tade said:
thanks, and seems like there's something rather odd and interesting

and its interesting that the beginning does match, and the rest of the string does sound very similar to the actual song
and if your code has an error, i was wondering if there might be an interesting mathematical property behind how it still sounds like a hashed version of the actual song

perhaps it might be related to this aspect
willem2 said:
One consequence is that each note has only 2 different notes that can follow it, and two different notes that can precede it.
 
Physics news on Phys.org
Of note to the perceived octave doubling : that would almost certainly be sawtooth + square (same frequency, phase). Not sure if it's an up or down saw that does it.

(And, I imagine writing the RNG routine inline saves a few bytes compared to an external call. This thread's out of my league, mostly)
 
Last edited:
hmmm27 said:
Of note to the perceived octave doubling : that would almost certainly be sawtooth + square (same frequency, in sync). Not sure if it's an up or down saw that does it.

(And, I imagine writing the RNG routine inline saves a few bytes compared to an external call. This thread's out of my league, mostly)
oh interesting
i'm mainly interested in how to get the sequence of key presses on a piano or something like that lol
 
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:
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.
 
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 _