
Could Someone Translate This Code To VB?
Marc,
This is a tough one.
This code is not only in C, but in old-style C, with parameter
declarations inside the function!
Strange.
My comments throughout the code..
Quote:
> Hello
> I have been looking at some code to read MP3 files but I can't figure out how
> to read the bitrate and a few other things. Here is the original source code
> in C. I don't do C and am pretty new at VB so any help would be appreciated.
> /************ Layer I, Layer II & Layer III ******************/
The following 3 lines translate to the VB code:
Sub decode_info(ByRef bs as Bit_stream_struc, ByRef fr_ps as
frame_params)
Quote:
> void decode_info(bs, fr_ps)
> Bit_stream_struc *bs;
> frame_params *fr_ps;
> {
The following shows a "C" feature which VB does not have.
The variable "hdr" is a pointer to a "layer". VB does not really support
pointers in this way.
What this is doing is getting a reference to the "header" structure
within the fr_ps structure.
In VB, you couldn't do it like this, so you would set the members of the
structure directly (see below)
Quote:
> layer *hdr = fr_ps->header;
The rest of the code sets members of the "header" structure.
I would guess that the code is getting one or two bits at a time from
the bitstream "bs".
The bitstream probably points to the MP3 file. Now, in that MP3 file,
there is a header
which describes some characteristics of the data to follow. This code is
reading that header
one or more bits at a time and filling the hdr structure with the
information. I would guess
that the get1bit and getbits functions return the (1 or 2 byte) value of
the specified number
of bits from the stream. So getbits(bs,4) would return the value of the
next 4 bits in the
stream.
In VB you would reference the structure directly like this:
fr_ps.header.version = get1bit(bs)
Quote:
> hdr->version = get1bit(bs);
> hdr->lay = 4-getbits(bs,2);
> hdr->error_protection = !get1bit(bs); /* error protect. TRUE/FALSE */
> hdr->bitrate_index = getbits(bs,4);
> hdr->sampling_frequency = getbits(bs,2);
> hdr->padding = get1bit(bs);
> hdr->extension = get1bit(bs);
> hdr->mode = getbits(bs,2);
> hdr->mode_ext = getbits(bs,2);
> hdr->copyright = get1bit(bs);
> hdr->original = get1bit(bs);
> hdr->emphasis = getbits(bs,2);
> }
<snip>
In all honesty, this is probably a bit too much to tackle if you are a
novice programmer.
Do you know any other languages? Pascal, Java, QuickBasic?
You may not want to hear this, but C is better for this application. It
CAN be done in VB,
but you would have to take a completely different approach to tasks such
as this.
C just requires a little bit different approach than VB. There are a few
core concepts which
are difficult at first (pointers in particular), but all in all, it's
not too {*filter*}ce you
get past the initial difficulties.
Feel free to email me with questions or comments. I am busy, so I cannot
guarantee
a reply. I'll do my best, though.
Good Luck,
Dave
(remove x's from email address)
--
I am a resident of Washington state. In Washington, Spam
is subject to a $500 or greater penalty. You are warned.