playSong - vec = ; for ndx = 1:length(ca) if...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function [ampvec sf] = playSong(fn,ca,vecdur) %It's all downhill from here. Using parseInput, transposeSound, and a %well implemented for loop, make a song out of the input sound file. To %make a song, use transposeSound to create each note, and then %concatenate the notes together. (Remember sound is a column vector.) [snd fs] = wavread(fn); vecsteps = parseInput(ca); veclength = length(vecsteps) function vecamp = transposeSound(amp,sf,half,newdur) amp = amp(round(linspace(1,end,(end/2.^(half./12))))); duration2 = length(amp)./sf; if newdur > duration2 change = (newdur - duration2).*sf; newlength = zeros(change,1); vecamp = [amp;newlength]; else change = round(newdur.*sf); vecamp = [amp(1:change)]; end end function vec = parseInput(ca)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: vec = ; for ndx = 1:length(ca) if length(ca{ndx})==2 switch ca{ndx}(1) case 'C' step = 0; case 'D' step = 2; case 'E' step = 4; case 'F' step = 5; case 'G' step = 7; case 'A' step = 9; case 'B' step = 11; end octnum = str2double(ca{ndx}(2)); octave = 12.*(octnum-4); vec = [vec octave+step]; elseif length(ca{ndx})==3 switch ca{ndx}(1) case 'C' step = 0; case 'D' step = 2; case 'E' step = 4; case 'F' step = 5; case 'G' step = 7; case 'A' step = 9; case 'B' step = 11; end if strcmp(ca{ndx}(2),'#') num = 1; elseif strcmp(ca{ndx}(2),'b') num = -1; end octnum = str2double(ca{ndx}(3)); octave = 12.*(octnum-4); vec = [vec octave+step+num]; end end end end...
View Full Document

Page1 / 2

playSong - vec = ; for ndx = 1:length(ca) if...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online