Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 69 additions & 37 deletions src/pocketsphinx/ad.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
Copyright (c) 2017 Damian Woroch, http://r1me.pl }

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$mode delphi}{$H+}
{$ENDIF}

interface

uses
dynlibs;

const
{$IFDEF Linux}
sphinxadlib = 'libsphinxad.so.3';
Expand Down Expand Up @@ -41,43 +44,72 @@ ad_rec_s = record
ad_rec_t = ad_rec_s;
pad_rec_t = ^ad_rec_t;

{**
* Open a specific audio device for recording.
*
* The device is opened in non-blocking mode and placed in idle state.
*
* @return pointer to read-only ad_rec_t structure if successful, NULL
* otherwise. The return value to be used as the first argument to
* other recording functions.
*}
function ad_open_dev(const dev: PUTF8Char; samples_per_sec: Integer): pad_rec_t; cdecl; external sphinxadlib;

{**
* Open the default audio device with a given sampling rate.
*}
function ad_open_sps(samples_per_sec: Integer): pad_rec_t; cdecl; external sphinxadlib;

{**
* Open the default audio device.
*}
function ad_open: pad_rec_t; cdecl; external sphinxadlib;

{* Start audio recording. Return value: 0 if successful, <0 otherwise *}
function ad_start_rec(rec: pad_rec_t): Integer; cdecl; external sphinxadlib;

{* Stop audio recording. Return value: 0 if successful, <0 otherwise *}
function ad_stop_rec(rec: pad_rec_t): Integer; cdecl; external sphinxadlib;

{* Close the recording device. Return value: 0 if successful, <0 otherwise *}
function ad_close(rec: pad_rec_t): Integer; cdecl; external sphinxadlib;

{*
* Read next block of audio samples while recording; read upto max samples into buf.
* Return value: # samples actually read (could be 0 since non-blocking); -1 if not
* recording and no more samples remaining to be read from most recent recording.
*}
function ad_read(rec: pad_rec_t; buf: Pointer; max: Integer): Integer; cdecl; external sphinxadlib;
type
{**
* Open a specific audio device for recording.
*
* The device is opened in non-blocking mode and placed in idle state.
*
* @return pointer to read-only ad_rec_t structure if successful, NULL
* otherwise. The return value to be used as the first argument to
* other recording functions.
*}
Tad_open_dev = function (const dev: PUTF8Char; samples_per_sec: Integer): pad_rec_t; cdecl;

{**
* Open the default audio device with a given sampling rate.
*}
Tad_open_sps = function (samples_per_sec: Integer): pad_rec_t; cdecl;

{**
* Open the default audio device.
*}
Tad_open = function : pad_rec_t; cdecl;

{* Start audio recording. Return value: 0 if successful, <0 otherwise *}
Tad_start_rec = function (rec: pad_rec_t): Integer; cdecl;

{* Stop audio recording. Return value: 0 if successful, <0 otherwise *}
Tad_stop_rec = function (rec: pad_rec_t): Integer; cdecl;

{* Close the recording device. Return value: 0 if successful, <0 otherwise *}
Tad_close = function(rec: pad_rec_t): Integer; cdecl;

{*
* Read next block of audio samples while recording; read upto max samples into buf.
* Return value: # samples actually read (could be 0 since non-blocking); -1 if not
* recording and no more samples remaining to be read from most recent recording.
*}
Tad_read = function (rec: pad_rec_t; buf: Pointer; max: Integer): Integer; cdecl;

var
Lib: TLibHandle;
ad_open_dev: Tad_open_dev;
ad_open_sps: Tad_open_sps;
ad_open: Tad_open;
ad_start_rec: Tad_start_rec;
ad_stop_rec: Tad_stop_rec;
ad_close: Tad_close;
ad_read: Tad_read;

implementation

procedure LoadLibrary;
begin
Lib := DynLibs.LoadLibrary(sphinxadlib);
if Lib <> DynLibs.NilHandle then
begin
ad_open_dev := GetProcAddress(Lib, 'ad_open_dev');
ad_open_sps := GetProcAddress(Lib, 'ad_open_sps');
ad_open := GetProcAddress(Lib, 'ad_open');
ad_start_rec := GetProcAddress(Lib, 'ad_start_rec');
ad_stop_rec := GetProcAddress(Lib, 'ad_stop_rec');
ad_close := GetProcAddress(Lib, 'ad_close');
ad_read := GetProcAddress(Lib, 'ad_read');
end;
end;

initialization
LoadLibrary;

end.
27 changes: 24 additions & 3 deletions src/pocketsphinx/cmd_ln.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
Copyright (c) 2017 Damian Woroch, http://r1me.pl }

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$mode delphi}{$H+}
{$ENDIF}

interface

uses
dynlibs;

const
{$IFDEF Linux}
sphinxbaselib = 'libsphinxbase.so.3';
Expand Down Expand Up @@ -39,16 +42,34 @@ interface
* @param strict Whether to fail on duplicate or unknown arguments.
* @return A cmd_ln_t* containing the results of command line parsing, or NULL on failure.
*}
function cmd_ln_init(inout_cmdln: pcmd_ln_t; defn: parg_t; bfailunk: Boolean): pcmd_ln_t; cdecl; varargs external sphinxbaselib;
Tcmd_ln_init = function(inout_cmdln: pcmd_ln_t; defn: parg_t; bfailunk: Boolean): pcmd_ln_t; cdecl varargs;

{**
* Release a command-line argument set and all associated strings.
*
* @return new reference count (0 if freed completely)
*}
function cmd_ln_free_r(cmdln: pcmd_ln_t): Integer; cdecl; external sphinxbaselib;
Tcmd_ln_free_r = function(cmdln: pcmd_ln_t): Integer; cdecl;

var
Lib: TLibHandle;
cmd_ln_init: Tcmd_ln_init;
cmd_ln_free_r: Tcmd_ln_free_r;

implementation

procedure LoadLibrary;
begin
Lib := DynLibs.LoadLibrary(sphinxbaselib);
if Lib <> DynLibs.NilHandle then
begin
cmd_ln_init := GetProcAddress(Lib, 'cmd_ln_init');
cmd_ln_free_r := GetProcAddress(Lib, 'cmd_ln_free_r');
end;
end;

initialization
LoadLibrary;

end.

Loading