mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-30 22:49:53 +08:00
2b6bd5a532
* [audio] added sdl audio backend and in-tree atrac9 decoder * [input] replaced per-platform pad readers with sdl gamepad input * [video] added sdl window and host display plumbing * [gui] added host display options and per-game render settings * [bink] synced host movie playback to the guest audio clock * [cpu] hooked windows write faults into guest image tracking * [perf] added guest and render profiling, reserved host cpu lanes * [kernel] fixed stale pthread mutex handle alias * [host] wired the sdl session, save-data paths and project references * [audio] hoisted ajm trace stackalloc out of its loop * [video] Add guest image sync setting * [build] Strip native symbols * reuse
65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
// SPDX-License-Identifier: MIT
|
|
#nullable disable
|
|
using System;
|
|
using LibAtrac9.Utilities;
|
|
|
|
namespace LibAtrac9
|
|
{
|
|
internal class HuffmanCodebook
|
|
{
|
|
public HuffmanCodebook(short[] codes, byte[] bits, byte valueCountPower)
|
|
{
|
|
Codes = codes;
|
|
Bits = bits;
|
|
if (Codes == null || Bits == null) return;
|
|
|
|
ValueCount = 1 << valueCountPower;
|
|
ValueCountPower = valueCountPower;
|
|
ValueBits = Helpers.Log2(codes.Length) >> valueCountPower;
|
|
ValueMax = 1 << ValueBits;
|
|
|
|
int max = 0;
|
|
foreach (byte bitSize in bits)
|
|
{
|
|
max = Math.Max(max, bitSize);
|
|
}
|
|
|
|
MaxBitSize = max;
|
|
Lookup = CreateLookupTable();
|
|
}
|
|
|
|
private byte[] CreateLookupTable()
|
|
{
|
|
if (Codes == null || Bits == null) return null;
|
|
|
|
int tableSize = 1 << MaxBitSize;
|
|
var dest = new byte[tableSize];
|
|
|
|
for (int i = 0; i < Bits.Length; i++)
|
|
{
|
|
if (Bits[i] == 0) continue;
|
|
int unusedBits = MaxBitSize - Bits[i];
|
|
|
|
int start = Codes[i] << unusedBits;
|
|
int length = 1 << unusedBits;
|
|
int end = start + length;
|
|
|
|
for (int j = start; j < end; j++)
|
|
{
|
|
dest[j] = (byte)i;
|
|
}
|
|
}
|
|
return dest;
|
|
}
|
|
|
|
public short[] Codes { get; }
|
|
public byte[] Bits { get; }
|
|
public byte[] Lookup { get; }
|
|
public int ValueCount { get; }
|
|
public int ValueCountPower { get; }
|
|
public int ValueBits { get; }
|
|
public int ValueMax { get; }
|
|
public int MaxBitSize { get; }
|
|
}
|
|
}
|