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

mmap() failed on Raspberry Pi #124

Open
JasXSL opened this issue Oct 28, 2018 · 1 comment
Open

mmap() failed on Raspberry Pi #124

JasXSL opened this issue Oct 28, 2018 · 1 comment

Comments

@JasXSL
Copy link

JasXSL commented Oct 28, 2018

Possibly related to #90

I can play a short sound a few times, and then it crashes

mmap() failed: Cannot allocate memory
Failed to create permanent mapping for memfd region with ID = 909071082
mmap() failed: Cannot allocate memory
Failed to create permanent mapping for memfd region with ID = 3399700439
Ignoring received block reference with non-registered memfd ID = 3399700439
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Protocol error

[../deps/mpg123/src/output/alsa.c:165] error: cannot open device default
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: open() failed: -1
    at Speaker._open (/home/pi/halloween/node_modules/speaker/index.js:106:13)
    at Speaker._write (/home/pi/halloween/node_modules/speaker/index.js:183:23)
    at doWrite (/home/pi/halloween/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/home/pi/halloween/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at Speaker.Writable.write (/home/pi/halloween/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Volume.ondata (_stream_readable.js:666:20)
    at Volume.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Volume.Readable.push (_stream_readable.js:219:10)
Emitted 'error' event at:
    at Speaker.onerror (_stream_readable.js:690:12)
    at Speaker.emit (events.js:182:13)
    at onwriteError (/home/pi/halloween/node_modules/readable-stream/lib/_stream_writable.js:443:12)
    at onwrite (/home/pi/halloween/node_modules/readable-stream/lib/_stream_writable.js:470:11)
    at WritableState.onwrite (/home/pi/halloween/node_modules/readable-stream/lib/_stream_writable.js:180:5)
    at Speaker._write (/home/pi/halloween/node_modules/speaker/index.js:185:16)
    at doWrite (/home/pi/halloween/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    [... lines matching original stack trace ...]
    at Volume.ondata (_stream_readable.js:666:20)

Here's the full code:

const Speaker = require('speaker');
const fs = require('fs');
const stream = require('stream');
const Volume = require('pcm-volume');
const lame = require('lame');
const streamToBuffer = require('stream-to-buffer');

function loadSound( sound ){
	return new Promise((res, rej) => {
		const decoder = new lame.Decoder();
		decoder.on('format', format => {
			streamToBuffer(decoder, (err, buffer) => {
				err ? rej(err) : res(buffer);
			});
		});
		fs.createReadStream(__dirname+'/'+sound).pipe(decoder);
	});
}

function playSound( buffer, volume = 1 ){
	let bufferStream = new stream.PassThrough();
	bufferStream.end(buffer);
	// Setup volume
	const v = new Volume();
	v.setVolume(volume);
	// Setup speaker
	let speaker = new Speaker();
	v.pipe(speaker);
	bufferStream.pipe(v);
}

var i = 0;
async function exec(){
	let sound = await loadSound('coin_in_cauldron.mp3');
	let timeout = setInterval(() => {
		playSound(sound);
		if( ++i > 4 )
			clearTimeout(timeout);
	}, 1000);
	playSound(sound);
}

exec();

@PimTournaye
Copy link

I have the same issue, sound is just not outputting

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

No branches or pull requests

2 participants