Log in

View Full Version : AC3 real-time encoding


LoKi128
21st June 2002, 06:29
As I understand it, if you use a multichannel OGG (or some other non-AC3 format) for your audio, you cannot use the digital output of your sound card straight into a DD receiver, because the multichannel audio does not get reencoded into a DD stream.

But now that there is an AC3 encoder out there, could it perform the duties of "recompressing" all the channels back into a DD stream so that any file format can be sent down digitally to the receiver.

I understand that recompressing of audio will degrade it, and if this is done that would have been the third time (AC3->OGG->AC3), but since we are not really storing the 3rd stream, we could use a pretty large bitrate to minimize the artifacts.

I guess this would mainly help in the convenience area. Instead of having 7 cables from the PC to the receiver (in case of an HTPC, 6 audio + 1 video) you would only need 1 video and 1 audio cable. But other advantages would be that any audio format can then be used for multichannel sound.

Something else that would be neat is that if a settings panel is created, we could create different virtual audio devices and then send each different stream to a different speaker in a system. This way, you could have a cheap way of multi-room sound (cheap DD receiver, front channels for one room, rears for the other, or 5 different mono channels).

Anyway, I think the main problem would be CPU usage. After all, you will be decoding the video stream, decoding the audio stream, plus reencoding the audio stream all at the same time. Maybe the current 2GHz processors can do it, but my lowly 400MHz celeron can barely keep up with a XviD stream :)

So... would this be at all possible? :) Thanks!

Emp3r0r
22nd June 2002, 19:14
It is possible. I do it. I have no idea what the nForce southbridge reencodes at but I am satisfied with the quality. As far as playing back surround sources, I've only played back AC3 files which "pass-through" and vorbis or MP3 files which play as prologic sound. All in all things sound great using the DD encoder of the nForce and the optical digital hookup from my motherboard to my receiver. I'm satisfied with this setup.

tateu
12th July 2002, 09:12
So, are there any AC3 Encoder DirectShow filters available? Or is it possible to modify the source code to BeSweet's ac3enc.dll to work as a realtime Directshow filter? I know a small amount about DirectShow programming in C++ but have not yet written any of my own filters.

The reason I ask is that I have written a DirectShow based capture application for my Dazzle DVC-II mpeg card and it captures to multiplexed mpeg-2 with mp2 or LPCM audio and to separate video and audio files in mp2 or wav format. It would be nice to also put a DirectShow AC3 encoder in the capture graph to cut out the intermediate step of capturing to wav and then converting to AC3.

Thanks for your help.

DSPguru
12th July 2002, 09:22
@tateu
if you'd like to write a direct-show ac3 encoder, i can guide you thru the sources, and we'll work on it together.

ChristianHJW
12th July 2002, 10:03
Where is MaTTer ? His heart should be jumping up and down when reading this !!!!

tateu
12th July 2002, 18:12
DSPguru,

Yes, I would like that. As I said, I don't know a lot about it, but any help you can provide would be very much appreciated. Thanks.

DSPguru
12th July 2002, 18:20
i can help you with AC3 encoding and with digital signal processing, but not with windows programming. that's not my forte..

tateu
12th July 2002, 21:19
Well then, before I waste any of your time helping me with the finer details of the audio encoding, I think my first order of business should be to figure out how to write a DirectShow filter and get it connected to my capture graph/wav files. I am still in the very infantile stages of my programming skills and I'm afraid any help you could provide at this stage would probably fly right over my head.

If I am able to get that working, I can then come back and ask for your assistance with the actual audio encoding functions.

Again, thanks for your offer of help, hopefully I will be able to take you up on it.

DSPguru
12th July 2002, 21:30
okay, good luck! and let's hope for the best :D.

Dg.

ChristianHJW
13th July 2002, 07:35
@tateu :

have a look at the example filter 'gargle' ( or similar ) from Windows SDK .... this seems to be a good start.

tateu
13th July 2002, 17:48
Yes, thank you. That is exactly where I started. I'm afraid it's going to be awhile (if ever), though, so if for some reason anyone is holding their breath for this...please breathe in deeply now.

ChristianHJW
16th July 2002, 22:34
^bump ... be assured i wont loose this thread tateu ;) .. any progress ? everything else we could help with ?

tateu
17th July 2002, 06:31
I won't lose it either but progress is going to be slow. I don't have a whole lot of time, at the moment. I just got hit with atleast a weeks worth of heavy overtime at work and I'm also trying to get a new version of my DVC-II capture app ready to release.

But I did spend a couple of hours this weekend going through the sample SDK filters; I didn't have much luck, though. I wasn't exactly sure what I was looking at. I know there are input and output pins and they must have a Mediatype associated with them but that's about all at the moment. I sort of know how to setup an array of Mediatypes and I thought I had multiple input pins setup, but only one showed up on the filter. Also, my main goal is to get this connected to the PCM output of my capture card and I was having some trouble with that.

I probably have several hundred hours put into my capture app and, in the beginning, I had a few 30+ hour weekends of nothing but DirectShow code. I'm still not very proficient with it and there are tons of c++ things I know absolutely nothing about, but I've been able to get the job done and have a working capture app that I have released for public use. I need to be able to spend some of that same quality time of trial and error testing with the sample filter code and hopefully I will start to gain some understanding of it all. I have the source code for a couple of other freely available filters also that will hopfully help me.

But I just don't see this happenning quickly. Even without a lot of overtime, I usually only have time enough for programming on the weekends.

As for help...I don't even know enough yet to be able to ask any questions. I suppose you could buy me a winning lottery ticket and then I could quit my job and have more time to devote to this...

ChristianHJW
17th July 2002, 16:54
tateu,

you are in the same process as our new MCF dev team member myFUN is ... he is grabbing his way throught Dshow SDK to code the MCF parser filter. May i invite you to join on IRC, openprojects , #mcf . May be interesting to talk to him. We also sometimes have the pleasure to have Ingo Ralf Blum on our channel ( he is logging very often, but not posting too much ), and he can be looked at as being the absolute Dshow expert, maybe only rivalled by Nic . It should be well possible to get some great input from Ingo, if you are interested to do something here.

( IRC client : www.mirc.com )

BlackSun
19th July 2002, 09:34
On Eugene's homepage you'll find the source code for PCM to VOB, he use this code to send MP3 to the Hollywood+ SPDIF Output. You now have everything you need :)

Good luck, I'm really interested in this !

BlackSun
19th July 2002, 12:44
For your convenience, here the link to Eugene website, the PCM2VOB source code will help you a lot :)

http://eugene7777.tripod.com/

Unfortunately it's unavailable atm (the website) :/

tateu
20th July 2002, 00:13
BlackSun,
Thanks for the link. I have the code now and will see if it can help me.


ChristianHJW,
Thanks for the invitation. Are there any specific days and times that are better to stop by? Since this is a global community, obviously times when I am available do not correspond to everyone else.

spyder
20th July 2002, 17:41
Any time is good, but since most of the MCF team is located in Europe, the best times here(I am in Central US Time Zone) are between 10:00 AM and 5:00PM(8:00AM and 3:00PM for you??). This is during the late evening there and most are back from work already.

BlackSun
24th July 2002, 14:52
Originally posted by tateu
BlackSun,
Thanks for the link. I have the code now and will see if it can help me.


Keep us informed ;)

scherian
27th July 2002, 05:22
Hey,
Does anyone have any idea what kind of processing power is required to encode 5.1 or 2.0 AC-3 in real-time?
Also, is there anyway to output nForce encoded DD5.1 to a file instead of sending it straight to the SPDIF-out?

thx

MaTTeR
9th September 2002, 17:38
Shameful bump;)

Just wondering if the project has gotten off the ground yet. Sounds very interesting to say the least.

tateu
10th September 2002, 19:37
Unfortunately, no, atleast I haven't gotten anywhere with it. I never really got involved in this thread with the intention of writing my own filter but when I found out that none existed I thought it would be great if I could write one.

If you've been following the "Start Programming" thread in the development forum...well, I fall into the category of not really a programmer. I certainly don't know asm (it looks like an alien language to me) and I know only a little in C++ (most of which has been done with MFC). I just sort of learn things as I go along and it's a slow process. I don't have a lot of time for programming and most of the time I do have is spent on two other programs of mine. My first step is to learn how to write a DirectShow filter and I've only spent a little time with that but have not had any success. Usually I will struggle with something for awhile and then, all of a sudden, it will just "click" but nothing like that with DirectShow filters has happened. And then I get easily sidetracked when I'm frustrated with a concept that I can't seem to understand. Like now, I haven't even looked at DirectShow filter code in a few weeks and have switched to trying to write an NT Service that allows me to remotely reboot or shutdown my computer.

I haven't given up on the AC3 filter yet, but it's slow going and will be for quite awhile.

sherpya
17th September 2002, 15:50
I'm trying to implement a dshow ac3 encoder.
These my problems/dubts:
(hope Dspguru and Tobias can help me)

- I've made a mingw c dll wrapper for libavcodec (works with clean cvs)
- I can't make a c++ dll (Problem with naming decoration with msvc)
- I use CTransformFilter for my class and I set sample size to AC3_FRAME_SIZE ( 1536 ) but Source is always 3072 byte, why?
- The encoder seams to work (i.e. moonlight odio dekoda says right settings and led on my ac3 decoder is on)
- I've also made an bs_ac3 in mingw that works with cvs of libavcodec but is bigger than bs_ac3 by dspguru
- I hate c++
- I hate dshow
:D
Waiting for feedbacks

DSPguru
17th September 2002, 17:53
Originally posted by sherpya
- I can't make a c++ dll (Problem with naming decoration with msvc)use a .def file, or add 'extern "C"' as a prefix to your exported functions.
- I use CTransformFilter for my class and I set sample size to AC3_FRAME_SIZE ( 1536 ) but Source is always 3072 byte, why?ac3 holds 1536 samples per frame per channel.
if samples are represented in int16 (short), you'll get 3072 bytes per channel.
- I hate c++
- I hate dshowagreed.

sherpya
17th September 2002, 19:51
3072 hmm double of 1536...
libavcodec needs shorts, dshow is sending me unsigned char
2 uchar = 1 short
I need to convert 3072 unsigned char to 1536 shorts
what about a cast?
Anyway I'm getting only noise

Another issue is ogg decoder send me 32 bit samples (or says it)
I suppose libavodec needs 16 bits samples

edit: bitpersamples = 16 then casting to unsigned it should be
enought (at least for NullIp example)
But oggds outputs at 32 bit... hmmm


extern C or a .def are used exporting a c dll, and works fine.
I need to export a class
my lib (c++) exports:
_ZN8CEncoder4initEiii
_ZN8CEncoder6encodeEPhiPs
_ZN8CEncoderC1Ev
_ZN8CEncoderC2Ev
_ZN8CEncoderD1Ev
_ZN8CEncoderD2Ev

but msvc is searching for ??C1Encoder@XYZ etc

with the c dll I've solved selecting cdecl instead of stdcall in vs linking options

sherpya
18th September 2002, 04:23
Sound is not noise now, but is crappy like losing some samples...
It works only with 16bit audio and the graph stops after 24 seconds...
The encoder samplerate and bitrate are set according the source.
I'm making progress... :D

DSPguru
18th September 2002, 17:40
Originally posted by sherpya
Sound is not noise now, but is crappy like losing some samples...
It works only with 16bit audio and the graph stops after 24 seconds...
The encoder samplerate and bitrate are set according the source.
I'm making progress... :D Cheers !!

sherpya
21st September 2002, 00:00
Ok for mono is working... I've some problems with sample alignment (i.e. samples is not divisible by AC3_FRAME_SIZE * 2, and this introduces some artifatcs, better if I find a way to call Transform with only one frame of data). For two channel the intereaving is different, I need to figure how send channel > 1 data to the ac3 encoder and how to handle 8 and 32 bit samples (24?).
Btw my pc is a k7 tb 1.2G and can do at least mono ac3 encoding in realtime (libavocdec rocks).

I'm not an audio coding expert, but really where I can find info about sample representation, I've seen on audiocoding wiki but I can't find nothing usefull for me.
So far I known
8 bit samples -> unsigned/signed char
16 bit samples -> unsingned char (2) -> short int
32 bit samples -> float ?

with a source of 48000 khz stereo 16 bit I have 48000 samples of unsigned char in dshow, with a source of 48000 khz mono I have 24000 samples.

DSPguru
21st September 2002, 10:16
i think the best thing would be to handle all samples in one format only - 32bit floating point.
if you're interested, show me the code, i'll work on it whenever i have some free time.

sherpya
21st September 2002, 11:57
It's not my choice dshow sends me unsigned chars,
however the filter will be opensourced (when it will starting to work).
In the meanwhile I can send you the code (where?), but there are some problems:
- I've messed somewhere the code and the filter can't connects anymore to ac3 decoder (I've a .grf file to work on, you can run removepath on it)
- ac3 encoder wrapper dll is built with mingw (however I have dll and lib for linking)

DSPguru
21st September 2002, 12:06
i currently don't have much time to work on this, but if you'll send me the sources i'll give you a hand.

MaTTeR
21st September 2002, 12:22
Good to see progress on this:) I'd be glad to help if I had any idea how to code but unfortunately I don't.

sherpya
22nd September 2002, 14:28
Since libavcodec needs short int samples and dshow sends me unsigned chars...
Samples types can be:
8 bit PCM (unsigned char) -> must be converted to short
16 bit PCM (2x unsigned char) -> casting to short int is enough
32 ieee float (4x unsigned char ?) -> cmust be converted to short multiplying by 0x7fff

These should be the sample conversions, then interleaving:
1channel -> no interleaving

2 channels:
8 bit-> 1 uchar (1st channel), 1 uchar (2nd channel)
16 bit-> 2 uchar (1st channel), 2 uchar (2nd channel)
32 bit-> 4 uchar (1st channel), 4 uchar (2nd channel)

3 channels:
8 bit-> 1 uchar (1st channel), 1 uchar (2nd channel), 1 unchar (3rd channel)
16 bit-> 2 uchar (1st channel), 2 uchar (2nd channel), 2 uchar (3rd channel)
32 bit-> 4 uchar (1st channel), 4 uchar (2nd channel), 4 uchar (3rd channel)

etc...

It's is right?

The how I should send these interleaved data to libavcodec?

oddball
25th September 2002, 19:31
OK I have just read this thread after posting my annoyance with 5.1 audio from WMA and OGG etc and am very excited about the possibility of realtime AC3 encoding to SPDIF out. However there is another possibility here. Realtime encoding to file from 5.1 inputs.

Not sure how this would work as my SBLive only has stereo in. But for cards that can take 6 channels in at the same time this could be very usefull.

BlackSun
2nd October 2002, 09:36
- I hate c++
- I hate dshow


If you guys are talking about writing a Dshow filter, then I agree (and i totally agree on the c++ part :D). But Dshow provide some very interesting possibilties and you guys are exploring one of them.

Keep up the good work !

daveidmx
11th October 2002, 14:26
i am another anxious proponent of this project. great work so far all! i'm starting to get excited!

what's the current state? did you figure out that interleaving/casting/conversion thing?

is there anything i might be able to help with?

DSPguru
11th October 2002, 14:30
http://sourceforge.net/projects/ac3encode

MaTTeR
12th October 2002, 17:05
Dg,

So it seems you guys have a version available. What are the possible uses for it now in it's current state? I'm assuming another application such as a player needs to make a call to the dll?

Just curious and anxious to try it out.

DSPguru
12th October 2002, 18:53
hmm.. it's too early for testing, but not too far either.

MaTTeR
12th October 2002, 18:59
Sounds good. Maybe I won't need to purchase that nForce motherboard for my HTPC this year after all:)

UGAthecat
30th October 2002, 03:20
Sorry to butt my head into a work in progress, (especially since I really don't have the expertise to contribute) but wouldn't it be easier to write a driver that windows will think is a 6ch soundcard, then take the input coming to that driver and convert it to AC3, then patch the AC3 stream out through the real sound card's digital out?

This should give a few advantages, the biggest being that it would work with every audio source, including games :cool: .
Another advantage would be you dont have to have a long filter chain being made for demux source>whatever audio decoder>ac3encoder>ac3decode filter set to pass through to sound card.
EDIT/ another advantage would be volume adjustment controls in pretty much any player/program would work, and you could even use the windows volume controls as well.
I'm sure there would be some disadvantages, probably the biggest being development related./EDIT

EDIT2/ ok, I don't know what I was smoking with that games thing, the only way to support the 3d audio in games would be to get the game to use your real soundcard to make the 3d audio using directsound3d or whatever, and then take the output from that and send it to the virtual 6ch audio driver, which then sends the digital out through your sound card; or you could write a software directsound3d decoder into the virtual 6ch audio driver which would be pretty cpu intensive and kill your games, and be too much work.
I imagine using the sound card for 2 things at once like this would probably require per hardware driver specific hacks so it wouldn't be worth it. Once you get to this point you might as well be writing the thing so that it integrates itself into your real soundcard's drivers which would probably be entirely too dificult.
The virtual 6ch sound card would still work for movies and video programs tho.
maybe the whole idea is just too much work :( . Heh, I think I talked myself out of my own idea :) /edit2



please feel free to call me crazy and proceed with your work, this is just an idea I had :)

DIggedy
1st November 2002, 00:41
Great work guys, I'm interested to see how this turns out...

I have a quick question, would it be possible to use this filter to send a 5.1 mix from a software multichannel mixer such as mx51 to the optical out to preview it in 5.1? The reason I'm wondering is I want to get a new soundcard with optical out but without 6ch i/o but want to be able to do my own 6ch mixes, and as far as I know the only way to preview these in realtime at the moment is using a 6ch soundcard.