Recent

Author Topic: Dynamic load of PortAudio is here !  (Read 9354 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 1670
    • miXimum is the DJ's best friend
Dynamic load of PortAudio is here !
« on: July 12, 2012, 10:51:50 pm »
Hello Lazarus lovers.  ::)

Im very happy to announce that the dynamic library loader for PortAudio library is ready.

Download lazdyn_portaudio.pas and the famous TestPAbasic_dynamic_LCL example here :

https://sites.google.com/site/fiensprototyping/dynportaudio.tar.gz

PS 1 : For Linux : In the example there is a 64 bits portaudio lib.   You have to compile the example with Lazarus 64 bits to load it.

PS 2 : For Windows, it is the 32 bits portaudio.dll then you must compile the test example with a 32 bits version of Lazarus.

PS 3 : PS 1 and PS 2 because it seems that Lazarus can dynamically load only libraries with same bits that the version of Lazarus.

PS 4 : Of course you may use the PortAudio lib of your choice, i give that lib only for testing.

PS 5 : For Mac OSX, the library is there but i do not have try it...

OK, see my next post...

Have fun
« Last Edit: July 13, 2012, 01:49:15 am by Fred vS »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Dynamic load of PortAudio is here !
« Reply #1 on: July 12, 2012, 11:03:32 pm »
Quote
it seems that Lazarus can dynamically load only libraries with same bits

I don't think that's just a limitation of FPC, there is no thunking between 32/64 bit like they used to be with 16/32 bit, so any communication between 32/64 is done via IPC.  Well, this is the case with Windows, not sure about MacOS/Linux.

Fred vS

  • Hero Member
  • *****
  • Posts: 1670
    • miXimum is the DJ's best friend
Re: Dynamic load of PortAudio is here !
« Reply #2 on: July 13, 2012, 01:41:25 am »
Hello everybody.

Here complete package for Linux, Windows and MacOSX (all system tested and with example compiled).

https://sites.google.com/site/fiensprototyping/dynportaudio.tar.gz

Cheers
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 1670
    • miXimum is the DJ's best friend
Re: Dynamic load of PortAudio is here !
« Reply #3 on: July 13, 2012, 12:00:10 pm »
Hello.
I have upgraded the package. (see first post). Now the sine wave example is included (yes, PortAudio can do noise  :) ).

The Lazdyn_Portaudio.pas has changed as well, this version works better for Windows.

Cheers
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Dynamic load of PortAudio is here !
« Reply #4 on: July 13, 2012, 12:16:11 pm »
Nice, Fred, thanks a lot!

Haven't looked at it, but you might want to promote your work a bit:
Posting this on the Third Party Announcements section might get some exposure.

Wiki pages:

Thanks,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Fred vS

  • Hero Member
  • *****
  • Posts: 1670
    • miXimum is the DJ's best friend
Re: Dynamic load of PortAudio is here !
« Reply #5 on: July 13, 2012, 12:32:51 pm »
@ BigChimp : Thanks for the thanks  :)

I gonna take a look at your links.

I love Lazarus but, in my opinion, the Audio part of the project is a little "light".

The next step is to do it with Libsndfile and create some easy and friendly audio procedure using both PortAudio and Libsndfile.

Cheers
« Last Edit: July 13, 2012, 12:52:00 pm by Fred vS »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 1670
    • miXimum is the DJ's best friend
Re: Dynamic load of PortAudio is here !
« Reply #6 on: July 13, 2012, 12:42:52 pm »
@ BigChimp : I have seen that you have included in the Bass library section the old link to my DJ's application : http://members.lycos.co.uk/mixk/.

This is a obsolete link, could you change it with the new and operational one ?
https://sites.google.com/site/fiensprototyping/

PS: You forget to write that miXimum is working for Linux, Windows and Mac osX as well.   :-[

Many thanks.
« Last Edit: July 13, 2012, 12:55:08 pm by Fred vS »
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Dynamic load of PortAudio is here !
« Reply #7 on: July 13, 2012, 12:54:59 pm »
@Fred: No idea about which page you are talking about regarding those links; I didn't edit anything regarding miximum today. If I did so in the past, it's a long time ago...

Fortunately you can modify the wiki yourself ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Fred vS

  • Hero Member
  • *****
  • Posts: 1670
    • miXimum is the DJ's best friend
Re: Dynamic load of PortAudio is here !
« Reply #8 on: July 13, 2012, 12:58:59 pm »
@ BigChimp : it is in the Bass section of :

http://wiki.lazarus.freepascal.org/Multimedia_Programming#PortAudio;

Ok, i gonna try to do it by myself (i never do it and did not know that it was possible to edit-change it.)

Bye
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

HomePlaneR

  • New member
  • *
  • Posts: 34
Re: Dynamic load of PortAudio is here !
« Reply #9 on: February 02, 2013, 01:50:51 pm »
Fred vS,

I've succeeded to plug PortAudio to my project thanks to your header file. Now I have my native output through MMSystem and several others provided by PortAudio.  8-)

I made some modifications of your code and, as the original license recommends, I'm putting it here in order to share it.

There was an error with Pa_IsFormatSupported: instead of passing the stream parameter records, pointers must be passed: PPaStreamParameters instead of PaStreamParameters (Lots of "P" at the beginning: non-conventional type naming led to the error. Maybe there are some more errors of this kind.)

Also, I added the reference counting for loading and unloading and formatted the code a little bit (your original code was formatted so well that even JEDI in Lazarus version I use refused to fix up the formatting  :) ).

Code: [Select]
{
    - Reference counting and some code formatting are added
    - Pa_IsFormatSupported fixed: PaStreamParameters -> PPaStreamParameters in arguments
        by Max Karpushin, homeplaner@yandex.ru
}

{This is the Dynamic loadinng version of PortAudio.pas from the HuMuS team.
 You can choose the folder and file of the PortAudio library with Pa_load() and
 release it with Pa_unload().

 Fred van Stappen / fiens@hotmail.com
 }

{
  PortAudio bindings for FPC by the HuMuS team.
  Latest version available at: http://sourceforge.net/apps/trac/humus/

  Copyright (c) 2009-2010 HuMuS Project
  Maintained by Roland Schaefer

  PortAudio Portable Real-Time Audio Library
  Latest version available at: http://www.portaudio.com

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  The text above constitutes the entire PortAudio license; however,
  the PortAudio community also makes the following non-binding requests:

  Any person wishing to distribute modifications to the Software is
  requested to send the modifications to the original developer so that
  they can be incorporated into the canonical version. It is also
  requested that these non-binding requests be included along with the
  license above.
}


unit LazDyn_PortAudio;



interface

uses dynlibs, CTypes;


type
  PaError = CInt32;
  PaErrorCode =(
    paNotInitialized := -10000,
    paUnanticipatedHostError,
    paInvalidChannelCount,
    paInvalidSampleRate,
    paInvalidDevice,
    paInvalidFlag,
    paSampleFormatNotSupported,
    paBadIODeviceCombination,
    paInsufficientMemory,
    paBufferTooBig,
    paBufferTooSmall,
    paNullCallback,
    paBadStreamPtr,
    paTimedOut,
    paInternalError,
    paDeviceUnavailable,
    paIncompatibleHostApiSpecificStreamInfo,
    paStreamIsStopped,
    paStreamIsNotStopped,
    paInputOverflowed,
    paOutputUnderflowed,
    paHostApiNotFound,
    paInvalidHostApi,
    paCanNotReadFromACallbackStream,
    paCanNotWriteToACallbackStream,
    paCanNotReadFromAnOutputOnlyStream,
    paCanNotWriteToAnInputOnlyStream,
    paIncompatibleStreamHostApi,
    paBadBufferPtr,
    paNoError := 0
  );


  PaDeviceIndex = CInt32;
 
  PaHostApiIndex = CInt32;
 
 
  PaHostApiTypeId =(paInDevelopment := 0,
    paDirectSound := 1,   
    paMME := 2,
    paASIO := 3,
    paSoundManager := 4,
    paCoreAudio := 5,
    paOSS := 7,
    paALSA := 8,
    paAL := 9,
    paBeOS := 10,
    paWDMKS := 11,
    paJACK := 12,
    paWASAPI := 13,
    paAudioScienceHPI := 14
  );
 
 
  PaHostApiInfo = record
    structVersion : CInt32;
    _type : PaHostApiTypeId ;
    _name : PChar;
    deviceCount : CInt32;
    defaultInputDevice : PaDeviceIndex;
    defaultOutputDevice : PaDeviceIndex;
  end;
  PPaHostApiInfo = ^PaHostApiInfo;
 
 
  PaHostErrorInfo = record
    hostApiType : PaHostApiTypeId;
    errorCode : CLong;
    errorText : PChar;
  end;
  PPaHostErrorInfo = ^PaHostErrorInfo;
 
 
  PaTime = CDouble;
 
  PaSampleFormat = pCULongLong;
 
 
  PaDeviceInfo = record
    structVersion : CInt32;
    _name : PChar;
    hostApi : PaHostApiIndex;
    maxInputChannels : CInt32;
    maxOutputChannels : CInt32;
    defaultLowInputLatency : PaTime;
    defaultLowOutputLatency : PaTime;
    defaultHighInputLatency : PaTime;
    defaultHighOutputLatency : PaTime;
    defaultSampleRate : CDouble;
  end;
  PPaDeviceInfo = ^PaDeviceInfo;


  PaStreamParameters = record
    device : PaDeviceIndex;
    channelCount : CInt32;
    sampleFormat : PaSampleFormat;
    suggestedLatency : PaTime;
    hostApiSpecificStreamInfo : Pointer;
  end;
  PPaStreamParameters = ^PaStreamParameters;


  // ************************* Streaming types *************************

  PaStream = Pointer;
  PPaStream = ^PaStream;
  PPPaStream = ^PPaStream;

  PaStreamFlags = CULong;

  PaStreamCallbackTimeInfo = record
    inputBufferAdcTime : PaTime;
    currentTime : PaTime;
    outputBufferDacTime : PaTime;
  end;
  PPaStreamCallbackTimeInfo = ^PaStreamCallbackTimeInfo;
 

  PaStreamCallbackFlags = CULong;


  PaStreamCallbackResult =(
    paContinue := 0,
    paComplete := 1,
    paAbort := 2);
 
 
  PaStreamCallback = function(
    input : Pointer;
    output : Pointer;
    frameCount : CULong;
    timeInfo : PPaStreamCallbackTimeInfo;
    statusFlags : PaStreamCallbackFlags;
    userData : Pointer) : CInt32;
  PPaStreamCallback = ^PaStreamCallback; 


  PaStreamFinishedCallback = procedure(userData : Pointer);
  PPaStreamFinishedCallback = ^PaStreamFinishedCallback;


  PaStreamInfo = record
    structVersion : CInt32;
    inputLatency : PaTime;
    outputLatency : PaTime;
    sampleRate : CDouble;
  end;
  PPaStreamInfo = ^PaStreamInfo;



const
  paFormatIsSupported = 0;
  paFramesPerBufferUnspecified = 0;
  paNoDevice = PaDeviceIndex(-1);
  paUseHostApiSpecificDeviceSpecification = PaDeviceIndex(-2);
  paFloat32 = PaSampleFormat($00000001);
  paInt32 = PaSampleFormat($00000002);
  paInt24 = PaSampleFormat($00000004);
  paInt16 = PaSampleFormat($00000008);
  paInt8 = PaSampleFormat($00000010);
  paUInt8 = PaSampleFormat($00000020);
  paCustomFormat = PaSampleFormat($00010000);
  paNonInterleaved = PaSampleFormat($80000000);

  paNoFlag = PaStreamFlags(0);
  paClipOff = PaStreamFlags($00000001);
  paDitherOff = PaStreamFlags($00000002);
  paNeverDropInput = PaStreamFlags($00000004);
  paPrimeOutputBuffersUsingStreamCallback = PaStreamFlags($00000008);
  paPlatformSpecificFlags = PaStreamFlags($FFFF0000);

  paInputUnderflow = PaStreamCallbackFlags($00000001);
  paInputOverflow = PaStreamCallbackFlags($00000002);
  paOutputUnderflow = PaStreamCallbackFlags($00000004);
  paOutputOverflow = PaStreamCallbackFlags($00000008);
  paPrimingOutput = PaStreamCallbackFlags($00000010);

  ////// Dynamic load : Vars that will hold our dynamically loaded functions...

// *************************** functions *******************************

var Pa_GetVersion: function():CInt32 ; cdecl;

var Pa_GetVersionText: function():PChar ; cdecl;

var Pa_GetErrorText: function(errorCode : PaError):PChar ; cdecl;

var Pa_Initialize: function():PaError ; cdecl;

var Pa_Terminate: function():PaError ; cdecl;

var Pa_GetHostApiCount: function():PaHostApiIndex ; cdecl;

var Pa_GetDefaultHostApi: function():PaHostApiIndex ; cdecl;

var Pa_GetHostApiInfo: function(hostApi : PaHostApiIndex):PPaHostApiInfo ; cdecl;

var Pa_HostApiTypeIdToHostApiIndex: function(_type : PaHostApiTypeId):PaHostApiIndex ; cdecl;

var Pa_HostApiDeviceIndexToDeviceIndex: function(hostApi : PaHostApiIndex;hostApiDeviceIndex : CInt32):PaDeviceIndex ; cdecl;

var Pa_GetLastHostErrorInfo: function():PPaHostErrorInfo ; cdecl;

// ************** Device enumeration and capabilities ******************

var Pa_GetDeviceCount: function:PaDeviceIndex ; cdecl;

var Pa_GetDefaultInputDevice: function:PaDeviceIndex ; cdecl;

var Pa_GetDefaultOutputDevice: function:PaDeviceIndex ; cdecl;

var Pa_GetDeviceInfo: function(device : PaDeviceIndex):PPaDeviceInfo ; cdecl;

var Pa_IsFormatSupported: function(inputParameters,outputParameters : PPaStreamParameters; sampleRate : CDouble):PaError ; cdecl;

// *********************** Stream function *****************************

var Pa_OpenStream: function(
  stream : PPPaStream;
  inputParameters : PPaStreamParameters;
  outputParameters : PPaStreamParameters;
  sampleRate : CDouble;
  framesPerBuffer : CULong;
  streamFlags : PaStreamFlags;
  streamCallback : PPaStreamCallback;
  userData : Pointer
):PaError ; cdecl;

var Pa_OpenDefaultStream: function(
  stream : PPPaStream;
  numInputChannels : CInt32;
  numOutputChannels : CInt32;
  sampleFormat : PaSampleFormat;
  sampleRate : CDouble;
  framesPerBuffer : CULong;
  streamCallback : PPaStreamCallback;
  userData : Pointer
):PaError ; cdecl;

var Pa_CloseStream: function(stream : PPaStream):PaError ; cdecl;

var Pa_SetStreamFinishedCallback: function(stream : PPaStream; streamFinishedCallback : PPaStreamFinishedCallback):PaError ; cdecl;

var Pa_StartStream: function(stream : PPaStream):PaError ; cdecl;

var Pa_StopStream: function(stream : PPaStream):PaError ; cdecl;

var Pa_AbortStream: function(stream : PPaStream):PaError ; cdecl;

var Pa_IsStreamStopped: function(stream : PPaStream):PaError ; cdecl;

var Pa_IsStreamActive: function(stream : PPaStream):PaError ; cdecl;

var Pa_GetStreamInfo: function(stream : PPaStream):PPaStreamInfo ; cdecl;

var Pa_GetStreamTime: function(stream : PPaStream):Patime ; cdecl;

var Pa_GetStreamCpuLoad: function(stream : PPaStream):CDouble ; cdecl;

var Pa_ReadStream: function(stream : PPaStream; buffer : Pointer;frames : CULong):PaError ; cdecl;

var Pa_WriteStream: function(stream : PPaStream; buffer : Pointer;frames : CULong):PaError ; cdecl;

var Pa_GetStreamReadAvailable: function(stream : PPaStream):CSLong ; cdecl;

var Pa_GetStreamWriteAvailable: function(stream : PPaStream):CSLong ; cdecl;

// ****************** Miscellaneous utilities **************************

var Pa_GetSampleSize: function(format : PaSampleFormat):PaError ; cdecl;

var Pa_Sleep: function(msec : CLong) : integer; cdecl;

///////////////////////////////////////////////

{Special function for dynamic loading of lib ...}

Function Pa_Load(const libfilename:string) :boolean; // load the lib

Procedure Pa_Unload(); // unload and frees the lib from memory : do not forget to call it before close application.

function Pa_IsLoaded : boolean; inline;

/////////////////////////////////////////////////////////////////////////////////////////////////

implementation

var Pa_Handle:TLibHandle = dynlibs.NilHandle; // this will hold our handle for the lib; it functions nicely as a mutli-lib prevention unit as well...

  ReferenceCounter : cardinal = 0;  // Reference counter


Function Pa_Load (const libfilename:string) :boolean;
begin
  Result := False;
  if Pa_Handle <> dynlibs.NilHandle then
  begin
    result:=true; {is it already there ?}
    //Reference counting
    Inc(ReferenceCounter);
  end
  else begin {go & load the library}
    if Length(libfilename) = 0 then exit;
    Pa_Handle:=DynLibs.LoadLibrary(libfilename); // obtain the handle we want
  if Pa_Handle <> DynLibs.NilHandle then
    begin {now we tie the functions to the VARs from above}
      Pointer(Pa_GetVersion)
        := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetVersion'));
      Pointer(Pa_GetVersionText)
        := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetVersionText'));
      Pointer(Pa_GetErrorText)
        := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetErrorText'));
      Pointer(Pa_Initialize)
        := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_Initialize'));
      Pointer(Pa_Terminate)
        := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_Terminate'));
      Pointer(Pa_GetHostApiCount)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetHostApiCount'));
      Pointer(Pa_GetDefaultHostApi)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetDefaultHostApi'));
      Pointer(Pa_GetHostApiInfo)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetHostApiInfo'));
      Pointer(Pa_HostApiTypeIdToHostApiIndex)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_HostApiTypeIdToHostApiIndex'));
      Pointer(Pa_HostApiDeviceIndexToDeviceIndex)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_HostApiDeviceIndexToDeviceIndex'));
      Pointer(Pa_GetLastHostErrorInfo)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetLastHostErrorInfo'));
      //////////////////
      Pointer(Pa_GetDeviceCount)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetDeviceCount'));
      Pointer(Pa_GetDefaultInputDevice)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetDefaultInputDevice'));
      Pointer(Pa_GetDefaultOutputDevice)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetDefaultOutputDevice'));
      Pointer(Pa_GetDeviceInfo)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetDeviceInfo'));
      Pointer(Pa_IsFormatSupported)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_IsFormatSupported'));
      //////////////////////
      Pointer(Pa_OpenStream)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_OpenStream'));
      Pointer(Pa_OpenDefaultStream)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_OpenDefaultStream'));
      Pointer(Pa_CloseStream)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_CloseStream'));
      Pointer(Pa_SetStreamFinishedCallback)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_SetStreamFinishedCallback'));
      Pointer(Pa_StartStream)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_StartStream'));
      Pointer(Pa_StopStream)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_StopStream'));
      Pointer(Pa_AbortStream)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_AbortStream'));
      Pointer(Pa_IsStreamStopped)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_IsStreamStopped'));
      Pointer(Pa_IsStreamActive)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_IsStreamActive'));
      Pointer(Pa_GetStreamInfo)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetStreamInfo'));
      Pointer(Pa_GetStreamTime)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetStreamTime'));
      Pointer(Pa_GetStreamCpuLoad)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetStreamCpuLoad'));
      Pointer(Pa_ReadStream)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_ReadStream'));
      Pointer(Pa_WriteStream)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_WriteStream'));
      Pointer(Pa_GetStreamReadAvailable)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetStreamReadAvailable'));
      Pointer(Pa_GetStreamWriteAvailable)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetStreamWriteAvailable'));
      Pointer(Pa_GetSampleSize)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_GetSampleSize'));
      Pointer(Pa_Sleep)
      := DynLibs.GetProcedureAddress(PA_Handle, PChar('Pa_Sleep'));
    end;
    Result := Pa_IsLoaded;
    ReferenceCounter:=1;
  end;
end;


Procedure Pa_Unload;
begin
  // < Reference counting
  if ReferenceCounter > 0 then
    dec(ReferenceCounter);
  if ReferenceCounter > 0 then
    exit;
  // >
  if Pa_IsLoaded then
  begin
    Pa_Terminate();
    DynLibs.UnloadLibrary(Pa_Handle);
    Pa_Handle:=DynLibs.NilHandle;
  end;
end;


function Pa_IsLoaded: boolean;
begin
 Result := (Pa_Handle <> dynlibs.NilHandle);
end;


end.
« Last Edit: February 02, 2013, 01:54:44 pm by HomePlaneR »

Fred vS

  • Hero Member
  • *****
  • Posts: 1670
    • miXimum is the DJ's best friend
Re: Dynamic load of PortAudio is here !
« Reply #10 on: February 02, 2013, 02:25:54 pm »
@ HomePlaneR

Many thanks, i gonna check it out and add it to UOS.  ;D
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs