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

channelCount constraint of getUserMedia is ignored #74

Open
trevorparscal opened this issue Feb 4, 2024 · 3 comments · Fixed by #76
Open

channelCount constraint of getUserMedia is ignored #74

trevorparscal opened this issue Feb 4, 2024 · 3 comments · Fixed by #76

Comments

@trevorparscal
Copy link

When using an audio interface with more than 2 channels, getUserMedia should be able to return a media stream with more than 2 channels by providing a channelCount constraint. Browsers generally don't support more than 2, but I was hoping since the spec does support it that this project might achieve it.

Here's some test code. One of my audio devices has 18 inputs, but it reports 2. I tired using 18, { exact: 18 } and { ideal: 18 } as constraints, but all were ignored.

import { mediaDevices, AudioContext } from 'node-web-audio-api';

async function init() {
	const audioContext = new AudioContext();

	const devices = await mediaDevices.enumerateDevices();

	console.log( audioContext.destination.channelCount, 'outputs' );

	for ( const device of devices ) {
		if ( device.kind === 'audioinput' ) {
			console.log( device.label );
			const mediaStream = await mediaDevices.getUserMedia( {
				audio: {
					deviceId: device.deviceId,
					channelCount: 18
				}
			} );
			const source = audioContext.createMediaStreamSource( mediaStream );
			console.log( '>', source.channelCount, 'inputs' );
			source.disconnect();
		}
	}

	audioContext.close();
}

init()
	.then( () => process.exit() )
	.catch( console.error );
@b-ma
Copy link
Collaborator

b-ma commented Feb 4, 2024

Hey, thanks for the feedback,

Indeed, I don't think multi channel input is something we have really tested. Would be really nice to have, but I guess this also relates to the upstream crate and not only the bindings. I really can't assure this will be fixed in the short term as we are focusing on consolidating Web Audio spec compliance right now (...and media devices API is not per se part of the Web Audio spec).

Let's keep this open as a reminder

@trevorparscal
Copy link
Author

I opened an issue upstream

orottier/web-audio-api-rs#446

@trevorparscal
Copy link
Author

I tested today with version web-audio-api 0.44.0 and still am only seeing 2 inputs and 2 outputs when using my multichannel interface. In this case, the interface is a Presonus StudioLive 16.0.2 USB device, which under MacOS (with no special driver installed) reports 18 inputs and 16 outputs.

Here's my test code...

use web_audio_api::context::AudioContext;
use web_audio_api::media_devices::{self, MediaTrackConstraints};
use web_audio_api::media_devices::MediaStreamConstraints;
use web_audio_api::node::AudioNode;

fn main() {
	let context = AudioContext::default();

	let devices = media_devices::enumerate_devices_sync();
	for device in devices.iter() {
		println!( "{}", device.label() );

		let mut media_track_constraints = MediaTrackConstraints::default();
		media_track_constraints.device_id = Some( device.device_id().to_string() );
		media_track_constraints.channel_count = Some( 18 );
		let input = media_devices::get_user_media_sync(
			MediaStreamConstraints::AudioWithConstraints( media_track_constraints )
		);
		let stream = context.create_media_stream_source(&input);

		println!( "> {}", stream.channel_count() );
	}
}

@b-ma b-ma reopened this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants