Skip to content

Segmentation fault #1

@MatthD

Description

@MatthD

First thanks for your library wich is really well written! 😎

I tested some project to benchmark resampler of audio file.
With node-opushenc I am facing segmentation fault issue with this code .

I am loading a wav file and just try to send it via sox to the stdout to parse the data and then just change the sample rate from 44100 to 16000hz
If you have better and safer idea, let me know :)

// https://github.com/victorqueiroz/node-opusenc
import opus from "libopus";
import { spawn } from "child_process";
import { resolve } from "path";
import "dotenv/config";

console.log(process.env.LARGE_WAV_PATH);

const comments = new opus.opusenc.Comments();
const enc = new opus.opusenc.Encoder();
enc.createFile(
  comments,
  resolve(__dirname, "../output/output-libopus-js.ogg"),
  16000,
  2,
  0
);
const pcm = spawn("sox", [
  process.env.LARGE_WAV_PATH ||
    "/Users/dieudonn/Downloads/large-sample-usa.wav",
  "-t",
  "wav",
  "-",
]);
console.log("Start converting sample rate...");
pcm.stdout.on("data", (chunk) => {
  const samples = Math.floor(chunk.byteLength / Float32Array.BYTES_PER_ELEMENT);
  const buf = new Float32Array(samples);
  buf.set(new Float32Array(chunk.buffer, chunk.byteOffset, samples));
  enc.writeFloat(buf, samples);
});
new Promise<void>((resolve) => {
  pcm.stdout.on("exit", (code) => {
    console.log("Finished converting file");
    enc.drain();
    resolve();
  });
});

Capture d’écran 2023-10-12 à 10 06 54

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions