playing sound 
Author Message
 playing sound

Hi,

I have made this program to exercise maths. Now I want to add sound to
it. (it's my first real program...) The sound says "good" or "bad"
from a file. Everything works fine, except when it goes a little too
fast. Now I was wondering : is there a way to load all sounds into
memory and play them from there instead of getting them from the
harddisk every time ?

Thanks in advance !

Bart

Sorry if I've missed FAQ, but I'm new to this group and need the
answer rather quickly. Ow, and English isn't my first language ;-)



Tue, 11 May 2004 04:02:48 GMT  
 playing sound
Try this example:

Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" _
  Alias "sndPlaySoundA" (ByVal lpszSoundName _
  As String, ByVal uFlags As Long) As Long
Const SND_ALIAS = &H10000
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Const SND_LOOP = &H8
Const SND_MEMORY = &H4
Const SND_NODEFAULT = &H2
Const SND_NOSTOP = &H10
Const SND_SYNC = &H0
'Dim SoundFile As String
Dim SoundInMemory(1 To 8) As String

Private Function LoadSound(FileName As String) As String
On Error GoTo Error_Handler
Dim FreeFileNumber As Integer
Dim SoundBuffer As String
FreeFileNumber = FreeFile
SoundBuffer = Space$(FileLen(FileName))
Open FileName For Binary As #FreeFileNumber
Get #FreeFileNumber, , SoundBuffer
Close FreeFileNumber
LoadSound = Trim$(SoundBuffer)
Error_Handler:
Select Case Err
Case 0
Case Else
Err.Clear
LoadSound = ""
End Select
End Function

Private Sub Form_Load()
SoundInMemory(1) = LoadSound("c:\windows\media\notify.wav")
SoundInMemory(2) = LoadSound("c:\windows\media\chord.wav")
SoundInMemory(3) = LoadSound("c:\windows\media\chimes.wav")
End Sub

Private Sub Command1_MouseDown(Button As Integer, _
  Shift As Integer, X As Single, Y As Single)
' Play a sound file (held in memory)
sndPlaySound SoundInMemory(1), SND_ASYNC Or SND_MEMORY
End Sub

Private Sub Command2_MouseDown(Button As Integer, _
  Shift As Integer, X As Single, Y As Single)
' Play a sound file (held in memory)
sndPlaySound SoundInMemory(2), SND_ASYNC Or SND_MEMORY
End Sub

Private Sub Command3_MouseDown(Button As Integer, _
  Shift As Integer, X As Single, Y As Single)
' Play a sound file (held in memory)
sndPlaySound SoundInMemory(3), SND_ASYNC Or SND_MEMORY
End Sub


Quote:
> Hi,

> I have made this program to exercise maths. Now I want to add sound to
> it. (it's my first real program...) The sound says "good" or "bad"
> from a file. Everything works fine, except when it goes a little too
> fast. Now I was wondering : is there a way to load all sounds into
> memory and play them from there instead of getting them from the
> harddisk every time ?

> Thanks in advance !

> Bart

> Sorry if I've missed FAQ, but I'm new to this group and need the
> answer rather quickly. Ow, and English isn't my first language ;-)



Tue, 11 May 2004 04:56:34 GMT  
 playing sound
On Thu, 22 Nov 2001 20:56:34 -0000, "Maureen"

Quote:

>Try this example:

Thank you very much ! I'll try it as soon as possible !

Bart



Wed, 12 May 2004 00:55:42 GMT  
 playing sound
On Thu, 22 Nov 2001 20:56:34 -0000, "Maureen"

Quote:

>Try this example:

<snip>

Thank you very much ! I'll try it as soon as possible !

Bart



Wed, 12 May 2004 02:01:25 GMT  
 playing sound


Quote:
>On Thu, 22 Nov 2001 20:56:34 -0000, "Maureen"

>>Try this example:

>Thank you very much ! I'll try it as soon as possible !

It works just fine !! (some small modifications to suit my needs ;-)

Thank you very much !

Bart



Sat, 15 May 2004 02:24:33 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Playing sounds even if other applications are playing sounds

2. play sound after sound.

3. Urgent, How to: Play sound using sound card?

4. Urgent, How to: Play sound using sound card?

5. Play sound from OLE field

6. How to play sound coming from OLE object field in VB

7. How to Play sounds and then move to a new Record withOUT errors

8. Playing Sound file on event??!!

9. Msgbox don't play sounds, Uh?

10. Msgbox don't play sounds, uh?

11. play sound file on open

12. Playing sounds in VB.NET

 

 
Powered by phpBB® Forum Software