playSong - newlength = zeros(change,1); vecamp =...

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 sf] = wavread(fn); %reads in the sound file vecsteps = parseInput(ca); %gets the vector of steps ampvec = []; %creates an empty vector for ndx = 1:length(vecsteps) vecsnd = transposeSound(snd,sf,vecsteps(ndx),vecdur(ndx)); %uses the transposeSound function to fix the vector into the desired %length ampvec = [ampvec; vecsnd]; %concatenates this onto the initialized vector end e 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 = round((newdur - duration2).*sf);
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: newlength = zeros(change,1); vecamp = [amp;newlength]; else change = round(newdur.*sf); vecamp = [amp(1:change)]; end end e function vec = parseInput(ca) 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

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Institute of Technology.

Page1 / 2

playSong - newlength = zeros(change,1); vecamp =...

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