From f06461313ed9b45ca61c9c6bad5e622015cf68f6 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 28 Dec 2023 17:47:35 +0200 Subject: [PATCH] Return the version in little endian --- README.md | 2 +- package.json | 2 +- src/lib.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fe979e6..bfd5210 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ await analyze("/path/to/track.mp3") // returns Uint8Array ``` ## Return value -The output of `bliss-rs` consists of single-precision floats, currently 20 of them. This fork contains code to convert it into an array of 80 bytes in little endian order. An additional version (also comes from `bliss-rs`, currently equal to `1`) is prepended at the start as 16 bits in platform endianness. Therefore, the total output size is 82 bytes. +The output of `bliss-rs` consists of single-precision floats, currently 20 of them. This fork contains code to convert it into an array of 80 bytes in little endian order. An additional version (also comes from `bliss-rs`, currently equal to `1`) is prepended at the start (16-bit unsigned little-endian integer). Therefore, the total output size is 82 bytes. ### Usage The output (without the version) is meant to be converted back into floats and used to calculate the [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance#Higher_dimensions) between two songs. Other distance algorithms are being worked on by the Bliss team. diff --git a/package.json b/package.json index a532ae5..18cf9a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bliss-rs/bliss-rs", - "version": "0.0.2", + "version": "0.0.3", "description": "A fork of the bliss-rs library with Node.js bindings", "main": "index.js", "types": "index.d.ts", diff --git a/src/lib.rs b/src/lib.rs index 7377069..7f3f9c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,7 +44,7 @@ fn analyze_async(mut cx: FunctionContext) -> JsResult { Ok(promise) } -/// Returns a Uint8Array, with the first 2 bytes being the version in platform endianness +/// Returns a Uint8Array, with the first 2 bytes being the version (16-bit unsigned little endian) /// and the rest (currently 80 bytes) being the analysis data in little endian fn analyze(mut cx: FunctionContext) -> JsResult { let path = cx.argument::(0)?.value(&mut cx); @@ -65,7 +65,7 @@ fn analyze(mut cx: FunctionContext) -> JsResult { fn analyze_raw(path: &str) -> BlissResult<([u8; 2], [u8; 80])> { let song = Song::from_path(path)?; - let version_bytes = song.features_version.to_ne_bytes(); + let version_bytes = song.features_version.to_le_bytes(); let analysis_bytes = song.analysis.as_bytes(); Ok((version_bytes, analysis_bytes)) }