Making Noise with MMPM/2 - Part 1

by Marc van Woerkom

Introduction
Beginning with version 2.1, IBM has delivered two new disks with OS/2 containing the previously separately sold Multimedia Presentation Manager/2 1.1 (MMPM/2). Having once visited a colleague who used a Mac and being enamoured with the characteristic  emminating from the system speaker after he dropped some superfluous files on a toilet icon, I installed it to try out the system sounds on my SoundBlaster-equipped machine. Although it is quite satisfying in its own right that our beloved operating system is now able to cope with the Mac in this particular area, one should take the little extra time to have a closer look on the MMPM/2 for it has more to offer.

This is the first of two articles which do so. It gives an overview of MMPM/2 and introduces programming for multimedia, using the REXX language which is sufficient for many cases. The second article will deal with MMPM/2 programming in C and C++. Both articles focus on the audio capabilities of MMPM/2.

MMPM/2 Overview
Like its name suggests, the Multimedia Presentation Manager adds multimedia capabilities to IBM's OS/2 2.1 operating system, but what does this actually mean? For me, the term multimedia has acquired a slightly negative connotation in recent months because it is used so extensively by computer hardware vendors to hawk their wares. They take a PC, put a soundboard and a CD-ROM drive into it, drape it with two tiny speakers and voila(!) it's perfect multimedia! The hardware is sold but the purpose is still rather vague.

In the publication "OS/2 2.1 Technical Update" (GG24-3948-00) IBM writes:
 * The key benefit of multimedia is an enhanced quality of information and communication. When audio, image, and video are combined with text and graphics, customers can access richer forms of information, and communication becomes more effective.

This is not a bad definition. The variety of the types of data computers are asked to crunch has become richer over the years, starting with numbers and text, followed by graphics, and now also images (be it photos or live motion video) and audio data. The need for the capability to combine these different kinds of data is also crucial.

IBM writes further:
 * MMPM/2 enables this increase in productivity by providing device control, streaming, synchronization, and multimedia object I/O support.

That is a brief summary of MMPM/2. The package consists of: Also several multimedia utilities are delivered with MMPM/2, like a CD audio player, a waveaudio player and editor, software video players and more.
 * Physical Device Drivers (PDD):A collection of drivers for multimedia hardware like soundcards, CD-ROM drives, video digitizers, video disc-players, MIDI devices, etc
 * Media Control Interface (MCI):The MCI is a programming interface which allows the easy use of the media devices, handling them all in a common way via command strings like open, close, play, record, stop, seek, etc.
 * Synchronization & Streaming Programming Interface (SPI):The SPI multimedia subsystem is responsible for the smooth execution of multimedia applications under OS/2. It ensures that those tasks get the needed processor time and synchronizes different streams of multimedia data.
 * Multimedia I/O Services:The MMIO subsystem extends the OS/2 file services. It provides a standard mechanism for accessing and manipulating multimedia data files (media elements). Supported are buffered I/O, RIFF file I/O, memory file I/O, compound file I/O; it is also possible to add additional I/O procedures to the MMIO subsystem
 * PM Extensions:MMPM/2 provides some new Presentation Manager window classes tailored for the control of multimedia applications (graphical button, circular slider, etc.)

This first article only deals with the MCI because it is programmable from REXX in a very easy way and gives a nice impression of the MMPM/2 architecture. The other features will be treated in the second article.

The Media Control Interface
If you have installed MMPM/2 you'll find on your harddisk an online manual about using the MCI from a REXX programmer's point of view

Note: this manual has many gaps! A more complete description can be found in the MMPM/2 Programming Reference of the OS/2 Technical Library (available in online form on the bookware CD-ROM).

To allow interaction with the multimedia hardware MMPM/2 defines a set of media devices on top of the PDDs, which can be controlled via the textual string commands of the Media Control Interface (MCI), defined by IBM and Microsoft in 1991.

The standard media devices are: The MMPM/2 headers also define these devices: These media devices are modelled closely after their real-world pendants and their programming via the MCI command strings mirrors the actions one usually performs on a common audio or video component. Also the controls of the utilities delivered with the MMPM/2 have the same typical look and feel of their real-world counterparts.

All devices are either of simple or compound type. Compound devices use data files (in MCI-speak: can load a device element in the device context), simple devices don't. CDaudio is a simple device, Waveaudio a compound one.

Let's start with a simple example which should play a certain waveform audio file. The MCI command strings one needs for this are: open Waveaudio alias wave shareable wait load wave c:\mmos2\sounds\boing.wav wait play wave wait close wave wait First the Waveaudio device is opened in shareable mode (in MCI-speak: a device context is created) and it gets the alias wave assigned to it. Then using the alias to address the media device, the BOING.WAV file is loaded into memory. A play command is issued on wave and finally the device is closed. This also frees the memory assigned to the media device when loading the *.WAV file. The wait keyword tells MMPM/2 to wait until the command has finished before continuing.

Now let's play the end from "U got the look" (track 1, 3.40) to the beginning of "if I was your girlfriend" (track 2, 0.20) from disc 2 of Prince's "Sign o' the Times" album: open CDaudio alias cd wait set cd time format tmsf wait play cd from 1:3:40 to 2:0:20 wait close cd wait The CDaudio device is opened and the alias cd is assigned to it. Next the media device is told to count in tracks, minutes, seconds, and frames. Finally, both tracks are played from the given positions and the device is closed.

Note that the CDaudio device is directly manipulated; it is not necessary to load a data file.

The third examples plays a software video slowed down to 25% speed. Note that in this mode audio is switched off. open digitalvideo alias video wait info video product wait load video some.avi wait set video speed format percentage wait play video speed 25 wait close video wait The digitalvideo device gets opened and video is the assigned alias. Then the device is queried for the information product; this will create a return string with some describing text. The file SOME.AVI gets loaded and the format for speed settings is set to percentages. The video is then played with 25% speed and the device is closed.

I hope the basic recipe of a MCI script was conveyed from these examples. They illustrate that the different media devices are handled in similar manners. Armed with a MCI manual you should be able to write your own scripts.

To send those command strings to the interpreting Media Device Manager (MDM) one can use either REXX, C/C++ or the String Test tool provided with the Multimedia Toolkit.

Using the MCI from REXX
Now let's look how to realize those examples in REXX.

Example 1:
The first step in BOING.CMD is to register the MCI REXX application interface using the call to RxFuncAdd and then by initializing it via a call to mciRxInit.

Statements of the form mciRxSendString('some_MCI_command',RetStr,'0','0') send the MCI command string to the MDM and may receive a return string in the RetStr variable.

Business finishes with a call to mciRxExit.

Example 2:
This example also uses the function mciRxGetErrorString to receive the error message belonging to the return value RC.

Example 3:
This one starts with a parsing of the command line arguments. Later the example queries the digitalvideo device for a product description string which is delivered into the videoinfo variable.

Note that the digitalvideo device needs the Presentation Manager, so if this REXX procedure is to be used from the command line, one has to call it through PMREXX.

Example 4:
Did you notice already the menu item lock disk in the context menu of the CD-ROM drive icon? As does that menu item, this procedure locks the door of the CD-ROM drive so that it can't be opened with a push on the external open/close button.

Example 5:
This procedure unlocks the CD-ROM drive, reenabling the external open/close button.

Example 6:
This procedure opens the door of your CD-ROM drive and ejects the tray. I admit, it is a bit drole (somehow it reminds me of little R2-D2 from Star Wars) but I'd be grateful if someone points out a serious application of this to me.

Example 7:
I wrote this procedure to try out a whole directory of audio files at once. To play all *.WAV files from the current directory and all directories under it, type playall. wav rec on the command line.

Literature on MMPM/2
OS/2 2.x Notebook - The Best of OS/2 Developer Magazine. Van Nostrand Reinhold, New York, 1993. MMPM/2 Programming Guide. "Describes application and subsystem programming interfaces to help you select and implement functions for OS/2 multimedia applications" MMPM/2 Programming Reference. "Provides detailed information on multimedia functions, messages, and data structures to enable you to write code for multimedia applications" MMPM/2 Sample Programs Workbook. "Gives code examples from MMPM/2 sample application programms and templates for subsystem components" CUA Guide to Multimedia User Interface Design. "Describes design concepts to consider when designing a CUA multimedia interface" OS/2 Multimedia Advantages. "Describes advantages offered by OS/2 and MMPM/2 multimedia platform" Complete MMPM/2 Technical Library. A Multimedia Class Library for Windows. Dr. Dobb's Journal, 7:84-90, 1993.
 * Dick Conklin (Ed.):
 * IBM Doc. S41G-2919:
 * IBM Doc. S41G-2920:
 * IBM Doc. S41G-2921:
 * IBM Doc. S41G-2922:
 * IBM Doc. S41G-2923:
 * IBM Doc. S41G-3321:
 * John Musser: