Example: Playing a Waveform File

The following procedure uses the Media Control Interface to play part of a waveform file.

TO PLAY.WAVEFORM
  IGNORE MCI [open c:\\windows\\media\\ding.wav type waveaudio alias ding]
  MCI [set ding time format samples]
  MCI [play ding from 0 to 5000]
  WAIT 120
  MCI [close ding]
END

Let's take a closer look at each instruction in the example above.

The procedure first opens "c:\windows\media\ding.wav" by issuing an open command. We use the alias parameter so that we can refer to this media entity as ding instead of always using the full path to ding.wav. Unlike most other commands, the open command outputs a value on success. Since Logo programs must do something with every value that is output, we simply IGNORE it.

The set command is used to specify the time format as "samples". A sample is the smallest unit of sound within a given waveform file.

The play command is used to start playing from one time to another. The waveform plays asynchornously, which means that FMSLogo doesn't wait for the audio clip to finish playing before running the next instruction. If you wanted to wait until the track was done before moving on to the next instruction, you could add wait to the end of the MCI instruction, as in

MCI [play ding from 0 to 5000 wait]

It is not necessary to specify an end time for the play command. If you wanted to play the entire waveform, you could do so with:

MCI [play ding from 0]

The WAIT instruction just waits for two seconds. This has nothing to do with MCI, it just gives you some time to listen to your waveform.

The close command is used to tell the Media Control Interface that you are done with the waveform file.


SourceForge.net Logo