Making music (sort of)
Description:
MIDI is a way of representing musical notes electronically. According to the MIDI specification, middle C (C5) is defined as note 60. As you ascend the scale upwards, each note's number also increases. For example, the A above middle C, which has a frequency of 440Hz and is used for tuning, has a MIDI value of 69. The lowest value (0) represents C0 and the highest value (127) represents G10.
Given an input representing musical notes as an array of objects containing the MIDI value
and the note length
in seconds, find the frequency of each note and create the appropriate sine wave. Your output should be an array of samples at 0.1s intervals (i.e. our sample rate is 10 times per second, or 10Hz). The samples should be string values to seven decimal places. You should output one single array with the samples from each note coming in the order of the input array. An example is below.
[{value: 100, length: 0.5}, {value: 67, length: 1}]
The above example should output:
[ '0.000000',
'-0.9549495',
'0.5667977',
'0.6185342',
'-0.9339205',
'0.000000',
'0.9501665',
'0.5924155',
'-0.5808036',
'-0.9545385',
'-0.01433779',
'0.9455991',
'0.6039056',
'-0.5690723',
'-0.9587143' ]
The sample rate of 10Hz is to keep the results length manageable. This means that a note of length 1 second will output 10 values, a note of 0.5 seconds 5 values, and so on. For example, you can see that the example above has returned an array of length 15. The first 5 values represent the first note and the 10 values following are from the second note. You can see that the samples from the second note begins on the sixth value (the '0.000000'
).
Throw an error if the MIDI input is invalid (see more here).
You will need to consider how to convert a MIDI note to a frequency (hint: use the A note provided as a starting point and research how going up or down a note affects the frequency) and then how to create the sine wave.
Similar Kata:
Stats:
Created | Jul 26, 2016 |
Published | Jul 26, 2016 |
Warriors Trained | 45 |
Total Skips | 0 |
Total Code Submissions | 71 |
Total Times Completed | 7 |
JavaScript Completions | 7 |
Total Stars | 1 |
% of votes with a positive feedback rating | 25% of 2 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 2 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |