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

Discussion Overview

The discussion revolves around understanding the mathematical principles behind a Commodore 64 program that generates melodies, specifically focusing on the procedural generation of notes in the audio-visual demo "A Mind is Born." Participants express interest in the mathematical formulas and algorithms used in the program rather than the coding aspects.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • Some participants express a desire to understand the mathematical formulas used to generate the melody, indicating a lack of technical knowledge.
  • It is noted that the C64's sound generation is hardware-based, utilizing a sound chip rather than software alone.
  • A Linear Feedback Shift Register (LFSR) is mentioned as a method used in the program to generate notes, described as a simple random number generator.
  • Frequency values for notes are discussed, with specific ratios provided for musical intervals, such as the relationship between notes A and B.
  • Participants debate the mathematical operations involved in the LFSR process and the implications of using binary digits in the algorithm.
  • Some participants clarify that the term "formula" may not be appropriate in this context, suggesting "algorithm" as a more suitable term.

Areas of Agreement / Disagreement

There is no consensus on the specific mathematical formulas used in the melody generation, and multiple viewpoints exist regarding the terminology and understanding of the underlying processes.

Contextual Notes

Participants express uncertainty about the technical details of the algorithm and its implementation, indicating that a full understanding may require more advanced knowledge of programming and music theory.

  • #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 71 ·
3
Replies
71
Views
3K
  • · Replies 25 ·
Replies
25
Views
9K
  • · 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