Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer #51

Open
LuvbCa opened this issue Dec 9, 2020 · 4 comments
Open

Buffer #51

LuvbCa opened this issue Dec 9, 2020 · 4 comments
Labels

Comments

@LuvbCa
Copy link

LuvbCa commented Dec 9, 2020

Please describe the problem you are having in as much detail as possible:
When i try to construct the Method OpusEncoder node exits with errno 4294930435 or with Error: Cannot create a Buffer larger than 0x100000000 bytes.

The first one occurs only when rate is set to 32000 on the constructor and the scond on on every other rate

Include a reproducible code sample here, if possible:
just construct OpusEncoder.

import Microphone from 'node-microphone'
import { io } from 'socket.io-client'
import { OpusEncoder } from '@discordjs/opus'

const socket = io("http://localhost:3000");
const encoder = new OpusEncoder(16000, 2);


var mic = new Microphone({
    bitwidth: 16,
    channels: 1,
    rate: 32000,
    encoding: 'unsigned-integer',
    endian: 'big'
});

var micStream = mic.startRecording();

micStream.on('data', (data) => {
    var encodedData = encoder.encode(data);
    console.log(encodedData);
    socket.emit('stream', data);
});

Further details:
the problem occurs in line 6

  • @discordjs/opus version:

  • Node.js version: 15.3.0

  • Operating system: Windows 10 Pro 64bit

  • Priority this issue should have – please be realistic and elaborate if possible:
    medium

@LuvbCa LuvbCa added the bug Something isn't working label Dec 9, 2020
@mikkeldamsgaard
Copy link

mikkeldamsgaard commented Mar 22, 2021

You need to make sure that the length of the argument to encoder.encode() is a multiple of 2.5ms. Since you are encoding with 16000 and two channels (!) that would be multiple of 1622.5 = 80 frames that is 160 bytes. A good normal window size is 20ms, so that would make you have the data buffer at 8*160 bytes exactly.

That said, then the implementation does not check for the return value of int compressedLength = opus_encode(this->encoder, pcm, frameSize, &(this->outOpus[0]), MAX_PACKET_SIZE);. If the data buffer is not exactly aligned it returns -1 which in unsigned form is 0x100000000 and that generates the error as the code tries to allocate a buffer right after this call with the compressedLength.

@LuvbCa
Copy link
Author

LuvbCa commented Apr 5, 2021

im currently not working on that project anymore but i will need it in the near future, so im thankful for your answer! i will close this issue when i get to try this!

@iCrawl iCrawl added question and removed bug Something isn't working labels Apr 16, 2021
@iocmet
Copy link

iocmet commented May 4, 2022

You need to make sure that the length of the argument to encoder.encode() is a multiple of 2.5ms. Since you are encoding with 16000 and two channels (!) that would be multiple of 16_2_2.5 = 80 frames that is 160 bytes. A good normal window size is 20ms, so that would make you have the data buffer at 8*160 bytes exactly.

That said, then the implementation does not check for the return value of int compressedLength = opus_encode(this->encoder, pcm, frameSize, &(this->outOpus[0]), MAX_PACKET_SIZE);. If the data buffer is not exactly aligned it returns -1 which in unsigned form is 0x100000000 and that generates the error as the code tries to allocate a buffer right after this call with the compressedLength.

and how i can fix it?

@AxioDev
Copy link

AxioDev commented Apr 28, 2023

Up, thanks for your answer, but can you provide a code example to solve the problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants