77GitHub: https://github.com/mackron/dr_libs
88*/
99
10- #ifndef dr_flac_h
11- #define dr_flac_h
10+ #ifndef DR_FLAC_H
11+ #define DR_FLAC_H
1212
1313#ifdef __cplusplus
1414extern "C" {
1515#endif
1616
17+ #include <stdint.h>
18+ #include <stddef.h> /* For size_t. */
19+
1720#define DRFLAC_STRINGIFY (x ) #x
1821#define DRFLAC_XSTRINGIFY (x ) DRFLAC_STRINGIFY(x)
1922
@@ -22,8 +25,6 @@ extern "C" {
2225#define DRFLAC_VERSION_REVISION 42
2326#define DRFLAC_VERSION_STRING DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MAJOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MINOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_REVISION)
2427
25- #include <stddef.h> /* For size_t. */
26-
2728/* Sized Types */
2829typedef signed char drflac_int8 ;
2930typedef unsigned char drflac_uint8 ;
@@ -59,6 +60,27 @@ typedef drflac_uint32 drflac_bool32;
5960#define DRFLAC_FALSE 0
6061/* End Sized Types */
6162
63+ /*
64+ BIT READING ATTEMPT #2
65+
66+ This uses a 32- or 64-bit bit-shifted cache - as bits are read, the cache is shifted such that the first valid bit is sitting
67+ on the most significant bit. It uses the notion of an L1 and L2 cache (borrowed from CPU architecture), where the L1 cache
68+ is a 32- or 64-bit unsigned integer (depending on whether or not a 32- or 64-bit build is being compiled) and the L2 is an
69+ array of "cache lines", with each cache line being the same size as the L1. The L2 is a buffer of about 4KB and is where data
70+ from onRead() is read into.
71+ */
72+ #define DRFLAC_CACHE_L1_SIZE_BYTES (bs ) (sizeof((bs)->cache))
73+ #define DRFLAC_CACHE_L1_SIZE_BITS (bs ) (sizeof((bs)->cache)*8)
74+ #define DRFLAC_CACHE_L1_BITS_REMAINING (bs ) (DRFLAC_CACHE_L1_SIZE_BITS(bs) - (bs)->consumedBits)
75+ #define DRFLAC_CACHE_L1_SELECTION_MASK (_bitCount ) (~((~(drflac_cache_t)0) >> (_bitCount)))
76+ #define DRFLAC_CACHE_L1_SELECTION_SHIFT (bs , _bitCount ) (DRFLAC_CACHE_L1_SIZE_BITS(bs) - (_bitCount))
77+ #define DRFLAC_CACHE_L1_SELECT (bs , _bitCount ) (((bs)->cache) & DRFLAC_CACHE_L1_SELECTION_MASK(_bitCount))
78+ #define DRFLAC_CACHE_L1_SELECT_AND_SHIFT (bs , _bitCount ) (DRFLAC_CACHE_L1_SELECT((bs), (_bitCount)) >> DRFLAC_CACHE_L1_SELECTION_SHIFT((bs), (_bitCount)))
79+ #define DRFLAC_CACHE_L1_SELECT_AND_SHIFT_SAFE (bs , _bitCount )(DRFLAC_CACHE_L1_SELECT((bs), (_bitCount)) >> (DRFLAC_CACHE_L1_SELECTION_SHIFT((bs), (_bitCount)) & (DRFLAC_CACHE_L1_SIZE_BITS(bs)-1)))
80+ #define DRFLAC_CACHE_L2_SIZE_BYTES (bs ) (sizeof((bs)->cacheL2))
81+ #define DRFLAC_CACHE_L2_LINE_COUNT (bs ) (DRFLAC_CACHE_L2_SIZE_BYTES(bs) / sizeof((bs)->cacheL2[0]))
82+ #define DRFLAC_CACHE_L2_LINES_REMAINING (bs ) (DRFLAC_CACHE_L2_LINE_COUNT(bs) - (bs)->nextL2Line)
83+
6284/* Allocation Callbacks */
6385typedef struct
6486{
@@ -514,6 +536,38 @@ typedef struct
514536 drflac_uint8 pExtraData [1 ];
515537} drflac ;
516538
539+ /* Structure representing an iterator for vorbis comments in a VORBIS_COMMENT metadata block. */
540+ typedef struct
541+ {
542+ drflac_uint32 countRemaining ;
543+ const char * pRunningData ;
544+ } drflac_vorbis_comment_iterator ;
545+
546+ /* Structure representing an iterator for cuesheet tracks in a CUESHEET metadata block. */
547+ typedef struct
548+ {
549+ drflac_uint32 countRemaining ;
550+ const char * pRunningData ;
551+ } drflac_cuesheet_track_iterator ;
552+
553+ /* The order of members here is important because we map this directly to the raw data within the CUESHEET metadata block. */
554+ typedef struct
555+ {
556+ drflac_uint64 offset ;
557+ drflac_uint8 index ;
558+ drflac_uint8 reserved [3 ];
559+ } drflac_cuesheet_track_index ;
560+
561+ typedef struct
562+ {
563+ drflac_uint64 offset ;
564+ drflac_uint8 trackNumber ;
565+ char ISRC [12 ];
566+ drflac_bool8 isAudio ;
567+ drflac_bool8 preEmphasis ;
568+ drflac_uint8 indexCount ;
569+ const drflac_cuesheet_track_index * pIndexPoints ;
570+ } drflac_cuesheet_track ;
517571
518572/*
519573Opens a FLAC decoder.
@@ -716,7 +770,7 @@ Return Value
716770-------------
717771`DRFLAC_TRUE` if successful; `DRFLAC_FALSE` otherwise.
718772*/
719- drflac_bool32 drflac_seek_to_pcm_frame (drflac * pFlac , drflac_uint64 pcmFrameIndex );
773+ uint32_t drflac_seek_to_pcm_frame (drflac * pFlac , uint64_t pcmFrameIndex );
720774
721775/*
722776Opens a FLAC decoder from a pre-allocated block of memory
@@ -760,62 +814,8 @@ Set pAllocationCallbacks to the same object that was passed to drflac_open_*_and
760814*/
761815void drflac_free (void * p , const drflac_allocation_callbacks * pAllocationCallbacks );
762816
763-
764- /* Structure representing an iterator for vorbis comments in a VORBIS_COMMENT metadata block. */
765- typedef struct
766- {
767- drflac_uint32 countRemaining ;
768- const char * pRunningData ;
769- } drflac_vorbis_comment_iterator ;
770-
771- /* Structure representing an iterator for cuesheet tracks in a CUESHEET metadata block. */
772- typedef struct
773- {
774- drflac_uint32 countRemaining ;
775- const char * pRunningData ;
776- } drflac_cuesheet_track_iterator ;
777-
778- /* The order of members here is important because we map this directly to the raw data within the CUESHEET metadata block. */
779- typedef struct
780- {
781- drflac_uint64 offset ;
782- drflac_uint8 index ;
783- drflac_uint8 reserved [3 ];
784- } drflac_cuesheet_track_index ;
785-
786- typedef struct
787- {
788- drflac_uint64 offset ;
789- drflac_uint8 trackNumber ;
790- char ISRC [12 ];
791- drflac_bool8 isAudio ;
792- drflac_bool8 preEmphasis ;
793- drflac_uint8 indexCount ;
794- const drflac_cuesheet_track_index * pIndexPoints ;
795- } drflac_cuesheet_track ;
796-
797- /*
798- BIT READING ATTEMPT #2
799-
800- This uses a 32- or 64-bit bit-shifted cache - as bits are read, the cache is shifted such that the first valid bit is sitting
801- on the most significant bit. It uses the notion of an L1 and L2 cache (borrowed from CPU architecture), where the L1 cache
802- is a 32- or 64-bit unsigned integer (depending on whether or not a 32- or 64-bit build is being compiled) and the L2 is an
803- array of "cache lines", with each cache line being the same size as the L1. The L2 is a buffer of about 4KB and is where data
804- from onRead() is read into.
805- */
806- #define DRFLAC_CACHE_L1_SIZE_BYTES (bs ) (sizeof((bs)->cache))
807- #define DRFLAC_CACHE_L1_SIZE_BITS (bs ) (sizeof((bs)->cache)*8)
808- #define DRFLAC_CACHE_L1_BITS_REMAINING (bs ) (DRFLAC_CACHE_L1_SIZE_BITS(bs) - (bs)->consumedBits)
809- #define DRFLAC_CACHE_L1_SELECTION_MASK (_bitCount ) (~((~(drflac_cache_t)0) >> (_bitCount)))
810- #define DRFLAC_CACHE_L1_SELECTION_SHIFT (bs , _bitCount ) (DRFLAC_CACHE_L1_SIZE_BITS(bs) - (_bitCount))
811- #define DRFLAC_CACHE_L1_SELECT (bs , _bitCount ) (((bs)->cache) & DRFLAC_CACHE_L1_SELECTION_MASK(_bitCount))
812- #define DRFLAC_CACHE_L1_SELECT_AND_SHIFT (bs , _bitCount ) (DRFLAC_CACHE_L1_SELECT((bs), (_bitCount)) >> DRFLAC_CACHE_L1_SELECTION_SHIFT((bs), (_bitCount)))
813- #define DRFLAC_CACHE_L1_SELECT_AND_SHIFT_SAFE (bs , _bitCount )(DRFLAC_CACHE_L1_SELECT((bs), (_bitCount)) >> (DRFLAC_CACHE_L1_SELECTION_SHIFT((bs), (_bitCount)) & (DRFLAC_CACHE_L1_SIZE_BITS(bs)-1)))
814- #define DRFLAC_CACHE_L2_SIZE_BYTES (bs ) (sizeof((bs)->cacheL2))
815- #define DRFLAC_CACHE_L2_LINE_COUNT (bs ) (DRFLAC_CACHE_L2_SIZE_BYTES(bs) / sizeof((bs)->cacheL2[0]))
816- #define DRFLAC_CACHE_L2_LINES_REMAINING (bs ) (DRFLAC_CACHE_L2_LINE_COUNT(bs) - (bs)->nextL2Line)
817-
818817#ifdef __cplusplus
819818}
820819#endif
821- #endif /* dr_flac_h */
820+
821+ #endif /* DR_FLAC_H */
0 commit comments