summaryrefslogtreecommitdiff
path: root/plugins/gme/game-music-emu-0.6pre/gme/s_logtbl.h
blob: 3abc79c11556a0bb70cf5288a083c0a217fd0cde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef S_LOGTBL_H__
#define S_LOGTBL_H__

#ifdef __cplusplus
extern "C" {
#endif

#define LOG_BITS 12
#define LIN_BITS 7
#define LOG_LIN_BITS 30

typedef struct
{
	void *ctx;
	void (*release)(void *ctx);
	Uint32 lineartbl[(1 << LIN_BITS) + 1];
	Uint32 logtbl[1 << LOG_BITS];
} KMIF_LOGTABLE;

KMIF_LOGTABLE *LogTableAddRef(void);

__inline static Uint32 LinToLog(KMIF_LOGTABLE *kmif_lt, Int32 l)
{
	return (l < 0) ? (kmif_lt->lineartbl[-l] + 1) : kmif_lt->lineartbl[l];
}

__inline static Int32 LogToLin(KMIF_LOGTABLE *kmif_lt, Int32 l, Uint32 sft)
{
	Int32 ret;
	Uint32 ofs;
	ofs = l + (sft << (LOG_BITS + 1));
	sft = ofs >> (LOG_BITS + 1);
	if (sft >= LOG_LIN_BITS) return 0;
	ofs = (ofs >> 1) & ((1 << LOG_BITS) - 1);
	ret = kmif_lt->logtbl[ofs] >> sft;
	return (l & 1) ? -ret : ret;
}

#ifdef __cplusplus
}
#endif

#endif /* S_LOGTBL_H__ */