[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:


I'm trying to find a working set of code for the wavemix.dll. Downloaded a few from Torry but they either don't work, are for the wrong version, or have missing files. I'm using D7 Pro on XP Pro, but target machines range from NT4 to Win2k to XP Pro.

What I need is some free source code or a component to play several wave files simultaneously. I do actually have a nearly working version of the interface to Wavemix.dll, but the Play function crashes. Tried all the usual stuff like word/dword, stdcall etc, but I think I'm missing something obvious. WMixWave works; WMixPlay doesn't. Either fixing this or supplying new code/components will get the points!


Geoff M.

----code follows----

unit Wmix; {WaveMix DLL import module May 1995 by Gavin R. Kujawa}



            TWMixInfo = packed record           {Storage record for WMixGetInfo}
                                    Size: word;            {Record size}
                                    Vmajor: byte;          {'Major' version # (i.e. '#.')}
                                    Vminor: byte;          {'Minor' version # (i.e. '.#')}
                                    Date: array[0..11] of char;{Compilation date as 'mmm dd yyyy[null]'}
                                    Formats: longint;      {PCM formats supported as flags}

            TWMixConfig = packed record         {Storage record for WMixConfigure}
                                          Size: word;          {Record size}
                                          Flags: longint;      {Flags (see below). Must OR with both...}
                                          Channels: word;      {1(mono) or 2(stereo) And ...}
                                          SampRate: word;      {11, 22, or 44 kHz}

            TWMixParams = packed record         {Storage record for WMixPlay}
                                          Size: word;          {Record size}
                                          Session: THandle;       {WaveMix session handle}
                                          Channel: integer;    {Play on channel(0 to 7)}
                                          Wave: Pointer;       {Memory pointer to Wave file}
                                          Notify: HWnd;        {Handle to send MM_WOM_DONE message to}
                                          Flags: dword;      {Play flags (see below)}
                                          Loops: word;         {# of times to loop ($FFFF = indefinite)}

            TWMixMessage = record        {Message record used by WMixPlay}
                                                 Msg: integer;     {Message #: $03BD (MM_WOM_DONE)}
                                                 Channel: integer; {Channel # just played}
                                                 Wave: pointer;    {Pointer to Wave file in memory}
                                                 Result: longint;  {Not used (?) by WaveMix}

const                                {WaveMix bit flags}
     WMix_File: longint = $0001;       {WMixOpen: from disk file}
     WMix_Resource: longint = $0002;   {WMixOpen: from system resource file}
     WMix_Memory: longint = $0004;     {WMixOpen: from memory}
     WMix_OpenSingle: longint = $0000; {WMixChannel: open one Play channel}
     WMix_OpenAll: longint = $0001;    {WMixChannel: open ALL eight channels}
     WMix_OpenCount: longint = $0002;  {WMixChannel: open # channels}
     WMix_FlushAll: longint = $0001;   {WMixFlush & Close: do ALL channels}
     WMix_NoRemix: longint = $0002;    {WMixFlush: don't remix sound data}
     WMix_Channels: longint = $0001;   {WMixConfigure: set channels}
     WMix_SamplingRate: longint = $0002;{WMixConfigure: set playback rate}
     WMix_QueueWave: longint = $0000;  {WMixPlay: play when previous finishes}
     WMix_ClearQueue: longint = $0001; {WMixPlay: play sound immediately}
             WMix_UseLRUChannel: longint = $0002;{WMixPlay: play on next available chan}
             WMix_HiPriority: longint = $0004; {WMixPlay: remix play buffer immediately}
             WMix_Wait: longint = $0008;       {WMixPlay: hold until next 'Play'}
             MM_WOM_DONE: integer = $03BD;     {Message used by WMixPlay when done}

function WMixInit: THandle; far; stdcall;
                         {WaveMixInit: returns WaveMix session handle}
function WMixConfigure(Config: TWMixConfig): word; far; stdcall;
                         {WaveMixConfigureInit: also returns WaveMix session handle}
procedure WMixActivate(Session: THandle; Activate: boolean); stdcall;
                              {WaveMixActivate: gains/releases Wave player}
function WMixWave(Session: THandle; Wave: PChar; Instance: longint; Flags: longint): Pointer; far; stdcall;
                         {WaveMixOpenWave: returns pointer to WaveMix Wave data}
procedure WMixChannel(Session: THandle; Channel: integer; Flags: longint); stdcall;
                              {WaveMixOpenChannel: opens play channels}
procedure WMixPlay(Params: TWMixParams); stdcall;
                              {WaveMixPlay: plays file using Params (see above)}
procedure WMixFlush(Session: THandle; Channel: integer; Flags: longint); stdcall;
                              {WaveMixFlushChannel: clears selected channel}
procedure WMixClose(Session: THandle; Channel: integer; Flags: longint); stdcall;
                              {WaveMixCloseChannel: closes selected channel}
procedure WMixFree(Session: THandle; Wpointer: Pointer); stdcall;
                              {WaveMixFreeWave: clears Wave file from memory}
procedure WMixExit(Session: THandle); stdcall;
                              {WaveMixCloseSession: stops & unloads WaveMix DLL}
procedure WMixPump; stdcall;
                              {WaveMixPump: play next mixing buffer}
function WMixGetInfo(Info: TWMixInfo): word; far; stdcall;
                         {WaveMixGetInfo: fills in Info record (see above)}

implementation  {Define WMix functions from WaveMix DLL}

      DLL_NAME = 'wavmix32.dll';

function WMixInit; external DLL_NAME name 'WaveMixInit';
function WMixConfigure; external DLL_NAME name 'WaveMixConfigureInit';
procedure WMixActivate; external DLL_NAME name 'WaveMixActivate';
function WMixWave; external DLL_NAME name 'WaveMixOpenWave';
procedure WMixChannel; external DLL_NAME name 'WaveMixOpenChannel';
procedure WMixPlay; external DLL_NAME name 'WaveMixPlay';
procedure WMixFlush; external DLL_NAME name 'WaveMixFlushChannel';
procedure WMixClose; external DLL_NAME name 'WaveMixCloseChannel';
procedure WMixFree; external DLL_NAME name 'WaveMixFreeWave';
procedure WMixExit; external DLL_NAME name 'WaveMixCloseSession';
procedure WMixPump; external DLL_NAME name 'WaveMixPump';
function WMixGetInfo; external DLL_NAME name 'WaveMixGetInfo';

1 Solution
Another way is to utilise DirectSound and you can play all the wave files simultaneously.
gmayoAuthor Commented:
If only life were that simple... it took me months to learn Direct3d and there were some good examples. DirectSound does not have such good samples, either on MS or on Jedi. Direct3d doesn't even support loading WAV files - you have to write your own reader! Ever heard of "re-inventing the wheel" Microsoft?

There's also the problem of it not being fully supported on NT4.

But thanks anyway. I've got all the other functions in this DLL working fine, except the Play one - if only I could get that to work...

Geoff M.
If you use directshow it takes care of all file reading

       CoCreateInstance(CLSID_FilterGraph, Nil,  INPROC_SERVER,
                                    IID_IGraphBuilder, Graph);
        Graph.QueryInterface(IID_IMediaControl, MediaControl);
        Graph.QueryInterface(IID_IMediaEventEx, MediaEvent);
        Graph.QueryInterface(IID_IBasicAudio, BasicAudio);  
        if not Succeeded(Graph.RenderFile(Fname, Nil)) then
              raise Exception.create('Unable to Render File');

May not be supported on NT4
Russell LibbySoftware Engineer, Advisory Commented:

Not sure if this helps, but it is my understanding that the WaveMixPlay function requires the parameter buffer "by reference", and not "by value".

  PWMixParams       =  ^TWMixParams;
  TWMixParams       =  packed record  {Storage record for WMixPlay}
     Size:          WORD;             {Record size}
     Session:       THandle;          {WaveMix session handle}
     Channel:       Integer;          {Play on channel(0 to 7)}
     Wave:          Pointer;          {Memory pointer to Wave file}
     Notify:        HWND;             {Handle to send MM_WOM_DONE message to}
     Flags:         DWORD;            {Play flags (see below)}
     Loops:         WORD;             {# of times to loop ($FFFF = indefinite)}

// The exported call would then needs to be defined as one of the following

procedure  WMixPlay(Params: PWMixParams); stdcall;


procedure WMixPlay(var Params: TWMixParams); stdcall;



gmayoAuthor Commented:
Thanks Russell, that did the trick! I don't know why I didn't think of that, oh well!


Geoff M.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now