Beta

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.

Algorithms
Mathematics

More By Author:

Check out these other kata created by tbtommyb

Stats:

CreatedJul 26, 2016
PublishedJul 26, 2016
Warriors Trained45
Total Skips0
Total Code Submissions71
Total Times Completed7
JavaScript Completions7
Total Stars1
% of votes with a positive feedback rating25% of 2
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments2
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • tbtommyb Avatar
Ad