GPWiki.org
GPWiki.org
It is currently Wed Jun 19, 2013 10:16 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Using Multiple sounds
PostPosted: Sat Jul 11, 2009 6:44 pm 
I need help with playing wave files when a user presses a button on my game. I am currently using an API that utilizes directShow to play background music. This background music is a WAV file converted from an MP3 file. I just need to allow the user to press a button and it will play a sound effect without interrupting the background music as well.

I didn't know how sophisticated this could be.


Top
  
 
 Post subject:
PostPosted: Sun Jul 12, 2009 1:31 am 
King Code Monkey
User avatar

Joined: Wed Sep 01, 2004 3:05 pm
Posts: 11199
Location: Abingdon, MD
Well, since you didn't bother to tell us what API are we supposed to guess? ;) :lol

_________________
Bored? Head on over to my blog and see what I'm up to.

Microsoft XNA MVP


Top
 Profile  
 
 Post subject: RE: API
PostPosted: Sun Jul 12, 2009 1:48 am 
The API I am using is Microsoft Multimedia Control 6.0 w/SP3


Top
  
 
 Post subject:
PostPosted: Sun Jul 12, 2009 2:23 am 
King Code Monkey
User avatar

Joined: Wed Sep 01, 2004 3:05 pm
Posts: 11199
Location: Abingdon, MD
That's a control, not an API. I recommend upgrading to something a bit more recent.

_________________
Bored? Head on over to my blog and see what I'm up to.

Microsoft XNA MVP


Top
 Profile  
 
PostPosted: Sun Jul 12, 2009 3:54 am 
Option Explicit



Private Const MAX_VOLUME As Long = 100

Private Const MAX_BALANCE As Long = 100

Private Const MAX_SPEED As Long = 226



Public DirectShow_Event As IMediaEvent

Public DirectShow_Control As IMediaControl

Public DirectShow_Position As IMediaPosition

Public DirectShow_Audio As IBasicAudio



Public Function DirectShow_Load_Media(File_Name As String) As Boolean



On Error GoTo Error_Handler





If Right(File_Name, 4) = ".mp3" Then



Set DirectShow_Control = New FilgraphManager

DirectShow_Control.RenderFile (File_Name)



Set DirectShow_Audio = DirectShow_Control



DirectShow_Audio.Volume = 0

DirectShow_Audio.Balance = 0



Set DirectShow_Event = DirectShow_Control

Set DirectShow_Position = DirectShow_Control



DirectShow_Position.Rate = 1


DirectShow_Position.CurrentPosition = 0



Else



GoTo Error_Handler



End If



DirectShow_Load_Media = True



Exit Function



Error_Handler:



DirectShow_Load_Media = False



End Function





Public Function DirectShow_Play() As Boolean



On Error GoTo Error_Handler



DirectShow_Control.Run



DirectShow_Play = True



Exit Function



Error_Handler:



DirectShow_Play = False



End Function





Public Function DirectShow_Stop() As Boolean



On Error GoTo Error_Handler



DirectShow_Control.Stop



DirectShow_Position.CurrentPosition = 0



DirectShow_Stop = True



Exit Function



Error_Handler:



DirectShow_Stop = False



End Function





Public Function DirectShow_Pause() As Boolean



On Error GoTo Error_Handler



DirectShow_Control.Stop



DirectShow_Pause = True



Exit Function



Error_Handler:



DirectShow_Pause = False



End Function



Public Function DirectShow_Volume(ByVal Volume As Long) As Boolean



On Error GoTo Error_Handler



If Volume >= MAX_VOLUME Then Volume = MAX_VOLUME



If Volume <= 0 Then Volume = 0



DirectShow_Audio.Volume = (Volume * MAX_VOLUME) - 10000



DirectShow_Volume = True



Exit Function



Error_Handler:



DirectShow_Volume = False



End Function





Public Function DirectShow_Balance(ByVal Balance As Long) As Boolean



On Error GoTo Error_Handler



If Balance >= MAX_BALANCE Then Balance = MAX_BALANCE



If Balance <= -MAX_BALANCE Then Balance = -MAX_BALANCE



DirectShow_Audio.Balance = Balance * MAX_BALANCE



DirectShow_Balance = True



Exit Function



Error_Handler:



DirectShow_Balance = False



End Function





Public Function DirectShow_Speed(ByVal Speed As Single) As Boolean



On Error GoTo Error_Handler



If Speed >= MAX_SPEED Then Speed = MAX_SPEED



If Speed <= 0 Then Speed = 0


DirectShow_Position.Rate = Speed / 100



DirectShow_Speed = True



Exit Function



Error_Handler:



DirectShow_Speed = False



End Function





Public Function DirectShow_Set_Position(ByVal Hours As Long, ByVal Minutes As Long, ByVal Seconds As Long, Milliseconds As Single) As Boolean



On Error GoTo Error_Handler



Dim Max_Position As Single



Dim Position As Double



Dim Decimal_Milliseconds As Single



'Keep minutes within range



Minutes = Minutes Mod 60



'Keep seconds within range



Seconds = Seconds Mod 60



'Keep milliseconds within range and keep decimal



Decimal_Milliseconds = Milliseconds - Int(Milliseconds)



Milliseconds = Milliseconds Mod 1000



Milliseconds = Milliseconds + Decimal_Milliseconds



'Convert Minutes & Seconds to Position time



Position = (Hours * 3600) + (Minutes * 60) + Seconds + (Milliseconds * 0.001)



Max_Position = DirectShow_Position.StopTime



If Position >= Max_Position Then



Position = 0



GoTo Error_Handler



End If



If Position <= 0 Then



Position = 0



GoTo Error_Handler



End If



DirectShow_Position.CurrentPosition = Position



DirectShow_Set_Position = True



Exit Function



Error_Handler:



DirectShow_Set_Position = False



End Function





Public Function DirectShow_End() As Boolean



On Error GoTo Error_Handler



If DirectShow_Loop = False Then



If DirectShow_Position.CurrentPosition >= DirectShow_Position.StopTime Then DirectShow_Stop



End If



DirectShow_End = True



Exit Function



Error_Handler:



DirectShow_End = False



End Function





Public Function DirectShow_Loop() As Boolean



On Error GoTo Error_Handler



If DirectShow_Position.CurrentPosition >= DirectShow_Position.StopTime Then



DirectShow_Position.CurrentPosition = 0



End If


DirectShow_Loop = True



Exit Function



Error_Handler:



DirectShow_Loop = False



End Function


Public Sub DirectShow_Shutdown()




Set DirectShow_Audio = Nothing

Set DirectShow_Event = Nothing

Set DirectShow_Control = Nothing

Set DirectShow_Position = Nothing


Top
  
 
 Post subject: Resolved
PostPosted: Sun Jul 12, 2009 5:33 am 
I found the solution, thanks anyway. And here it is...

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long)

Top 2 lines are 1 line instead of 2

As Long
Dim returnval As Long
Dim soundfile As String
returnval = PlaySound("c:\vb6\vb98\RPGSounds\button3.wav", 0, &H0)


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: Baidu [Spider] and 1 guest


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

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group