Write a script (not a function) to assemble a 10-30 second musical groove in one
ID: 1922913 • Letter: W
Question
Write a script (not a function) to assemble a 10-30 second musical groove in one long sound vector. Use concatenation and your repeater toplay sounds in sequence in a track, fade or shift them, and use your mixer to layer the tracks together. You can make additional functions if you want. For example, you could modify repeat to allow you to insert silence between repeats, and so on.After youExplanation / Answer
function [ output1, output2 ] = FunctionName( parameter1, parameter2 ) This function MUST be written in a ?le called FunctionName.m (use a descriptive name, obviously). Then this ?rst line means that the function will accept some parameters, and will output whatever is in outputVariable when it’s done running. If output1 isn’t de?ned in the function, then it won’t return anything. Also note that the output1 is only de?ned within the scope of the function. You can’t use this value unless you explicitly capture the function’s return value at the matlab prompt, like so: >> x = FunctionName(param1, param2) The ?rst set of comments (immediately after the ?rst line in the function) is what will be displayed on screen if you type help FunctionName. This should be a general description of your function and its syntax. Now enter help fade at the matlab prompt. If you saved the ?le correctly, you will see the help text from the M-?le in response to help fade. Notice that you can use the new command that you just added to matlab as if it were a built-in function. Enter the following at the matlab prompt: >> time = 0:0.01:1; >> y = cos(time .* pi .* 0.25); >> plot(time, fade(y)); You can see in the plot that fade does fade out the cosine wave. You can use this function on audio signals as well. This function works ?ne, but o?ers the user no control. Therefore, your assignment is to edit the fade function so that you can adjust the slope of the ramp that fades the signal. In order to do so, notice in the code that there’s an unused parameter named level. The variable level should be the ?nal volume level after fading, as a percentage of the original input. You must ensure that level only takes on values between 0 and 1, because you can’t fade to less than 0% nor more than 100% of the original input volume. You also need to handle the case where the user does not specify the value of level. The desired behavior in this case is speci?ed in the code A simple way to repeat things an arbitrary number of times is with a for loop. Inside the for loop you will need to concatenate the sound signals. If you have two vectors x and y, you can concatenate them as follows: >> x = [1 4 2 2]; >> y = [3 6 8 0]; >> x = [x y] x = 1 4 2 2 3 6 8 0 The next function to implement is one that time-delays a signal by some amount of time delay. A time delay is the same as prepending silence to the original signal. Because you’re working with digital data, a 0 sounds like silence. You can therefore implement a time delay by zero-padding the start of the vector containing the signal. To zero-pad something means to ?ll a space with only zeros, so in this case you’re concatenating some number of zeros with the signal. The number of zeros to add will depend on the time delay and the sample rate of the signal. Adding 4000 zeros to a signal sampled at 4kHz will delay it by 1 second; adding 4000 zeros to a signal sampled at 8kHz will delay it by only 0.5 seconds. You may ?nd the matlab command zeros to be useful. Most of the sound ?les in these labs are sampled at 8000Hz, but this is not always true. You may want to change this later, so it’s good programming practice to have the sample rate Fs be another input to the function.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.