Sound Formats

Like images, there are a number of different file formats for digital audio that affect the quality and file size. Pygame supports two audio formats for sound effects: WAV (uncompressed only) and Ogg. Most, if not all, software that deals with sound will be able to read and write WAV files. Support for Ogg is not quite as universal but is still very common. If an application doesn't support Ogg directly, it may be possible to add it via an upgrade or plug-in.

There are a number of attributes for sound that can affect the quality and file size:

• Sample format—The size of a single sample, which is typically either 8-bit or 16-bit integers, although some formats do support float samples. Generally you should use 16-bit when storing sound files, because it can reproduce CD-quality sound and is best supported by sound cards.

• Sample rate—The number of samples stored per second. The most common values for sample rate are 11025Hz, 22050Hz, or 44100Hz, but there are a number of other potential values. Higher sample rates produce better-quality sound but will result in larger files.

• Channels—Sound files can be mono (a single channel of sound), or stereo (an individual channel for the left and right speakers). Stereo tends to sound better, but uses up to twice the amount of memory in uncompressed audio files.

• Compression—Sound can generate large files. For example, a one-minute-long, 44100Hz, 16-bit, stereo audio will create approximately 10MB of data. Fortunately, audio can be compressed so that it fits into a much smaller space. Pygame doesn't support compressed WAV files, but it does support the Ogg format, which has very good compression.

Actual wave

Amplitude

Actual wave

Amplitude

Figure 10-2. Sample sound wave

Sample points

Sample points

Time

Deciding what combination of these attributes you need usually depends on how you will be distributing your game. If you will be distributing your game on a CD or DVD, you will probably have plenty of space to store high-quality sounds. However, if you want to distribute your game via e-mail or download, you may want to sacrifice a little quality for smaller files.

Was this article helpful?

0 0

Post a comment