[Implemented] IsPlaying and other commands for sound

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

[Implemented] IsPlaying and other commands for sound

Post by Lebostein »

Hi,

it's possible to add
- IsPlayingSound
- IsPlayingModule
to check the status of playing?

Other basic and useful commands for the modplug library are:
- CatchModule
- ModulePan
and possibility to play modules in loop.

Thank you!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

+277282737272772 :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

From Stephan Moebius at the www.Purebasic-Lounge.de Board:

Code: Select all

Structure DSBCAPS 
  dwSize.l 
  dwFlags.l 
  dwBufferBytes.l 
  dwUnlockTransferRate.l 
  dwPlayCpuOverhead.l 
EndStructure 

Procedure _DirectSoundCB(guid,desc,module,context) 
  CopyMemory(desc,context,256) 
  ProcedureReturn 0 
EndProcedure 

Procedure IsSoundPlaying(Sound);returns weather the Sound is playing or not. 
  Address=IsSound(Sound) 
  If Address=0:ProcedureReturn 0:EndIf 
  *DSB.IDirectSoundBuffer=PeekL(Address) 
  *DSB\GetStatus(@Status) 
  If Status=1 Or Status=5 
    ProcedureReturn 1 
  EndIf 
  ProcedureReturn 0 
EndProcedure 

Procedure GetSoundPosition(Sound);returns the current position of the Sound.(in bytes) 
  Address=IsSound(Sound) 
  If Address=0:ProcedureReturn 0:EndIf 
  *DSB.IDirectSoundBuffer=PeekL(Address) 
  *DSB\GetCurrentPosition(@Position,0) 
  ProcedureReturn Position 
EndProcedure 

Procedure SetSoundPosition(Sound,Position);sets the current position of the Sound.(in bytes) 
  Address=IsSound(Sound) 
  If Address=0:ProcedureReturn 0:EndIf 
  *DSB.IDirectSoundBuffer=PeekL(Address) 
  ProcedureReturn *DSB\SetCurrentPosition(Position) 
EndProcedure 

Procedure GetSoundSize(Sound);Returns the size of the Sound in bytes. 
  Address=IsSound(Sound) 
  If Address=0:ProcedureReturn 0:EndIf 
  *DSB.IDirectSoundBuffer=PeekL(Address) 
  Caps.DSBCAPS\dwSize=SizeOf(DSBCAPS) 
  *DSB\GetCaps(@Caps) 
  ProcedureReturn Caps\dwBufferBytes 
EndProcedure 

Procedure GetSoundFrequency(Sound) 
  Address=IsSound(Sound) 
  If Address=0:ProcedureReturn 0:EndIf 
  *DSB.IDirectSoundBuffer=PeekL(Address) 
  *DSB\GetFrequency(@Freq) 
  ProcedureReturn Freq 
EndProcedure 

Procedure.s GetSoundCardName() 
  hModule=GetModuleHandle_("dsound.dll") 
  If hModule=0:ProcedureReturn "":EndIf 
  Addr=GetProcAddress_(hModule,"DirectSoundEnumerateA") 
  If Addr=0:ProcedureReturn "":EndIf 
  String$=Space(256) 
  CallFunctionFast(Addr,@_DirectSoundCB(),String$) 
  ProcedureReturn String$ 
EndProcedure 




;Example: 
InitSound() 

MessageRequester("",GetSoundCardName()) 

File$=OpenFileRequester("Load wav-file","*.wav","wav-file |*.wav",0) 

Result=LoadSound(1,File$) 

If Result=0:MessageRequester("ERROR","Can't load sound."):End:EndIf 

OpenWindow(1,0,0,400,25,#PB_Window_MinimizeGadget|#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Play") 

PlaySound(1) 
Repeat 
  Event=WindowEvent() 
  
  SetWindowTitle(1,Str(GetSoundPosition(1))+"/"+Str(GetSoundSize(1))) 
Until Event=#PB_Event_CloseWindow Or IsSoundPlaying(1)=0

Check out OOP support for PB here!
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

blueznl wrote:+277282737272772 :-)
We're not counting feature requests in quads... :twisted:

Code: Select all

Line 1: Overflow error: a 'long' value (.l) must be between -2147483648 and +4294967295
quidquid Latine dictum sit altum videtur
Post Reply