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-
2017#define DRFLAC_STRINGIFY (x ) #x
2118#define DRFLAC_XSTRINGIFY (x ) DRFLAC_STRINGIFY(x)
2219
@@ -25,6 +22,8 @@ extern "C" {
2522#define DRFLAC_VERSION_REVISION 42
2623#define DRFLAC_VERSION_STRING DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MAJOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MINOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_REVISION)
2724
25+ #include <stddef.h> /* For size_t. */
26+
2827/* Sized Types */
2928typedef signed char drflac_int8 ;
3029typedef unsigned char drflac_uint8 ;
@@ -60,27 +59,6 @@ typedef drflac_uint32 drflac_bool32;
6059#define DRFLAC_FALSE 0
6160/* End Sized Types */
6261
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-
8462/* Allocation Callbacks */
8563typedef struct
8664{
@@ -536,38 +514,6 @@ typedef struct
536514 drflac_uint8 pExtraData [1 ];
537515} drflac ;
538516
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 ;
571517
572518/*
573519Opens a FLAC decoder.
@@ -770,7 +716,7 @@ Return Value
770716-------------
771717`DRFLAC_TRUE` if successful; `DRFLAC_FALSE` otherwise.
772718*/
773- uint32_t drflac_seek_to_pcm_frame (drflac * pFlac , uint64_t pcmFrameIndex );
719+ drflac_bool32 drflac_seek_to_pcm_frame (drflac * pFlac , drflac_uint64 pcmFrameIndex );
774720
775721/*
776722Opens a FLAC decoder from a pre-allocated block of memory
@@ -814,8 +760,62 @@ Set pAllocationCallbacks to the same object that was passed to drflac_open_*_and
814760*/
815761void drflac_free (void * p , const drflac_allocation_callbacks * pAllocationCallbacks );
816762
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+
817818#ifdef __cplusplus
818819}
819820#endif
820-
821- #endif /* DR_FLAC_H */
821+ #endif /* dr_flac_h */
0 commit comments