Web Audio Api destination maxChannelCount always is 2 on Linux - linux

I have a problem with Web Audio API and an usb audio interface on Linux;
I wrote some audio player code on Web Audio API.
Everything is alright when I connect my 7.1 USB Audio Interface (TASCAM 16x08 - there are 8 output channels) and start my APP on Windows machine. context.destination.maxChannelCount equals 8 and I can select the channel to output the sound.
But when I do the same on Linux machine context.destination.maxChannelCount always is 2 (stereo).
I tried to:
create virtual audio multichannel device = same result - always only 2 maxChannelCount;
setting alsa, pulseaudio, jack audio connection kit and more...
The result is the same: in my code context.destination.maxChannelCount is always is 2
but the operating systems settings dialog detects 8 channels.
This is some code to be clear:
var context = new (window.AudioContext || window.webkitAudioContext)();
var audio = new Audio();
var source = context.createMediaElementSource(audio);
source.connect(context.destination);
audio.src = 'audio.mp3';
audio.play();
console.log(context.destination.maxChannelCount); //output on win: 2
on linux: 8
What can be the problem?

I found solution here https://ubuntuforums.org/archive/index.php/t-1072792.html
solved it by editing /etc/pulse/daemon.conf.
; default-sample-channels
= 2 uncomment the line and add more channels.

What browser are you running? Browser is responsible for giving you those available outputs, if they're not there (in all available browsers) then i think you're out of luck. I have done some things with Web Audio and multiple outputs and even on the same OS i got different results from different browsers.

Related

Electron disable specific camera device access or set default webcam

We are using atom electron to run an app in a "kiosk" type setting, we have 4 webcam devices connected to the physical computer, we want specifically 1 of those to be used for webrtc inside of the electron browser, then other 3 we use some C code to capture still frames. We know the USB path or the /dev/video{#} for the device we want.
Is there a way to either disable access by the view layer to the 3 webcams in node before we launch the electron window? Or another option is to set the default camera before we launch the view layer so that it will default to the webcam we want.
In the view layer we can get a list of devices and see if they are audio or video, but we can't get their /dev/video# or their USB path to figure out which one is the target webrtc cam, so this has not been very helpful yet.
Any help is great, I feel weird for having to post a question since for the last 12 years I have been able to find what I needed by searching, but its been about 3 hours so its time to ask for help.
I don't think Chromium provides a way to retrieve the USB path for a media source. You'll probably need to display a configuration screen to allow the user to select the correct camera (similar to this demo) the first time around and then use the source/device id as a mandatory constraint from that point on.
Another option is to find the correct camera based on the device label, though obviously this will only work if each camera has a distinct label. You can get all the device labels and ids by running this snippet in the DevTools console:
navigator.mediaDevices.enumerateDevices()
.then(devices => devices.forEach(
device => console.log(`kind: ${device.kind}: ${device.label} id=${device.deviceId}`)
))
.catch(err => console.log(err));
Either way, once you have the source/device id you can specify it as a mandatory constraint to ensure that only that one particular camera is used:
navigator.webkitGetUserMedia(
{
audio: false,
video: {
mandatory: {
chromeMediaSourceId: 'the camera source id obtained earlier',
}
}
},
stream => console.dir(stream),
error => console.log(error)
);

Windows Universal App - MediaElement and M3U

is it possible to open up a m3u webradio stream in a MediaElement class in Windows 10?
Sample stream would be
http://www.antenne.de/webradio/channels/top-40.m3u
Opening normal mp3 in the internet work perfect but i do not get any m3u file opened.
Kind regards
Michael
Starting from Windows 10 version 1607, it is recommended to use the MediaPlayer class instead of MediaElement for media playback & The lightweight XAML control MediaPlayerElement.
Then you can use the MediaPlaybackList to create playlist for the MediaPlayer.
StorageFolder vfolder = Windows.Storage.KnownFolders.VideosLibrary;
StorageFileQueryResult query = vfolder.CreateFileQueryWithOptions(Constants.QueryOptions);
var files = await query.GetFilesAsync();
MediaPlaybackList playbackList = new MediaPlaybackList();
foreach (StorageFile file in files)
{
MediaSource source = MediaSource.CreateFromStorageFile(file);
playbackList.Items.Add(new MediaPlaybackItem(source));
}
_mediaPlayer = new MediaPlayer();
_mediaPlayer.AutoPlay = true;
_mediaPlayer.Source = playbackList;
MPElement.SetMediaPlayer(_mediaPlayer);
_mediaPlayer.Play();
More information Microsoft Docs
In m3u file (playlist file), there are often links point out to the source of audio. You need to get the file, open, parse it to get urls, and supply one of them to MediaElement. Its the same when you try to streaming video.
A M3U file isn't supported as it's not a media file. The playlist file format is simple and documented well enough that I'd recommend just parsing the M3U file and playing the individual files.
Unfortunately, Windows 10 UWP apps do not have access to the Playlist class which would be helpful in your scenario. It's only available for Desktop applications and in a Windows 8 app.

Windows Phone 8.1 play audio data stream through speaker?

I receive over network PCM audio data stream and this part works fine so I am ending up with
DataReader incomming = args.GetDataReader();
byte[] RcvBuffer = new byte[incomming.UnconsumedBufferLength];
incomming.ReadBytes(RcvBuffer);
I have all audio data in buffer.
How I can play this through telephone Speaker ? Can you point me in some direction ?
Thanks
There're many ways to do that.
You can prepend the WAVE header to your data, and use MediaElement for playback, see the documentation for SetSource method.
If however by “telephone speaker” you mean the earphone, then it is only possible if you are creating a VoIP app.
It took a while but I sorted it, maybe someone else will need help in the future.
First Problem - since I just started app development for Windows Phone I have chosen Blank App (Windows Phone) instead Blank App (Windows Phone Silverlight) and I did not have access to many features that are available in Silverlight projects, so my suggestions for beginners: understand what each project is for.
Like Soonts said there are many ways to do this, this is one that I used.
I simplified this code and retyped this so there can be some typos.
using Microsoft.Xna.Framework.Audio;
using System.IO;
1) Create Stream to load your incoming data:
MemoryStream stream = new MemoryStream();
2) Load data from buffer to stream:
stream.Write(RcvBuffer, 0, RcvBuffer.Length);
3) I am using SoundEfect to play this through Loud-Speaker. Sample rate that I use is 8 kHz
SoundEffect sound;
sound = new SoundEffect(stream.toArray(), 8000, AudioChannels.Mono)
sound.Play();

How to play audio in background with firefox os?

In my manifest file I've add the audio-channel-content in permissions:
"permissions": {
"audio-channel-content":{"description":"Use the audio channel for the music player"}
}
In my index.html I've got an audio tag like:
<audio mozaudiochannel="content" preload="none" src="http://my-stream-url"></audio>
I can play my audio stream during 2mn:
The first one when the phone is unlock.
After 1mn my phone auto-lock the screen and it continue playing for another minute.
Does it possible to play this audio stream more than 1mn after the lock?
Thanks in advance.
The code and permission block you have are correct and I can confirm it is working in Firefox OS 1.1. You can also do the whole thing in Javascript:
audio = new Audio();
audio.preload = 'none';
audio.mozAudioChannelType = 'content';
It's because the wifi is closed after screen shutdown (auto-lock)?
Are you using the dev version of gaia? Wifi is set to always connect in product version.

How can I select an audio output device in directshow

I was wondering how I can select the output device for audio in directshow. I am able to get available audio output devices in directshow. But how can I make one of these to be audio output device. Its always going for the default audio device. I want to be able to output audio on my choice of device. I have been struggling through google but couldn't find anything useful. All I could get was this link but it doesn't really solve my problem.
Any help will be really helpful for me.
First off, if you're not using DirectShow .NET (DirectShowLib), get that here: It serves as a (very complete) interface between unmanaged DirectShow and C#
What follows is a pretty simple example of how to play an audio file, to the desired audio device
using DirectShowLib;
private IGraphBuilder m_objFilterGraph = null;
private IBasicAudio m_objBasicAudio = null;
private IMediaControl m_objMediaControl = null;
private void playAudioToDevice(string fName, int devIndex)
{
object source = null;
DsDevice[] devices;
devices = DsDevice.GetDevicesOfCat(FilterCategory.AudioRendererCategory);
DsDevice device = (DsDevice)devices[devIndex];
Guid iid = typeof(IBaseFilter).GUID;
device.Mon.BindToObject(null, null, ref iid, out source);
m_objFilterGraph = (IGraphBuilder)new FilterGraph();
m_objFilterGraph.AddFilter((IBaseFilter)source, "Audio Render");
m_objFilterGraph.RenderFile(fName, "");
m_objBasicAudio = m_objFilterGraph as IBasicAudio;
m_objMediaControl = m_objFilterGraph as IMediaControl;
m_objMediaControl.Run();
}
It is up to user to manage audio devices and choose a primary device (such as via Control Panel applet). You can find ways to switch devices programmatically in Windows XP, however in Vista+ it is impossible without interactive user action by design.
See also Larry's answer here: How to change default sound playback device programmatically?
UPDATE: The mentioned above refers to modifying system configuration trying to alter default audio output device. An application is however not limited to default device only. Instead, it can enumerate available devices (see Using the System Device Enumerator + CLSID_AudioRendererCategory) and then create an instance of renderer for specific device with BindToObject call. From there on, it is a regular filter, just bound internally to device of interest.

Resources