function achilles_project
close all
clear all

[wave11,fs]=audioread('project.wav'); % read file 

%t=0:1/fs:(length(wave11)-1)/fs; % and get sampling frequency */
%plot(t,wave11);

figure(1)
subplot(3,1,1)
ylim([-.75 .75])
h = animatedline(0,0); 

L = length(wave11(:,1)); %length
player = audioplayer(wave11,fs); 
%'TimerPeriod' sets how often to call 'TimerFcn'
player.set('TimerPeriod', .05);
player.set('TimerFcn', @(x,y)fft_bunch(h, wave11, x.CurrentSample, fs, 1))
player.playblocking;

function D = fft_bunch(h, wave, offset, fs, window)
stepn = window*fs; %gives # iterations per window time
subset = max(offset-stepn+1,1):offset;
t = subset/fs;
L = length(subset);
y = wave(subset,1);
Y = fft(y);
P2 = abs(Y/L); 
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fs*(0:(L/2))/L;
outpoints = P1./f';

%~~~~ plot raw audio data (time series) on top ~~~~~

subplot(3,1,1)
whitebg('k')
plot(t,y,'r');
ylim([-1 1])

%~~~~ plot fourier transformed chunk in middle, log(x axis)

subplot(3,1,2)
semilogx(f,outpoints,'r')
ylim([0 .7e-3])
xlim([10 1.5e3])

%~~~~ plot fourier transformed chunk on bottom, without log(x axis) 

subplot(3,1,3)
plot(f,outpoints,'r')
ylim([0 .7e-3])
xlim([10 1000])
drawnow










