From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,435e65f4acf8bd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-01-14 11:48:32 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!falcon.america.net!sunqbc.risq.qc.ca!newsfeed.direct.ca!look.ca!wn1feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc07-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3A622CE5.89C9378E@worldnet.att.net> From: srini X-Mailer: Mozilla 4.72 [en] (Windows NT 5.0; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: bitstreams References: <93se2v$nen$1@eol.dd.chalmers.se> Content-Type: multipart/mixed; boundary="------------9F966ADF3242D617ECA5C48E" Date: Sun, 14 Jan 2001 19:46:08 GMT NNTP-Posting-Host: 12.77.88.160 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc07-news.ops.worldnet.att.net 979501568 12.77.88.160 (Sun, 14 Jan 2001 19:46:08 GMT) NNTP-Posting-Date: Sun, 14 Jan 2001 19:46:08 GMT Organization: AT&T Worldnet Xref: supernews.google.com comp.lang.ada:4005 Date: 2001-01-14T19:46:08+00:00 List-Id: This is a multi-part message in MIME format. --------------9F966ADF3242D617ECA5C48E Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I do not know much about mp3 etc but I have developed a bit stream package which allows you to perform reads in terms of bits. I use these in my own compression/decompression test software. The spec is attached. I would be happy to send you the body as well if you are interested. Daniel Nilsson wrote: > > Hi. > In my mp3 decoder I will have to search for bit-patterns in a buffer of > bytes, how is this best done, and How can I "shift" in a sequence of bits > into a byte, or word efficiently? (I want ex. take 5 bits from a buffer and > put them rightadjusted in a unsigned_32) > > /Daniel Nilsson --------------9F966ADF3242D617ECA5C48E Content-Type: text/plain; charset=us-ascii; name="bits_io.ads" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="bits_io.ads" with Interfaces ; with ada.streams ; with ada.streams.stream_io ; ---------------------------------------------------------------------- -- Abstract : Bits_Io -- This package converts a normal I/O stream into a bit level I/O ---------------------------------------------------------------------- package Bits_Io is type File_Type is limited private; type File_Mode is (In_File, Out_File, Append_File); type Vector_type is array (natural range <>) of boolean ; pragma pack( Vector_Type ) ; -- Abstract : Open -- A file is opened using normal File Management facilities first and then -- a Bit Stream File is created using the following procedure. It is the same -- procedure whether performing input or output. It is assumed that the file -- is used only for one of these purposes at any time. procedure Open (File : in out File_Type; Mode : in File_Mode ; Stream : access Ada.Streams.Root_Stream_Type'Class ) ; -- Abstract : Read/Write -- The following two procedures allow an Unsigned_8 variable to read or -- write. Similar procedures for Unsigned_16 and Unsigned_32 are also provided procedure Read (File : in out File_Type ; Item : out Interfaces.Unsigned_8 ; Last : out Ada.Streams.Stream_Element_Offset) ; -- Returns the number of bits actually read procedure Write (File : in out File_Type ; Item : in Interfaces.Unsigned_8 ; Last : in integer ); -- How many bits should really be written? procedure Read (File : in out File_Type ; Item : out Interfaces.Unsigned_16 ; Last : out Ada.Streams.Stream_Element_Offset) ; procedure Write (File : in out File_Type ; Item : in Interfaces.Unsigned_16 ; Last : in integer ); procedure Read (File : in out File_Type ; Item : out Interfaces.Unsigned_32 ; Last : out Ada.Streams.Stream_Element_Offset) ; procedure Write (File : in out File_Type ; Item : in Interfaces.Unsigned_32 ; Last : in integer ); -- Abstract : Read/Write -- These are the real I/O procedures where all the work is done. The above -- routines simply call these internally. procedure Read (File : in out File_Type ; Item : out Vector_Type ; Last : out Ada.Streams.Stream_Element_Offset) ; procedure Write (File : in out File_Type ; Item : in Vector_Type ); -- Abstract : Flush -- Used for writing operations, sends any residual bits to the output stream -- packed in a byte. procedure Flush (File : in out File_Type ) ; private type Root_Stream_Access_Type is access all Ada.Streams.Root_Stream_Type'Class ; type File_Type is record Opened : Boolean := False ; Ac : Root_Stream_Access_Type ; Mode : File_Mode ; Residue : Interfaces.Unsigned_8 ; Bits_Used : Integer ; end record ; end Bits_Io ; -- $Author: Administrator $ -- $Revision: 1.1.1.1 $ -- $Log: bits_io.ads,v $ -- Revision 1.1.1.1 2000/08/04 06:07:07 Administrator -- Initial Checkin -- -- Revision 1.1 1998/09/12 04:43:32 srinivr -- Bit level Stream Input/Output routines. Initial Check in with -- some known problems. -- -- Revision 1.1 1998/01/27 03:39:33 srinivr -- Added annotations -- --------------9F966ADF3242D617ECA5C48E--