Some checks failed
Bindings Tests (Go) / ubuntu-22 (push) Failing after 31s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/ppc64le, icx, icpx, ON) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/ppc64le, icx, icpx, ON) (push) Failing after 3s
CI (vad) / vad (push) Failing after 3s
CI (wasm) / emscripten (Release) (push) Failing after 4s
Bindings Tests (Ruby) / ubuntu-22 (push) Failing after 37s
CI (android) / android (push) Failing after 16s
CI (android) / android_java (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Release) (push) Failing after 2s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Release) (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-low-perf (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-high-perf (push) Failing after 2s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Release) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Release) (push) Failing after 4s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Release) (push) Failing after 3s
CI (quantize) / quantize (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (ADDRESS) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (THREAD) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (UNDEFINED) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm64, icx, icpx, ON) (push) Failing after 3s
Examples WASM / deploy-wasm-github-pages (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (20.x) (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (22.x) (push) Failing after 2s
CI (coreml) / coreml-base-en (push) Has been cancelled
CI (self-hosted) / gpu-vulkan (push) Has been cancelled
CI (self-hosted) / npu-amd-windows (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm2 (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Debug) (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Release) (push) Has been cancelled
CI (self-hosted) / gpu-cuda (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-low-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf-sve (push) Has been cancelled
CI (freebsd) / freeBSD-latest (push) Has been cancelled
CI (self-hosted) / gpu-metal (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Debug) (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Release) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=iOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=macOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=tvOS) (push) Has been cancelled
CI (self-hosted) / npu-amd-linux (push) Has been cancelled
CI (windows) / windows-msys2 (Release, clang, clang-x86_64, CLANG64) (push) Has been cancelled
CI (windows) / windows-msys2 (Release, gcc, ucrt-x86_64, UCRT64) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-cuda.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-cuda]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-intel.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-intel]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-musa.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-musa]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-vulkan]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-vulkan-arm64]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-arm64]) (push) Has been cancelled
Mark inactive issues stale / mark-issues (push) Failing after 1s
112 lines
2.5 KiB
C
112 lines
2.5 KiB
C
#include <ruby.h>
|
|
#include <ruby/memory_view.h>
|
|
#include <ruby/encoding.h>
|
|
|
|
typedef struct {
|
|
VALUE audio_path;
|
|
int n_samples;
|
|
const char *audio_path_str;
|
|
float *data;
|
|
short *samples;
|
|
} jfk_alloc_args;
|
|
|
|
static VALUE
|
|
jfk_reader_alloc_resources(VALUE arg)
|
|
{
|
|
jfk_alloc_args *a = (jfk_alloc_args *)arg;
|
|
a->audio_path_str = StringValueCStr(a->audio_path);
|
|
a->data = ALLOC_N(float, a->n_samples);
|
|
a->samples = ALLOC_N(short, a->n_samples);
|
|
return Qnil;
|
|
}
|
|
|
|
static VALUE
|
|
jfk_reader_initialize(VALUE self, VALUE audio_path)
|
|
{
|
|
rb_iv_set(self, "audio_path", audio_path);
|
|
return Qnil;
|
|
}
|
|
|
|
static bool
|
|
jfk_reader_get_memory_view(const VALUE obj, rb_memory_view_t *view, int flags)
|
|
{
|
|
VALUE audio_path = rb_iv_get(obj, "audio_path");
|
|
// n_samples is a fixed constant (not derived from user input).
|
|
const int n_samples = 176000;
|
|
|
|
jfk_alloc_args args = {
|
|
.audio_path = audio_path,
|
|
.n_samples = n_samples,
|
|
.audio_path_str = NULL,
|
|
.data = NULL,
|
|
.samples = NULL,
|
|
};
|
|
|
|
int state;
|
|
rb_protect(jfk_reader_alloc_resources, (VALUE)&args, &state);
|
|
if (state) {
|
|
if (args.samples) xfree(args.samples);
|
|
if (args.data) xfree(args.data);
|
|
return false;
|
|
}
|
|
|
|
FILE *file = fopen(args.audio_path_str, "rb");
|
|
if (file == NULL) {
|
|
xfree(args.samples);
|
|
xfree(args.data);
|
|
return false;
|
|
}
|
|
|
|
fseek(file, 78, SEEK_SET);
|
|
fread(args.samples, sizeof(short), n_samples, file);
|
|
fclose(file);
|
|
for (int i = 0; i < n_samples; i++) {
|
|
args.data[i] = args.samples[i] / 32768.0;
|
|
}
|
|
xfree(args.samples);
|
|
|
|
view->obj = obj;
|
|
view->data = (void *)args.data;
|
|
view->byte_size = sizeof(float) * n_samples;
|
|
view->readonly = true;
|
|
view->format = "e";
|
|
view->item_size = sizeof(float);
|
|
view->item_desc.components = NULL;
|
|
view->item_desc.length = 0;
|
|
view->ndim = 1;
|
|
view->shape = NULL;
|
|
view->sub_offsets = NULL;
|
|
view->private_data = NULL;
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
jfk_reader_release_memory_view(const VALUE obj, rb_memory_view_t *view)
|
|
{
|
|
if (view->data) {
|
|
xfree(view->data);
|
|
view->data = NULL;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
jfk_reader_memory_view_available_p(const VALUE obj)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static const rb_memory_view_entry_t jfk_reader_view_entry = {
|
|
jfk_reader_get_memory_view,
|
|
jfk_reader_release_memory_view,
|
|
jfk_reader_memory_view_available_p
|
|
};
|
|
|
|
void Init_jfk_reader(void)
|
|
{
|
|
VALUE cJFKReader = rb_define_class("JFKReader", rb_cObject);
|
|
rb_memory_view_register(cJFKReader, &jfk_reader_view_entry);
|
|
rb_define_method(cJFKReader, "initialize", jfk_reader_initialize, 1);
|
|
}
|