DzikoSoft Excel Gaming Forum
September 06, 2010, 11:24:16 PM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Excel Games Library now lists over 150 games!
Home
Help
Login
Register
DzikoSoft Excel Gaming Forum
>
Excel Gaming
>
Developers' Lair
(Moderators:
Clut
,
Thargoid
) >
Multiple sounds playing in Excel
Pages: [
1
]
« previous
next »
Print
Author
Topic: Multiple sounds playing in Excel (Read 676 times)
Faz
Apprentice
Posts: 45
Multiple sounds playing in Excel
«
on:
February 21, 2010, 12:57:48 PM »
I know DirectX has been around for a while, but I've always thought that Excel was only capable of playing one sound at a time. I found this code that proves me wrong...
I've changed it slightly to help show what it does. Also, you MUST have DirectX 7 registered with VB on your computer for this to work. If you don't it can easily be added. Enter this code in to a module of a new workbook, go to Object Browser, right-click and check References. Scroll down the list to find 'DirectX 7', tick the box and OK the window. Here is the code...
Private obj As DirectX7
Public theDirectSound As DirectSound
Public theBufferDesc As DxVBLib.DSBUFFERDESC
Public theWaveFormat As DxVBLib.WAVEFORMATEX
Public testSound As DirectSoundBuffer
Sub Auto_Open()
Set obj = New DirectX7
Set theDirectSound = obj.DirectSoundCreate("")
Call theDirectSound.SetCooperativeLevel(Application.Hwnd, DSSCL_PRIORITY)
theBufferDesc.lFlags = DSBCAPS_CTRLFREQUENCY Or DSBCAPS_CTRLPAN _
Or DSBCAPS_CTRLVOLUME Or DSBCAPS_STATIC
theWaveFormat.nFormatTag = 1
theWaveFormat.nChannels = 2
theWaveFormat.lSamplesPerSec = 22050
theWaveFormat.nBitsPerSample = 16
theWaveFormat.nBlockAlign = theWaveFormat.nBitsPerSample * 8 / theWaveFormat.nChannels
theWaveFormat.lAvgBytesPerSec = theWaveFormat.lSamplesPerSec * theWaveFormat.nBlockAlign
End Sub
Public Function playTestSound()
Set testSound = theDirectSound.CreateSoundBufferFromFile(ThisWorkbook.Path & "\Test.wav", theBufferDesc, theWaveFormat)
Call testSound.Play(DSBPLAY_LOOPING)
End Function
To test this, just make sure you have a test wav file in the same folder as the new workbook you have created, call the wav file “Test”. Then run the Auto_Open macro.
You can use CreateSoundBufferFromFile any number of times so you can be using multiple sound objects at the same time. Even better, each sound object has individual controls for volume, panning and frequency/pitch!
Logged
Faz
Apprentice
Posts: 45
Re: Multiple sounds playing in Excel
«
Reply #1 on:
March 15, 2010, 04:08:46 AM »
I made a video a few days ago to demonstrate the use of multiple sounds. Has anyone else got this to work yet? If you don't have directx7, all you need for it to work is the DLL file and you're good to go. I know this because my computer doesn't have it so I copied the DLL from a friend and put it on mine. It was as simple as doing that and then running something like a REG program to register the DLL by giving it the file path. So redicilously and surprisingly simple. No need to download or install software or anything like that.
http://www.youtube.com/watch?v=lwoEtLocO6U
Logged
Ched80
Spellcaster
Gender:
Posts: 67
Re: Multiple sounds playing in Excel
«
Reply #2 on:
March 16, 2010, 02:44:07 AM »
hey faz,
This is an excellent find. I haven't started experimenting with this yet, but I'm definitely going to. Sound can add so much atmosphere to a game. you can't imagine bioshock without hearing the dripping and creaking of rapture so why should excel gamers play in silence.
Have you thought about writing a short tutorial for bart's website? It would be an excellent addition.
Logged
Thargoid
Moderator
Gender:
Posts: 48
Re: Multiple sounds playing in Excel
«
Reply #3 on:
March 16, 2010, 04:35:03 PM »
True - to a point.
The first time I played Doom, it was without sound.
I damn near soiled my pants.
Logged
Faz
Apprentice
Posts: 45
Re: Multiple sounds playing in Excel
«
Reply #4 on:
March 17, 2010, 06:06:41 AM »
Quote
I damn near soiled my pants.
Wow! It was that good without sound?
Logged
Thargoid
Moderator
Gender:
Posts: 48
Re: Multiple sounds playing in Excel
«
Reply #5 on:
March 18, 2010, 03:52:07 PM »
Oh yes.
It's lost a lot of impact now but it was stunning back in the day.
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Excel Gaming
-----------------------------
=> Excel Games - General
=> Developers' Lair
=> Project RPG.XLS: The Buried Curse
-----------------------------
Off -topic
-----------------------------
=> Coffee Break
Loading...