Play Audio from Line In (NOT FOR KARAOKE, sry X3lectric ;-) )
#1
I'm working on a feature for XBMC that, initially, will require audio from a line in or microphone to be sent to the visualizer. How to best accomplish this?

My thought was to create a new protocol, linein://. Then, when XBMC is requested to play linein://, it loads a LineInCodec. The LineInCodec simply reads in the waveform and echos it to paplayer (and, from what I understand, paplayer already hands the audio and fft to the visualizer using OnAudioData()).

linein:// wouldn't have any directories, files or options after the ://. Therefore, I can avoid creating a CLineInDirectory. The OS layer would need to be abstracted, and I am unsure whether I should do this in LineInCodec or create a CFileLineIn. Either way, the actual line in device would be chosen in the settings and the OS abstraction would use this setting to choose the appropriate device.

Is this an appropriate way to do this? Should I implement a CFileLineIn or offload microphone reading to the LineInCodec? Should the protocol be called linein://, audioin://, microphone://, device://XXX or something else?

I don't care about latency at all. However, I know there's a lot of people requesting microphone for karaoke, so ideally I hope to do this feature in such a way that it can be used to easily enable karaoke in the future.
Reply
#2
Filesystem seems to fit the best. Makes the code more reusable eg for karaoke...
Reply
#3
I got Line In audio playback working. Here's the boring details. Line In is added to the filesystem using the linein:// protocol (with nothing following the linein:// part). You can add linein:// as a source, or play it using XBMC.PlayMedia(linein://). linein:// is then hooked up to a LineInCodecWASAPI (atm only WASAPI is implemented). From there, it plays like a normal file.

The source is https://github.com/garbear/xbmc/commits/linein. Originally I implemented this "codec" on gnif's AE branch (my AE-branch source, explanation of the difference between the two). The patch on top of AE works much better than master, as such I recommend not even considering this patch for inclusion until AE is merged.

Being able to play audio from the line in opens up many new features for XBMC. In a way, many devices now become supported (USB turntables, external CD players, AM/FM/Satellite radio. Also, audio is upmixed to the number of speakers available, audio effects can be applied (when/if these implemented), and visualizations can utilize the frequency data.

In theory, karaoke can be done on top of this by playing both audio and microphone streams at the same time (two streams are already used for the crossfading of tracks).


<images removed for efficiency, see post below>
Reply
#4
for kareoke its probably easier to add support to trigger the loopback features of the current audio system. PulseAudio you can simply load a module and michrophone gets rerouted to output, not sure if alsa has something similair or if this is the way to go for that.

Other than that yeah, its probably reusable for soundsystems which doesn't have the reroute support.
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#5
My goal is to pass the audio to audio callbacks, both visualizer and another callback i hope to write in the future
Reply
#6
Topfs2, Spiff,

I re-implemented this in xbmc's vfs. A call to XBMC.PlayMedia(device://Microphone (Realtek High Definition Audio)) will play audio from the line in device. Also, XBMC.PlayMedia(device://default) will automatically select the default recording device.

My new tree is https://github.com/garbear/xbmc/tree/device. The call above creates a new CFileDeviceWASAPI on windows that imitates a wav file, the file is then played using PAPlayer's WAVCodec (modified to include my pull request 421 fixes).

For my little tech demo, I used WASAPI instead of libavdevice because I was having IDE problems under linux. I'm a little clueless about libavdevice :/ Is libavdevice cross-platform? How would I go about starting to using it?

Another thing I'm clueless about is writing CDeviceDirectoryWASAPI and/or CDeviceDirectoryFFmpeg. Should browsing to device:// list all devices? if two devices are present, should xbmc list device://default as a third option? Should both WASAPI and FFmpeg devices show up under windows (maybe under subfolders device://wasapi/... etc), or should I just curb-stomp wasapi?


Image
Reply
#7
This is great! Just what I've been looking for for my USB/linein turntable. Is there a way to backport this support to Dharma 10.1?
Reply
#8
Hey fiveisalive,

Glad you're interested. Unfortunately it'll be a while. College classes make XBMC a fun summer project for me. Hang in there until Summer '12 and I'll see what I can do Smile

Best Regards,
Garrett
Reply
#9
hi,

Very excited to be in summer !!! Need this Feature Smile

Thanks for your developing
Reply
#10
any advances on this, as far as I have noticed, NO support for line in or MIC is supported in XBMC. AE has been merged and nothing has been done about audio input.

hellllllllllllllllppppppppp
Reply
#11
(2012-09-29, 09:22)bugme Wrote: any advances on this, as far as I have noticed, NO support for line in or MIC is supported in XBMC. AE has been merged and nothing has been done about audio input.

hellllllllllllllllppppppppp

+1
Reply
#12
All AE cares about is the stream - if it gets it - it plays it. I haven't looked at garbear's code but he should be able to just add packets to an AE stream and the visualizer will be taken care of as well as the audio output.

@garbear - ping! Wink
System: XBMC HTPC with HDMI WASAPI & AudioEngine - Denon  AVR-3808CI  - Denon DVD-5900 Universal Player  - Denon DCM-27 CD-Changer
- Sony BDP-S580 Blu-Ray  - X-Box 360  - Android tablet wireless remote - 7.1 Streem/Axiom/Velodyne Surround System
If I have been able to help feel free to add to my reputation +/- below - thanks!
Reply
#13
in Linux if I plugin a mic (pink plug) XBMC does not output any sound whatsoever (I have my output via hdmi), I would presume that AE is not able to grab input from the input (pink plug) and send it to output (whatever output is set)...

alsamixer has all relevant channels unmuted and maxed in volume.

So AE doesnt GET the input stream it or PLAY it. If it does it does it in a way it is unnoticeable for the input devices.

Reply
#14
I got this working with WASAPI, but for cross-platform support I would need to use libavdevice and sound on linux has never been nice to me. Unless someone can get the linux ball rolling, I'm shelving this project until I feel like doing battle with libavdevice Sad
Reply
#15
DDDamian and you should chat... the fact AE doesnt handle input devices is bad...
Reply

Logout Mark Read Team Forum Stats Members Help
Play Audio from Line In (NOT FOR KARAOKE, sry X3lectric ;-) )2