Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vassbo committed Feb 27, 2025
1 parent ac33874 commit e518a66
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
# npm ci is better, but requires package-lock.json file
run: npm install

# Needed for OPUS
- name: Rebuild Native Modules
run: npx electron-rebuild

- name: Build and release app
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
"filter": [
"connector-*"
]
},
{
"from": "node_modules/@discordjs/opus",
"to": "app.asar.unpacked/node_modules/@discordjs/opus"
}
],
"mac": {
Expand Down
18 changes: 15 additions & 3 deletions src/electron/audio/processAudio.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import { OpusEncoder } from "@discordjs/opus"
import { NdiSender } from "../ndi/NdiSender"

// const isStopping = false
const channelCount = 2
const sampleRate = 48000 // Hz

const opusEncoder = new OpusEncoder(sampleRate, channelCount)
let opusEncoder: any = null
try {
const { OpusEncoder } = require("@discordjs/opus")
opusEncoder = new OpusEncoder(sampleRate, channelCount)
} catch (err) {
console.log("OPUS not found!")
}

export async function processAudio(buffer: Buffer, timeDelay = 0) {
if (!opusEncoder) return

/* optionally delay the processing */
const offset = timeDelay
if (offset > 0) await new Promise((resolve) => setTimeout(resolve, offset))
// if (isStopping) return

// decode raw OPUS packets into raw PCM/interleaved/signed-int16/little-endian data
buffer = opusEncoder.decode(buffer)
try {
buffer = opusEncoder.decode(buffer)
} catch (err) {
console.log("Could not process audio.")
return
}

NdiSender.sendAudioBufferNDI(buffer, { sampleRate, channelCount })
// Object.keys(NdiSender.NDI).forEach((id) => {
Expand Down

0 comments on commit e518a66

Please sign in to comment.