## Sound Wave Frequencies

For the discussion of the sciences. Physics problems, chemistry equations, biology weirdness, it all goes here.

Moderators: gmalivuk, Moderators General, Prelates

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Sound Wave Frequencies

Hey guys,

I am designing a project in which I utilize the buzzer on a pc motherboard to play songs.
I currently have it playing melodies and everything wonderfully but now I am faced with the challenge of polyphonic sounds.
To do this I need to find a way to determine the frequency of a sound given two or more other frequencies. ie. if frequencies of 55 and 440 (both A notes) meant to be played simultaneously, what note should the buzzer play given I can only alter frequency and duration, not volume.

I have done many internet searches and spoken to physics teachers and the only other option we can think of is to test it and get approximations from which to create a formula.

Thanks for anything you can think of,
Jem

Turambar
Posts: 234
Joined: Sat May 10, 2008 9:43 pm UTC

### Re: Sound Wave Frequencies

Well, you could try 385 Hz, which will be the resultant beat pattern from the interference of the waves (if I recall correctly).

Otherwise, talk to one of those physics teachers again and ask to use a sound probe and record the wave pattern of those two As being played, and then measure the frequency of the resultant wave.
"Physics is like sex. Sure, it may give some practical results, but that's not why we do it."
--Richard Feynman

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Re: Sound Wave Frequencies

Turambar wrote:Well, you could try 385 Hz, which will be the resultant beat pattern from the interference of the waves (if I recall correctly).

Thanks for the reply although I need it to be dynamic. ie. I will always know the two frequencies but the can be any two notes of ~6octaves, also there may be more than two notes.

evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

### Re: Sound Wave Frequencies

yes i'd say the first order approx would be the beat frequency i.e. the magnitude of the difference of the two frequencies. you should also get more complex harmonics (pretty much any frequency you can get by multiplying adding or subtracting the frequencies but these will be lower amplitude i think.

is there a particular reason it has to be played with the system speaker rather than soundcard?
in ur beanz makin u eveel

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Re: Sound Wave Frequencies

evilbeanfiend wrote:is there a particular reason it has to be played with the system speaker rather than soundcard?

It is actually a Music Task to create a 20th century composition and I just felt the urge to recreate a classical piece with a technological twist.
The written program can currently play the first page of Fur Elise but only the melody mono-phonically.
My teacher is currently pleased with what I have accomplished although she said to get a higher ranged mark it needs to have mare layers and the only way is to be able to play rhythm simultaneously behind the melody.. which to do currently the program will need to derive a frequency of the given melody and rhythm frequencies.
If that makes sense to you...

The only other alternative I can think of is separating the parts and playing them on separate computers... kind of a computer orchestra if you will...

Either way the first will be a lot easier to do.

evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

### Re: Sound Wave Frequencies

well the soundcard should be able to play several channels simultaneously (either with different hardware channels or by doing the software bit for you) - you might want to look into midi . or would that be cheating (i'm assuming its the music part that is interesting rather than the tech part per se?

otherwise yes have several pcs each playing a different 'instrument'. the biggest problem here will by synchronising them i would think. but it would make quite an interesting visual impact with each pc sitting at a different place in the orchestra.
in ur beanz makin u eveel

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Re: Sound Wave Frequencies

evilbeanfiend wrote:well the soundcard should be able to play several channels simultaneously (either with different hardware channels or by doing the software bit for you) - you might want to look into midi . or would that be cheating (i'm assuming its the music part that is interesting rather than the tech part per se?

I actually wanted the monotonic sound being played from the motherboard over the music itself.

evilbeanfiend wrote:otherwise yes have several pcs each playing a different 'instrument'. the biggest problem here will by synchronising them i would think. but it would make quite an interesting visual impact with each pc sitting at a different place in the orchestra.

I figured sync. would be quite easy as I would be playing them on the school pc.s which should has synced clocks from the server and using a timer start each track simultaneously.

Thanks for all of your help by the way.

Luthen
Posts: 2021
Joined: Thu Feb 21, 2008 6:42 am UTC
Location: Dealing with xkcdian immigration
Contact:

### Re: Sound Wave Frequencies

When two sounds interfere, their amplitudes add and their frequencies average, overlaid with a volume "beat" with a frequency equal to the difference between them. Graphically it looks like an envelope of a sinusoidal wave.

That is: for sound A=440 Hz, B=660Hz,
A+B=550Hz with a 220Hz "beat"

*Will do some graphs*

Real instruments aren't just one frequency, they also include the harmonies of each note. Eg. A piano plays not just C5 (I think middle C) but also C6, G6, C7, E7, G7, C8, etc. Try playing that on a piano, adding one note at a time, its difficult to hear the entrance of each new note.
My fancy new blog I am not a vampire! PM my location for a prize!*

rnew: ALL GLORY TO THE HYPNOAVATAR!
*Terms + conditions changeable

evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

### Re: Sound Wave Frequencies

yes not only harmonies but at second order beats between harmonies, and 3rd order beats between beats etc.
in ur beanz makin u eveel

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Re: Sound Wave Frequencies

Thanks guys, unless I can get a formula to make this work I think I will go with the second option.
Dependent on the outcome I may post a recording of what I end up with.

Luthen
Posts: 2021
Joined: Thu Feb 21, 2008 6:42 am UTC
Location: Dealing with xkcdian immigration
Contact:

### Re: Sound Wave Frequencies

Wikipedia has a useful page on beats.

Here's the main formula:

It probably get way out hand if you're adding three or more sounds.
A computer orchestra sounds like a really cool idea.
My fancy new blog I am not a vampire! PM my location for a prize!*

rnew: ALL GLORY TO THE HYPNOAVATAR!
*Terms + conditions changeable

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Re: Sound Wave Frequencies

Luthen wrote:Wikipedia has a useful page on beats.
Here's the main formula:

I saw that formula in my browsing but couldn't figure what t was refering to and trial and error of values didn't portray any usful values.

Luthen wrote:It probably get way out hand if you're adding three or more sounds.

The plan was to average two then average it with the other value and so on..

Luthen wrote:A computer orchestra sounds like a really cool idea.

I agree, definitely doing this one.. even if not for my assignment.. my new software teacher would be very inclined to help so this looks quite hopeful
Any ideas of what to make it play? remember it can only support frequencies at one note per pc; so no percussion and I am limited by how many pcs I can use to about 8 at most.

evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

### Re: Sound Wave Frequencies

t would be time or the time at which you sample the wave.

as for what to play hows about "waltz in black" or another stranglers track? or if you prefer something more classical bach's "toccata en fuge"? i guess i've just reached the conclusion that your computer orchestra will sound like an electronic organ, so anything that has an organ in it should be good (cue frankie howard or kenneth williams).

edit: for extra marks i think you should conduct while your pc orchestra/organ plays
in ur beanz makin u eveel

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Re: Sound Wave Frequencies

EDIT wrote:...remember it can only support frequencies at one note per pc; so no percussion and I am limited by how many pcs I can use to about 8 at most.

Meaning one at a time/pc so essentially no more than ~8 simultaneous notes at one time...
Just to clarify.

evilbeanfiend wrote:as for what to play hows about "waltz in black" or another stranglers track? or if you prefer something more classical bach's "toccata en fuge"? i guess i've just reached the conclusion that your computer orchestra will sound like an electronic organ, so anything that has an organ in it should be good (cue frankie howard or kenneth williams).

The Bach song looks good.. It currently plays a bit of Beethoven.
And as for the sound it is a bit like an electric organ... but imagine ~8 playing together at once...

evilbeanfiend wrote:for extra marks i think you should conduct while your pc orchestra/organ plays

Turambar
Posts: 234
Joined: Sat May 10, 2008 9:43 pm UTC

### Re: Sound Wave Frequencies

jemthealmighty wrote:
Turambar wrote:Well, you could try 385 Hz, which will be the resultant beat pattern from the interference of the waves (if I recall correctly).

Thanks for the reply although I need it to be dynamic. ie. I will always know the two frequencies but the can be any two notes of ~6octaves, also there may be more than two notes.

Well, as long as you're just doing two notes, the frequency of the beat pattern is equal to the difference between the frequencies of the two notes.
"Physics is like sex. Sure, it may give some practical results, but that's not why we do it."
--Richard Feynman

Sam Weir
Posts: 98
Joined: Thu Apr 05, 2007 1:08 am UTC
Location: Arlington, MA

### Re: Sound Wave Frequencies

@jemthealmighty:

I disagree with the suggestions that the right thing to do is to simply play the beat frequency. Rather, I agree with (evilbean??)'s comment that you use a simple formula to populate a buffer with amplitude values as a function of time. Rather than use that sin + sin = coscos thing, just use A sin(f1 t) + B sin(f2 t) = s. It's just the addition of two waves.
That is, I recommend you figure out how to load a sequence of amplitudes into memory, and then play back memory at a defined rate (samples/second) through the speaker. For instance, pick 20,000 samples/second. You use the formula by plugging in a value for "t" for each memory address that you fill with an amplitude. I.e., you should calculate 20,000 numbers for every second that you want to play back. So you start with t = 0 sec, and plug in an f1 and f2. Load that into memory. Then go to t = 0.00005 seconds, plug in f1 and f2 for that moment in time, and then load that into the next memory location. Etc.

(Sure, it doesn't have to be 20,000.)

If you are really stuck with only frequency playback, I'm not sure how you'd do it. I would agree with the comments that you could try your soundcard's built-in polyphony, instead.

You might get a kick out of googling for the so-called 8-bit music style that's making a retro comeback.

-sw

Posts: 424
Joined: Fri Dec 14, 2007 1:58 am UTC
Location: Minneapolis, MN

### Re: Sound Wave Frequencies

Sam Weir wrote:@jemthealmighty:

I disagree with the suggestions that the right thing to do is to simply play the beat frequency. Rather, I agree with (evilbean??)'s comment that you use a simple formula to populate a buffer with amplitude values as a function of time. Rather than use that sin + sin = coscos thing, just use A sin(f1 t) + B sin(f2 t) = s. It's just the addition of two waves.

+1. Playing just the beat frequency won't give you the effect you want. It'll just sound like a single frequency, not like two separate frequencies played simultaneously.

gmalivuk
GNU Terry Pratchett
Posts: 26819
Joined: Wed Feb 28, 2007 6:02 pm UTC
Location: Here and There
Contact:

### Re: Sound Wave Frequencies

asad137 wrote:Playing just the beat frequency won't give you the effect you want. It'll just sound like a single frequency, not like two separate frequencies played simultaneously.

Right. If you want to simulate A110 and A440 simultaneously being played, by using the "beat" frequency (which phenomenon doesn't even really exist when the notes differ by more than a couple percent of their frequencies), you'll be playing 330Hz. Which is approximately the E above middle C on a piano. Which doesn't sound at all the same as playing A110 and A440 together.
Unless stated otherwise, I do not care whether a statement, by itself, constitutes a persuasive political argument. I care whether it's true.
---
If this post has math that doesn't work for you, use TeX the World for Firefox or Chrome

(he/him/his)

ossix
Posts: 25
Joined: Sat Mar 08, 2008 12:36 pm UTC

### Re: Sound Wave Frequencies

just to make it clear:

if you are stuck with giving a frequency and have it played you will not be able to have something like chords coming out of the speaker.
you would need the buffer-playback thing for that.

it might be worth trying to play two rapidly alternating frequencies, but i have no idea how that would sound (probably also depends on your motherboard and speaker).

Mettra
Posts: 96
Joined: Tue Apr 29, 2008 1:37 am UTC

### Re: Sound Wave Frequencies

ossix wrote:just to make it clear:

if you are stuck with giving a frequency and have it played you will not be able to have something like chords coming out of the speaker.
you would need the buffer-playback thing for that.

it might be worth trying to play two rapidly alternating frequencies, but i have no idea how that would sound (probably also depends on your motherboard and speaker).

This is the suggestion I was thinking about, but didn't post anything since I don't have a solid solution. If you want to play a harmony, switch extremely rapidly between the individual notes. There is probably an 'optimal' frequency with which to switch them (or optimal range of frequencies) but I wouldn't know how to find it offhand. Solo strings often use this technique (though not as rapidly as to make them sound 'seemless') to keep the listener well-apprised of the mode they are working within or to introduce a key change. It won't sound the same as a real harmony, but the listener's ear will do will the work for you.
zenten wrote:Maybe I can find a colouring book to explain it to you or something.

Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

### Re: Sound Wave Frequencies

PCM baby!

http://en.wikipedia.org/wiki/Pulse_code_modulation

That is where you feed a buffer of amplitudes to the speaker, instead of frequency+time.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Re: Sound Wave Frequencies

ossix wrote:it might be worth trying to play two rapidly alternating frequencies, but i have no idea how that would sound (probably also depends on your motherboard and speaker).

This may work.
My computer is down for the moment, but when it is up I shall test and reply with results.

Thanks again.

Godskalken
Posts: 159
Joined: Wed May 14, 2008 3:29 pm UTC

### Re: Sound Wave Frequencies

There is a simple reason why pc-speakers and old cell-phones sound so horrible:
They can't play polyphonic sounds.
If it was possible to feed the pc-speaker with samples at your own will, then the pc-speaker would sound like any other soundcard- clearly it is not so. In other words, no PCM for you.
And it doesn't help knowing that the sum of two sines equals the product of two different sines, if the above is true, the pc-speaker can't produce either.

Think about it, have you ever heard a pc-speaker or an old cell-phone play polyphonic (or even remotely polyphonic-sounding) sounds?

On the other hand, depending on how fast it is possible to switch between different frequencies, you might be able to produce some "illusional" effects - though I still doubt you'll make something beautiful. For example, I've heard speech through a pc-speaker (sounds worse than a robot in a 60's sci-fi movie, but still).
For us to be able to help you, you need to provide the API. That is, how do you tell the pc-speaker what sounds to produce?

endolith
Posts: 229
Joined: Tue Jan 01, 2008 2:14 am UTC
Location: New York, NY
Contact:

### Re: Sound Wave Frequencies

Playing a beat frequency is not going to help at all. You will try to play two notes at once but just end up playing an entirely different note. The buzzer is outputting square waves, right? How much control do you have over the frequency? Can you change it very quickly?

phlip
Restorer of Worlds
Posts: 7573
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

### Re: Sound Wave Frequencies

Wikipedia has some interesting information about the capabilities of the PC Speaker.

Basically: It can be hooked up to a simple timer to get square waves, or you can control it directly to get 1-bit PCM. If you take the 1-bit direct output and twiddle it really quickly, then you can use PWM to fake a higher-precision PCM... just relying on the reaction times of the circuitry to get a voltage in between 1 and 0.

Now, there's no simple way to have it play two frequencies... if it had two PSGs and a mixer, then you could use that in the obvious way, if it had just the one PSG but it had a volume control, then you could fake it with the beat frequency (let the PSG generate the fast wave in the multiplicative form, and use the volume control to build the slow wave as a volume envelope)... but the PC speaker has neither.

Incidentally: Having it very quickly alternate between the two frequencies probably won't sound that good... I remember trying that once, it didn't go too well.

Code: Select all

`enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}`
[he/him/his]

Dream
WINNING
Posts: 4338
Joined: Tue Dec 04, 2007 7:20 pm UTC
Location: The Hollow Scene Epic

### Re: Sound Wave Frequencies

jemthealmighty wrote:My computer is down for the moment, but when it is up I shall test and reply with results.

Thanks again.

This would result in the output frequency being a function of both the two alternated frequencies, and significantly the rate of modulation between them. Look up Ring Modulation for a similar, but not preciesely the same effect. Your experiment might well turn out to be the came as the two alternated frequencies both being ring modulated by the same frequency at the same time, at opposite phases.

I think.
I knew a woman once, but she died soon after.

endolith
Posts: 229
Joined: Tue Jan 01, 2008 2:14 am UTC
Location: New York, NY
Contact:

### Re: Sound Wave Frequencies

phlip wrote:Basically: It can be hooked up to a simple timer to get square waves, or you can control it directly to get 1-bit PCM.

Then output the equivalent of the two frequencies summed together and then clipped? It doesn't exactly sound like a cello...[/quote]
Attachments
waves.png (23.79 KiB) Viewed 3227 times

jemthealmighty
Posts: 145
Joined: Fri May 23, 2008 6:55 am UTC
Location: Dubbo, NSW, Australia
Contact:

### Re: Sound Wave Frequencies

Thanks for all your help guys,

I didn't really have time to work on any of this for my assessment so I ended up recording a couple of tracks, poorly, then overlaying them in Audacity.

After my exams I think I will stay on this and see if I can get anything promising from it.

Thanks again for all your help,
Jem