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

  • Thread starter Thread starter tade
  • Start date Start date
Click For Summary
The discussion centers on the audio-visual demo "A Mind is Born," created for the Commodore 64, which uses only 256 bytes of memory and procedural generation to create music. Participants express interest in understanding the mathematical formulas behind the melody generation, specifically how the program uses a Linear Feedback Shift Register (LFSR) to produce notes. The melody consists of seven notes and a rest, with specific frequency values assigned to each note, and the algorithm relies on the last three bits of an 8-bit pseudo-random number for note selection. The conversation also touches on the differences in tuning between the C64 and standard pianos, as well as the technical aspects of the SID sound chip. Overall, the thread emphasizes the blend of programming and mathematical concepts in music generation on vintage hardware.
  • #31
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.
 
Technology news on Phys.org
  • #32
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:
  • #33
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
 
  • #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:
  • #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

Replies
29
Views
5K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 25 ·
Replies
25
Views
8K
  • · Replies 71 ·
3
Replies
71
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • Sticky
  • · Replies 0 ·
Replies
0
Views
4K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K