function [sinetable, len] =  scale(f_note,int)

% f_note is freq of note, int is the interrupt frequency

% produces a sinetable with 8 bits per sample

note_period = 1/f_note;  % period of note

n = round(note_period / (1/int));   % number of samples in array

sine = zeros(n+1,1);

sinetable = zeros(n+1,2);  % initialize sinetable

% loop to calculate 8-bit sample values (positive) based on

% interrupt freq, outputs hex numbers

for i = 1:n+1,

sine(i) = floor(sin(((2*pi*f_note)*(i-1))/int) * 32) + 32;

%sinetable(i,1) = floor(sine(i)/16);

%sinetable(i,2) = mod(sine(i),16);

end

sinetable = sine;

len = length(sine)

----------------------------------------------------------------------------------------------------------------------

function [sinetable, len] =  samples(f_note,int)

% f_note is freq of note, int is the interrupt frequency

% produces a sinetable with 8 bits per sample

close all

note_period = 1/f_note;  % period of note

n = round(note_period / (1/int));   % number of samples in array

sine = zeros(n+1,1);

sinetable = zeros(n+1,2);  % initialize sinetable

% fourier coefficients - clarinet

a0 = 0;

a1 = 0.5;

b1 = 1;

a2 = 0;

b2 = 0;

a3 = 0.3;

b3 = 0.4;

a4 = 0;

b4 = 0;

a5 = 0.5;

b5 = 0.16;

% loop to calculate 8-bit sample values (positive) based on

% interrupt freq, outputs hex numbers

for i = 1:n+1,

sine(i) = a0 + a1*cos(((2*pi*f_note)*(i-1))/int) + b1*sin(((2*pi*f_note)*(i-1))/int) ...

+ a2*cos(((2*2*pi*f_note)*(i-1))/int) + b2*sin(((2*2*pi*f_note)*(i-1))/int) ...

+ a3*cos(((3*2*pi*f_note)*(i-1))/int) + b3*sin(((3*2*pi*f_note)*(i-1))/int) ...

+ a4*cos(((4*2*pi*f_note)*(i-1))/int) + b4*sin(((4*2*pi*f_note)*(i-1))/int) ...

+ a5*cos(((5*2*pi*f_note)*(i-1))/int) + b5*sin(((5*2*pi*f_note)*(i-1))/int);

end

high = max(sine);

low = min(sine);

factor = high - low;

for i = 1:n+1,

sine(i) = floor((sine(i) / factor) * 32) + 32;

sinetable(i,1) = floor(sine(i)/16);

sinetable(i,2) = mod(sine(i),16);

end

factor

plot(sine);

len = length(sine)