I did some research. Here is what I found:
1) 樂 first meant music instruments, pronounced 'ngok'(逆角切). In Japanese, it is がく[楽](gaku).
2) The meaning happy '悦/樂' first had the same pronunciation 樂 as in 音樂. This was probably the case in 战国 (周朝),because according to《爾雅·釋詁》(written after BC 476), 悦: 樂也。
3) In 唐韵 (written in 732 AD, 樂 meaning happy is pronounced 'lok' (盧各切). So the pronunciation changed between 周 and 唐, which is a long time (~1000 years). To cut the time shorter, we can look at Japanese, which borrowed a lot of Chinese characters between the 3rd - 5th century. In Japanese, [楽]meaning happy is pronounced らく [raku]. So we know the 'lok' sound formed before 500 AD.
The timeframes map into the distinction between Old Chinese and Middle Chinese. Old Chinese 上古汉语 was used until the 3rd century and Middle Chinese 中古汉语 starts from the 3rd century.
Using this terminology, we can say this distinction is in Middle Chinese but not Old Chinese.
Furthermore, Old Chinese is considered to be very regular -- characters with the same component sound the same, and one character has only one pronunciation.
Now I guess the problem is solved. It seems that mathematical abstractions can help in reasoning and discovery! :)
PS. there could be a small difference in Old Chinese that led to larger difference in Middle Chinese. Old Chinese had double consonants. Later, double consonants are systematically dropped, and some words had consonant A and some with B. According to 韵典网 (ytenx.org/dciangx/dzih/%E6%A8%82),樂's Old Chinese pronunciation was /ŋraːwɢs/, or transliterated as "ngrawgs". It had double consonants ŋ and r, so some words became ŋok, some became lok (r and l are the same), and some became ŋaw. The two meanings music and happy might had slight differences in Old Chinese.