Need help to translate c++ -> PB

Just starting out? Need help? Post your questions and find answers here.
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Need help to translate c++ -> PB

Post by WolfgangS »

Hi !
I try to play some music via the audiere sound library(audiere.sourceforge.net. Unfortunately i had some problems with that. I need help to translate c++ code to PB. The OpenDevice function works fine but I get always 0 when I call the OpenSound function.

Is someone able to help me ?
Thanks ....WolfgangS

OpenDevice declarations in audiere.h

Code: Select all

   /**
   * Open a new audio device. If name or parameters are not specified,
   * defaults are used. Each platform has its own set of audio devices.
   * Every platform supports the "null" audio device.
   *
   * @param  name  name of audio device that should be used
   * @param  parameters  comma delimited list of audio-device parameters;
   *                     for example, "buffer=100,rate=44100"
   *
   * @return  new audio device object if OpenDevice succeeds, and 0 in case
   *          of failure
   */
  inline AudioDevice* OpenDevice(
    const char* name = 0,
    const char* parameters = 0)
  {
    return hidden::AdrOpenDevice(name, parameters);
  }


OpenSound declarations in audiere.h

Code: Select all

 * @param device  AudioDevice in which to open the output stream.
   *
   * @param source  SampleSource used to generate samples for the sound
   *                object.  OpenSound takes ownership of source, even
   *                if it returns 0.  (In that case, OpenSound immediately
   *                deletes the SampleSource.)
   *
   * @param streaming  If false or unspecified, OpenSound attempts to
   *                   open the entire sound into memory.  Otherwise, it
   *                   streams the sound from the file.
   *
   * @return  new output stream if successful, 0 otherwise
   */
  inline OutputStream* OpenSound(
    const AudioDevicePtr& device,
    const SampleSourcePtr& source,
    bool streaming = false)
  {
    return hidden::AdrOpenSound(device.get(), source.get(), streaming);
  }

The PB source UPDATED

Code: Select all

#getName= #20

Debug 1
device.l=OpenDevice(@"directsound",@"buffer=100,rate=44100")    
If device.l=0
MessageRequester("","Error open Device",0):End:EndIf

Debug PeekS(CallDX(#getName,device.l))      ; = debug device->getName() ... wow, looks cool ;)
; the above line works fine. It shows "directsound"

Debug 2
sound.l=OpenSound(device.l,@"E:\@Projekte\Audiere Player\04_Shadows_Of_Mine.mp3",#True)              
If sound.l=0     ; Unfortunately sound.l is always 0  :cry: 
MessageRequester("","Error OpenSound",0):End:EndIf
Debug 3
Last edited by WolfgangS on Sun Sep 14, 2003 11:22 am, edited 1 time in total.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Should...

sound=OpenSound(*device.l,...

be...

sound=OpenSound(device.l,...

?
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

Code: Select all

Should... 

sound=OpenSound(*device.l,... 

be... 

sound=OpenSound(device.l,... 

?
True. But now it crashes all time. Dunno why :cry:

Please HELP !
WolfgangS
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Just a little something i found out....

Purebasic does not work with dll's that are meant to work in C++, i tested many... Or it crashes, or it does not work...

Fred :?:
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

Purebasic does not work with dll's that are meant to work in C++, i tested many... Or it crashes, or it does not work...
:cry: ..... Image

I updated the source with some kind of "device->getName()" it works fine

MFG
WolfgangS
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Num3 wrote:Just a little something i found out....

Purebasic does not work with dll's that are meant to work in C++, i tested many... Or it crashes, or it does not work...

Fred :?:
Call "CallCFunction(#Library, FunktionsName$ [,Parameter1 [, Parameter2...]]) "

GPI
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

Call "CallCFunction(#Library, FunktionsName$ [,Parameter1 [, Parameter2...]]) "
It´s unchanged with CallCFunction(foo)

MFG
WolfgangS
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

I can figure it out....

Code: Select all

  /*
   * Since this file is background music, we don't need to load the
   * whole thing into memory.
   */
  OutputStreamPtr stream(OpenSound(device, "music.ogg", true));
  if (!stream) {
    // failure
  }
should be in Pure:

Code: Select all

Procedure.l OpenSound(device.l,string.l,flag.l) 
  ProcedureReturn CallCFunction(0,"_AdrOpenFile@8",device,string,flag) 
EndProcedure 

sound.l=OpenSound(device.l ,@"E:\mp3\dunas.mp3",#True)
But it just crashes
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

Num3 wrote:should be in Pure:
...
HI !
Question:How do you know you have to use CallCFunction instead of CallFunction ?
I figure it out just with try and error ...
But it is DAMNED interesting to know why it crashes all times ...

MFG
WolfgangS
Fred
Administrator
Administrator
Posts: 18263
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

WolfgangS wrote:
Num3 wrote:should be in Pure:
...
HI !
Question:How do you know you have to use CallCFunction instead of CallFunction ?
I figure it out just with try and error ...
But it is DAMNED interesting to know why it crashes all times ...

MFG
WolfgangS
You have to look closely to the C function definition and see if the functions is STDCALL or not (there is some aliases in Win32 for the STDCALL form, like WINAPI, CALLBACK etc...). If it's STDCALL, it's CallFunction(), else it's CallCFunction().
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

Thank you for the information.

MFG
WolfgangS
Sebi
New User
New User
Posts: 4
Joined: Fri Apr 25, 2003 3:34 pm

Post by Sebi »

Very simple example......

Code: Select all


FileName.s="<here the filename!!!>" ;<-- CHANGE!!!!

#audiere = 0
 
Procedure GetSupportedAudioDevices()
  ProcedureReturn CallFunction(#audiere,"_AdrGetSupportedAudioDevices@0")
EndProcedure
 
Procedure.l OpenDevice(device.l,parameter.l)
  ProcedureReturn CallFunction(#audiere,"_AdrOpenDevice@8",device.l,parameter.l)
EndProcedure
 
Procedure.l GetVersion()
  ProcedureReturn CallFunction(#audiere,"_AdrGetVersion@0")
EndProcedure
 
Procedure.l OpenSound(device.l,name.l,flag.l)
  ProcedureReturn CallFunction(#audiere,"_AdrOpenSound@12",device.l,name.l,flag.l)  ; "_AdrOpenSound@12"
EndProcedure
 
Procedure.l CreateTone(device.l,bla.l)
  ProcedureReturn CallFunction(#audiere,"_AdrCreateTone@8",device,bla.l)
EndProcedure
 
Procedure.l CreateWhiteNoise()
  ProcedureReturn CallFunction(#audiere,"_AdrCreateWhiteNoise@0")
EndProcedure
  
Procedure.l OpenSampleSource(file.s,filetyp.l)
  ProcedureReturn CallFunction(#audiere,"_AdrOpenSampleSource@8",@file,filetyp)
EndProcedure
 
Procedure _Device_getName(device.l)
  #getName=20
  ProcedureReturn CallCOM(#getName,device)
EndProcedure

Procedure _Sound_Play(sound.l)
  #play=8
  ProcedureReturn CallCOM(#play,sound)
EndProcedure

 
  If OpenConsole()=0
    MessageRequester("","Error open Console",0)
    End
  EndIf
  
  audierelib=OpenLibrary(#audiere,"audiere.dll")
  If audierelib=0
    MessageRequester("","Error open audiere.dll",0)
    End
  EndIf
  
  PrintN("Version-Info: "+PeekS(GetVersion()))
  PrintN("Devices: "+PeekS(GetSupportedAudioDevices()))

  device.l=OpenDevice(@"directsound",@"buffer=100,rate=44100")  
  
  If device.l=0
    MessageRequester("","Error open Device",0)
    End
  EndIf
  
  PrintN("-> Device opended: "+ PeekS(_Device_getName(device)))
  
  #FF_AUTODETECT=0

  samplesource = OpenSampleSource(FileName.s,#FF_AUTODETECT)

  PrintN("-> Sound opened: $"+Hex(samplesource))

  sound.l=OpenSound(device,samplesource,0)               
  If sound.l=0
    MessageRequester("","Error OpenSound",0)
    End
  EndIf
  
  _Sound_Play(sound)
  
  PrintN("-> Play!")
  
  Repeat
  ForEver
  
  ;CloseLibrary(#audiere)
Cu,
PureFan / Sebi
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

HURRAY!!!!

Finally working !!!

What tiped you off to CALLCOM ???
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

Great Sebi !!!! How do you figured out the information #play=8 ?

MFG
WolfgangS
Sebi
New User
New User
Posts: 4
Joined: Fri Apr 25, 2003 3:34 pm

Post by Sebi »

Num3/WolfgangS: Is this what you want to know?

Code: Select all

Procedure myCALLCOM( offset.l,addr.l)
  functionaddr = PeekL(PeekL(addr)+offset)
  ProcedureReturn CallFunctionFast(functionaddr ,addr)
EndProcedure
It does exactly the same as CALLCOM()/CALLDX() ! :)

The value "Offset" I just tried out... ;)

Cu,
PureFan
Post Reply