Play Audio from Line In (NOT FOR KARAOKE, sry X3lectric ;-) )

  Thread Rating:
  • 2 Votes - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
garbear Offline
Team-XBMC Developer
Posts: 699
Joined: Dec 2010
Reputation: 30
Location: gangsta's paradise
Post: #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.
find quote
spiff Offline
Retired Developer
Posts: 12,386
Joined: Nov 2003
Post: #2
Filesystem seems to fit the best. Makes the code more reusable eg for karaoke...
find quote
garbear Offline
Team-XBMC Developer
Posts: 699
Joined: Dec 2010
Reputation: 30
Location: gangsta's paradise
Post: #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>
(This post was last modified: 2011-09-14 13:06 by garbear.)
find quote
topfs2 Offline
Team-XBMC Developer
Posts: 3,962
Joined: Dec 2007
Reputation: 9
Post: #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: badge.gif]

"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#."
find quote
garbear Offline
Team-XBMC Developer
Posts: 699
Joined: Dec 2010
Reputation: 30
Location: gangsta's paradise
Post: #5
My goal is to pass the audio to audio callbacks, both visualizer and another callback i hope to write in the future
find quote
garbear Offline
Team-XBMC Developer
Posts: 699
Joined: Dec 2010
Reputation: 30
Location: gangsta's paradise
Post: #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: screenshot003.png]
(This post was last modified: 2011-09-14 13:41 by garbear.)
find quote
fiveisalive Offline
Fan
Posts: 365
Joined: Jul 2009
Reputation: 0
Location: United States
Post: #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?
find quote
garbear Offline
Team-XBMC Developer
Posts: 699
Joined: Dec 2010
Reputation: 30
Location: gangsta's paradise
Post: #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
find quote
yallah Offline
Senior Member
Posts: 203
Joined: May 2011
Reputation: 0
Location: Cannes, France
Post: #9
hi,

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

Thanks for your developing
find quote
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #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
find quote
yallah Offline
Senior Member
Posts: 203
Joined: May 2011
Reputation: 0
Location: Cannes, France
Post: #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
find quote
DDDamian Offline
Team-XBMC Developer
Posts: 3,030
Joined: Sep 2011
Reputation: 254
Location: Canada
Post: #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!
find quote
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #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.
(This post was last modified: 2012-10-02 10:26 by bugme.)
find quote
garbear Offline
Team-XBMC Developer
Posts: 699
Joined: Dec 2010
Reputation: 30
Location: gangsta's paradise
Post: #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
find quote
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #15
DDDamian and you should chat... the fact AE doesnt handle input devices is bad...
find quote
Post Reply