From: srini <r.srinivasan@worldnet.att.net>
Subject: Re: bitstreams
Date: Sun, 14 Jan 2001 19:46:08 GMT
Date: 2001-01-14T19:46:08+00:00 [thread overview]
Message-ID: <3A622CE5.89C9378E@worldnet.att.net> (raw)
In-Reply-To: 93se2v$nen$1@eol.dd.chalmers.se
[-- Attachment #1: Type: text/plain, Size: 605 bytes --]
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
[-- Attachment #2: bits_io.ads --]
[-- Type: text/plain, Size: 3363 bytes --]
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
--
next prev parent reply other threads:[~2001-01-14 19:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-01-14 14:47 bitstreams Daniel Nilsson
2001-01-14 15:10 ` bitstreams Larry Kilgallen
2001-01-14 16:15 ` bitstreams tmoran
2001-01-14 19:46 ` srini [this message]
2001-01-15 19:56 ` bitstreams mark_lundquist
2001-01-15 21:54 ` bitstreams Tucker Taft
2001-01-16 0:41 ` bitstreams Robert Dewar
2001-01-16 0:39 ` bitstreams Robert Dewar
2001-01-16 23:26 ` bitstreams Rajagopalan Srinivasan
2001-01-15 19:21 ` bitstreams mark_lundquist
2001-01-15 20:43 ` bitstreams Pat Rogers
2001-01-15 21:15 ` bitstreams mark_lundquist
2001-01-16 0:59 ` bitstreams Robert Dewar
2001-01-16 17:36 ` bitstreams mark_lundquist
2001-01-16 20:08 ` bitstreams Pat Rogers
2001-01-17 2:15 ` bitstreams Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox