home made music for game

Started by
21 comments, last by sakky 21 years, 9 months ago
Yikes, calm down brotha. That was a light-hearted comment towards the whole thread - sometimes overanalyzing rudimentary theories causes one to lose sight of the original objective. Didn''t mean to strike a nerve.
Advertisement

It''s sometimes funny to see how comments get
interpreted, when they''re only read, and the voice
doesn''t get transmitted

You didn''t "srike a nerve", I just wondered why
you said "counterproductive", as if my thought
would cause an earthquake

in general I don''t think it''s so bad to discuss something
somehow related to the subject of a thread, when the
original question has gotten answered.


quote:Original post by UnshavenBastard
If you sample a frequency 1/2 the sample rate,
you have 2 sample points for a complete wave.
Say, it''s THE basic wave: sine.
If your two sample points hit the two extrema, you''re fine.
If the first hits 0, and the second pi or 2pi, the
value is zero for both points. It could be a sine wave
with a very high amplitude, but you won''t be able to
reproduce it.

I''m not entirely sure what you''re saying, since I never deal in terms of pi or whatever, but I think you might be missing the crucial point.

Note that the frequency you can sample is up to the sampling rate divided by 2, but not including the sampling rate divided by two exactly.

Now, with that in mind, if your sampling rate is more than double the frequency of what you''re recording - no matter by how small an amount - then you are guaranteed at least 3 samples along the wavelength. So even if 2 of those are zero, the third gives you the information you need.

Let''s imagine you''re sampling at 44KHz, and the tone you''re recording is 21999KHz (just under half, as required). If your first sample hits the zero at the start of the sine wave before it goes up to full amplitude, the next sample will be just before that wave dips back down below zero towards negative amplitude. The sample after that will come just before the wave repeats and will be just below zero, and so on. So the values might look like: 0, 0.001, -0.002, 0.003, -0.004, etc. Given these values, you have enough information to reconstruct the wave, both in terms of frequency and in terms of amplitude. You do need to read several values in order to work it out, but the information is there.

Of course, in the real world, samples can''t store fractional parts and therefore the sound degrades compared to the original pure tone. But that is a quantisation error rather than an aliasing error, which is what the Nyquist theorem addresses. This is why cd-quality sound is not perfect to all human ears - although the 44KHz sampling rate is high enough to reduce pretty much all audible aliasing, 16 bit quantisation is not high enough to make all the quantisation errors unnoticable. (Ironically, the human ear only needs about 17 bits, but that is not a very computer-friendly value.)

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

This topic is closed to new replies.

Advertisement