Log in

View Full Version : how to access the ac3enc.dll or mp2enc.dll


Inc
25th June 2005, 10:38
Hi,


Im writing a Captureediting appl. where you determine cuts also and finally you can encode the pcm wav of the input to ac3 or mp2.

Now I looked into the dll functionslist:

ac3enc.dll
AC3_encode_close
AC3_encode_frame
AC3_encode_init
AC3_encode_version

mp2enc.dll
beCloseStream
beDeinitStream
beEncodeChunk
beEncodeChunkFloat
beInitStream
beVersion


How can I (for example using VB) serve that 2.0 ch pcm raw stream to one of these dlls where finnaly I get the mp2 or ac3 on the disk, like Qenc does it?

I.e. by using the avifil32.dll API commands.
CallFunction( #Lib, "AVIFileGetStream", pAVIFile, @pAVIStream, #streamtypeAUDIO, 0 )

and finally using the avifil32.dll to save the resulted ac3 or mp2 bitstream as xxxxx.ac3 or xxxx.mp2 to my HD

Thanks a lot in advance!
:)

Inc
26th June 2005, 11:53
Well in case of ac3enc I found the following prams in the ac3enc.c

AC3_encode_init(&ctx, 44100, 64000, 1)

So an example to set? the encoder to encode at 44.1khz using a bitrate of 64kbit at one channel encoding

AC3_encode_frame(&ctx, frame, samples)

Ok the frame I could get out of parsing the source framecount via api and building a "for int firstframe to int lastframe", but what about the right "sample" value?

AC3_encode_close()

I think that speaks for itself.

But where can I allocate the pointer or whatever where the encoder finds the PCM data to encode?

The parameter &ctx I dont understand correctly as it seems that it points to an AC3EncodeContext Structure:
typedef struct AC3EncodeContext {
PutBitContext pb;
int nb_channels;
int nb_all_channels;
int lfe_channel;
int bit_rate;
unsigned int sample_rate;
unsigned int bsid;
unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */
unsigned int frame_size; /* current frame size in words */
int halfratecod;
unsigned int frmsizecod;
unsigned int fscod; /* frequency */
unsigned int acmod;
int lfe;
unsigned int bsmod;
short last_samples[AC3_MAX_CHANNELS][256];
unsigned int chbwcod[AC3_MAX_CHANNELS];
int nb_coefs[AC3_MAX_CHANNELS];

/* bitrate allocation control */
int sgaincod, sdecaycod, fdecaycod, dbkneecod, floorcod;
AC3BitAllocParameters bit_alloc;
int csnroffst;
int fgaincod[AC3_MAX_CHANNELS];
int fsnroffst[AC3_MAX_CHANNELS];
/* mantissa encoding */
int mant1_cnt, mant2_cnt, mant4_cnt;
} AC3EncodeContext

But how would I call that in for instance a VisualBasic syntax?

Do I have first to build a structure in VB where the whole AC3EncodeContext structure values will be allocated?



The api pcm data call I would use like this (ported to purebasic, thats no problem):

AviFileInit
AviFileOpen(PFile, Inputfile, 0, nil)
AviFileGetStream(PFile, PAvi, StreamTypeAudio, 0)


Can someone help me? :(

vhelp
27th June 2005, 05:51
@ inc

I don't know if this will work, because I did not have the complete code snip
(was using what you posted earlier) but, after porting to delphi, and ran it,
the code complete correctly.

I tested it on a new form with a set of dummy parameters. The code should
work fine, and with your added (missing) code snips, *should* (I hope)

Just trying to help out, and good luck :D

-vhelp



{
Sun - Jun 26, 2005.pm
code snip port to delphi, by vhelp (code structure theory)

INSTRUCTIONS:
-------------
* Drop a button; and an edit box on your form.
* copy/paste this code as is,
(AFTER you dropped button & edit box on form)


NOTES:
------
* AC3_MAX_CHANNELS
I don't know what the initial value is. I just made up 2, for stereo.
* PutBitContext
Is a dummy Type structure. Use what is in your code to port
* AC3BitAllocParameters
Again, is a dummy Type structure. Use what is in your code to port

MISC NOTES:
* Assuming that everything was setup correctly, you should
see a 'bit_rate: xxx' where 'xxx' is the value obtained from the
call in do_AC3EncodeContext(v_AC3EC), of the demo calling routine below.

}

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

const
AC3_MAX_CHANNELS = 2;
type
PutBitContext = record i: byte; end;
AC3BitAllocParameters = record i: byte; end;

AC3EncodeContext = record
pb : PutBitContext;
nb_channels : integer;
nb_all_channels: integer;
lfe_channel : integer;
bit_rate : integer;
sample_rate : cardinal;
bsid : cardinal;
frame_size_min : cardinal; // minimum frame size in case rounding is necessary
frame_size : cardinal; // current frame size in words
halfratecod : integer;
frmsizecod : cardinal;
fscod : cardinal; //* frequency */
acmod : cardinal;
lfe : integer;
bsmod : cardinal;
last_samples : array[0..AC3_MAX_CHANNELS,0..256] of shortint;
chbwcod : array[0..AC3_MAX_CHANNELS] of cardinal;
nb_coefs : array[0..AC3_MAX_CHANNELS] of integer;
//
//* bitrate allocation control */
//
sgaincod, sdecaycod, fdecaycod, dbkneecod, floorcod: Integer;
bit_alloc : AC3BitAllocParameters;
csnroffst : integer;
fgaincod : array[0..AC3_MAX_CHANNELS] of integer;
fsnroffst : array[0..AC3_MAX_CHANNELS] of integer;
//
//* mantissa encoding */
//
mant1_cnt, mant2_cnt, mant4_cnt: Integer;
end; // AC3EncodeContext

var
Form1 : TForm1;
v_AC3EC: AC3EncodeContext;

implementation

{$R *.dfm}

// hyperthetical usage below..

procedure do_AC3EncodeContext(AC3EC: AC3EncodeContext);
begin
form1.edit1.text := 'bit_rate: ' + intTostr( ac3ec.bit_rate );
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
//
do_AC3EncodeContext(v_AC3EC);
end;

end.

Inc
28th June 2005, 19:06
Thanks a lot Vhelp for your approaches. Lets see if I can get into it :)

D3s7
15th July 2005, 02:21
&ctx is a pointer to another variable declared as that typedef...

THe greater question you need to ask is if those routines are publically exported in a way they are exposed to VB.. most c++ routines are not available to VB