Skip to content

Commit 7fa5e57

Browse files
feat: Revamp shared libraries architecture and handling
1 parent ba57686 commit 7fa5e57

34 files changed

+2810
-414
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"rindow/rindow-math-matrix": "^2.0",
2323
"rindow/rindow-matlib-ffi": "^1.0",
2424
"rindow/rindow-openblas-ffi": "^1.0",
25-
"symfony/console": "^6.4|^7.0"
25+
"symfony/console": "^6.4|^7.0",
26+
"ffi/location": "^1.0"
2627
},
2728
"require-dev": {
2829
"pestphp/pest": "^2.31",

examples/bootstrap.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@
77

88
require_once './vendor/autoload.php';
99

10-
Transformers::setup()
11-
->setImageDriver(ImageDriver::IMAGICK)
12-
->apply();
10+
Transformers::setup()->setImageDriver(ImageDriver::IMAGICK);
1311

examples/misc/general-test.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Codewithkyrian\Transformers\FFI\Libs\FastTransformersUtils;
4+
use Codewithkyrian\Transformers\FFI\Libs\Libc;
5+
use Codewithkyrian\Transformers\FFI\Libs\Samplerate;
6+
use Codewithkyrian\Transformers\FFI\Libs\Sndfile;
7+
use Codewithkyrian\Transformers\FFI\Libs\OnnxRuntime;
8+
use Codewithkyrian\Transformers\Tensor\OpenBLASFactory;
9+
use Codewithkyrian\Transformers\Transformers;
10+
use Codewithkyrian\TransformersLibrariesDownloader\Libraries;
11+
use Rindow\Matlib\FFI\MatlibFactory;
12+
13+
include __DIR__.'/../vendor/autoload.php';
14+
15+
Transformers::setup();
16+
17+
dd(
18+
Libc::version(),
19+
Sndfile::version(),
20+
Samplerate::version(),
21+
OnnxRuntime::version(),
22+
FastTransformersUtils::version()
23+
);

examples/pipelines/asr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
$audioUrl = __DIR__ . '/../sounds/gettysburg.wav';
2424
$audioUrl = __DIR__ . '/../sounds/kyrian-speaking.wav';
2525
$audioUrl = __DIR__ . '/../sounds/ted_60.wav';
26-
//$audioUrl = __DIR__ . '/../sounds/french-audio.wav';
26+
//$audioUrl = __DIR__ . '/../sounds/sample-1.mp3';
2727

2828

2929
$output = $transcriber($audioUrl,
File renamed without changes.

includes/fast_transformers_utils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef FAST_TRANSFORMERS_UTILS_H
2+
#define FAST_TRANSFORMERS_UTILS_H
3+
4+
enum {
5+
LOG_MEL_NONE = 0,
6+
LOG_MEL_LOG = 1,
7+
LOG_MEL_LOG10 = 2,
8+
LOG_MEL_DB = 3
9+
};
10+
11+
void pad_reflect(float *input, int length, float *padded, int padded_length);
12+
13+
void spectrogram(
14+
float *waveform, int waveform_length, float *spectrogram, int spectrogram_length, int hop_length, int fft_length,
15+
float *window,int window_length, int d1, int d1_max, float power, int center, float preemphasis, float *mel_filters,
16+
int num_mel_filters, int num_frequency_bins, float mel_floor, int log_mel, int remove_dc_offset, int do_pad, int transpose
17+
);
18+
19+
#endif // FAST_TRANSFORMERS_UTILS_H

includes/matlib.h

Lines changed: 333 additions & 0 deletions
Large diffs are not rendered by default.

includes/onnxruntime.h

Lines changed: 369 additions & 0 deletions
Large diffs are not rendered by default.

includes/openblas.h

Lines changed: 426 additions & 0 deletions
Large diffs are not rendered by default.

includes/samplerate.h

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#ifndef SAMPLERATE_H
2+
#define SAMPLERATE_H
3+
4+
/* Opaque data type SRC_STATE. */
5+
typedef struct SRC_STATE_tag SRC_STATE;
6+
7+
/* SRC_DATA is used to pass data to src_simple() and src_process(). */
8+
typedef struct
9+
{ const float *data_in ;
10+
float *data_out ;
11+
12+
long input_frames, output_frames ;
13+
long input_frames_used, output_frames_gen ;
14+
15+
int end_of_input ;
16+
17+
double src_ratio ;
18+
} SRC_DATA ;
19+
20+
/*
21+
** User supplied callback function type for use with src_callback_new()
22+
** and src_callback_read(). First parameter is the same pointer that was
23+
** passed into src_callback_new(). Second parameter is pointer to a
24+
** pointer. The user supplied callback function must modify *data to
25+
** point to the start of the user supplied float array. The user supplied
26+
** function must return the number of frames that **data points to.
27+
*/
28+
29+
typedef long (*src_callback_t) (void *cb_data, float **data) ;
30+
31+
/*
32+
** Standard initialisation function : return an anonymous pointer to the
33+
** internal state of the converter. Choose a converter from the enums below.
34+
** Error returned in *error.
35+
*/
36+
37+
SRC_STATE* src_new (int converter_type, int channels, int *error) ;
38+
39+
/*
40+
** Clone a handle : return an anonymous pointer to a new converter
41+
** containing the same internal state as orig. Error returned in *error.
42+
*/
43+
SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;
44+
45+
/*
46+
** Initilisation for callback based API : return an anonymous pointer to the
47+
** internal state of the converter. Choose a converter from the enums below.
48+
** The cb_data pointer can point to any data or be set to NULL. Whatever the
49+
** value, when processing, user supplied function "func" gets called with
50+
** cb_data as first parameter.
51+
*/
52+
53+
SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
54+
int *error, void* cb_data) ;
55+
56+
/*
57+
** Cleanup all internal allocations.
58+
** Always returns NULL.
59+
*/
60+
61+
SRC_STATE* src_delete (SRC_STATE *state) ;
62+
63+
/*
64+
** Standard processing function.
65+
** Returns non zero on error.
66+
*/
67+
68+
int src_process (SRC_STATE *state, SRC_DATA *data) ;
69+
70+
/*
71+
** Callback based processing function. Read up to frames worth of data from
72+
** the converter int *data and return frames read or -1 on error.
73+
*/
74+
long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
75+
76+
/*
77+
** Simple interface for performing a single conversion from input buffer to
78+
** output buffer at a fixed conversion ratio.
79+
** Simple interface does not require initialisation as it can only operate on
80+
** a single buffer worth of audio.
81+
*/
82+
83+
int src_simple (SRC_DATA *data, int converter_type, int channels) ;
84+
85+
/*
86+
** This library contains a number of different sample rate converters,
87+
** numbered 0 through N.
88+
**
89+
** Return a string giving either a name or a more full description of each
90+
** sample rate converter or NULL if no sample rate converter exists for
91+
** the given value. The converters are sequentially numbered from 0 to N.
92+
*/
93+
94+
const char *src_get_name (int converter_type) ;
95+
const char *src_get_description (int converter_type) ;
96+
const char *src_get_version (void) ;
97+
98+
/*
99+
** Set a new SRC ratio. This allows step responses
100+
** in the conversion ratio.
101+
** Returns non zero on error.
102+
*/
103+
104+
int src_set_ratio (SRC_STATE *state, double new_ratio) ;
105+
106+
/*
107+
** Get the current channel count.
108+
** Returns negative on error, positive channel count otherwise
109+
*/
110+
111+
int src_get_channels (SRC_STATE *state) ;
112+
113+
/*
114+
** Reset the internal SRC state.
115+
** Does not modify the quality settings.
116+
** Does not free any memory allocations.
117+
** Returns non zero on error.
118+
*/
119+
120+
int src_reset (SRC_STATE *state) ;
121+
122+
/*
123+
** Return TRUE if ratio is a valid conversion ratio, FALSE
124+
** otherwise.
125+
*/
126+
127+
int src_is_valid_ratio (double ratio) ;
128+
129+
/*
130+
** Return an error number.
131+
*/
132+
133+
int src_error (SRC_STATE *state) ;
134+
135+
/*
136+
** Convert the error number into a string.
137+
*/
138+
const char* src_strerror (int error) ;
139+
140+
/*
141+
** The following enums can be used to set the interpolator type
142+
** using the function src_set_converter().
143+
*/
144+
145+
enum
146+
{
147+
SRC_SINC_BEST_QUALITY = 0,
148+
SRC_SINC_MEDIUM_QUALITY = 1,
149+
SRC_SINC_FASTEST = 2,
150+
SRC_ZERO_ORDER_HOLD = 3,
151+
SRC_LINEAR = 4,
152+
} ;
153+
154+
/*
155+
** Extra helper functions for converting from short to float and
156+
** back again.
157+
*/
158+
159+
void src_short_to_float_array (const short *in, float *out, int len) ;
160+
void src_float_to_short_array (const float *in, short *out, int len) ;
161+
162+
void src_int_to_float_array (const int *in, float *out, int len) ;
163+
void src_float_to_int_array (const float *in, int *out, int len) ;

0 commit comments

Comments
 (0)