% read input
[y, fs, nbits] = wavread('example1.wav');

% use only left channel
y = y(:,1);

fd = fopen('output.abc', 'wt');

fprintf(fd, 'X:1\nT:example1\nM:1/8\nL:1/4\nK:C octave=0\nQ:1/2=100\nV:1\n\%\%MIDI program 5\n')

delta = round(fs/8);
for i = 1 : delta : length(y) - delta
  f = fft(y(i : i + delta));
  [maxval maxi] = max(abs(f));
  freq = maxi*(fs/delta);
  printf("%d %d %f\n", i, freq, maxval);
  fprintf(fd, "%s\n", freqtosemitone(freq))
endfor

fclose(fd);

%specgram(y)
%plot(y);
%pause;