This section describes all functions available for MIDAS system control. This includes error handling.
DWORD MIDASallocateChannel(void)
Allocates a single Sound Device channel.
None.
This function allocates a single Sound Device channel, and returns its number. Sound Device are used for all sound playback, but most functions take care of allocating and deallocating channels automatically. If you wish to play a sample on a specific channel, to ensure it won't be replaced by other samples, you'll need to pass MIDASplaySample a specific channel number, and this function is used to allocate those channels.
Channels allocated with this function need to be deallocated with MIDASfreeChannel. Before any channels can be allocated, some sound channels need to be opened with MIDASopenChannels.
Channel number for the allocated channel, or MIDAS_ILLEGAL_CHANNEL if failed.
All
MIDASopenChannels, MIDASfreeChannel.
BOOL MIDAScloseChannels(void)
Closes Sound Device channels opened with MIDASopenChannels.
None.
This function closes Sound Device channels that were opened with MIDASopenChannels. Note that you may not use this function to close channels that were opened by MIDASplayModule -- MIDASstopModule will do that automatically.
TRUE if successful, FALSE if not.
All
MIDASopenChannels, MIDASplayModule, MIDASstopModule
BOOL MIDASfreeChannel(DWORD channel)
Deallocates a single Sound Device channel.
This function deallocates a single Sound Device channel that has previously been allocated with MIDASallocateChannel. Any sound playback on the channel should be stopped before deallocating it.
TRUE if successful, FALSE if not.
All
char *MIDASgetErrorMessage(int errorCode)
Gets an error message corresponding to an error code.
This function returns a textual error message corresponding to a MIDAS error code. It can be used for displaying an error message to the user. Use MIDASgetLastError to determine the error code.
This function can be called at any point after MIDASstartup has been called.
Error message string corresponding to the error code.
All
int MIDASgetLastError(void)
Gets the MIDAS error code for last error.
None.
This function can be used to read the error code for most recent failure. When a MIDAS API function returns an error condition, this function can be used to determine the actual cause of the error, and this error can then be reported to the user or ignored, depending on the kind of response needed. Use MIDASgetErrorMessage to get a textual message corresponding to an error code.
This function can be called at any point after MIDASstartup has been called.
MIDAS error code for the most recent error.
All
char *MIDASgetVersionString(void)
Gets the current MIDAS version as a string.
None.
This function can be used to determine the MIDAS version being loaded. It returns a text string description of the version. Version numbers are usually of form ``x.y.z'', where ``x'' is the major version number, ``y'' minor version number and ``z'' patch level. In some occasions, ``z'' can be replaced with a textual message such as ``rc1'' for Release Candidate 1. All MIDAS versions with the major and minor version numbers equal have a compatible DLL API, and can be used interchangeably.
MIDAS Digital Audio System version number as a string.
Win32, Linux
BOOL MIDASopenChannels(int numChans)
Opens Sound Device channels for sound and music output.
This function opens a specified number of channels for digital sound and music output. The channels opened can be used for playing streams, samples and modules.
If this function has not been called before MIDASplayModule is called, MIDASplayModule will open the channels it needs for module playback. However, if this function has been called, but the number of available channels is inadequate for the module, MIDASplayModule will return an error and refuse to play the module.
TRUE if successful, FALSE if not.
All
MIDAScloseChannels, MIDASplayModule
BOOL MIDASpoll(void)
Polls the MIDAS sound and music player.
None.
This function can be used to poll MIDAS sound and music player manually. It plays music forward, mixes sound data, and sends it to output. When using manual polling, make sure you call MIDASpoll often enough to make sure there are no breaks in sound output -- at least two times during buffer length, preferably four times or more. Under multitasking operating systems such as Win32 and Linux, this may be difficult, so very short buffer sizes can't be used reliably.
Also note that currently this function is not available under MS-DOS. Under MS-DOS, playback is always done in background using the system timer (IRQ 0).
TRUE if successful, FALSE if not.
Win32, Linux
MIDASstartBackgroundPlay, MIDASstopBackgroundPlay
BOOL MIDASremoveTimerCallbacks(void)
Removes the user timer callbacks.
None.
This function removes the user timer callbacks set with MIDASsetTimerCallbacks. The callback functions will no longer be called. This function may not be called if MIDASsetTimerCallbacks has not been called before.
It is not necessary to call this function without exiting even if the callbacks have been used -- MIDASclose will remove the callbacks automatically. On the other hand, if the callback functions or rate are changed with MIDASsetTimerCallbacks, this function must be called to remove the previous ones first.
TRUE if successful, FALSE if not.
MS-DOS
BOOL MIDASresume(void)
Resumes MIDAS sound playback.
None.
This function re-allocates the system audio device to MIDAS, and resumes sound playback, after being suspended with MIDASsuspend. See MIDASsuspend documentation for more information about suspending MIDAS.
Note that this function may fail, if another application has captured the sound output device while MIDAS was suspended.
TRUE if successful, FALSE if not.
Win32
BOOL MIDASsetAmplification(DWORD amplification)
Sets sound output amplification level.
This function changes the output amplification level. Amplification can be used to boost the volume of the music, if the sounds played are unusually quiet, or lower it if the output seems distorted.. The amplification level is given as a percentage -- 100 stands for no amplification, 200 for double volume, 400 for quadruple volue, 50 for half volume etc.
MIDAS has some build-in amplification, but the default amplification is designed for situations where most channels have data played at moderate volumes (eg. module playback). If a lot of the channels are empty, or sounds are played at low volumes, adding amplification with this function can help to get the total sound output at a reasonable level. The amplification set with this function acts on top of the default MIDAS amplification, so nothing will be overridden.
This function can be called at any point after MIDASstartup.
TRUE if successful, FALSE if not.
All
BOOL MIDASsetTimerCallbacks(DWORD rate, BOOL displaySync, void (MIDAS_CALL *preVR)(), void (MIDAS_CALL *immVR)(), void (MIDAS_CALL *inVR)());
Sets the user timer callback functions and their rate.
This function sets the user timer callback functions and their call rate. The functions will be called periodically by the MIDAS timer interrupt, one after another. Any of the callback function pointers may be set to NULL -- the callback is then ignored.
If displaySync is TRUE, the timer system attempts to synchronize the callbacks to the display refresh. In that case, preVR is called just before the Vertical Retrace starts, immVR immediately after it has started, and inVR later during retrace. preVR can then be used for changing the display start address, for example. If display synchronization is used, rate has to be set to the value returned by MIDASgetDisplayRefreshRate.
If displaySync is FALSE, or the timer system is unable to synchronize to display refresh (running under Win95, for example), the functions are simply called one after another: first preVR, then immVR and last inVR. Note that display synchronization is not always possible, and this may happen even if displaySync is set to 1.
In either case, both the preVR and immVR functions have to be kept as short as possible, to prevent timing problems. They should not do more than update a few counters, or set a couple of hardware registers. inVR can take somewhat longer time, and be used for, for example, setting the VGA palette. It should not take more than one quarter of the time between callbacks though.
The most common use for the timer callback functions is to use them for controlling the program speed. There one of the callbacks, usually preVR is simply used for incrementing a counter. This counter then can be used to determine when to display a new frame of graphics, for example, or how many frames of movement needs to be skipped to maintain correct speed.
Note that this function may cause a small break to music playback with some sound cards. Therefore it should not be called more often than necessary. Also, if the application changes display modes, any display-synchronized timer callbacks must be resetted, and a separate refresh rate must be read for each display mode used.
MIDAS_CALL is the calling convention used for the callback functions -- __cdecl for Watcom C, empty (default) for DJGPP. As the functions will be called from an interrupt, the module containing the callback functions must be compiled with the ``SS==DS'' setting disabled (command line argument ``-zu'' for Watcom C, default setting for DJGPP).
TRUE if successful, FALSE if not.
MS-DOS
MIDASremoveTimerCallbacks, MIDASgetDisplayRefreshRate
BOOL MIDASstartBackgroundPlay(DWORD pollRate)
Starts playing music and sound in the background.
This function starts playing sound and music in the background. pollRate controls the target polling rate -- number of polls per second. Polling might not be done at actually the set rate, although usually it will be faster. Under Win32 and Linux, a new thread will be created for playing. Under MS-DOS this function is currently ignored, and background playback starts immediately when MIDAS is initialized.
TRUE if successful, FALSE if not.
All, but see MS-DOS note above.
MIDASstopBackgroundPlay, MIDASpoll
BOOL MIDASstopBackgroundPlay(void)
Stops playing sound and music in the background.
None.
This function stops music and sound background playback that has been started with MIDASstartBackgroundPlay. Under Win32 and Linux, this function also destroys the thread created for playback. Under MS-DOS this function is currently ignored, and background playback starts immediately when MIDAS is initialized.
If background playback has been started with MIDASstartBackgroundPlay, this function bf must be called before the program exits.
TRUE if successful, FALSE if not.
All, but see MS-DOS note above.
MIDASstartBackgroundPlay, MIDASpoll
BOOL MIDASsuspend(void)
Suspends MIDAS Digital Audio System.
None.
This function suspends all MIDAS Digital Audio System output, and releases the system audio device to other programs. Playback can be resumed with MIDASresume. Suspending and resuming MIDAS can be used to change some of the initial configuration options (set with MIDASsetOption) on the fly. In particular, the DirectSound mode and DirectSound window handle can be changed while MIDAS is suspended, and the new values take effect when MDIAS is restarted. Buffer size can also be changed, although this is not recommended. Output mode and mixing rate cannot be changed without completely uninitializing MIDAS.
While MIDAS is suspended, all MIDAS functions can be called normally -- the sound simply is not played. Also, stream, module and sample playback positions do not change while MIDAS is suspended.
Note that MIDASsuspend and MIDASresume are only available in Win32 systems at the moment.
TRUE if successful, FALSE if not.
Win32