Page 1 of 2

Need help to translate c++ -> PB

Posted: Sun Sep 14, 2003 12:26 am
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

Posted: Sun Sep 14, 2003 8:43 am
by dmoc
Should...

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

be...

sound=OpenSound(device.l,...

?

Posted: Sun Sep 14, 2003 9:36 am
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

Posted: Sun Sep 14, 2003 10:56 am
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 :?:

Posted: Sun Sep 14, 2003 11:29 am
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

Posted: Sun Sep 14, 2003 1:12 pm
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

Posted: Sun Sep 14, 2003 1:27 pm
by WolfgangS
Call "CallCFunction(#Library, FunktionsName$ [,Parameter1 [, Parameter2...]]) "
It´s unchanged with CallCFunction(foo)

MFG
WolfgangS

Posted: Mon Sep 15, 2003 7:16 pm
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

Posted: Mon Sep 15, 2003 8:01 pm
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

Posted: Tue Sep 16, 2003 4:57 pm
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().

Posted: Tue Sep 16, 2003 6:51 pm
by WolfgangS
Thank you for the information.

MFG
WolfgangS

Posted: Sat Sep 20, 2003 4:47 pm
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

Posted: Sat Sep 20, 2003 5:30 pm
by Num3
HURRAY!!!!

Finally working !!!

What tiped you off to CALLCOM ???

Posted: Sat Sep 20, 2003 5:45 pm
by WolfgangS
Great Sebi !!!! How do you figured out the information #play=8 ?

MFG
WolfgangS

Posted: Sat Sep 20, 2003 5:55 pm
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