编译依赖外部库 Opus 和 Faac 的 WebAssembly 程序
Compile WebAssembly program dependent on external libraries Opus and Faac
1.I git 克隆 opus 和 faac。
2.second,我正在编码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <opus.h>
#include <faac.h>
void Opus2AacInit() {
int err_code = 0;
unsigned long input_samples = 0;
decoder = opus_decoder_create(SAMPLE_RATE, CHANNELS, &err_code);
if ( err_code < 0 ) {
flag = FALSE;
DebugPrint("%s Opus2Pcm-> opus_decoder_create err_code < 0, err_code:%d\n", ERROR, err_code);
return;
}
enc_handle = faacEncOpen(SAMPLE_RATE, CHANNELS, &input_samples, &max_output_bytes);
if ( enc_handle == NULL ) {
flag = FALSE;
DebugPrint("%s Opus2AacInit-> hEncoder == NULL, failed\n", ERROR);
return;
}
pcm_buffer_size = input_samples * PCM_BIT_SIZE / 8;
DebugPrint("%s Opus2AacInit-> input_samples:%lu, max_output_bytest:%lu, pcm_buffer_size:%d\n", INFO, input_samples, max_output_bytes, pcm_buffer_size);
aac_buffer = (unsigned char *)malloc(max_output_bytes);
pcm_buffer = (unsigned char *)malloc(pcm_buffer_size);
enc_configuration = faacEncGetCurrentConfiguration(enc_handle);
enc_configuration->inputFormat = FAAC_INPUT_16BIT;
aac_ret = faacEncSetConfiguration(enc_handle, enc_configuration);
flag = TRUE;
}
你可以看到,我在我的项目中使用了 opus 和 aac。但是当我编译我的项目以使用 webassembly 时出现问题。
emcc ../hello/aac/opus2aac.c -s WASM=1 -s "MODULARIZE=1" -s "EXPORT_NAME='Opus2Aac'" -s "BINARYEN_METHOD='native-wasm'" -s "EXPORTED_FUNCTIONS=['_Opus2AacInit', '_Opus2Aac', '_test']" -o ../hello/aac/opus2aac.js -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
#include <opus.h>
^~~~~~~~
1 error generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
所以,我不知道如何使用 webassembly 为我的项目构建两个库?
谢谢。
您需要将 libopus
和 faac
的源代码和头文件包含在您计算机上的适当位置,类似于:
emcc \
-o ../hello/aac/opus2aac.js \
-s WASM=1 -s "MODULARIZE=1" -s "EXPORT_NAME='Opus2Aac'" \
-s "BINARYEN_METHOD='native-wasm'" \
-s "EXPORTED_FUNCTIONS=['_Opus2AacInit', '_Opus2Aac', '_test']" \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \
-I "$LIBOPUS_DIR/include" \
-I "$FAAC_DIR/include" \
"$LIBOPUS_DIR" \
"$FAAC_DIR" \
../hello/aac/opus2aac.c
为了加快开发速度,我建议您使用 emcc
分别编译 libopus
和 facc
,然后将编译后的 *.dylib
文件包含到您的构建命令中. I did something similar with Opus in this Makefile
1.I git 克隆 opus 和 faac。
2.second,我正在编码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <opus.h>
#include <faac.h>
void Opus2AacInit() {
int err_code = 0;
unsigned long input_samples = 0;
decoder = opus_decoder_create(SAMPLE_RATE, CHANNELS, &err_code);
if ( err_code < 0 ) {
flag = FALSE;
DebugPrint("%s Opus2Pcm-> opus_decoder_create err_code < 0, err_code:%d\n", ERROR, err_code);
return;
}
enc_handle = faacEncOpen(SAMPLE_RATE, CHANNELS, &input_samples, &max_output_bytes);
if ( enc_handle == NULL ) {
flag = FALSE;
DebugPrint("%s Opus2AacInit-> hEncoder == NULL, failed\n", ERROR);
return;
}
pcm_buffer_size = input_samples * PCM_BIT_SIZE / 8;
DebugPrint("%s Opus2AacInit-> input_samples:%lu, max_output_bytest:%lu, pcm_buffer_size:%d\n", INFO, input_samples, max_output_bytes, pcm_buffer_size);
aac_buffer = (unsigned char *)malloc(max_output_bytes);
pcm_buffer = (unsigned char *)malloc(pcm_buffer_size);
enc_configuration = faacEncGetCurrentConfiguration(enc_handle);
enc_configuration->inputFormat = FAAC_INPUT_16BIT;
aac_ret = faacEncSetConfiguration(enc_handle, enc_configuration);
flag = TRUE;
}
你可以看到,我在我的项目中使用了 opus 和 aac。但是当我编译我的项目以使用 webassembly 时出现问题。
emcc ../hello/aac/opus2aac.c -s WASM=1 -s "MODULARIZE=1" -s "EXPORT_NAME='Opus2Aac'" -s "BINARYEN_METHOD='native-wasm'" -s "EXPORTED_FUNCTIONS=['_Opus2AacInit', '_Opus2Aac', '_test']" -o ../hello/aac/opus2aac.js -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
#include <opus.h>
^~~~~~~~
1 error generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
所以,我不知道如何使用 webassembly 为我的项目构建两个库?
谢谢。
您需要将 libopus
和 faac
的源代码和头文件包含在您计算机上的适当位置,类似于:
emcc \
-o ../hello/aac/opus2aac.js \
-s WASM=1 -s "MODULARIZE=1" -s "EXPORT_NAME='Opus2Aac'" \
-s "BINARYEN_METHOD='native-wasm'" \
-s "EXPORTED_FUNCTIONS=['_Opus2AacInit', '_Opus2Aac', '_test']" \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \
-I "$LIBOPUS_DIR/include" \
-I "$FAAC_DIR/include" \
"$LIBOPUS_DIR" \
"$FAAC_DIR" \
../hello/aac/opus2aac.c
为了加快开发速度,我建议您使用 emcc
分别编译 libopus
和 facc
,然后将编译后的 *.dylib
文件包含到您的构建命令中. I did something similar with Opus in this Makefile