forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Wavemix32.dll - Realtime multichannel sound mixing !!

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code
View previous topic :: View next topic  
Author Message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Sat Jul 19, 2003 3:52 pm    Post subject: Wavemix32.dll - Realtime multichannel sound mixing !! Reply with quote

Wavemix32.dll VDS 5.x Interface :

What is WaveMix :
-----------------
The WaveMix DLL is a utility that allows multiple WAV files to be played simultaneously. It is designed to be as simple to use as possible but still have the power to do what is required by games. The DLL supports 8 channels of simultaneous wave play, the ability to queue up waves along the same channel and wave completion notification.

WaveMix uses the standard sound drivers, it is not dependent of special drivers. The advantage is that it works directly with any version of Windows, starting from 3.1 and with virtually any sound card.

Why WaveMix at all now that DirectSound exists? For simple programs that need simple sound mixing (without strict low-latency requirements), WaveMix works fairly well and it is simple to install with the program.

Wavemix in VDS 5.x
------------------
I have made a script that calls this dll from VDS 5.x
This provides multichannel sound capabilities to VDS programmers especially those who write games in VDS.
It also helps for those who need mixing of different sounds for other purposes and with suitable additions to the code these mixed sounds can be recorded to a wave file !!!

The included code plays 8 channels simultaneously at 22KHz.
I have kept it at that for compatibility with most computers.
If you want a better performance change it to 44KHz in the ini file.
The version of the dll (1.80) included doesn't require you to install the dll in system directory - You have to place it in the app directory.

I have also written a dll to help calculate hiword and loword values. You can do without it and calculate using the code commented in the dsc (thanks to mindpower). However this may be a little slower, a difference that may be noticed in games etc.

I hope this helps VDS programmers.

Using Advanced options:
-----------------------
There are several advanced options available which are intentionally omitted from the source code(dsc) file to keep it simple.
If you want to use them see the attached documentation (eg You can change the volume of individual channels close a channel silence a channel and so on).

Copyrights:
------------
All the included documentation codes and the Wavemix dll are copyright of their respective owners including Microsoft Corporation.
You are free to distribute this source code unaltered as well as modify and compile it as long as you include the relevant copyright information AND the conditions of the included component owners don't prevent you.(As far as I know there is no restrictions on distribution)

Disclaimer:
----------
As with calling any non VDS dll you do it at your own risk. I advise you to save your work before running /debugging it to safeguard your data. The dll is known to crash VDS IDE during unload. You may compile and test it to avoid this.
This compilation is not declared to be fit for any purpose whatsoever.

You can download the source code with complete help and required dlls at:
"http://www.geocities.com/codescript2002/Wavmix_VDS.zip"
Paste in Internet explorer without the quotes

Enjoy !!
Code:

#|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||#
#|||||                                                                    ||||#
#||||  ||||||              ||         |||||               ||          |   ||||#
#|||| |||   ||   |||    || ||  ||||  ||   ||   |||   ||||    || |||  |||  ||||#
#|||| ||       ||| ||| || ||| ||  ||  |||||  ||| ||| ||   || ||| ||| ||   ||||#
#|||| ||    || ||   || |   || ||||||     ||| ||      ||   || ||   || ||   ||||#
#||||  ||||||| ||| ||| || ||| ||     ||||||| ||| ||| ||   || ||| ||| ||   ||||#
#||||   ||||     |||    |||||  |||||   ||||    ||||  ||   || || |||   ||  ||||#
#|||||                                                       ||           ||||#
#||||||                                                                   ||||#
#|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||#
#-----------------------------------------------------------------------------#
#  Info:    Wavemix32.dll VDS 5.x Interface                                   #
#                                                                             #
# Author:  CodeScript                                                         #
#                                                                             #
# Copyright: Portions  © Copyright  2003 - CodeScript                         #
#            Portions  © copyright 1993-1994, Microsoft Corporation.          #
#                                                                             #
# This script can be modified or used in any application free of cost provided#
# the above copyright messages appear in the documantation                    #
# Thanks to : Mindpower for his valuable support.                             #
#                                                                             #
# Disclaimer : This script uses Non VDS dll. Use at your own risk.            #
#-----------------------------------------------------------------------------#
  TITLE Wavemix32.dll VDS 5.x Interface - By CodeScript
  DIALOG CREATE,Wavemix32.dll VDS 5.x Interface - By CodeScript,-1,0,455,213,CLASS wavemix
  DIALOG ADD,BUTTON,BUTTON1,26,78,60,50,Sound  1
  DIALOG ADD,BUTTON,BUTTON2,26,158,60,50,Sound  2
  DIALOG ADD,BUTTON,BUTTON3,26,236,60,50,Sound  3
  DIALOG ADD,BUTTON,BUTTON4,26,310,60,50,Sound  4
  DIALOG ADD,BUTTON,BUTTON5,90,78,60,50,Sound  5
  DIALOG ADD,BUTTON,BUTTON6,90,158,60,50,Sound  6
  DIALOG ADD,BUTTON,BUTTON7,90,236,60,50,Sound  7
  DIALOG ADD,BUTTON,BUTTON8,90,310,60,50,Sound  8
  DIALOG ADD,TEXT,TEXT1,154,122,,,You can also play the sounds by pressing
  DIALOG ADD,TEXT,TEXT2,178,146,,,keys 1 to 8 on your keyboard!
  DIALOG SHOW
Hotkey add,1,1
Hotkey add,2,2
Hotkey add,3,3
Hotkey add,4,4
Hotkey add,5,5
Hotkey add,6,6
Hotkey add,7,7
Hotkey add,8,8
%%file1 = @path(%0)1.WAV
%%file2 = @path(%0)2.WAV
%%file3 = @path(%0)3.WAV
%%file4 = @path(%0)4.WAV
%%file5 = @path(%0)5.WAV
%%file6 = @path(%0)6.WAV
%%file7 = @path(%0)7.WAV
%%file8 = @path(%0)8.WAV
LOADLIB @PATH(%0)WAVMIX32.dll
LOADLIB @PATH(%0)hilo.dll
 %I = @lib(WAVMIX32,WaveMixInit,INT:,)
 %J = @lib(WAVMIX32,WaveMixOpenChannel,INT:,%I,7,1)
 %K = @lib(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file1)
 # the closing bracket at the end can be removed to
 # prevent it entering the variable %K 3434) for example.
 # if it should occur; by removing it in the function.
 # Example:(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file1,,
 # This may be a bug? in VDS or the dll ;)
 %L = @lib(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file2)
 %M = @lib(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file3)
 %N = @lib(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file4)
 %O = @lib(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file5)
 %P = @lib(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file6)
 %Q = @lib(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file7)
 %R = @lib(WAVMIX32,WaveMixOpenWave,INT:,%I,STR:%%file8)
 %S = @lib(WAVMIX32,WaveMixActivate,INT:,%I,INT:1)
 

:EVLOOP
wait event
goto @event()

:HOTKEY
%Y = @HOTKEY()
goto SOUND%Y

:BUTTON1BUTTON
:SOUND1
# %%ChannelHi value is always zero.
%%ChannelHi = 0
# %%ChannelLo value can be 0 t0 7 (8 channels)
%%ChannelLo = 0
%%hWndNotifyHi = 0
%%hWndNotifyLo = 0
%%FlagsHi = 0
# %%FlagsLo = 5 stands for WMIX_CLEARQUEUE Or WMIX_HIGHPRIORITY
#Alternative values for %%FlagsLo are here:
#(Refer to documentation for further details)
#WMIX_QUEUEWAVE As Long = 0
#WMIX_CLEARQUEUE As Long = 1
#WMIX_USELRUCHANNEL As Long = 2
#WMIX_HIGHPRIORITY As Long = 4
#WMIX_WAIT As Long = 8
%%FlagsLo = 5
#You can do away with the hilo.dll and use the following
#to calculate hiword and loword as suggested by mindpower:
#%%Hiword = @div(%%My32Num,65536)
#%%Loword = @diff(%%My32Num,@prod(%%Hiword,65536))
#but this will be SLOWER for gaming environment etc.
#where speed is everything !
%%MixSessionHi = @LIB(hilo,HI,INT:,%I)
%%MixSessionLo = @LIB(hilo,LO,INT:,%I)
%%MixWaveHi = @LIB(hilo,HI,INT:,%K)
%%MixWaveLo = @LIB(hilo,LO,INT:,%K)
%%wLoops = 0
#CREATE STRUCT OF MIXPLAYPARAMS %S HOLDS THIS
%T = @BINARY(WORD,24)@BINARY(WORD,%%MixSessionLo)@BINARY(WORD,%%MixSessionHi)@BINARY(WORD,%%ChannelLo)@BINARY(WORD,%%ChannelHi)@BINARY(WORD,%%MixWaveLo)@BINARY(WORD,%%MixWaveHi)@BINARY(WORD,%%hWndNotifyLo)@BINARY(WORD,%%hWndNotifyHi)@BINARY(WORD,%%FlagsLo)@BINARY(WORD,%%FlagsHi)@BINARY(WORD,%%wLoops)
#END OF STRUCTURE
#NOW PALY THE WAVE
%U = @lib(WAVMIX32,WaveMixPlay,INT:,%T)
goto EVLOOP

:BUTTON2BUTTON
:SOUND2
%%ChannelHi = 0
%%ChannelLo = 1
%%hWndNotifyHi = 0
%%hWndNotifyLo = 0
%%FlagsHi = 0
%%FlagsLo = 5
%%MixSessionHi = @LIB(hilo,HI,INT:,%I)
%%MixSessionLo = @LIB(hilo,LO,INT:,%I)
%%MixWaveHi = @LIB(hilo,HI,INT:,%L)
%%MixWaveLo = @LIB(hilo,LO,INT:,%L)
%%wLoops = 0
%T = @BINARY(WORD,24)@BINARY(WORD,%%MixSessionLo)@BINARY(WORD,%%MixSessionHi)@BINARY(WORD,%%ChannelLo)@BINARY(WORD,%%ChannelHi)@BINARY(WORD,%%MixWaveLo)@BINARY(WORD,%%MixWaveHi)@BINARY(WORD,%%hWndNotifyLo)@BINARY(WORD,%%hWndNotifyHi)@BINARY(WORD,%%FlagsLo)@BINARY(WORD,%%FlagsHi)@BINARY(WORD,%%wLoops)
%U = @lib(WAVMIX32,WaveMixPlay,INT:,%T)
goto EVLOOP

:BUTTON3BUTTON
:SOUND3
%%ChannelHi = 0
%%ChannelLo = 2
%%hWndNotifyHi = 0
%%hWndNotifyLo = 0
%%FlagsHi = 0
%%FlagsLo = 5
%%MixSessionHi = @LIB(hilo,HI,INT:,%I)
%%MixSessionLo = @LIB(hilo,LO,INT:,%I)
%%MixWaveHi = @LIB(hilo,HI,INT:,%M)
%%MixWaveLo = @LIB(hilo,LO,INT:,%M)
%%wLoops = 0
%T = @BINARY(WORD,24)@BINARY(WORD,%%MixSessionLo)@BINARY(WORD,%%MixSessionHi)@BINARY(WORD,%%ChannelLo)@BINARY(WORD,%%ChannelHi)@BINARY(WORD,%%MixWaveLo)@BINARY(WORD,%%MixWaveHi)@BINARY(WORD,%%hWndNotifyLo)@BINARY(WORD,%%hWndNotifyHi)@BINARY(WORD,%%FlagsLo)@BINARY(WORD,%%FlagsHi)@BINARY(WORD,%%wLoops)
%U = @lib(WAVMIX32,WaveMixPlay,INT:,%T)
goto EVLOOP

:BUTTON4BUTTON
:SOUND4
%%ChannelHi = 0
%%ChannelLo = 3
%%hWndNotifyHi = 0
%%hWndNotifyLo = 0
%%FlagsHi = 0
%%FlagsLo = 5
%%MixSessionHi = @LIB(hilo,HI,INT:,%I)
%%MixSessionLo = @LIB(hilo,LO,INT:,%I)
%%MixWaveHi = @LIB(hilo,HI,INT:,%N)
%%MixWaveLo = @LIB(hilo,LO,INT:,%N)
%%wLoops = 0
%T = @BINARY(WORD,24)@BINARY(WORD,%%MixSessionLo)@BINARY(WORD,%%MixSessionHi)@BINARY(WORD,%%ChannelLo)@BINARY(WORD,%%ChannelHi)@BINARY(WORD,%%MixWaveLo)@BINARY(WORD,%%MixWaveHi)@BINARY(WORD,%%hWndNotifyLo)@BINARY(WORD,%%hWndNotifyHi)@BINARY(WORD,%%FlagsLo)@BINARY(WORD,%%FlagsHi)@BINARY(WORD,%%wLoops)
%U = @lib(WAVMIX32,WaveMixPlay,INT:,%T)
goto EVLOOP

:BUTTON5BUTTON
:SOUND5
%%ChannelHi = 0
%%ChannelLo = 4
%%hWndNotifyHi = 0
%%hWndNotifyLo = 0
%%FlagsHi = 0
%%FlagsLo = 5
%%MixSessionHi = @LIB(hilo,HI,INT:,%I)
%%MixSessionLo = @LIB(hilo,LO,INT:,%I)
%%MixWaveHi = @LIB(hilo,HI,INT:,%O)
%%MixWaveLo = @LIB(hilo,LO,INT:,%O)
%%wLoops = 0
%T = @BINARY(WORD,24)@BINARY(WORD,%%MixSessionLo)@BINARY(WORD,%%MixSessionHi)@BINARY(WORD,%%ChannelLo)@BINARY(WORD,%%ChannelHi)@BINARY(WORD,%%MixWaveLo)@BINARY(WORD,%%MixWaveHi)@BINARY(WORD,%%hWndNotifyLo)@BINARY(WORD,%%hWndNotifyHi)@BINARY(WORD,%%FlagsLo)@BINARY(WORD,%%FlagsHi)@BINARY(WORD,%%wLoops)
%U = @lib(WAVMIX32,WaveMixPlay,INT:,%T)
goto EVLOOP

:BUTTON6BUTTON
:SOUND6
%%ChannelHi = 0
%%ChannelLo = 5
%%hWndNotifyHi = 0
%%hWndNotifyLo = 0
%%FlagsHi = 0
%%FlagsLo = 5
%%MixSessionHi = @LIB(hilo,HI,INT:,%I)
%%MixSessionLo = @LIB(hilo,LO,INT:,%I)
%%MixWaveHi = @LIB(hilo,HI,INT:,%P)
%%MixWaveLo = @LIB(hilo,LO,INT:,%P)
%%wLoops = 0
%T = @BINARY(WORD,24)@BINARY(WORD,%%MixSessionLo)@BINARY(WORD,%%MixSessionHi)@BINARY(WORD,%%ChannelLo)@BINARY(WORD,%%ChannelHi)@BINARY(WORD,%%MixWaveLo)@BINARY(WORD,%%MixWaveHi)@BINARY(WORD,%%hWndNotifyLo)@BINARY(WORD,%%hWndNotifyHi)@BINARY(WORD,%%FlagsLo)@BINARY(WORD,%%FlagsHi)@BINARY(WORD,%%wLoops)
%U = @lib(WAVMIX32,WaveMixPlay,INT:,%T)
goto EVLOOP

:BUTTON7BUTTON
:SOUND7
%%ChannelHi = 0
%%ChannelLo = 6
%%hWndNotifyHi = 0
%%hWndNotifyLo = 0
%%FlagsHi = 0
%%FlagsLo = 5
%%MixSessionHi = @LIB(hilo,HI,INT:,%I)
%%MixSessionLo = @LIB(hilo,LO,INT:,%I)
%%MixWaveHi = @LIB(hilo,HI,INT:,%Q)
%%MixWaveLo = @LIB(hilo,LO,INT:,%Q)
%%wLoops = 0
%T = @BINARY(WORD,24)@BINARY(WORD,%%MixSessionLo)@BINARY(WORD,%%MixSessionHi)@BINARY(WORD,%%ChannelLo)@BINARY(WORD,%%ChannelHi)@BINARY(WORD,%%MixWaveLo)@BINARY(WORD,%%MixWaveHi)@BINARY(WORD,%%hWndNotifyLo)@BINARY(WORD,%%hWndNotifyHi)@BINARY(WORD,%%FlagsLo)@BINARY(WORD,%%FlagsHi)@BINARY(WORD,%%wLoops)
%U = @lib(WAVMIX32,WaveMixPlay,INT:,%T)
goto EVLOOP

:BUTTON8BUTTON
:SOUND8
%%ChannelHi = 0
%%ChannelLo = 7
%%hWndNotifyHi = 0
%%hWndNotifyLo = 0
%%FlagsHi = 0
%%FlagsLo = 5
%%MixSessionHi = @LIB(hilo,HI,INT:,%I)
%%MixSessionLo = @LIB(hilo,LO,INT:,%I)
%%MixWaveHi = @LIB(hilo,HI,INT:,%R)
%%MixWaveLo = @LIB(hilo,LO,INT:,%R)
%%wLoops = 0
%T = @BINARY(WORD,24)@BINARY(WORD,%%MixSessionLo)@BINARY(WORD,%%MixSessionHi)@BINARY(WORD,%%ChannelLo)@BINARY(WORD,%%ChannelHi)@BINARY(WORD,%%MixWaveLo)@BINARY(WORD,%%MixWaveHi)@BINARY(WORD,%%hWndNotifyLo)@BINARY(WORD,%%hWndNotifyHi)@BINARY(WORD,%%FlagsLo)@BINARY(WORD,%%FlagsHi)@BINARY(WORD,%%wLoops)
%U = @lib(WAVMIX32,WaveMixPlay,INT:,%T)
goto EVLOOP

:close
#PUT ANY CODE TO BE EXECUTED BEFOR EXIT HERE:

############
Hotkey remove,1
Hotkey remove,2
Hotkey remove,3
Hotkey remove,4
Hotkey remove,5
Hotkey remove,6
Hotkey remove,7
Hotkey remove,8
%Z = @lib(WAVMIX32,WaveMixFreeWave,INT:,%I,%K)
%Z = @lib(WAVMIX32,WaveMixFreeWave,INT:,%I,%L)
%Z = @lib(WAVMIX32,WaveMixFreeWave,INT:,%I,%M)
%Z = @lib(WAVMIX32,WaveMixFreeWave,INT:,%I,%N)
%Z = @lib(WAVMIX32,WaveMixFreeWave,INT:,%I,%O)
%Z = @lib(WAVMIX32,WaveMixFreeWave,INT:,%I,%P)
%Z = @lib(WAVEMIX32,WaveMixCloseChannel,INT:,%I,7,1)
%Z = @lib(WAVEMIX32,WaveMixCloseSession,INT:,%I)
FREELIB @PATH(%0)hilo.dll
FREELIB @PATH(%0)WAVMIX32.dll
exit


_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sat Jul 19, 2003 5:44 pm    Post subject: Reply with quote

CodeScript, maybe it is easier for other people to make includable code. That way people who don't understand the sourcecode, can still use it... Just a thought... Wink
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Sun Jul 20, 2003 3:13 am    Post subject: Reply with quote

Skit
I have never written include scripts but I think it should be easier than the script i wrote Smile.
Also do U think that the script/or others in this section are very difficult to follow ? I always try to simplify things by commenting as much as possible.
I am busy now but will try writing one.
In the meanwhile if U want U R welcome to can write one.

BTW does the dll work fine or does it give scratchy sounds and needs configuring. I was just wondering.

Regards

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Sun Jul 20, 2003 6:26 am    Post subject: Reply with quote

It works very well on my system playing sounds and playing them simultaneously. However, I get
an "error loading library" when exiting the sample program, line 256:

Code:
%Z = @lib(WAVEMIX32,WaveMixCloseChannel,INT:,%I,7,1)


Hasta la vista, baby!

Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Sun Jul 20, 2003 3:31 pm    Post subject: Reply with quote

Dr. Dread wrote:
However, I get an "error loading library" when exiting the sample program, line 256:

Code:
%Z = @lib(WAVEMIX32,WaveMixCloseChannel,INT:,%I,7,1)

Dread


I think you R on Win 9x. In win 2k it crashes the IDE badly on exit. So it is advisable to compile and run it. I think it is a bug in the dll. It sometimes crashes VB IDE too on exit. I have tried some small workaround. The updated package may not crash the IDE on exit even on XP.

Additional info:
I have updated the package
Stereo sound has been enabled.
Better Sound quality.
Detailed step by step help file has been added !.
DLL configuration utility added.
Some small bug fixes.

Please note that I have not updated the above script posted here as it may take hours Sad on my slow dialup.

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Mon Jul 21, 2003 8:10 am    Post subject: Reply with quote

CodeScript wrote:
I think you R on Win 9x.


Nope, I'm on XP...

But, never mind. With your changes, it now works just fine! No problems so far.

Greetz
Dr. Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group