Unverified Commit 8302a7ef authored by Wolle's avatar Wolle Committed by GitHub

use mask in bitreader

it's much faster than bit shifting
parent 82cf74f2
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* adapted to ESP32 * adapted to ESP32
* *
* Created on: Jul 03,2020 * Created on: Jul 03,2020
* Updated on: Feb 10,2023 * Updated on: Apr 10,2023
* *
* Author: Wolle * Author: Wolle
* *
...@@ -80,6 +80,12 @@ void FLACDecoder_FreeBuffers(){ ...@@ -80,6 +80,12 @@ void FLACDecoder_FreeBuffers(){
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
// B I T R E A D E R // B I T R E A D E R
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
const uint32_t mask[] = {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};
uint32_t readUint(uint8_t nBits, int *bytesLeft){ uint32_t readUint(uint8_t nBits, int *bytesLeft){
while (m_bitBufferLen < nBits){ while (m_bitBufferLen < nBits){
uint8_t temp = *(m_inptr + m_rIndex); uint8_t temp = *(m_inptr + m_rIndex);
...@@ -92,7 +98,7 @@ uint32_t readUint(uint8_t nBits, int *bytesLeft){ ...@@ -92,7 +98,7 @@ uint32_t readUint(uint8_t nBits, int *bytesLeft){
m_bitBufferLen -= nBits; m_bitBufferLen -= nBits;
uint32_t result = m_bitBuffer >> m_bitBufferLen; uint32_t result = m_bitBuffer >> m_bitBufferLen;
if (nBits < 32) if (nBits < 32)
result &= (1 << nBits) - 1; result &= mask[nBits];
return result; return result;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* flac_decoder.h * flac_decoder.h
* *
* Created on: Jul 03,2020 * Created on: Jul 03,2020
* Updated on: Jan 08,2023 * Updated on: Apr 09,2023
* *
* Author: wolle * Author: wolle
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment