BST_Node *BST_harmonize(BST_Node *root, int semitones, double time_shift) { /* Let's play with notes, because we can. * * This function traverses the BST, and for each existing * note, inserts a new, modified note (i.e. it will add sounds * to an already existing song, based on the notes it already has) * * The new note has the followin properties: * - The frequency is shifted by the specified number of semitones * (A semitone is the difference between one note and the * immediately next one in the musical scale - ot what is the * same, the difference in pitch between a white key and the * black key immediately next to it in a piano) * - It plays in the same *bar* as the original note * - But its *index* is shifted by the specified time_shift * (this value is between 0 and 1, but you have to check * that the final index remains between 0 and 1) * * Both the 'semitones' and 'time_shift' parameter can be * positive or negative. A typical value for semitones * could be 4 or 7, corresponding to musical 3rds or * musical 5ths - this should produce some interesting * harmony! but you can play with this function and try * various things for fun. * * In practice, figuring out the frequency of the note * you have to insert is easy. For instance, suppose * you have an existing note in the BST with * * freq=440.0, at bar=10, index=.25 * * Now suppose the user specified * * semitones=4 * time_shift=.1 * * Then you go to the note_freq[] array, find the index * of the entry for frequency 440.0 (let's say it's * j), then go to note_freq[j+4] to find the frequency * of the note you need to add. * * NOTE: If the value of j+semitones is < 0 or > 99 * then there is no note with the frequency you * want. In that case you don't insert a new * note. * * You then add a new note with that frequency at * bar=10 (same bar!) * index=.25 + .1 (the original index plus the time_shift) * * NOTE: If the resulting index is less than 0, or >= 1, * then you DO NOT insert the new note. * * This function is crunchy - and if you don't think it * through before you start implementing it you'll run into * all kinds of trouble. * * This is the problem solving exercise for A2, so don't * look for people on Piazza to give you answers, or tell you * what to do, or verify you're doing the right thing. * * It's up to you how to solve this, and if you want an opinion, * you can come to visit us during office hours! * * Expected result: The BST will have about twice as many notes * as before, and the new notes are shifted in pitch and * in time as specified by the parameters. */ /*** TO DO: * Implement this function ****/ return NULL; }
-
Engineering 2022-05-15 19:04:59