Solved

Wavemix.dll

Posted on 2004-08-02
5
506 Views
Last Modified: 2010-04-04
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!

Thanks

Geoff M.


----code follows----

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

interface

uses
      Windows;

type
            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}
            end;

type
            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}
            end;

type
            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)}
            end;

type
            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}
            end;

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}

const
      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';

end.
0
Comment
Question by:gmayo
5 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 11696487
Another way is to utilise DirectSound and you can play all the wave files simultaneously.
0
 
LVL 8

Author Comment

by:gmayo
ID: 11702107
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.
0
 
LVL 2

Expert Comment

by:philipjc
ID: 11702813
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');
        MediaControl.Run();

May not be supported on NT4
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
ID: 11707985

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

type
  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)}
  end;

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

procedure  WMixPlay(Params: PWMixParams); stdcall;

or

procedure WMixPlay(var Params: TWMixParams); stdcall;

---------

Regards,
Russell

0
 
LVL 8

Author Comment

by:gmayo
ID: 11713955
Thanks Russell, that did the trick! I don't know why I didn't think of that, oh well!

Cheers

Geoff M.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now