[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] PC speaker emulation (fixed point)

From: Joachim Henke
Subject: [Qemu-devel] [PATCH] PC speaker emulation (fixed point)
Date: Mon, 23 Jan 2006 22:10:46 +0100

I still prefer using a sine wave, it sounds more smooth and won't hurt our ears (and speakers) too much. I don't think that people want to play square waves, when they have their PC connected to their hifi system (c: The main purpose of the PC speaker is to generate tones and many programmers used it to play melodies. Why shouldn't we take this chance to make it sound as good as we can manage it?

I rewrote the wave form generation routine to fit into 32 bit integer, with the highest fixed point precision for the range of all possible parameters. To retrieve the sine values, we use a small lookup table with a resolution of 1024 entries (we need to store the first quarter only, since the rest is symmetric).

I extensively tested these routines (on iMac G5 / AMD K6, gcc 3 / gcc 4) to ensure, that the final sample values differ at most by +/-1 from their double float calculated counterparts. This difference doesn't seem to be much, but when comparing directly, you can hear a minor noise for frequencies below 200 Hz. Maybe it also depends a bit on the speakers used.

However, this approach should still be sufficient for our purpose. Most programs don't use too low frequencies, and if they do, people probably won't notice.

Just test the attached patch yourselves


Sebastian Kaliszewski wrote:
One more note about that. PC-speaker generates just plain square wave not sine wave, so this would be more realistic. Then fixed point calculation (16 bit integer part and 16 bit fractional) is easy without all those sin calculation.

Joachim Henke

Attachment: pc_speaker.diff.gz
Description: GNU Zip compressed data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]