-
-
Save rodgarcialima/9001325941003ec6b43afc239e1eeb64 to your computer and use it in GitHub Desktop.
libchromaprint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <emscripten/emscripten.h> | |
#include "chromaprint.h" | |
extern "C" { | |
EMSCRIPTEN_KEEPALIVE | |
uintptr_t js_chromaprint_new(int algorithm) { | |
return (uintptr_t)chromaprint_new(algorithm); | |
} | |
EMSCRIPTEN_KEEPALIVE | |
int js_chromaprint_start(uintptr_t ctx, int sample_rate, int num_channels) { | |
return chromaprint_start((ChromaprintContextPrivate *)ctx, sample_rate, num_channels); | |
} | |
EMSCRIPTEN_KEEPALIVE | |
void js_chromaprint_free(uintptr_t ctx) { | |
chromaprint_free((ChromaprintContextPrivate *)ctx); | |
} | |
EMSCRIPTEN_KEEPALIVE | |
void js_chromaprint_dealloc(uintptr_t ptr) { | |
chromaprint_dealloc((void *)ptr); | |
} | |
EMSCRIPTEN_KEEPALIVE | |
int js_chromaprint_feed(uintptr_t ctx, uintptr_t data, int size) { | |
return chromaprint_feed((ChromaprintContextPrivate *)ctx, (int16_t *)data, size); | |
} | |
EMSCRIPTEN_KEEPALIVE | |
int js_chromaprint_finish(uintptr_t ctx) { | |
return chromaprint_finish((ChromaprintContextPrivate *)ctx); | |
} | |
EMSCRIPTEN_KEEPALIVE | |
uintptr_t js_chromaprint_fingerprint(uintptr_t ctx) { | |
char *fp = NULL; | |
chromaprint_get_fingerprint((ChromaprintContextPrivate *)ctx, &fp); | |
return (uintptr_t)fp; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make sure chromaprint source is in $PWD/chromaprint | |
# after run use $PWD/chromaprint/libchromaprint.min.js | |
# does not use --bind and set NO_DYNAMIC_EXECUTION to generate code | |
# that don't use eval | |
CC = emcc | |
CXX = em++ | |
CFLAGS = -O2 -DUSE_KISSFFT=1 -Isrc -Ivendor/kissfft | |
CXXFLAGS = -O2 -std=c++11 -DUSE_KISSFFT=1 -Isrc -Ivendor/kissfft | |
LDFLAGS = \ | |
-s MODULARIZE=1 \ | |
-s EXPORT_NAME="'libchromaprint'" \ | |
-s TOTAL_MEMORY=100000000 \ | |
-s NO_DYNAMIC_EXECUTION=1 \ | |
-s NO_EXIT_RUNTIME=1 \ | |
-s NO_FILESYSTEM=1 \ | |
-s ELIMINATE_DUPLICATE_FUNCTIONS=1 | |
OBJS = \ | |
src/chromaprint.o \ | |
src/audio_processor.o \ | |
src/chroma.o \ | |
src/chroma_resampler.o \ | |
src/chroma_filter.o \ | |
src/spectrum.o \ | |
src/fft_lib_kissfft.o \ | |
src/fft.o \ | |
src/fingerprinter.o \ | |
src/image_builder.o \ | |
src/simhash.o \ | |
src/silence_remover.o \ | |
src/fingerprint_calculator.o \ | |
src/fingerprint_compressor.o \ | |
src/fingerprint_decompressor.o \ | |
src/fingerprinter_configuration.o \ | |
src/fingerprint_matcher.o \ | |
src/utils/base64.o \ | |
src/avresample/resample2.o \ | |
vendor/kissfft/kiss_fft.o \ | |
vendor/kissfft/tools/kiss_fftr.o \ | |
jsbindings.o | |
all: libchromaprint.js libchromaprint.min.js | |
libchromaprint.js: $(OBJS) | |
$(CC) $(LDFLAGS) $(OBJS) -o $@ | |
%.min.js: %.js | |
java -jar /emscripten/third_party/closure-compiler/compiler.jar \ | |
--language_in ECMASCRIPT5 \ | |
--js_output_file $@ $< | |
docker: | |
docker run \ | |
--rm -ti \ | |
-v "$(PWD)/chromaprint:/src" \ | |
-v "$(PWD)/Makefile:/src/Makefile" \ | |
-v "$(PWD)/jsbindings.cpp:/src/jsbindings.cpp" \ | |
apiaryio/emcc make clean all | |
clean: | |
rm -f libchromaprint.js libchromaprint.min.js $(OBJS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment