Frequencies and times

So

Lifer
Jul 2, 2001
25,921
14
81
So, I'm doing a project where I play back some 'music' stored off a micro controller. The original assignment was the "Big Ben" chimes, but I want to spice it up. I've produced an algorithm to play back a selected frequency for a desired time and then move on to the next, but being a musical neophite, I have no clue how to turn this:
http://www.themushroomkingdom.net/stuff/sheet_smb_over1.jpg

into something like
"440Hz for .25 seconds"
"316Hz for .18 seconds"

etc.

Anyone wanna try and help? It'd be icing on the cake since I have the project basically done...
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Can't you use this frequency chart? It's been a long time since I've read music, but each of the notes is something like 1/16 of a beat, 1/8, etc. You just need to define how long each full beat is.
 

So

Lifer
Jul 2, 2001
25,921
14
81
Thanks! That actually helps alot, but I still need to know how which are 1/8, 1/16 etc and what note each one is...
 

So

Lifer
Jul 2, 2001
25,921
14
81
Also, note, I can only use integer frequencies, so if there is no way to do that, I'm screwed.
 

jessicak

Senior member
Aug 15, 2003
542
0
0
I have actually done this before, granted not with a microcontroller. Last year I wrote some matlab code that you could use to "make a song". It took a cosine wave with a certain frequency, phase, duration, and sampling frequency and used these to recreate a note. The sound was then played through the computer speakers.

The way that I changed the length of the note was useing the "duration" parameter. Here is the code I used for matlab, it may or may not be useful.

function [waveform] = myCos(frequency, phase, duration, Fs)

interval = 1 / Fs;

numSamples = duration / interval;

t = 0:interval: duration;

waveform = cos (2 * pi * frequency * t + phase );

return;

end


Also, by taking the FFT of various instrumental recordings, we were able to reconstruct the notes to make them sound like any instrument. For example, we took the FFT of a guitar being played and used the first 10 frequencies to reconstruct cosines that sounded just like a guitar.
 

So

Lifer
Jul 2, 2001
25,921
14
81
Originally posted by: jessicak
I have actually done this before, granted not with a microcontroller. Last year I wrote some matlab code that you could use to "make a song". It took a cosine wave with a certain frequency, phase, duration, and sampling frequency and used these to recreate a note. The sound was then played through the computer speakers.

The way that I changed the length of the note was useing the "duration" parameter. Here is the code I used for matlab, it may or may not be useful.

function [waveform] = myCos(frequency, phase, duration, Fs)

interval = 1 / Fs;

numSamples = duration / interval;

t = 0:interval: duration;

waveform = cos (2 * pi * frequency * t + phase );

return;

end


Also, by taking the FFT of various instrumental recordings, we were able to reconstruct the notes to make them sound like any instrument. For example, we took the FFT of a guitar being played and used the first 10 frequencies to reconstruct cosines that sounded just like a guitar.

:beer:

I understand what you're getting at, but I'm dealing with a program that can output one square wave (which I use a low pass filter to round into a sine) of one frequency at any given time, so nothing nearly that nice, I'm afraid.

That must have been fun though...well the result anyway. ;)
 

jessicak

Senior member
Aug 15, 2003
542
0
0
Originally posted by: So
Originally posted by: jessicak
I have actually done this before, granted not with a microcontroller. Last year I wrote some matlab code that you could use to "make a song". It took a cosine wave with a certain frequency, phase, duration, and sampling frequency and used these to recreate a note. The sound was then played through the computer speakers.

The way that I changed the length of the note was useing the "duration" parameter. Here is the code I used for matlab, it may or may not be useful.

function [waveform] = myCos(frequency, phase, duration, Fs)

interval = 1 / Fs;

numSamples = duration / interval;

t = 0:interval: duration;

waveform = cos (2 * pi * frequency * t + phase );

return;

end


Also, by taking the FFT of various instrumental recordings, we were able to reconstruct the notes to make them sound like any instrument. For example, we took the FFT of a guitar being played and used the first 10 frequencies to reconstruct cosines that sounded just like a guitar.

:beer:

I understand what you're getting at, but I'm dealing with a program that can output one square wave (which I use a low pass filter to round into a sine) of one frequency at any given time, so nothing nearly that nice, I'm afraid.

That must have been fun though...well the result anyway. ;)


it was just about the most fun a lab has ever been. 30 kids all playing music from the computer speakers.
 

Rubycon

Madame President
Aug 10, 2005
17,768
485
126
We did it in the early 80's before the Ad Lib card came out.

Used IBM BASICA with the PLAY statement. No polyphony and yes it sounds VERY awkward. As bad as FM synthesis sounded on the original Ad Lib compared to the wavetables of today, it sounded great over that PC speaker. :)