【问题标题】:Compile WebAssembly program dependent on external libraries Opus and Faac编译依赖于外部库 Opus 和 Faac 的 WebAssembly 程序
【发布时间】:2018-10-11 04:25:03
【问题描述】:

1.I git clone opus 和 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;
}

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

谢谢。

【问题讨论】:

    标签: c webassembly


    【解决方案1】:

    您需要将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
    

    为了加快开发速度,我建议您将libopusfaccemcc 分开编译,然后将编译后的*.dylib 文件包含到您的构建命令中。 I did something similar with Opus in this Makefile

    【讨论】:

    • 明白了,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    相关资源
    最近更新 更多