npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sbc-decoder

v1.0.1

Published

SBC 音频格式解码库,基于 Node.js 原生扩展实现,支持 SBC 格式音频数据解码为 PCM 数据。

Readme

sbc-decoder

SBC 音频格式解码库,基于 Node.js 原生扩展实现,支持 SBC 格式音频数据解码为 PCM 数据。

安装

npm install sbc-decoder

基本使用

JavaScript 示例

const SBC = require('sbc-decoder');
const fs = require('fs');

// 初始化 SBC 解码器
const initResult = SBC.init();
if (initResult !== 0) {
  console.error('解码器初始化失败');
  process.exit(1);
}

// 读取 SBC 编码文件
const sbcData = fs.readFileSync('input.sbc');

// 准备目标缓冲区(根据实际需求调整大小,通常 PCM 数据量大于 SBC 数据)
const pcmBuffer = Buffer.alloc(sbcData.length * 4); // 预估缓冲区

// 解码 SBC 数据
const decodedLength = SBC.decode(sbcData, sbcData.length, pcmBuffer);

if (decodedLength > 0) {
  console.log(`解码成功,PCM 数据长度:${decodedLength} 字节`);
  // 写入解码后的 PCM 数据(16位音频格式)
  fs.writeFileSync('output.pcm', pcmBuffer.slice(0, decodedLength));
} else {
  console.error('解码失败');
}

TypeScript 示例

import SBC from 'sbc-decoder';
import fs from 'fs';

// 初始化解码器
const initResult = SBC.init();
if (initResult !== 0) {
  console.error('解码器初始化失败');
  process.exit(1);
}

// 读取 SBC 数据
const sbcData = fs.readFileSync('input.sbc');
const pcmBuffer = Buffer.alloc(sbcData.length * 4);

// 解码
const decodedLength = SBC.decode(sbcData, sbcData.length, pcmBuffer);

if (decodedLength > 0) {
  console.log(`解码成功,长度: ${decodedLength} 字节`);
  fs.writeFileSync('output.pcm', pcmBuffer.slice(0, decodedLength));
} else {
  console.error('解码失败');
}

API 说明

init(): number

初始化 SBC 解码器。

  • 返回值0 表示初始化成功,非 0 表示初始化失败。

decode(srcBuffer: Buffer, dataLen: number, dstBuffer: Buffer): number

解码 SBC 格式音频数据到 PCM 格式。

  • 参数
    • srcBuffer:包含 SBC 编码数据的缓冲区
    • dataLen:SBC 数据的长度(字节数)
    • dstBuffer:用于存储解码后 PCM 数据的缓冲区(需提前分配足够空间)
  • 返回值:解码后的 PCM 数据长度(字节数),0 表示解码失败。

注意事项

  1. 必须先调用 init() 并确保返回 0 后,才能调用 decode() 方法
  2. dstBuffer 需要提前分配足够的空间,建议大小为 SBC 数据长度的 4 倍以上
  3. 解码后的 PCM 数据为 16 位音频格式
  4. 支持的采样率由 SBC 编码格式决定,包括 16000Hz、32000Hz、44100Hz、48000Hz

许可证

MIT 许可证,详见 LICENSE 文件。