Wiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008 (779888), страница 35
Текст из файла (страница 35)
It is more expensive because it needs morestorage space for digitized audio files (even if they’re compressed) andrequires more CPU power to process them. Nevertheless, they soundclosest to the real thing. Given the fact that Symbian OS supports playingdigitized audio, it is an attractive option for rich games that have fewerstorage limitations.There are a few ways of playing digital background music in a SymbianOS game. The first method is playing the background music using audiostreaming. Just like any other audio file, a file that contains the audiotrack of the game in a format compatible with the device can be playedwith the methods described in section 4.3.Because of the single audio channel support of Symbian OS devices,if the file is played independently, it will use the only available audiochannel.
This will limit the game design, because the user will only beable to hear music or sound effects, not both.One solution to this problem is to use another application (for example,the built-in media player application of the device or a special executablecreated just for this purpose) to play the music in the background, whilethe main game application itself plays the sound effects. Doing so willonly produce the desired outcome on some devices where sound outputsfrom different processes are mixed by the policy server.
This is not genericbehavior and it may not even be possible to control the mixing in any way(for example, setting the volume or balance on the external application).Therefore, this solution is not recommended.148ADDING AUDIO TO GAMES ON SYMBIAN OSA better option is to use the software mixer approach and mix inthe music, on an additional dedicated channel, together with the soundeffects. The drawback is that the music and sound effects need to beencoded in a mixable (i.e., raw) format, so that they can be mixedtogether.
Doing this rules out having compressed music because of themixing problem. The only options are either having a short looping trackor a longer but lower quality track.In the mixing method, another trick is to stream the file from the diskwhile playing it. The background music file will most probably be bigand it will not be feasible to load all of it into the heap.
One way ofachieving streaming is by implementing a buffering mechanism for filereading, similar to the buffering mechanism used for playing sounds inthe MMF. When the MMF buffer requests more data, the pre-read datafrom the file is transferred from the file buffer to the MMF buffer. Thelower quality mixing option, with file streaming, is demonstrated in thesoftware mixer example code provided on this book’s website.One more method of mixing background music together with multiplesimultaneous sound effects is to use Mobile XMF/DLS.
Instead of mixingdigitized effects to an audio stream inside the software mixer that is implemented in game code, game developers can create the sound effects asinstruments in a custom sound bank and load them together with a MIDIfile into an XMF file. The MIDI engine will take care of playing the fileusing the real instruments, and the game engine will send any effects tothe mixer in real time as single notes of the custom effect instruments.Depending on the polyphony of the device, the MIDI engine can playmany effects simultaneously with multi-track background music.Of course, use of this method depends on the Mobile XMF/DLSsupport of the devices the game developer is targeting.
Details of thismethod are outside the scope of this book, but more information isavailable from various sources. For example, see the MIDI Manufacturer’sAssociation for more information on XML/DLS (www.midi.org/aboutmidi/dls/abtmdls.shtml). For authoring tools and usage related to gamedevelopment, check out the companies listed at www.midi.org/aboutmidi/xmf/xmfprods.shtml.4.4.3 Playing Digitized Music with CodecsPlaying compressed format codecs such as MP3 or AAC is no differentfrom playing any other non-compressed format using the aforementionedMMF APIs. If the devices support the desired format, just providing thecorrect FourCC code to the initialization methods is sufficient to playthese files using the audio clip and streaming APIs.iStreamUtil->SetDataTypeL(KMMFFourCCCodeMP3);...iDevSound->InitializeL(*this, KMMFFourCCCodeAAC, EMMFStatePlaying);BACKGROUND MUSIC149The software mixing method will not work as described in the previoussection, because most compressed codecs are not suitable for mixing intheir encoded form.
In order to mix them with audio data of otherformats, they have to be decoded in real time and then mixed. Usuallyboth decoding and mixing these formats in software will be an extremelyheavy load and will starve the CPU, leaving no time for other game tasks.Until Symbian OS provides support for mixing audio on multiplechannels, using compressed codecs as in-game background music is nota feasible option.
This, of course, doesn’t mean that they cannot be usedas background music in menu screens, demos and cut-scenes, wheremixing with another audio stream effect or voice-over is not necessary.Symbian OS also supports playing DRM-protected content using itscontent access framework (CAF). Certain MMF APIs have special methodsthat can be used to pass DRM-related information (UIDs, DRM accessintent and so on) to the MMF classes that are used to access the DRMprotected audio files.
Clients of the MMF APIs also need to possess theDRM platform security capability to access these files. A game executablemust have this capability if it needs to access DRM-protected content ona device.4.4.4 Extending Symbian OS with Software CodecsSymbian OS provides third party developers with the infrastructure toextend a smartphone’s audio processing capabilities. Other than usingthe built-in audio codecs for background music and sound effects, it isalso possible to create MMF-compatible software audio codecs, and usethem in a game application.Using this method has the main advantage of making the gameindependent of any audio codec support from devices, if audio assetsof the game are encoded with this codec.
The software codec can beincluded in the installation package of the game and installed togetherwith the game on any Symbian smartphone that supports the MMF.Developing an audio engine that supports playback functionalitythrough the existing MMF APIs has another advantage. It allows a developer to use an existing codec like PCM for development purposes. PCMis easier to manipulate and debug, which makes it more suitable forprototyping. Once the audio engine is mature and music and effects arepolished, the switch to a compressed format will be quite easy.
It takesonly minimal changes to the engine code and a batch conversion of theaudio assets from PCM to the new format.The main disadvantage of the software codec method is the complexityof implementing the codec. Implementing a generic audio codec isa major development effort in itself. Even when there is an alreadydeveloped codec (for example, open source audio codecs or proprietarycodecs previously developed for other operating systems), it is still not150ADDING AUDIO TO GAMES ON SYMBIAN OStrivial to port it to Symbian OS. The MMF software codecs are EComplug-ins, and they have to adhere to a certain MMF compatible format.Details of codec porting to Symbian OS are outside the scope of thisbook, but information is available from online sources and forthcomingSymbian Press books. The prime example for game development purposesis the Ogg Vorbis3 codec port developed by Mathew Inwood of SymbianLtd.
This open source example allows decoding and playing back of OggVorbis compressed audio files and can be downloaded from SymbianDeveloper Network (developer.symbian.com/main/tools/appcode/cpp/ogg vorbis.jsp). Studying this example code and accompanyingdocumentation is a good way to start learning more about this advancedmethod.4.5 Best Practice in Mobile Game AudioOnly a few years ago, mobile phone games used only simple beeps;now they have the capability for sophisticated audio. Game sounds giveplayers meaningful feedback and communicate their progress throughthe game. Sounds in multiplayer games can be particularly useful to givefeedback about the other players’ actions. Background music is oftenused to set the mood of the game (particularly in the introductory screens)or while menus are visible.However, the use of sounds in mobile games needs to be consideredcarefully to give a good user experience.
It is important to remember thatmobile games are played in different contexts. In some contexts, such asa multiplayer Bluetooth game with a friend, audio enhances the gameexperience, whereas in others, such as on a train or in a meeting, it canbe extremely annoying for the player or other people! A game should bedesigned so it is easy to switch the context of the game, to play it silentlyor to play it with all sounds (music and sound effects) enabled. This isusually done through a menu option, giving the player full control overthe volume.
However, the game’s audio should also comply with theprofile of the phone, so if the user switches it into silent mode, the gameshould automatically become silent too.Another issue to consider with mobile games is that they may beplayed in environments where it is difficult to hear well over backgroundnoises. The sounds used must be easily distinguishable from each other inthe game and should also be sufficiently different to common ring tonesand alert tones, the use of which could otherwise confuse the player.3Ogg Vorbis is an open source multimedia format used by major game developers onother platforms. See www.vorbis.com for more information.WHAT’S NEXT?151Sounds should not be unpleasantly high pitched, and the default settingfor each should not be unpleasantly loud.4.6 What’s Next?Traditionally, developing cutting-edge games relies heavily on the maximum use of the available hardware and OS resources.
In the intenselycompetitive and innovative field of mobile phones, new devices with aseries of new hardware and software components come to market almostevery other week. It is imperative for a game developer to keep up to datewith available technologies.Symbian OS is a common code base shared by multiple licenseeswho use it in their devices. Each licensee adds the necessary supportingsoftware to its hardware on top of Symbian OS. In order to use the featuresspecific to a device, licensees provide their own APIs. If these devices aresuccessful, the ‘latest’ features on these devices become commonplacein time, and all the phones on the market support this feature by default.Think of ‘camera phones’ or ‘MP3 phones,’ which started as a ‘features’but are now supported by almost all smartphones, and all but the mostbasic feature phones.At this point, supporting multiple APIs in their respective SDKs to doessentially the same thing does not make sense for the licensees.
Instead,these different licensee APIs are consolidated into a common set of APIssupported by Symbian OS, essentially becoming a part of the shared codebase. The consolidation process creates new Symbian APIs that eitherclosely resemble licensee APIs, or that adopt an industry standard.The Internet is the best source of information on the available technologies, closely followed by books. Unfortunately, most books aboutsoftware development topics suffer from a common problem. The information they contain becomes obsolete fast because of the rapid changesin the topics they describe. This is less of a problem in theoretical booksbut more evident in books trying to explain the features in a specificversion of a software package.The following sub-sections attempt to overcome this problem byproviding some information on the upcoming audio standards and someaudio APIs supported by specific licensees.