Next: 3 Using MIDAS Digital Up: 2 Getting started Previous: 2.4 Using MIDAS from

# 2.5 A simple module player example

This section describes a very simple example program that uses MIDAS Digital Audio System for playing music. First, the complete program source is given in both C and Delphi format, and after that the operation of the program is described line by line. To keep the program as short as possible, all error checking is omitted, and therefore it should not be used as a template for building real applications -- the other example programs included in the MIDAS distribution are more suitable for that.

Both versions of the program should be compiled as console applications in the Win32 environment. Under MS-DOS and Linux the default compiler settings are fine.

## 2.5.1 C module player example

     1  #include <stdio.h>
     2  #include <conio.h>
     3  #include "midasdll.h"
     4
     5  int main(void)
     6  {
     7      MIDASmodule module;
     8      MIDASmodulePlayHandle playHandle;
     9
    10      MIDASstartup();
    11      MIDASinit();
    12      MIDASstartBackgroundPlay(0);
    13
    14      module = MIDASloadModule("..\\data\\templsun.xm");
    15      playHandle = MIDASplayModule(module, TRUE);
    16
    17      puts("Playing - press any key");
    18      getch();
    19
    20      MIDASstopModule(playHandle);
    21      MIDASfreeModule(module);
    22
    23      MIDASstopBackgroundPlay();
    24      MIDASclose();
    25
    26      return 0;
    27  }

## 2.5.2 Delphi module player example

     1  uses midasdll;
     2
     3  var module : MIDASmodule;
     4  var playHandle : MIDASmodulePlayHandle;
     5
     6  BEGIN
     7      MIDASstartup;
     8      MIDASinit;
     9      MIDASstartBackgroundPlay(0)
    10
    11      module := MIDASloadModule('..\data\templsun.xm');
    12      playHandle MIDASplayModule(module, true);
    13
    14      WriteLn('Playing - Press Enter');
    15      ReadLn;
    16
    17      MIDASstopModule(playHandle);
    18      MIDASfreeModule(module);
    19
    20      MIDASstopBackgroundPlay;
    21      MIDASclose;
    22  END.

## 2.5.3 Module player example description

Apart from minor syntax differences, the C and Delphi versions of the program work nearly identically. This section describes the operation of the programs line by line. The line numbers below are given in pairs: first for C, second for Delphi.

1-3, 1
  Includes necessary system and MIDAS definition files
7, 3
  Defines a variable for the module that will be played
8, 4
  Defines a variable for the module playing handle
10, 7
  Resets the MIDAS internal state -- This needs to be done before MIDAS is configured and initialized.
11, 8
  Initializes MIDAS
12, 9
  Starts playing sound in the background
14, 11
  Loads the module file
15, 12
  Starts playing the module we just loaded, looping it
17-18, 14-15
  Simply waits for a keypress
20, 17
  Stops playing the module
21, 18
  Deallocates the module we loaded
23, 20
  Stops playing sound in the background
24, 21
  Uninitializes the MIDAS Digital Audio System

Next: 3 Using MIDAS Digital Up: 2 Getting started Previous: 2.4 Using MIDAS from