diff options
author | Jakub Pawlowski <jpawlowski@google.com> | 2022-01-03 11:00:01 +0100 |
---|---|---|
committer | Jakub Pawlowski <jpawlowski@google.com> | 2022-01-03 13:04:07 +0100 |
commit | ce1cdfc8b9b8c542909f57d6778183b9b52d441c (patch) | |
tree | d927682b26ec74fb5ba156c9090621db4e1e211d /system/embdrv/lc3_dec/Decoder/BitReader.cpp | |
parent | 111ff202cab2c1cd1ac6df4fcde2abc9c68b2adc (diff) |
Move LC3 decoder
Make place for in-house implementation
Bug: 150670922
Change-Id: Id7734518835a8e08c8d617bb34073a836589a6de
Diffstat (limited to 'system/embdrv/lc3_dec/Decoder/BitReader.cpp')
-rw-r--r-- | system/embdrv/lc3_dec/Decoder/BitReader.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/system/embdrv/lc3_dec/Decoder/BitReader.cpp b/system/embdrv/lc3_dec/Decoder/BitReader.cpp new file mode 100644 index 0000000000..161dfb0e5e --- /dev/null +++ b/system/embdrv/lc3_dec/Decoder/BitReader.cpp @@ -0,0 +1,50 @@ +/* + * BitReader.cpp + * + * Copyright 2021 HIMSA II K/S - www.himsa.com. Represented by EHIMA - + * www.ehima.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "BitReader.hpp" + +namespace Lc3Dec { + +uint8_t read_bit(const uint8_t bytes[], uint16_t* bp, uint8_t* mask) { + uint8_t bit; + if (bytes[*bp] & *mask) { + bit = 1; + } else { + bit = 0; + } + if (*mask == 0x80) { + *mask = 1; + *bp -= 1; + } else { + *mask <<= 1; + } + return bit; +} + +uint16_t read_uint(const uint8_t bytes[], uint16_t* bp, uint8_t* mask, + uint8_t numbits) { + uint16_t value = read_bit(bytes, bp, mask); + for (uint8_t i = 1; i < numbits; i++) { + uint16_t bit = read_bit(bytes, bp, mask); + value += bit << i; + } + return value; +} + +} // namespace Lc3Dec |