依赖于外部库Opus和Faac编译WebAssembly程序

时间:2018-10-11 04:25:04

标签: c webassembly

1.I git clone opus and faac。

2秒,我正在编码:

#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;
}

您可以看到,我在项目中使用作品和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为我的项目构建两个库?

谢谢。

1 个答案:

答案 0 :(得分:2)

您需要在计算机上的正确位置包括libopusfaac的源代码和头文件,类似于:

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

为了加快开发过程的速度,我建议您分别与libopus一起编译faccemcc,然后将已编译的*.dylib文件包括在构建命令中。 I did something similar with Opus in this Makefile