Code Monkey home page Code Monkey logo

node-flac-bindings's Introduction

flac-bindings

Nodejs bindings to libFLAC

Node-API v8 Node CI Coverage Status

How to install

$ npm install flac-bindings

$ yarn add flac-bindings

This is a pure ESM package. If you get an error like require() of ES Module, then read this gist. If you still want to use CJS, then either import using require('flac-bindings'), use dynamic import import('flac-bindings'), or use any of the 2.7.x versions.

The library has some native code that binds the JS code to the flac library. Depending on your platform, an already-compiled library is available for you. The following logic applies:

  • If your CPU is amd64/x86_64 and the OS is Linux/glibc, Linux/musl, macOS or Windows, and node version is in the N-API compatibility table for v8, then the prebuild version will download.
  • If your CPU is arm64/aarch64 and the OS is Linux/glibc, Linux/musl or macOS, and node version is in the aformentioned compatibility table for v8, then the prebuild version will download.
  • If you have pkg-config and libFLAC development package installed (apt install libflac-dev, pacman -S flac, apk add flac-dev, brew install flac...), then it will use this library and only compile the binding code. Requires you to also have Cmake installed.
  • In any other case, it will download libogg and libFLAC source code and compile both libraries plus the binding code. Requires you to also have Cmake and git installed.

See How to compile section for more information.

How to use

For use it, include with

// ESM import (Streams and native API alias)
import {
  api,
  FileDecoder,
  StreamDecoder,
  FileEncoder,
  StreamEncoder,
} from 'flac-bindings';

// ESM import for native API
import {
  Encoder,
  Decoder,
  format,
  metadata,
  metadata0,
  SimpleIterator,
  Chain,
  Iterator,
  fns,
} from 'flac-bindings/api';

Note: this library has its own TypeScript typings, so it's possible to use it in a TS project and have the right types

Note: this library is written in ES Modules, and cannot be imported from CommonJS modules - see this

Examples

Here's an example of using flac-bindings to encode some raw PCM data coming from process.stdin to a FLAC file that gets piped to process.stdout:

import { StreamEncoder } from 'flac-bindings';

// create the Encoder instance
const encoder = new StreamEncoder({
  channels: 2,        // 2 channels (left and right)
  bitsPerSample: 16,  // 16-bit samples
  samplerate: 44100,  // 44,100 Hz sample rate

  compressionLevel: 7,
});

// raw PCM data from stdin gets piped into the encoder
process.stdin.pipe(encoder);

// the generated FLAC file gets piped to stdout
encoder.pipe(process.stdout);

See examples for more examples. See the tests directory for even more examples using advanced API.

How it works

The module is be divided in various sections:

  • StreamEncoder - a stream.Transform class for encoding raw PCM streams
  • FileEncoder - a stream.Writable class for encoding raw PCM streams into a file
  • StreamDecoder - a stream.Transform class for decoding FLAC into a PCM stream
  • FileDecoder - a stream.Readable class for decoding FLAC file into a PCM stream
  • api - the native bindings, easy to use from JS side
    • format - includes only the functions and some types
    • Encoder - the StreamEncoder API
    • Decoder - the StreamDecoder API
    • metadata - includes the StreamMetadata classes and their methods
    • metadata0 - metadata level 0 APIs
    • SimpleIterator - metadata level 1 iterator class
    • Chain - metadata level 2 Chain class
    • Iterator - metadata level 2 Iterator class

The package includes typings that could help you :)

All memory is managed by the library. But there are some methods that give you references to objects that can be destroyed before the JS object. These methods are documented with such special behaviour.

Almost every function/method expects his parameters in his right type (as in the FLAC documentation). If it not, an JS exception will be thrown, or in the worst scenario, a crash (report an issue if this happens). So, pay attention on the types of the functions (the typings are just to help you 😀).

Callbacks don't follow exactly the same signature that shows in Encoder and Decoder sections (from the FLAC documentation). They don't need some of the parameters as in JS there are other ways to get the encoder/decoder instance and some context. The init functions don't receive any private data.

There are asynchronous functions and methods for IO bound tasks. The syncrhonous API will be faster, but will block node. If you are writing an server or expect high concurrency, use the asynchronous API.

You need node version that supports v8 N-API (see compatibility table), which is supported in node v14.17.0/v16.0.0 or higher. Recommended use of BigInt when possible to have numbers be represented without truncation (Number can only store 53 bit integers! 🤨).

Note: Buffers from Encoder, Decoder and IO Callbacks (metadata level 2) have a strict lifetime: buffers are ensured to be valid inside the callback itself, if the buffer must be used outside the callback, make a copy.

Debug the library

When using StreamEncoder, StreamDecoder, FileEncoder or FileDecoder, and something does not work properly, you can enable verbose/debug logs by defining the environment variable DEBUG=flac:* (see debug package for more information). Each class has its own namespace, so you can enable debug logs only for some of them. See below the list of namespaces:

  • StreamEncoder: flac:encoder:stream
  • FileEncoder: flac:encoder:file
  • StreamDecoder: flac:decoder:stream
  • FileDecoder: flac:decoder:file
  • The post-install script: flac:build

!! These logs can be useful when creating a new issue.

You can also try to debug the native code by setting up a test JS file and launching the debugger with the node executable and arguments the script itself.

How to compile

To compile the bindings you need Cmake installed in your system and accessible from the terminal, and the C and C++ compilers as well. On Windows, the compilers can be installed easily with npm install --global --production windows-build-tools. Don't forget git. It is mandatory!

There are some options to use when compiling. The build tries to use an already installed compatible dev package of libflac (apt install libflac-dev, pacman -S flac, apk add flac-dev, brew install flac...), but with FLAC_BINDINGS_USE_FLAC_SOURCES will force to download the sources and compile everything from there.

Supported libFLAC versions are 1.3.x and 1.4.x (binary versions 10 and 12).

Then, you just need to recompile the package with: npm rebuild flac-bindings. If you are inside this repo tree, then run npm run install.

For more advanced commands for compilation inside the repo tree, see below:

# Compile (debug version)
# -p -> If desired, tell cmake to run with parallel jobs (faster)
npx cmake-js build --debug -p 4

# Compile with sanitizers (only available on Linux and macOS)
npx cmake-js configure --CDSANITIZE=ON --debug -p 4
npx cmake-js build --debug -p 4

# Force-compile with FLAC sources (can be combined with sanitizers)
npx cmake-js configure --CDUSE_FLAC_SOURCES --debug -p 4
npx cmake-js build --debug -p 4

# Clean compilation folder
npx cmake-js clean

How to run the tests

With a dev environment, and being able to compile the project, ensure to have installed the flac CLI (apt install flac, pacman -S flac, apk add flac, brew install flac...) and present in the $PATH. It is recommended to have installed the FLAC dev package. Also ensure to have installed Cmake and available in the $PATH.

The recommended steps are:

# Do not run tests with sanitizers enabled, it's tricky to make it work
npx cmake-js configure --debug
npx cmake-js build --debug -p 4
npm test

# To run tests with coverage (requires lcov to be installed)
scripts/coverage.sh rebuild # first time
script/coverage.sh          # next times

Happy npm test runs :)

The API

See the wiki for the documentation.

node-flac-bindings's People

Contributors

dependabot[bot] avatar melchor629 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

dmooney65

node-flac-bindings's Issues

Can't instantiate flac.FileDecoder

        this._dec = new flac.Decoder();
                    ^
TypeError: flac.Decoder is not a constructor
    at new FlacFileDecoder (node_modules\flac-bindings\lib\decoder.js:187:21)

Packages:

    "typescript": "^3.9.5",
    "flac-bindings": "^2.2.0",

Decoder initialization failed: Error_opening_file

Hi. I'm working on a desktop application using Electron. Flac to WAV format is used. I had a tricky problem. It worked on either an M1 chip or an Intel chip on a MAC, but when I used Windows, I had a problem.

QQ截图20220620130344

When I first saw that the file could not be opened, after checking at the code level, I replaced the delimiter of the FLAC file path with the symbol of different platforms through path.sep. But problems remain

QQ截图20220620130329

My Node version is V16.13.0. after I use "yarn install". Copy flac-bindings.node to /Release after going to node_modules/flac-bindings/build/Release

QQ截图20220620130550

QQ截图20220620130602

At present, this problem is bothering me. Please be sure to reply when you have a solution, 3Q

Miss check object on ptr

template<typename T>
static T* fromjs(const Local<Value> &m) {
  Nan::HandleScope scope;
  if(!m->IsObject()) { Nan::ThrowError(Nan::Error("Only objects accepted in metadata APIs")); return nullptr; }
  MaybeLocal<Value> ptr = Nan::Get(Nan::To<Object>(m).ToLocalChecked(), Nan::New("_ptr").ToLocalChecked());
  if(ptr.IsEmpty()) { Nan::ThrowError(Nan::Error("This object was not created by the FLAC API")); return nullptr; }
  if(!m->IsObject()) { Nan::ThrowError(Nan::Error("This object was not created by the API or was modified incorrecty")); return nullptr; }
  Local<Value> ptr2 = ptr.ToLocalChecked();
  if(!Buffer::HasInstance(ptr2)) { Nan::ThrowError(Nan::Error("This object was modified incorrectly")); return nullptr; }
  return UnwrapPointer<T>(ptr2);
}

There is a double check of !m->IsObject(), does is should be ptr.IsObject()

Support for foreign metadata RIFF chunks

Wave files can contain unofficial metadata, such as Sampler Chunk - "smpl":
https://sites.google.com/site/musicgapi/technical-documents/wav-file-format#smpl

These are used for audio looping players and samplers avoiding to loading multiple samples.

I have one such file here:
https://github.com/studiorack/basic-harmonica/blob/bf42d5bab7470cc201e3c4b6dee7925b19db6bff/samples/harmonica_1.wav

and a flac file converted using the official flac command line tool:
flac harmonica_1.wav --keep-foreign-metadata

When inspecting with exiftool it shows the RIFF metadata was copied:

$ exiftool harmonica_1.flac -G1

[RIFF]          Encoding                        : Microsoft PCM
[RIFF]          Num Channels                    : 1
[RIFF]          Sample Rate                     : 48000
[RIFF]          Avg Bytes Per Sec               : 96000
[RIFF]          Bits Per Sample                 : 16
[RIFF]          Manufacturer                    : 0
[RIFF]          Product                         : 0
[RIFF]          Sample Period                   : 20833
[RIFF]          MIDI Unity Note                 : 64
[RIFF]          MIDI Pitch Fraction             : 0
[RIFF]          SMPTE Format                    : none
[RIFF]          SMPTE Offset                    : 00:00:00:00
[RIFF]          Num Sample Loops                : 1
[RIFF]          Sampler Data Len                : 0
[RIFF]          Sampler Data                    : (Binary data 20 bytes, use -b option to extract)
[RIFF]          Unshifted Note                  : 64
[RIFF]          Fine Tune                       : 0
[RIFF]          Gain                            : 0
[RIFF]          Low Note                        : 0
[RIFF]          High Note                       : 127
[RIFF]          Low Velocity                    : 0
[RIFF]          High Velocity                   : 127
[RIFF]          Acidizer Flags                  : One shot
[RIFF]          Root Note                       : High C
[RIFF]          Beats                           : 2
[RIFF]          Meter                           : 4/4
[RIFF]          Tempo                           : 0
[RIFF]          Comment                         : Recorded on 7/10/2022 in Edison.
[RIFF]          Software                        : FL Studio 20
[Composite]     Duration                        : 0.87 s

I have tried all the metadata types in your bindings, but none appear to support the RIFF chunks:

new flac.FileEncoder({
  file: output || 'out.flac',
  compressionLevel: 9,
  metadata: [new metadata.ApplicationMetadata(), new metadata.PaddingMetadata(), new metadata.SeekTableMetadata(), new metadata.UnknownMetadata(), new metadata.VorbisCommentMetadata()]
})

How can I get this to work? Happy to submit a PR

Using flac-bindings v2.7.2 as I want my library to have backwards compatibility for CommonJS.

StreamDecoder : _le_chunks_ undefined

Hi there,

I am using this library to decode a flac stream recovered from a WebSocket.

When I pipe the flac stream into the decoder. I have the following error :

/node_modules/flac-bindings/lib/decoder.js:79
this._le_chunks[0].copy(buffer);
^

TypeError: Cannot read property '0' of undefined

The flac stream was originally encoded using this module. Do you have any idea on how to resolve this ?

When I packaged the Electron project, it didn't work

At present, everything is normal except the interruption problem mentioned in the last issue. We are currently working on packaging. But when I pack, the software crashes when I open it

QQ截图20220625160518

And I use "native-ext-loader "to process webpack, it can open, but can not to convert the format.

The first question is whether formal packaging can rely on flac-bindings under the same node_modules as DEV. Or do you need to rely directly on node files.
The second question is, how can my Webpack be configured to run properly if it is referenced directly under node_module? How can I modify my configuration to make it work if It is referenced through a Node file.

There is no detailed description of this aspect in readme. Maybe this is the first case of electron packing, so I may trouble you

New release breaks my code

I currently use "flac-bindings": "^3.0.0", with node v19.0.0

In the code I ran on node v16 I used "flac-bindings": "^2.7.0" and ran fine.

Here my code that runs fine with v2.7.0 on node v16:

var flacBindings = require('flac-bindings');
StreamEncoder = flacBindings.StreamEncoder;

Running with v3.0.0 on node v19 I get:

var flacBindings = require('flac-bindings');
                     ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/pi/rooExtend/node_modules/flac-bindings/lib/index.js from /home/pi/rooExtend/modPlay.js not supported.
Instead change the require of index.js in /home/pi/rooExtend/modPlay.js to a dynamic import() which is available in all CommonJS modules.

Changing my code as recommended to
import { StreamEncoder } from 'flac-bindings';

I see this error:

/home/pi/rooExtend/modPlay.js:111
                import { StreamEncoder } from 'flac-bindings';
                ^^^^^^

SyntaxError: Cannot use import statement outside a module

Help would be appreciated as I have to finish my new release and am stuck at that point.

Thanks' DrCWO

FLAC compressionLevel parameter is ignored

Hello again!

Low priority this one but nice to have.

  1. compressionLevel option is ignored - compression level 0 is always used.

  2. Default compression level for FLAC should be 5, but the bindings are using level 0.

Verified using flac command line tool on Ubuntu 16.04 vs bindings output.

Thanks

Installation fails on Android

Hello, I am trying to install flac-bindings on android with termux.

$ uname -a
> Linux localhost 4.9.186-perf-g344bf82 #1 SMP PREEMPT Thu Jun 11 00:40:19 CST 2020 aarch64 Android

First of all, I can see that there are prebuilts for amd64 but for some reason, it tries to compile it.
And when compiling , it fails with the following message:

$ yarn add flac-bindings
yarn add v1.22.10
info No lockfile found.
[1/4] Resolving packages...
warning flac-bindings > cmake-js > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
warning flac-bindings > cmake-js > request > [email protected]: this library is no longer supported
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
error /data/data/com.termux/files/home/test/node_modules/flac-bindings: Command failed.
Exit code: 1
Command: node scripts/flac-build.js
Arguments:
Directory: /data/data/com.termux/files/home/test/node_modules/flac-bindings
Output:
> prebuild-install -r napi
prebuild-install WARN install No prebuilt binaries found (target=6 runtime=napi arch=arm64 libc= platform=android)
> which brew >/dev/null 2>&1 && eval $(brew --env) && echo $PKG_CONFIG_LIBDIR
> PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig" pkg-config --modversion flac
> cmake-js build
[
  '/data/data/com.termux/files/usr/bin/node',
  '/data/data/com.termux/files/home/test/node_modules/flac-bindings/node_modules/.bin/cmake-js',
  'build'
]
info TOOL Using Unix Makefiles generator.
info CMD CONFIGURE
info RUN cmake "/data/data/com.termux/files/home/test/node_modules/flac-bindings" --no-warn-unused-cli -G"Unix Makefiles" -DCMAKE_JS_VERSION="6.1.0" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="/data/data/com.termux/files/home/test/node_modules/flac-bindings/build/Release" -DCMAKE_JS_INC="/data/data/com.termux/files/home/.cmake-js/node-arm64/v14.8.0/include/node" -DCMAKE_JS_SRC="" -DNODE_RUNTIME="node" -DNODE_RUNTIMEVERSION="14.8.0" -DNODE_ARCH="arm64"
Not searching for unused variables given on the command line.
-- The C compiler identification is Clang 10.0.1
-- The CXX compiler identification is Clang 10.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /data/data/com.termux/files/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /data/data/com.termux/files/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring libogg 1.3.4
-- Looking for include file inttypes.h
-- Looking for include file inttypes.h - found
-- Looking for include file stdint.h
-- Looking for include file stdint.h - found
-- Looking for include file sys/types.h
-- Looking for include file sys/types.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of int16_t
-- Check size of int16_t - done
-- Check size of uint16_t
-- Check size of uint16_t - done
-- Check size of u_int16_t
-- Check size of u_int16_t - done
-- Check size of int32_t
-- Check size of int32_t - done
-- Check size of uint32_t
-- Check size of uint32_t - done
-- Check size of u_int32_t
-- Check size of u_int32_t - done
-- Check size of int64_t
-- Check size of int64_t - done
-- Check size of short
-- Check size of short - done
-- Check size of int
-- Check size of int - done
-- Check size of long
-- Check size of long - done
-- Check size of long long
-- Check size of long long - done
-- Performing Test Iconv_IS_BUILT_IN
-- Performing Test Iconv_IS_BUILT_IN - Failed
-- Found Iconv: /data/data/com.termux/files/usr/lib/libiconv.so
-- Performing Test DODEFINE_FORTIFY_SOURCE
-- Performing Test DODEFINE_FORTIFY_SOURCE - Success
-- Performing Test HAVE_MBSTATE
-- Performing Test HAVE_MBSTATE - Success
-- Performing Test DODEFINE_EXTENSIONS
-- Performing Test DODEFINE_EXTENSIONS - Success
-- Looking for byteswap.h
-- Looking for byteswap.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for x86intrin.h
-- Looking for x86intrin.h - not found
-- Looking for fseeko
-- Looking for fseeko - found
-- Performing Test HAVE_BSWAP16
-- Performing Test HAVE_BSWAP16 - Success
-- Performing Test HAVE_BSWAP32
-- Performing Test HAVE_BSWAP32 - Success
-- Check if the system is big endian
-- Searching 16 bit integer
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Searching 16 bit integer - Using unsigned short
-- Check if the system is big endian - little endian
-- Performing Test HAVE_WERROR_FLAG
-- Performing Test HAVE_WERROR_FLAG - Success
-- Performing Test HAVE_DECL_AFTER_STMT_FLAG
-- Performing Test HAVE_DECL_AFTER_STMT_FLAG - Success
-- Performing Test HAVE_STACKREALIGN_FLAG
-- Performing Test HAVE_STACKREALIGN_FLAG - Success
-- Performing Test HAVE_WEFFCXX_FLAG
-- Performing Test HAVE_WEFFCXX_FLAG - Success
-- Performing Test HAVE_STACK_PROTECTOR_FLAG
-- Performing Test HAVE_STACK_PROTECTOR_FLAG - Success
-- Looking for cpuid.h
-- Looking for cpuid.h - not found
-- Looking for sys/param.h
-- Looking for sys/param.h - found
-- Looking for lround
-- Looking for lround - found
-- Check CPU architecture is x64
-- Check CPU architecture is x64 - no
-- Check CPU architecture is x86
-- Check CPU architecture is x86 - no
-- Looking for a ASM_NASM compiler
-- Looking for a ASM_NASM compiler - NOTFOUND
-- Looking for string.h
-- Looking for string.h - found
-- Found Intl: /data/data/com.termux/files/usr/include
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
-- Generating done
-- Build files have been written to: /data/data/com.termux/files/home/test/node_modules/flac-bindings/build
info CMD BUILD
info RUN cmake --build "/data/data/com.termux/files/home/test/node_modules/flac-bindings/build" --config Release
Scanning dependencies of target ogg
[  1%] Building C object _deps/ogg-build/CMakeFiles/ogg.dir/src/bitwise.c.o
[  2%] Building C object _deps/ogg-build/CMakeFiles/ogg.dir/src/framing.c.o
[  3%] Linking C static library libogg.a
[  3%] Built target ogg
Scanning dependencies of target FLAC
[  4%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/bitmath.c.o
[  6%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/bitreader.c.o
[  7%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/bitwriter.c.o
[  8%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/cpu.c.o
[  9%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/crc.c.o
[ 10%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/fixed.c.o
[ 12%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/fixed_intrin_sse2.c.o
[ 13%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/fixed_intrin_ssse3.c.o
[ 14%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/float.c.o
[ 15%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/format.c.o
[ 16%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/lpc.c.o
[ 18%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/lpc_intrin_sse.c.o
[ 19%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/lpc_intrin_sse2.c.o
[ 20%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/lpc_intrin_sse41.c.o
[ 21%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/lpc_intrin_avx2.c.o
[ 22%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/lpc_intrin_vsx.c.o
[ 24%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/md5.c.o
[ 25%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/memory.c.o
[ 26%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/metadata_iterators.c.o
[ 27%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/metadata_object.c.o
[ 28%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/stream_decoder.c.o
[ 30%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/stream_encoder.c.o
[ 31%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/stream_encoder_intrin_sse2.c.o
[ 32%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/stream_encoder_intrin_ssse3.c.o
[ 33%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/stream_encoder_intrin_avx2.c.o
[ 34%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/stream_encoder_framing.c.o
[ 36%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/window.c.o
[ 37%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/ogg_decoder_aspect.c.o
[ 38%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/ogg_encoder_aspect.c.o
[ 39%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/ogg_helper.c.o
[ 40%] Building C object _deps/flac-build/src/libFLAC/CMakeFiles/FLAC.dir/ogg_mapping.c.o
[ 42%] Linking C static library libFLAC.a
[ 42%] Built target FLAC
Scanning dependencies of target flac-bindings
[ 43%] Building CXX object CMakeFiles/flac-bindings.dir/src/decoder/async-decoder.cpp.o
[ 44%] Building CXX object CMakeFiles/flac-bindings.dir/src/decoder/decoder.cpp.o
[ 45%] Building CXX object CMakeFiles/flac-bindings.dir/src/encoder/async-encoder.cpp.o
[ 46%] Building CXX object CMakeFiles/flac-bindings.dir/src/encoder/encoder.cpp.o
[ 48%] Building CXX object CMakeFiles/flac-bindings.dir/src/format/format.cpp.o
[ 49%] Building CXX object CMakeFiles/flac-bindings.dir/src/index.cpp.o
[ 50%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/frame.cpp.o
[ 51%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/native_iterator.cpp.o
[ 53%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata.cpp.o
[ 54%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_application.cpp.o
[ 55%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_cuesheet.cpp.o
[ 56%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_cuesheet_index.cpp.o
[ 57%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_cuesheet_track.cpp.o
[ 59%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_padding.cpp.o
[ 60%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_picture.cpp.o
[ 61%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_seekpoint.cpp.o
[ 62%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_seektable.cpp.o
[ 63%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_streaminfo.cpp.o
[ 65%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_unknown.cpp.o
[ 66%] Building CXX object CMakeFiles/flac-bindings.dir/src/mappings/streammetadata_vorbiscomment.cpp.o
[ 67%] Building CXX object CMakeFiles/flac-bindings.dir/src/metadata/async-io-metadata2.cpp.o
[ 68%] Building CXX object CMakeFiles/flac-bindings.dir/src/metadata/metadata0.cpp.o
[ 69%] Building CXX object CMakeFiles/flac-bindings.dir/src/metadata/metadata1.cpp.o
[ 71%] Building CXX object CMakeFiles/flac-bindings.dir/src/metadata/metadata2.cpp.o
[ 72%] Building CXX object CMakeFiles/flac-bindings.dir/src/test_async.cpp.o
[ 73%] Linking CXX shared library Release/flac-bindings.node
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: _deps/flac-build/src/libFLAC/libFLAC.a(stream_decoder.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `FLAC__StreamDecoderStateString' which may bind externally can not be used when making a shared object; recompile with -fPIC
_deps/flac-build/src/libFLAC/libFLAC.a(stream_decoder.c.o): in function `FLAC__stream_decoder_get_resolved_state_string':
stream_decoder.c:(.text+0x10c0): dangerous relocation: unsupported relocation
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: _deps/flac-build/src/libFLAC/libFLAC.a(stream_encoder.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `FLAC__StreamEncoderStateString' which may bind externally can not be used when making a shared object; recompile with -fPIC
_deps/flac-build/src/libFLAC/libFLAC.a(stream_encoder.c.o): in function `FLAC__stream_encoder_get_resolved_state_string':
stream_encoder.c:(.text+0x3bd8): dangerous relocation: unsupported relocation
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: _deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `FLAC__crc8_table' which may bind externally can not be used when making a shared object; recompile with -fPIC
_deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): in function `FLAC__crc8':
crc.c:(.text+0x8): dangerous relocation: unsupported relocation
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: _deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `FLAC__crc16_table' which may bind externally can not be used when making a shared object; recompile with -fPIC
_deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): in function `FLAC__crc16':
crc.c:(.text+0x40): dangerous relocation: unsupported relocation
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: _deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `FLAC__crc16_table' which may bind externally can not be used when making a shared object; recompile with -fPIC
crc.c:(.text+0xf4): dangerous relocation: unsupported relocation
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: _deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `FLAC__crc16_table' which may bind externally can not be used when making a shared object; recompile with -fPIC
_deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): in function `FLAC__crc16_update_words32':
crc.c:(.text+0x120): dangerous relocation: unsupported relocation
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: _deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `FLAC__crc16_table' which may bind externally can not be used when making a shared object; recompile with -fPIC
_deps/flac-build/src/libFLAC/libFLAC.a(crc.c.o): in function `FLAC__crc16_update_words64':
crc.c:(.text+0x228): dangerous relocation: unsupported relocation
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/flac-bindings.dir/build.make:465: Release/flac-bindings.node] Error 1
make[1]: *** [CMakeFiles/Makefile2:320: CMakeFiles/flac-bindings.dir/all] Error 2
make: *** [Makefile:171: all] Error 2
ERR! OMG Process terminated: 2

I think I also installed all the dependencies correctly as well.
Please advise.

prebuild-install WARN install No prebuilt binaries found (target=12.18.0 runtime=node arch=x64 libc= platform=win32)

Could you please document which prebuilt binaries are available for download ? (I am on Windows 10 1909 x64)
And which version of Node are supported ? (I am using 12.18, and tested with 8, 10 and 12.14)

I have many warning while installing (compiling) flac-bindings:

D:\GitHub\Project\node_modules\flac-bindings\build_deps\flac-src\src\libFLAC\format.c(580): warning C4334: '<<' : résultat du décalage 32 bits converti implicitement en 64 bits (le décalage 64 bits est-il intentionnel ?) [D:\GitHub\Project\node_modules\flac-bindings\build_deps\flac-build\src\libFLAC\FLAC.vcxproj]

D:\GitHub\Project\node_modules\flac-bindings\build_deps\flac-src\src\libFLAC\metadata_iterators.c(579): warning C4244: 'return' : conversion de 'const __int64' en 'off_t', perte possible de données [D:\GitHub\Project\node_modules\flac-bindings\build_deps\flac-build\src\libFLAC\FLAC.vcxproj]

D:\GitHub\Project\node_modules\flac-bindings\build_deps\flac-src\src\libFLAC\window.c(71): warning C4244: 'fonction' : conversion de 'double' en 'float', perte possible de données [D:
GitHub\Project\node_modules\flac-bindings\build_deps\flac-build\src\libFLAC\FLAC.vcxproj]

Then, when executing simple code :
const it = new flac.api.SimpleIterator()
it.init(fullPath, false, false)
it.status() return 2: ERROR_OPENING_FILE

Any suggestions ?

macbook pro m1, 13.2 (22D49) can't load libflac

Hello, this is my new macbook, and i found that it cant covert flac to wav correctly.

I use node-flac-bindings v2.7.2 now

error message:

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: dlopen(/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/build/Release/flac-bindings.node, 0x0001): Library not loaded: /opt/homebrew/opt/flac/lib/libFLAC.8.dylib
Referenced from: /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/build/Release/flac-bindings.node
Reason: tried: '/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/usr/local/lib/libFLAC.8.dylib' (no such file), '/usr/lib/libFLAC.8.dylib' (no such file, not in dyld cache), '/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/usr/local/lib/libFLAC.8.dylib' (no such file), '/usr/lib/libFLAC.8.dylib' (no such file, not in dyld cache)
at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1800)
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1199:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1800)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:94:18)
at bindings (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/bindings/bindings.js:112:48)
at Object. (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/api.js:4:13)
(node:39010) UnhandledPromiseRejectionWarning: Error: dlopen(/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/build/Release/flac-bindings.node, 0x0001): Library not loaded: /opt/homebrew/opt/flac/lib/libFLAC.8.dylib
Referenced from: /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/build/Release/flac-bindings.node
Reason: tried: '/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/opt/homebrew/opt/flac/lib/libFLAC.8.dylib' (no such file), '/usr/local/lib/libFLAC.8.dylib' (no such file), '/usr/lib/libFLAC.8.dylib' (no such file, not in dyld cache), '/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/opt/homebrew/Cellar/flac/1.4.2/lib/libFLAC.8.dylib' (no such file), '/usr/local/lib/libFLAC.8.dylib' (no such file), '/usr/lib/libFLAC.8.dylib' (no such file, not in dyld cache)
at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1800)
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1199:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1800)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:94:18)
at bindings (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/bindings/bindings.js:112:48)
at Object. (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/api.js:4:13)
(node:39010) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

image

It seem like that flac.8.dylib disappear on latest macos

FLAC StreamDecoder unable to decode file when FileDecoder does

I'm experiencing a problem with a set of FLAC files I'm attempting to decode using the StreamDecoder class. I am able successfully decode other FLAC files, so this does work in some circumstances.

Do you have any idea what might be going on to cause a Readable being piped to the StreamDecoder could result in an error when playing directly from a file would not?

The following code results in an error being emitted:

const { StreamDecoder } = require('flac-bindings');
const { createReadStream } = require('fs');

const filePath = '...';

const decoder = new StreamDecoder();
const fileStream = createReadStream(filePath);

decoder.on('error', (error) => {
  console.error(error);
  process.exit(1);
});


fileStream.pipe(decoder);
decoder.pipe(process.stdout);

Output:

Trace: Decoder stream got empty: that is an issue
    at FlacStreamDecoder._readCbk (./node_modules/flac-bindings/lib/decoder.js:131:17)
{ Error: FLAC__STREAM_DECODER_ABORTED
    at FlacStreamDecoder._emitDecoderError (./node_modules/flac-bindings/lib/decoder.js:157:26)
    at FlacStreamDecoder._transform (./node_modules/flac-bindings/lib/decoder.js:70:33) code: 7 }

Process finished with exit code 1

With the FileDecoder, however, it works as expected:

const { FileDecoder } = require('flac-bindings');

const filePath = '...';

const decoder = new FileDecoder({ file: filePath });

decoder.on('error', (error) => {
  console.error(error);
  process.exit(1);
});

decoder.pipe(process.stdout);

Output:

[binary data]

Process finished with exit code 0

Illegal instruction (Core dumped) error on Synology DS718+

Hello,
I created a new docker image of my application and deployed it on my NAS. The container failed to start.
After investigation, I found that the problem is when loading flac-bindings.node.
I think it is the first time I build my image on a Intel MacOS to deploy in it on my Intel NAS, so maybe the bad version of flac-bindings.node is downloaded when creating the docker image.
So I uninstalled and reinstalled flac-bindings package in the container, but is does not solve the problem. I don't find trace of what version of the binary is downloaded when running npm install.
I tried with node 10, 12, 14 and 16 without success.

Any clue on why I can't get the good version of the binary for my NAS ? Or how I can solve the problem ?
Thanks for your support.

"Encoder has not been initialized yet" Error raised while using StreamEncoder

I am using the StreamEncoder to encode PCM data from a WebSocket and send the result to an S3 Bucket. I am initializing the encoder like this:

flacEncoder = new flac.StreamEncoder({
   channels: 1,
   bitsPerSample: 16,
   samplerate: sampleRate,
   compressionLevel: 7
});

After initialization, I pass the encoder object to the S3 uploader and begin calling flacEncoder.write when I receive PCM data on the WebSocket.

Usually, this works fine. But on one occasion, I saw in my logs that this error was raised:

throw Error::New(env, "Encoder has not been initialized yet");

Is there something I should be doing to wait for the encoder to initialize before streaming data to it? I didn't see anything in the docs or the interface.

Thanks for the great module! It's been very helpful.

Windows build errors

Hi,

Have the library running well on Linux but am having issues building for Windows.
I have cloned and successfully built flac libs from https://github.com/xiph/flac and can compile the "other" node-flac binding module successfully on Windows so am confident everything is available.

The compile works without including any external headers in the project but then fails at the linking stage. If I add the include headers to the project then the compile fails.

Does this project expect any locations or names for DLLs libs etc?

upgrade to 3.0.0, ES module error

Hi, again! The code is written in the same way as 2.7, but an error will be reported

import {FileDecoder} from "flac-bindings";
let decoder = new FileDecoder({
    file: srcPath,
})

App threw an error during load
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/flac-bindings/lib/index.js from /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts not supported.
Instead change the require of index.js in /Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts to a dynamic import() which is available in all CommonJS modules.
at Object.require.extensions. [as .js] (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:851:20)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
at Object. (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/util.ts:35:25)
at Module.m._compile (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:857:29)
at Object.require.extensions. [as .ts] (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:859:16)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
at Object. (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/windows/desktopLyricWindow.ts:3:16)
at Module.m._compile (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:857:29)
at Object.require.extensions. [as .ts] (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:859:16)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
at Object. (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/src/main/main.ts:35:46)
at Module.m._compile (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:857:29)
at Object.require.extensions. [as .ts] (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/ts-node/dist/index.js:859:16)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
at loadApplicationPackage (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:110:16)
at Object. (/Users/hoshizora-rin/Documents/important/electron/LoveLiveMusicPlayer/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:222:9)
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
at Object. (node:electron/js2c/browser_init:193:3197)
at Object../lib/browser/init.ts (node:electron/js2c/browser_init:193:3401)
at webpack_require (node:electron/js2c/browser_init:1:128)
at node:electron/js2c/browser_init:1:1200
at node:electron/js2c/browser_init:1:1267
at Function.c._load (node:electron/js2c/asar_bundle:5:13331)

24bit encoding

Hi,

I've been playing around with 24bit encoding and it looks like there's a problem.
Here's a gist that illustrates the problem.

The output.raw file is playable with aplay -f S24_LE -r 48000 -c 2 output.raw but the out.flac file is corrupt.

I played around with arecord and found that using arecord -f S24_3LE -r 48000 -c 2 > out.raw and then encoding that with FileEncoder produced a semi-playable file, but with periodic interference. Looks like something may be wrong with the 32bit to 24bit conversion?

Thanks

Crashes on node 14.x

Due to nodejs/node-addon-api#799 , using shared buffers causes crashes on node 14.x (and probably 15.x as well).
As it seems this is not going to be fixed soon, a workaround should be provided (maybe trying to do the work using the C API directly...) for node 14.x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.