Stereo to A52 (AC3) using a near real-time software encoder
#1
Hi All,

Like many on this forum, I have been struggling to get XBMC to output standard stereo of varying sample rates to IEC958 (SPDIF), and the developer that I am, I decide that it MUST be possible to encode it on the fly.

I then descovered the alsa A52 plugin, which while it partially worked for me, would not work at all properly with XBMC, I was getting time skipping backwards problems, and all sorts of weird issues.

After hours of hacking the A52 plugin source, I decided that it was crap, and dropped in in favour of re-writing it from scratch, and trying to learn the alsa plugin api, and came up with a perfect solution (for me anyway).

http://code.google.com/p/a52plug

This is another a52 plug for alsa, uses somewhat the same method as the original alsa one, except it uses Aften to encode, instead of ffmpeg. This was choosen because ffmpeg is not thread safe, and aften is, and it may have been the cause of the weird issues I was having.

The code is very experimental at this stage, but I am enjoying upmixed A52 encoded output to all my speakers for standard audio, and passthrough still works since it uses the IEC958 device directly. Even setting the SDL audio device to use alsa works with this plugin.

Please have a go and let me know what you think, how it works, or any mistakes due to my lack of understanding of the ALSA Plugin API. For a sample asound.conf, see the README included with the project.
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply
#2
Can I route Surround51 through it? Never looked through all this asoundrc stuff.
Reply
#3
yes, you can, the current version is broken though, if you go back a revision things should work. Due to the limitations of the ALSA plugin interface I am attempting to build this into XBMC directly though, so then everyone will get it if they turn it on Smile
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply
#4
This sounds great.
Used to have something like this under Windows as a Winamp Plugin...
I hope you'll be successfull in building this directly into XBMC !
Reply
#5
Well, I have good news!

I have got 90% of this working now, I have implemented an audio driver that does the encoding, passing the encoded IEC958 frames onto the underlying sound driver. I am only using ALSA, but it should work for any driver that supports passthrough.

To make audio work properly, it even detects the sample rate, and up-samples it to 48000hz so that the playback is not too fast.

I have one issue left to contend with, I have to add the code to clean up after the encoder is closed, at the moment when playback of a video is stopped the media center crashes. Also, an option to enable/disable the encoder is required, at the moment I have just hard coded it on for non encoded media.

I should have a diff ready in the next week depending on time to add this cool new feature Smile
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply
#6
gnif Wrote:...it even detects the sample rate, and up-samples it to 48000hz so that the playback is not too fast.
Cool, are you using SRC (Secret Rabbit Code) a.k.a. libsamplerate?
http://www.mega-nerd.com/SRC/

Huh ...this libsamplerate is what XBMC uses as a Sample Rate Converter Wink
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.
Reply
#7
No, I am using the ffmpeg resampler which is giving me a few problems, I did not realise that we linked with libsample rate. I will re-visit that code
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply
#8
I dont seem to be able to find libsamplerate in the sources anywhere, the closest I can find is xmc/cores/ssrc.(cpp|h) which seems to be a resampler of sorts, is this what you are referring toHuh
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply
#9
Well, I have re-written it to use the Cssrc class, which works great! Smile A little bit more testing and tweaking and I will have a patch ready.

I have also resolved the crashing issue on videos and changed the rules that will enable the encoder.

If passthrough is enabled and the audio driver is not opened with passthrough mode, the encoder will become active.

The encoder does not yet route channels, so it just encodes the signal it gets be in mono, stereo, or 5.1.
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply
#10
Ticket created with patch attached!
http://trac.xbmc.org/ticket/6499
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply
#11
This is wonderful and exactly what I've been looking for! I'm compiling it now as I type. Outputting an AC3 stream with the same amount of channels as the input is perfect as the receiver will probably do a better job of routing the channels to the correct speakers than XBMC ever will. My receiver (Onkyo TX-SR604E) has several selectable stereo routers/enhancers that aren't available when the input is multichannel.
Reply
#12
why is this tagged audiophile? adding another lossy encoding surely won't improve the quality Wink
Reply
#13
gnif Wrote:I dont seem to be able to find libsamplerate in the sources anywhere, the closest I can find is xmc/cores/ssrc.(cpp|h) which seems to be a resampler of sorts, is this what you are referring to?
hmm, perhaps it is only in the smoothvideo branch (that has yet to be merged into the mainline branch)?
http://forum.xbmc.org/showthread.php?tid=46091

Huh
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.
Reply
#14
Patch has been updated again to address numerous issues. See the ticket for more info
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply
#15
After hours of searching I have turned up the following good test files for non AC3/DTS 5.1 audio.

WMV/WMA3 5.1 test with visual output
http://samples.mplayerhq.hu/A-codecs/WMA...t_720p.wmv

Official Microsoft WAV & WMA in 5.1 (use unzip to extract it)
http://download.microsoft.com/download/w...hannel.exe

AAC 5.1 surround test
http://trac.xbmc.org/raw-attachment/tick...9/test.m4a

The WAV output will not come out correct due to missing WAV remap support, the following patch fixes this:
http://trac.xbmc.org/attachment/ticket/6...pping.diff

The AAC output will be down mixed to 2 channels, and even may play way too fast due to hardcoded 2 channel down mixing to work around a problem with the apple tv, the following patch fixes this, and also corrects the audio mapping.
http://trac.xbmc.org/attachment/ticket/6556/fixaac.diff
I am not scared of SVN - Cutting my hands open on the bleeding edge.
Reply



Logout Mark Read Team Forum Stats Members Help
Stereo to A52 (AC3) using a near real-time software encoder0
This forum uses Lukasz Tkacz MyBB addons.