Beginning Game Audio Programming [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Beginning Game Audio Programming [Electronic resources] - نسخه متنی

Mason McCuskey

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید





CLASS STRUGGLE

Before you jump in the ring with MIDI music, you need to decide how MIDI files are going to fit in to the structure of the beloved audio engine. As it stands now, the engine uses the CSound class to represent a sound effect. This is okay, but it isn't perfect. Following the principles of good C++ design, this chapter's code changes that slightly. It makes CSound a base class, with three new derived classes: CDirectMusicSegment, CSoundEffect, and CMIDIMusic. Figure 6.2 illustrates this new class layout.


Figure 6.2: The new class layout for the audio engine.

CSound has been gutted. In previous chapters it contained the DirectMusic segment, the volume, and a whole slew of other stuff. Now it's really just an abstract base class. This is because in this new class hierarchy, CSound is the base class for any audio object that comes out the speakers. This includes things like sound effects and MIDI music (which use DirectMusic segments), but also things that have nothing to do with DirectMusic, like MP3 or Ogg Vorbis music files (which you'll learn about in the next two chapters).

CSound has three pure virtual methods, Play, Stop, and Is Playing, along with two more virtual methods, GetVolume and SetVolume. These five methods represent what I consider to be the minimum interface needed for any type of sound that comes out the speakers. Whether it's an MP3, a WAV file, or a chunk of dynamic music composed on the fly by DirectMusic, at a minimum, you'll want to Play it, stop it, see if it's Playing, and adjust its volume.

Derived from CSound is the next new class: CDirectMusicSegment. This class represents a DirectMusic segment, and it contains everything that CSound used to contain. It has the DirectMusic segment pointer, and it uses that segment pointer in its implementations of Play, Stop, and IsPlaying. In the future, if there are additional things that you want to do to a segment (regardless if it's a music or sound effect segment), you can put those methods in this class.

Derived from CDirectMusicSegment are two more classes: CSoundEffect and CMIDIMusic. Methods that make sense for just sound effects or just MIDI music (for example, setting the tempo) belong here.

Why do this? It may seem silly to break out sound effects and music into separate classes, especially because DirectMusic goes to all that trouble making WAV files and MIDI files load into the same segment object. By doing this, DirectMusic allows you to treat WAV files and MIDI files the same way.

Just because you can, however, doesn't always mean that you should. There might be specific things that we want to do to music files that wouldn't really make sense to do to a sound effect. For example, tempo—tempo makes sense when dealing with MIDI music but not when dealing with WAV sound effects. The formats are interchangeable; WAV files and MIDI can both be used for sound effects and music, but the conceptual differences between "background music" and "sound effect" remain. (And hey, if you really don't want to make this distinction, just use the CDirectMusicSegment class instead of the CSoundEffect and CMIDIMusic derivatives!)

The rest of the class hierarchy of the engine remains the same. The manager still oversees the whole operation, and the various other classes (CWAVFile, CMixer, and so on) have not been modified.

/ 127