CN101340191A - Decoder and decoding method - Google Patents

Decoder and decoding method Download PDF

Info

Publication number
CN101340191A
CN101340191A CN 200810118000 CN200810118000A CN101340191A CN 101340191 A CN101340191 A CN 101340191A CN 200810118000 CN200810118000 CN 200810118000 CN 200810118000 A CN200810118000 A CN 200810118000A CN 101340191 A CN101340191 A CN 101340191A
Authority
CN
China
Prior art keywords
length
code stream
memory
byte
buffer memory
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN 200810118000
Other languages
Chinese (zh)
Other versions
CN101340191B (en
Inventor
邓昊
王箫程
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
JIANGSU MONTMERY ELEVATOR CO Ltd
Original Assignee
Vimicro Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Vimicro Corp filed Critical Vimicro Corp
Priority to CN 200810118000 priority Critical patent/CN101340191B/en
Publication of CN101340191A publication Critical patent/CN101340191A/en
Application granted granted Critical
Publication of CN101340191B publication Critical patent/CN101340191B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

The invention provides a decoder and a decoding method; the decoder reads a code stream from an external memory and carries out the decoding, and the packaging format of the code stream is as follows: various bits of a semantic term in the code stream are sequentially written from a low level to high level with the start from the idle lowest data level of target bytes; when the target bytes are written to be full, the residual bits of the semantic term are started to be written from the lowest data level of the next byte. The decoder and the decoding method can rapidly and effectively carry out the decoding of the code stream with the format; when the code stream is read from the memory, the reading is unrelated with the storage sequence of platform bytes.

Description

A kind of decoder and coding/decoding method
Technical field
The present invention relates to the decoding field, relate in particular to a kind of decoder and coding/decoding method.
Background technology
More common audio stream compressed format comprises MP3, AAC etc. at present, and wherein the bit-envelope of the code stream of different compressed formats order may be different, determine by its corresponding specification document.The bit-envelope that code stream adopts usually is in proper order: from idle the maximum data position (MSB) of target byte (destination), each bit of semantic item in the code stream is write to low level successively from a high position, write when full in target byte, the remaining bits of the described semantic item the maximum data position from next byte is begun to write.
Be illustrated in figure 1 as the method schematic diagram that in ACC idle bit stream, writes a semantic item in the prior art, to write 4 bit values " 12 " [b1100] in AAC idle bit stream is example, and its wiring method is: the idle the maximum data position (i.e. the 7th~No. 4 bit) that " 1100 " order is write 0 byte.Be illustrated in figure 2 as the method schematic diagram that in ACC idle bit stream, writes two semantic item in the prior art continuously, in AAC idle bit stream, to write 4 bit values " 12 " [b1100] successively and 7 bit values " 17 " [b0010001] are example, concrete, after according to method shown in Figure 1 " 1100 " being write, again " 0010001 " order is write other bits of residue (i.e. the 3rd~No. 0 bit) of 0 byte, write when full in 0 byte, begin order from the highest order of next byte and write remaining bit.The highest order (MSB) and the lowest order (LSB) of each byte No. 7 bits and No. 0 corresponding byte of bit difference among above-mentioned Fig. 1 and Fig. 2, " X " expression idle bit position.
After code stream is encoded through specific method for packing, when needs read, need carry out decode operation to code stream, the how corresponding above-mentioned coded system of decoder of the prior art, that is: read to high byte from the low byte of code stream successively, in byte, read to low level from a high position.
Ogg Vorbis is a kind of free audio compression stream format of increased popularity, it adopts the bit-envelope order different with common audio stream, specifically: from the idle minimum data position (LSB) of target byte (destination), each bit of semantic item in the code stream is write to a high position successively from low level, target byte write full after, the remaining bits of the described semantic item minimum data position from next byte is begun to write.
Be illustrated in figure 3 as the method schematic diagram that in Ogg Vorbis idle bit stream, writes a semantic item in the prior art, to write 4 bit values " 12 " [b1100] in Ogg Vorbis idle bit stream is example, and its wiring method is: the idle minimum data position (i.e. the 0th~No. 3 bit) that " 1100 " order is write 0 byte.Be illustrated in figure 4 as the method schematic diagram that in Ogg Vorbis idle bit stream, writes two semantic item in the prior art continuously, in Ogg Vorbis idle bit stream, to write 4 bit values " 12 " [b1100] successively and 7 bit values " 17 " [b0010001] are example, concrete, after according to method shown in Figure 3 " 1100 " being write, again " 0010001 " order is write other bits of residue (i.e. the 4th~No. 7 bit) of 0 byte, write when full in 0 byte, begin order from the lowest order of next byte and write remaining bit.Same, the highest order (MSB) and the lowest order (LSB) of each byte No. 7 bits and No. 0 corresponding byte of bit difference among above-mentioned Fig. 3 and Fig. 4, " X " expression idle bit position.
Because the encapsulation of the code stream of Ogg Vorbis form order is different with the encapsulation order of compressed format commonly used, therefore, the order of its decoding is also different, utilizes decoder of the prior art can't carry out correct decoding.
Summary of the invention
In view of this, the purpose of the embodiment of the invention is to provide a kind of decoder and coding/decoding method, can decode to the code stream of Ogg Vorbis encapsulation format fast and effectively.
For achieving the above object, the embodiment of the invention provides a kind of decoder, be used for reading code stream and decoding from external memory storage, the encapsulation format of described code stream is: from the idle minimum data position of target byte, each bit of semantic item in the described code stream is write to a high position successively from low level, after described target byte is write and is expired, the remaining bits of the described semantic item minimum data position from next byte is begun to write, the storage mode of described memory is: according to the order that receives, with described code stream from the low address byte to the high address bytes store, described decoder comprises:
First buffer memory is used to store the code stream that reads from described memory, and the storage mode of described first buffer memory is: the low address byte code stream that will read from described memory is stored in idle minimum data position;
Processing module, be used for reading designated length minimum data bit code stream and output from described first buffer memory, and with the described designated length of the data shift right position in described first buffer memory, described designated length is a less value in first length and second length, described first length is the current bit length that needs the semantic item of decoding, and described second length is the significant bit length of the data of current storage in described first buffer memory;
Read module is used for when described second length is zero, reads code stream and store in described first buffer memory from the available code stream of described memory;
First update module is used in described first length during greater than described second length, and the difference of obtaining described first length and described second length is as the first new length, and sends to described processing module;
Second update module is used for when the data of described first buffer memory change, and upgrades described second length, and sends to described processing module;
Second buffer memory is used to store the code stream of described processing module output, and the storage mode of described second buffer memory is: the code stream of described processing module output is stored in idle minimum data position;
When output module, the length that is used for the code stream stored at described second buffer memory equal the length of semantic item of described current needs decoding, with the output of the code stream in described second buffer memory, and with the described second buffer memory zero clearing.
Described processing module further comprises:
First obtains submodule, is used for the coding criterion according to described code stream, obtains the current bit length that needs the semantic item of decoding, as described first length;
Second obtains submodule, is used for obtaining the significant bit length of the data of the current storage of described first buffer memory, as described second length;
Comparison sub-module is used for more described first length and described second length;
Reading submodule is used for the numerical value that described first length and described second length is less as designated length, reads described designated length minimum data bit code stream and output from described first buffer memory;
First updating submodule is used for behind described reading submodule output code flow, with the described designated length of the data shift right position in described first buffer memory.
Described first obtains submodule further comprises:
First judging unit is used to judge whether described first length that gets access to is zero;
The zero setting unit is used for controlling the described second buffer memory zero setting when described first length is zero;
First transmitting element is used for when described first length is non-vanishing described first length being sent to described comparison sub-module.
Described second obtains submodule further comprises:
Second judging unit is used to judge whether described second length that gets access to is zero;
First notification unit is used for notifying described read module when described second length is zero;
Second transmitting element is used for when described second length is non-vanishing described second length being sent to described comparison sub-module.
Described read module further comprises:
Judge submodule, be used for when described second length is zero that whether the available code stream length of judging described memory is greater than first byte length, described first byte length is the maximum length of the data that can store of described first buffer memory;
Fill submodule, be used in described available code stream length during more than or equal to described first byte length, available code stream first address according to described memory, from the available code stream of described memory, read the code stream of described first byte length and be stored in described first buffer memory, in described available code stream length during, from described memory, read the code stream of described available code stream length and be stored in described first buffer memory less than described first byte length;
Second updating submodule is used for after described filling submodule reads code stream, upgrades described available code stream first address and described available code stream length.
Described code stream is the code stream of Ogg Vorbis form.
The embodiment of the invention also provides a kind of coding/decoding method, comprise the step that from external memory storage, reads code stream and decode, the encapsulation format of described code stream is: from the idle minimum data position of target byte, each bit of semantic item in the described code stream is write to a high position successively from low level, after described target byte is write and is expired, the remaining bits of the described semantic item minimum data position from next byte is begun to write, the storage mode of described memory is: according to the order that receives, with described code stream from the low address byte to the high address bytes store, described method is further comprising the steps of:
Obtain the current bit length that needs the semantic item of decoding, as first length;
Obtain the significant bit length of the data of current cache, as second length;
With the smaller value in described first length and described second length as designated length;
From data in buffer, read described designated length minimum data bit code stream, and described code stream is placed the idle minimum data position of returning numerical value, with the data in buffer described designated length position that moves to right;
Whether the length of judging code stream in the described return value equals the described current length that needs the semantic item of decoding;
When the length of code stream equals the length of the described current semantic item that needs decoding in described return value, with the output of the code stream in the described return value, and after output with described return value zero clearing;
Code stream is uneven in length during length in the described current semantic item that needs decoding in described return value, from described external memory storage, read the code stream row cache of going forward side by side, upgrade described first length and described second length, and return described the step of the smaller value in described first length and described second length as designated length.
The described significant bit length of obtaining the data of current cache also comprises as before second length:
Judge that whether described first length is zero, when described first length is zero, directly controls the step of described return value zero setting.
Described with the smaller value in described first length and described second length as also comprising before the designated length:
Judge that whether described second length be zero, when described second length is zero, from described external memory storage, read the code stream row cache of going forward side by side, upgrade the step of described first length and described second length.
Described the go forward side by side method of row cache of code stream that reads from described external memory storage is specially:
Whether the available code stream length of judging described memory greater than first byte length, and described first byte length is the maximum length that described decoder can data in buffer;
In described available code stream length during more than or equal to described first byte length, available code stream first address according to described memory, the code stream that from the available code stream of described memory, reads described first byte length row cache of going forward side by side, in described available code stream length during less than described first byte length, the code stream that from described memory, the reads described available code stream length row cache of going forward side by side;
Upgrade described available code stream first address and described available code stream length.
Described code stream is the code stream of Ogg Vorbis form.
Embodiments of the invention have the following advantages:
Decoder and coding/decoding method by the embodiment of the invention, when the code stream of Ogg Vorbis encapsulation format is decoded, can read code stream in the following order: reading in proper order between the byte to read to the high address byte from the low address byte, byte inner reads order for reading to higher bit position (MSB) from low bit (LSB), in addition, when from external memory storage, reading code stream, it always is unit with the byte, the code stream of the low address byte of memory is read the idle minimum data position of decoder buffer, therefore, the sequence independence of depositing with the platform byte.
Description of drawings
Fig. 1 is for writing the method schematic diagram of a semantic item in ACC idle bit stream in the prior art;
Fig. 2 is for writing the method schematic diagram of two semantic item continuously in ACC idle bit stream in the prior art;
Fig. 3 is for writing the method schematic diagram of a semantic item in Ogg Vorbis idle bit stream in the prior art;
Fig. 4 is for writing the method schematic diagram of two semantic item continuously in Ogg Vorbis idle bit stream in the prior art;
Fig. 5 is the decoder architecture schematic diagram of the embodiment of the invention;
Fig. 6 for the embodiment of the invention from memory, read code stream after, the corresponding schematic diagram of the code stream of storing in the code stream of storing in first buffer memory and the memory;
Fig. 7 is the decoder method schematic flow sheet of the embodiment of the invention.
Embodiment
The embodiment of the invention provides a kind of decoder and coding/decoding method, make when the code stream that receives is decoded, can read code stream in the following order: read order for to read to the high address byte from the low address byte between the byte, byte inner reads order for reading to higher bit position (MSB) from hanging down bit (LSB).
Below in conjunction with drawings and Examples, the specific embodiment of the present invention is described in further detail.
Be illustrated in figure 5 as the decoder architecture schematic diagram of the embodiment of the invention, this decoder 10, be used for reading code stream and decoding from external memory storage 20, the encapsulation format of described code stream is: from the idle minimum data position of target byte, each bit of semantic item in the described code stream is write to a high position successively from low level, after described target byte is write and is expired, the remaining bits of the described semantic item minimum data position from next byte is begun to write, the storage mode of described memory 20 is: according to the order that receives, with described code stream from the low address byte to the high address bytes store.
Decoder 10 comprises:
First buffer memory 11, be used for storing the code stream that reads from memory 20, the storage mode of first buffer memory 11 is: the low address bytes store that will read from memory 20 is in idle minimum data position, the length of the byte that reads from memory 20 is no more than first byte length, described first byte length is the maximum length of 11 data that can store of described first buffer memory, and described first byte length can be 4 bytes, 8 bytes or other bigger byte lengths.
Processing module 12, be used for reading designated length minimum data bit code stream and output from first buffer memory 11, and with the described designated length of the data shift right position in described first buffer memory 11, described designated length is a less value in first length and second length, described first length is the current bit length that needs the semantic item of decoding, described second length is the significant bit length of the data of current storage in first buffer memory 11, and described significant bit length is the length of the available code stream of storage in described first buffer memory 11.
Read module 13 is used for when described second length is zero, reads code stream and store in first buffer memory 11 from the available code stream of memory 20.
First update module 14 is used in described first length during greater than described second length, and the difference of obtaining described first length and described second length is as the first new length, and sends to processing module 12.
Second update module 15 is used for when the data of first buffer memory 11 change, and upgrades described second length, and sends to processing module 12.Data in described first buffer memory 11 change promptly: first buffer memory 11 carries out the dextroposition operation from the data that memory 20 reads the new code stream or first buffer memory 11.
Second buffer memory 16 is used for the code stream that stores processor module 12 is exported, and the storage mode of second buffer memory 16 is: the code stream of processing module 12 outputs is stored in idle minimum data position.
Output module 17 when being used for length at the code stream of second buffer memory 16 storage and equaling the length of semantic item of described current needs decoding, is exported the code stream in second buffer memory 16, and with 16 zero clearings of second buffer memory.
During the length (first length) of the code stream that the effective length (second length) of the data of storage reads less than current needs in first buffer memory 11, the code stream of above-mentioned processing module 12 outputs then is not a complete semantic item, therefore, the code stream output that output module 17 does not receive second buffer memory 16 immediately, but continue to wait for, the code stream that processing module 12 will be exported next time is stored in the idle minimum data position of second buffer memory 16, when the length of the code stream of storage equaled the length of the described current semantic item that need decode in second buffer memory 16, output module 17 was just exported the code stream in second buffer memory 16.
Above-mentioned processing module 12 further comprises:
First obtains submodule 121, is used for the coding criterion according to the code stream that receives, and obtains the current bit length that needs the semantic item of decoding, as first length.
Second obtains submodule 122, is used for obtaining the significant bit length of first buffer memory, 11 current storage data, as second length.
Comparison sub-module 123 is used for comparison first length and second length.
Reading submodule 124 is used for the numerical value that first length and second length is less as designated length, reads described designated length minimum data bit code stream and output from first buffer memory 11.
First updating submodule 125 is used for behind reading submodule 124 output code flows, with the described designated length of the data shift right position in first buffer memory 11.
Certainly, in second length less than first length, and reading submodule 124 reads described second length minimum data position from first buffer memory 11 after, also can not carry out the dextroposition operation of first updating submodule 125, but directly from memory, read new code stream, the data in first buffer memory 11 are covered.
The above-mentioned described code stream that receives can be the code stream of Ogg Vorbis form, can certainly be the code stream of the extended formatting identical with Ogg Vorbis bit-envelope order.
When described code stream is the code stream of Ogg Vorbis form, requirement according to Ogg Vorbis coding criterion, the semantic item that also may comprise 0 byte length in the described code stream, be above-mentioned first obtain that submodule 121 gets access to current to need the length (i.e. first length) of the semantic item of decoding may be zero, when first length is zero, then need not carry out above-mentioned comparison, read, upgrade operation, but obtain directly control second buffer memory 16 zero setting of submodule 121 by first, therefore, above-mentioned first acquisition module 121 further comprises:
First judging unit is used to judge whether described first length that gets access to is zero.
The zero setting unit is used for controlling 16 zero setting of described second buffer memory when described first length is zero.
First transmitting element is used for when described first length is non-vanishing described first length being sent to described comparison sub-module 123.
When above-mentioned first buffer memory, 11 stored valid data are sky, above-mentioned second to obtain second length that submodule 122 gets access to be zero, second obtains submodule 122 needs to notify read module 13 to read new code stream from memory 20 and store in first buffer memory 11 at this moment, therefore, described second obtain submodule 122 and further comprise:
Second judging unit is used to judge whether described second length that gets access to is zero.
First notification unit is used for notifying described read module 13 when described second length is zero.
Second transmitting element is used for when described second length is non-vanishing described second length being sent to described comparison sub-module 123.
Above-mentioned reading submodule 124 reads a described designated length minimum data position from first buffer memory 11 method is specially: the minimum data bit code stream of the described designated length in first buffer memory 11 is carried out and operation with particular data, the designated length of a described particular data minimum data position bit is 1, all the other bits are 0, described result with operation promptly is the code stream that need read, certainly, reading submodule 124 also can adopt additive method to read code stream from first buffer memory 11.
Above-mentioned read module 13 further comprises:
Judge submodule 131, be used for when described second length is zero that whether judge available code stream length in the memory 20 greater than first byte length, described first byte length is the maximum length of first buffer memory, 11 storable data.Described available code stream length is the byte length of the code stream that is not read in the memory 20, generally, when decoder 10 reads code stream from memory 20, also need to read the available code stream first address and the available code stream length of memory 20, described available code stream first address is the first address of the code stream that is not read in the described memory 20.
Fill submodule 132, be used in described available code stream length during more than or equal to described first byte length, available code stream first address according to described memory 20, from the available code stream of memory 20, read the code stream of described first byte length and store in first buffer memory 11, in described available code stream length during, from memory 20, read the code stream of described available code stream length and store in first buffer memory 11 less than described first byte length.
Second updating submodule 133 is used for upgrading described available code stream first address and described available code stream length after filling submodule 132 reads code stream.
The method that reads code stream and store in first buffer memory 11 from memory 20 is specially: the code stream that reads available code stream first address in the memory 20, and described code stream is stored into the idle minimum data position of first buffer memory 11, upgrade described available code stream first address, be about to available code stream first address and add one, repeat aforesaid operations, finish until reading.In the aforesaid operations, always the code stream of the low address byte of memory 20 is read the idle minimum data position of first buffer memory 11, the sequence independence of depositing with the platform byte, be illustrated in figure 6 as the embodiment of the invention from memory, read code stream after, the corresponding schematic diagram of the code stream of storing in the code stream of storing in first buffer memory and the memory.
Be illustrated in figure 7 as the coding/decoding method schematic flow sheet of the embodiment of the invention, specifically may further comprise the steps:
Step 701 according to the coding criterion of the code stream that reads from external memory storage, is obtained the current bit length that needs the semantic item of decoding, as first length.
The encapsulation format of described code stream is: from the idle minimum data position of target byte, each bit of semantic item in the described code stream is write to a high position successively from low level, after described target byte is write and is expired, the remaining bits of the described semantic item minimum data position from next byte is begun to write, and the low address byte code stream that described decoder will read from described memory is stored in idle minimum data position; The storage mode of described external memory storage is: according to the order that receives, with described code stream from the low address byte to the high address bytes store.
Step 702 is obtained the significant bit length of the data of current cache, as second length.
Step 703, with the smaller value in described first length and described second length as designated length.
Step 704 reads a described designated length minimum data bit code stream from data in buffer, and the described code stream that reads is placed the idle minimum data position of returning numerical value.
Step 705 is with the data in buffer described designated length position that moves to right.
Step 706 judges whether the length of code stream in the described return value equals the described current length that needs the semantic item of decoding, if enter step 709, otherwise enter step 707.
Step 707 reads the code stream row cache of going forward side by side from external memory storage.
Certainly, when external memory storage reads code stream, also can not carry out above-mentioned steps 705, but the code stream that will read covers original data in buffer at needs from external memory storage.
Step 708 is upgraded first length and second length, returns step 703.
At this moment, first length after the renewal equals the poor of former first length and former second length, and second length after the renewal is the length of the code stream that reads from external memory storage.
Step 709, with the code stream in the return value that obtains output, and after output with the return value zero clearing, the code stream of storing in the described return value is the current semantic item that needs decoding.
In addition, also comprise before the above-mentioned steps 703:
Whether the bit length (i.e. first length) of the current semantic item that need decode that judgement gets access to is zero step, when the bit length of the described current semantic item that need decode equals zero, directly return value zero setting is also exported; And
Judge that whether described second length is zero step, when described second length is zero, directly enters described step 707.
Read in the above-mentioned steps 704 data in buffer method can for: the designated length of a data in buffer minimum data bit code stream is carried out and operation with particular data, the bit of the designated length of a described particular data minimum data position is 1, other bits are 0, described result with operation promptly is the code stream that need read, and described designated length is first length or second length.Certainly, also can adopt additive method to read data in buffer.
The implementation method of above-mentioned steps 707 is specially:
Whether the available code stream length of judging described memory greater than first byte length, and described first byte length is the maximum length that described decoder can data in buffer;
In described available code stream length during more than or equal to described first byte length, available code stream first address according to described memory, the code stream that from the available code stream of described memory, reads described first byte length row cache of going forward side by side, in described available code stream length during less than described first byte length, the code stream that from described memory, the reads described available code stream length row cache of going forward side by side;
Upgrade described available code stream first address and described available code stream length.
Below be example with the code stream of Ogg Vorbis form, the coding/decoding method of the embodiment of the invention is elaborated.
Decoder at first needs to read code stream from external memory storage, generally, external memory storage is with the form of array code stream to be stored, the code stream of the byte of storage of each in the array, its storage mode is: according to the reception of code stream order, from the low address byte to the high address bytes store.
When decoder flows from the memory read code fetch, always be that unit reads with the byte, and the code stream of the low address byte of memory is stored in the idle minimum data position of first buffer memory of decoder, and therefore, the data independence that above-mentioned read operation and platform byte are deposited.
In addition, when decoder reads code stream from external memory storage, also need to read the first address bufPointer of current available code stream of memory and the length nBytes of available code stream, along with the carrying out of the read operation of code stream, this is constantly carried out bufPointer and adds one operation.
Below read the identifying code of code stream from external memory storage for decoder:
void?RefillBitstreamCache(BitStreamInfo*bsi)
{
int?nBytes=bsi->nBytes;
/*check?for?underflow?case*/
if(nBytes<=0)
{
bsi->cachedBits=0;
bsi->iCache=0;
bsi->nBytes=-1;
return;
}
/ * read operation, with the code stream of the low address byte of memory be stored in the idle minimum data position * of first buffer memory of decoder/
if(nBytes>=4){
bsi->iCache=(unsigned?int)(*bsi->bytePtr++);
bsi->iCache|=(((unsigned?int)(*bsi->bytePtr++))<<8);
bsi->iCache|=(((unsigned?int)(*bsi->bytePtr++))<<16);
bsi->iCache|=(((unsigned?int)(*bsi->bytePtr++))<<24);
bsi->cachedBits=32;
bsi->nBytes-=4;
}else{
int?n=0;
bsi->iCache=0;
while(nBytes--){
bsi->iCache|=((*bsi->bytePtr++)<<(8*n));
++n;
}
bsi->cachedBits=8*bsi->nBytes;
bsi->nBytes=0;
}
}
First buffer memory in the above-mentioned decoder is equivalent to a register, it can carry out bit manipulation to the code stream of buffer memory, is generally the length of 4 bytes, also may be the length of 8 bytes, perhaps the length of other bytes supposes in the embodiment of the invention that first buffer memory is the length of 4 bytes.
The length of the semantic item in the Ogg Vorbis code stream generally is less than or equal to 32 bits (i.e. 4 bytes).
The coding/decoding method of the embodiment of the invention is specially:
Obtain the current length nBits (regulation nBits is less than or equal to 32 bits) that needs the semantic item of decoding herein;
Owing to require can comprise in the code stream semantic item of 0 byte length in the coding criterion of Ogg Vorbis form, therefore, need also to judge whether nBits is zero, when nBits equals zero,, when nBits is non-vanishing, carry out following operation directly with return value zero setting;
Obtain the effective length cachedBits of the data of storing in first buffer memory, and judge that whether cachedBits is zero, when cachedBits is zero, from external memory storage, reads new code stream and store in first buffer memory, when cachedBits is non-vanishing, carry out following operation;
The above-mentioned method that reads code stream from memory is specially: whether the current available code stream length nBytes that judges memory is greater than the length 4 of first buffer memory; At nBytes more than or equal to 4 o'clock, available code stream first address bufPointer according to described memory, from the available code stream of described memory, read the code stream of 4 bytes and store in described first buffer memory,, from described memory, read the code stream of described nBytes length and store in described first buffer memory less than 4 o'clock at nBytes;
The size that compares nBits and cachedBits;
When nBits is less than or equal to cachedBits, utilize logical bit operation (with operation) to read nBits minimum data position in first buffer memory, being about to nBits minimum data position in first buffer memory carries out with particular data MASK_TAB and operates, the bit of the nBits of described particular data MASK_TAB minimum data position is 1, other bits are 0, place nBits the minimum data position of return value data, and first buffer memory is carried out dextroposition operate, delete nBits the bit that has been read in first buffer memory, with the low bit that is not read, place the minimum data position, upgrade cachedBits simultaneously, this stylish cachedBits equals the poor of nBits and former cachedBits;
At nBits during greater than cachedBits, promptly the bit number of the available code stream in first buffer memory is not enough, from first buffer memory, take out all remaining cachedBits available bits, place cachedBits the minimum data position of return value data, renewal nBits is nBits2, nBits2 is the poor of nBits and cachedBits, simultaneously, first buffer memory is carried out the dextroposition operation, with all the bit deletions in first buffer memory, be that cachedBits is zero, then from memory, read new code stream, and upgrade cachedBits, certainly, also can not carry out the dextroposition operation, the new code stream that directly will read covers former data; Suppose that available code stream length is greater than 4 bytes in memory this moment, therefore, the length that reads new code stream from memory is 4 bytes (32 bits); Because nBits is less than or equal to 32, nBits2 is inevitable less than 32, therefore, only need utilize the logical bit operation from first buffer memory, to read nBits2 minimum data position and can finish reading of semantic item, nBits2 the code stream that reads placed (cachedBits)~nBits-1 bit of return value data, the instant current semantic item that needs decoding of the code stream of storing among the described return value data this moment.
The identifying code of said process is as follows:
unsigned?int?GetBits(BitStreamInfo*bsi,int?nBits)
{
/*const?table?to?extract?fixed?length?bits?from?iCache*/
Static?const?unsigned?int?MASK_TAB[33]=
{
0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
0x3fffffff,0x7fffffff,0xffffffff
};
/*return?data?initialization*/
unsigned?int?data=0;
unsigned?int?mask=0;
/*limit?nBits*/
nBits=MIN(nBits,32);
nBits=MAX(nBits,0);
mask=MASK_TAB[nBits];
/*check?whether?nBits?is?zero*/
if(nBits==0)
return?0;
if(bsi->cachedBits>=nBits)
{
/*enough?readable?bits?in?iCache*/
/*extract?and?update*/
data=bsi->iCache&mask;
bsi->iCache>>=nBits; /*unsigned?type,zero-extending*/
bsi->cachedBits-=nBits;
}
else{
/*not?enough?readable?bits?in?iCache*/
/*extract?all?readable?bits*/
int?bit_num_read=bsi->cachedBits;
mask=MASK_TAB[bit_num_read];
data=bsi->iCache&mask;
/*update?nBits*/
nBits-=bit_num_read;
mask=MASK_TAB[nBits];
/*fill?iCache?with?new?data*/
RefillBitstreamCache(bsi);
/*appending?bits*/
data=data|((bsi->iCache&mask)<<bit_num_read);
/*update*/
bsi->iCache>>=nBits;
bsi->cachedBits-=nBits;
}
return?data;
}
The above only is a preferred implementation of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.

Claims (11)

1. decoder, be used for reading code stream and decoding from external memory storage, the encapsulation format of described code stream is: from the idle minimum data position of target byte, each bit of semantic item in the described code stream is write to a high position successively from low level, after described target byte is write and is expired, the remaining bits of the described semantic item minimum data position from next byte is begun to write, the storage mode of described memory is: according to the order that receives, with described code stream from the low address byte to the high address bytes store, it is characterized in that, comprising:
First buffer memory is used to store the code stream that reads from described memory, and the storage mode of described first buffer memory is: the low address byte code stream that will read from described memory is stored in idle minimum data position;
Processing module, be used for reading designated length minimum data bit code stream and output from described first buffer memory, and with the described designated length of the data shift right position in described first buffer memory, described designated length is a less value in first length and second length, described first length is the current bit length that needs the semantic item of decoding, and described second length is the significant bit length of the data of current storage in described first buffer memory;
Read module is used for when described second length is zero, reads code stream and store in described first buffer memory from the available code stream of described memory;
First update module is used in described first length during greater than described second length, and the difference of obtaining described first length and described second length is as the first new length, and sends to described processing module;
Second update module is used for when the data of described first buffer memory change, and upgrades described second length, and sends to described processing module;
Second buffer memory is used to store the code stream of described processing module output, and the storage mode of described second buffer memory is: the code stream of described processing module output is stored in idle minimum data position;
When output module, the length that is used for the code stream stored at described second buffer memory equal the length of semantic item of described current needs decoding, with the output of the code stream in described second buffer memory, and with the described second buffer memory zero clearing.
2. decoder according to claim 1 is characterized in that, described processing module further comprises:
First obtains submodule, is used for the coding criterion according to described code stream, obtains the current bit length that needs the semantic item of decoding, as described first length;
Second obtains submodule, is used for obtaining the significant bit length of the data of the current storage of described first buffer memory, as described second length;
Comparison sub-module is used for more described first length and described second length;
Reading submodule is used for the numerical value that described first length and described second length is less as designated length, reads described designated length minimum data bit code stream and output from described first buffer memory;
First updating submodule is used for behind described reading submodule output code flow, with the described designated length of the data shift right position in described first buffer memory.
3. decoder according to claim 2 is characterized in that, described first obtains submodule further comprises:
First judging unit is used to judge whether described first length that gets access to is zero;
The zero setting unit is used for controlling the described second buffer memory zero setting when described first length is zero;
First transmitting element is used for when described first length is non-vanishing described first length being sent to described comparison sub-module.
4. decoder according to claim 2 is characterized in that, described second obtains submodule further comprises:
Second judging unit is used to judge whether described second length that gets access to is zero;
First notification unit is used for notifying described read module when described second length is zero;
Second transmitting element is used for when described second length is non-vanishing described second length being sent to described comparison sub-module.
5. decoder according to claim 1 is characterized in that, described read module further comprises:
Judge submodule, be used for when described second length is zero that whether the available code stream length of judging described memory is greater than first byte length, described first byte length is the maximum length of the data that can store of described first buffer memory;
Fill submodule, be used in described available code stream length during more than or equal to described first byte length, available code stream first address according to described memory, from the available code stream of described memory, read the code stream of described first byte length and be stored in described first buffer memory, in described available code stream length during, from described memory, read the code stream of described available code stream length and be stored in described first buffer memory less than described first byte length;
Second updating submodule is used for after described filling submodule reads code stream, upgrades described available code stream first address and described available code stream length.
6. decoder according to claim 1 is characterized in that, described code stream is the code stream of Ogg Vorbis form.
7. coding/decoding method, comprise the step that from external memory storage, reads code stream and decode, the encapsulation format of described code stream is: from the idle minimum data position of target byte, each bit of semantic item in the described code stream is write to a high position successively from low level, after described target byte is write and is expired, the remaining bits of the described semantic item minimum data position from next byte is begun to write, the storage mode of described memory is: according to the order that receives, with described code stream from the low address byte to the high address bytes store, it is characterized in that, may further comprise the steps:
Obtain the current bit length that needs the semantic item of decoding, as first length;
Obtain the significant bit length of the data of current cache, as second length;
With the smaller value in described first length and described second length as designated length;
From data in buffer, read described designated length minimum data bit code stream, and described code stream is placed the idle minimum data position of returning numerical value, with the data in buffer described designated length position that moves to right;
Whether the length of judging code stream in the described return value equals the described current length that needs the semantic item of decoding;
When the length of code stream equals the length of the described current semantic item that needs decoding in described return value, with the output of the code stream in the described return value, and after output with described return value zero clearing;
Code stream is uneven in length during length in the described current semantic item that needs decoding in described return value, from described external memory storage, read the code stream row cache of going forward side by side, upgrade described first length and described second length, and return described the step of the smaller value in described first length and described second length as designated length.
8. coding/decoding method according to claim 7 is characterized in that, the described significant bit length of obtaining the data of current cache also comprises as before second length:
Judge that whether described first length is zero, when described first length is zero, directly controls the step of described return value zero setting.
9. coding/decoding method according to claim 7 is characterized in that, described with the smaller value in described first length and described second length as also comprising before the designated length:
Judge that whether described second length be zero, when described second length is zero, from described external memory storage, read the code stream row cache of going forward side by side, upgrade the step of described first length and described second length.
10. coding/decoding method according to claim 7 is characterized in that, described the go forward side by side method of row cache of code stream that reads from described external memory storage is specially:
Whether the available code stream length of judging described memory greater than first byte length, and described first byte length is the maximum length that described decoder can data in buffer;
In described available code stream length during more than or equal to described first byte length, available code stream first address according to described memory, the code stream that from the available code stream of described memory, reads described first byte length row cache of going forward side by side, in described available code stream length during less than described first byte length, the code stream that from described memory, the reads described available code stream length row cache of going forward side by side;
Upgrade described available code stream first address and described available code stream length.
11. coding/decoding method according to claim 7 is characterized in that, described code stream is the code stream of Ogg Vorbis form.
CN 200810118000 2008-08-19 2008-08-19 Decoder and decoding method Expired - Fee Related CN101340191B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200810118000 CN101340191B (en) 2008-08-19 2008-08-19 Decoder and decoding method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200810118000 CN101340191B (en) 2008-08-19 2008-08-19 Decoder and decoding method

Publications (2)

Publication Number Publication Date
CN101340191A true CN101340191A (en) 2009-01-07
CN101340191B CN101340191B (en) 2013-07-31

Family

ID=40214170

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200810118000 Expired - Fee Related CN101340191B (en) 2008-08-19 2008-08-19 Decoder and decoding method

Country Status (1)

Country Link
CN (1) CN101340191B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101699391B (en) * 2009-09-30 2013-01-16 江南大学 Byte code buffer device for improving instruction fetch bandwidth of Java processor and using method thereof
CN109858950A (en) * 2018-12-28 2019-06-07 金螳螂家装电子商务(苏州)有限公司 A kind of marketing data processing system of assembling platform

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101253550B (en) * 2005-05-26 2013-03-27 Lg电子株式会社 Method of encoding and decoding an audio signal

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101699391B (en) * 2009-09-30 2013-01-16 江南大学 Byte code buffer device for improving instruction fetch bandwidth of Java processor and using method thereof
CN109858950A (en) * 2018-12-28 2019-06-07 金螳螂家装电子商务(苏州)有限公司 A kind of marketing data processing system of assembling platform

Also Published As

Publication number Publication date
CN101340191B (en) 2013-07-31

Similar Documents

Publication Publication Date Title
CN101162449B (en) NAND FLASH controller and data interactive method with NAND FLASH chip
US20050198471A1 (en) Micro-controller for reading out compressed instruction code and program memory for compressing instruction code and storing therein
JPH07160585A (en) Low power data processor
CN102339641A (en) Error checking and correcting verification module and data reading-writing method thereof
US20120033738A1 (en) Virtual frame buffer system and method
EP1019809B1 (en) Apparatus and method for upgrading a computer system operating system
EP2130132B1 (en) Dsp including a compute unit with an internal bit fifo circuit
US20080140869A1 (en) Circuits and Methods for Correcting Errors in Downloading Firmware
CN100508604C (en) Arithmetic coding circuit and arithmetic coding control method
CN101310447B (en) Memory efficient erasure information table for decoding of mpe-fec frames
CN101340191B (en) Decoder and decoding method
US20040021591A1 (en) Processor, encoder, decoder, and electronic apparatus
JPH08340263A (en) In-place present condition/next condition register
CN102055553A (en) Receiving apparatus, and corresponding method, computer program and system
US20070226420A1 (en) Compression method and apparatus for a CPU
US7742544B2 (en) System and method for efficient CABAC clock
CN101510175B (en) Method for updating target data to memory and apparatus thereof
US8694138B2 (en) Sound data processing appartus
CN101854231A (en) Protocol encoding and decoding method based on protocol model
CN1293479C (en) Asynchronous FIFO data caching method
US20080178051A1 (en) Dvb-h system and method for performing forward error correction
CN202602827U (en) Variable-length decoding device based on universal format code table
US6928599B2 (en) Method and apparatus for decoding data
CN102156629A (en) Method for extending 32-bit instructions
JPWO2013128624A1 (en) Microcomputer and nonvolatile semiconductor device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
ASS Succession or assignment of patent right

Owner name: WUXI VIMICRO ELECTRONIC CO., LTD.

Free format text: FORMER OWNER: BEIJING ZHONGXING MICROELECTRONICS CO., LTD.

Effective date: 20110128

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 100083 15/F, SHINING BUILDING, NO.35, XUEYUAN ROAD, HAIDIAN DISTRICT, BEIJING TO: 214028 NATIONAL INTEGRATED CIRCUIT DESIGN PARK (CHUANGYUAN BUILDING), NO.21-1, CHANGJIANG ROAD, NEW DISTRICT, WUXI CITY, JIANGSU PROVINCE

TA01 Transfer of patent application right

Effective date of registration: 20110128

Address after: 214028 national integrated circuit design Park, Changjiang Road, New District, Jiangsu,, Wuxi

Applicant after: Wuxi Vimicro Co., Ltd.

Address before: 100083, Haidian District, Xueyuan Road, Beijing No. 35, Nanjing Ning building, 15 Floor

Applicant before: Beijing Vimicro Corporation

C14 Grant of patent or utility model
GR01 Patent grant
ASS Succession or assignment of patent right

Owner name: JIANGSU MONTGOMERY ELEVATOR CO., LTD.

Free format text: FORMER OWNER: WUXI VIMICRO CO., LTD.

Effective date: 20141115

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 214028 WUXI, JIANGSU PROVINCE TO: 226300 NANTONG, JIANGSU PROVINCE

TR01 Transfer of patent right

Effective date of registration: 20141115

Address after: 226300, No. 999, Tong Jin Road, Nantong hi tech Industrial Development Zone, Jiangsu

Patentee after: JIANGSU MONTMERY ELEVATOR CO., LTD.

Address before: 214028 national integrated circuit design Park, Changjiang Road, New District, Jiangsu,, Wuxi

Patentee before: Wuxi Vimicro Co., Ltd.

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20130731

Termination date: 20170819