4 #define DR_FLAC_NO_STDIO 21 #define DRFLAC_FALSE 0 27 #ifndef DR_FLAC_BUFFER_SIZE 28 #define DR_FLAC_BUFFER_SIZE 4096 41 #if defined(__x86_64__) || defined(__ppc64__) 53 #define DRFLAC_METADATA_BLOCK_TYPE_STREAMINFO 0 54 #define DRFLAC_METADATA_BLOCK_TYPE_PADDING 1 55 #define DRFLAC_METADATA_BLOCK_TYPE_APPLICATION 2 56 #define DRFLAC_METADATA_BLOCK_TYPE_SEEKTABLE 3 57 #define DRFLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT 4 58 #define DRFLAC_METADATA_BLOCK_TYPE_CUESHEET 5 59 #define DRFLAC_METADATA_BLOCK_TYPE_PICTURE 6 60 #define DRFLAC_METADATA_BLOCK_TYPE_INVALID 127 63 #define DRFLAC_PICTURE_TYPE_OTHER 0 64 #define DRFLAC_PICTURE_TYPE_FILE_ICON 1 65 #define DRFLAC_PICTURE_TYPE_OTHER_FILE_ICON 2 66 #define DRFLAC_PICTURE_TYPE_COVER_FRONT 3 67 #define DRFLAC_PICTURE_TYPE_COVER_BACK 4 68 #define DRFLAC_PICTURE_TYPE_LEAFLET_PAGE 5 69 #define DRFLAC_PICTURE_TYPE_MEDIA 6 70 #define DRFLAC_PICTURE_TYPE_LEAD_ARTIST 7 71 #define DRFLAC_PICTURE_TYPE_ARTIST 8 72 #define DRFLAC_PICTURE_TYPE_CONDUCTOR 9 73 #define DRFLAC_PICTURE_TYPE_BAND 10 74 #define DRFLAC_PICTURE_TYPE_COMPOSER 11 75 #define DRFLAC_PICTURE_TYPE_LYRICIST 12 76 #define DRFLAC_PICTURE_TYPE_RECORDING_LOCATION 13 77 #define DRFLAC_PICTURE_TYPE_DURING_RECORDING 14 78 #define DRFLAC_PICTURE_TYPE_DURING_PERFORMANCE 15 79 #define DRFLAC_PICTURE_TYPE_SCREEN_CAPTURE 16 80 #define DRFLAC_PICTURE_TYPE_BRIGHT_COLORED_FISH 17 81 #define DRFLAC_PICTURE_TYPE_ILLUSTRATION 18 82 #define DRFLAC_PICTURE_TYPE_BAND_LOGOTYPE 19 83 #define DRFLAC_PICTURE_TYPE_PUBLISHER_LOGOTYPE 20 203 typedef size_t (*
drflac_read_proc)(
void* pUserData,
void* pBufferOut,
size_t bytesToRead);
537 #ifndef DR_FLAC_NO_STDIO 552 drflac* drflac_open_file(
const char* filename);
592 #ifndef DR_FLAC_NO_STDIO 594 drflac_int32* drflac_open_and_decode_file_s32(
const char* filename,
unsigned int* channels,
unsigned int* sampleRate,
drflac_uint64* totalSampleCount);
597 drflac_int16* drflac_open_and_decode_file_s16(
const char* filename,
unsigned int* channels,
unsigned int* sampleRate,
drflac_uint64* totalSampleCount);
600 float* drflac_open_and_decode_file_f32(
const char* filename,
unsigned int* channels,
unsigned int* sampleRate,
drflac_uint64* totalSampleCount);
644 #ifdef DR_FLAC_IMPLEMENTATION 649 #if defined(__x86_64__) || defined(_M_X64) 651 #elif defined(__i386) || defined(_M_IX86) 653 #elif defined(__arm__) || defined(_M_ARM) 658 #if !defined(DR_FLAC_NO_SIMD) && (defined(DRFLAC_X86) || defined(DRFLAC_X64)) 659 #if defined(_MSC_VER) && !defined(__clang__) 662 static void drflac__cpuid(
int info[4],
int fid)
667 #define DRFLAC_NO_CPUID 670 #if defined(__GNUC__) || defined(__clang__) 671 static void drflac__cpuid(
int info[4],
int fid)
674 "cpuid" :
"=a"(
info[0]),
"=b"(
info[1]),
"=c"(
info[2]),
"=d"(
info[3]) :
"a"(fid),
"c"(0)
678 #define DRFLAC_NO_CPUID 682 #define DRFLAC_NO_CPUID 691 #if defined(_MSC_VER) && _MSC_VER >= 1500 && (defined(DRFLAC_X86) || defined(DRFLAC_X64)) 692 #define DRFLAC_HAS_LZCNT_INTRINSIC 693 #elif (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) 694 #define DRFLAC_HAS_LZCNT_INTRINSIC 695 #elif defined(__clang__) 696 #if __has_builtin(__builtin_clzll) || __has_builtin(__builtin_clzl) 697 #define DRFLAC_HAS_LZCNT_INTRINSIC 701 #if defined(_MSC_VER) && _MSC_VER >= 1300 702 #define DRFLAC_HAS_BYTESWAP_INTRINSIC 703 #elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) 704 #define DRFLAC_HAS_BYTESWAP_INTRINSIC 705 #elif defined(__clang__) 706 #if __has_builtin(__builtin_bswap16) && __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64) 707 #define DRFLAC_HAS_BYTESWAP_INTRINSIC 712 #ifndef DRFLAC_ASSERT 714 #define DRFLAC_ASSERT(expression) assert(expression) 716 #ifndef DRFLAC_MALLOC 717 #define DRFLAC_MALLOC(sz) malloc((sz)) 719 #ifndef DRFLAC_REALLOC 720 #define DRFLAC_REALLOC(p, sz) realloc((p), (sz)) 723 #define DRFLAC_FREE(p) free((p)) 725 #ifndef DRFLAC_COPY_MEMORY 726 #define DRFLAC_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz)) 728 #ifndef DRFLAC_ZERO_MEMORY 729 #define DRFLAC_ZERO_MEMORY(p, sz) memset((p), 0, (sz)) 732 #define DRFLAC_MAX_SIMD_VECTOR_SIZE 64 735 #define DRFLAC_INLINE __forceinline 738 #define DRFLAC_INLINE INLINE __attribute__((always_inline)) 740 #define DRFLAC_INLINE INLINE 745 #define DRFLAC_SUCCESS 0 746 #define DRFLAC_ERROR -1 747 #define DRFLAC_INVALID_ARGS -2 748 #define DRFLAC_END_OF_STREAM -128 749 #define DRFLAC_CRC_MISMATCH -129 751 #define DRFLAC_SUBFRAME_CONSTANT 0 752 #define DRFLAC_SUBFRAME_VERBATIM 1 753 #define DRFLAC_SUBFRAME_FIXED 8 754 #define DRFLAC_SUBFRAME_LPC 32 755 #define DRFLAC_SUBFRAME_RESERVED 255 757 #define DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE 0 758 #define DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2 1 760 #define DRFLAC_CHANNEL_ASSIGNMENT_INDEPENDENT 0 761 #define DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE 8 762 #define DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE 9 763 #define DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE 10 766 #define drflac_align(x, a) ((((x) + (a) - 1) / (a)) * (a)) 767 #define drflac_assert DRFLAC_ASSERT 768 #define drflac_copy_memory DRFLAC_COPY_MEMORY 769 #define drflac_zero_memory DRFLAC_ZERO_MEMORY 773 #ifndef DRFLAC_NO_CPUID 775 static void drflac__init_cpu_caps()
780 drflac__cpuid(
info, 0x80000001);
781 drflac__gIsLZCNTSupported = (
info[2] & (1 << 5)) != 0;
784 drflac__cpuid(
info, 1);
785 drflac__gIsSSE42Supported = (
info[2] & (1 << 19)) != 0;
791 static DRFLAC_INLINE
drflac_bool32 drflac__is_little_endian()
793 #if defined(DRFLAC_X86) || defined(DRFLAC_X64) 797 return (*(
char*)&
n) == 1;
803 #ifdef DRFLAC_HAS_BYTESWAP_INTRINSIC 804 #if defined(_MSC_VER) 805 return _byteswap_ushort(
n);
806 #elif defined(__GNUC__) || defined(__clang__) 807 return __builtin_bswap16(
n);
809 #error "This compiler does not support the byte swap intrinsic." 812 return ((
n & 0xFF00) >> 8) |
819 #ifdef DRFLAC_HAS_BYTESWAP_INTRINSIC 820 #if defined(_MSC_VER) 821 return _byteswap_ulong(
n);
822 #elif defined(__GNUC__) || defined(__clang__) 823 return __builtin_bswap32(
n);
825 #error "This compiler does not support the byte swap intrinsic." 828 return ((
n & 0xFF000000) >> 24) |
829 ((
n & 0x00FF0000) >> 8) |
830 ((
n & 0x0000FF00) << 8) |
831 ((
n & 0x000000FF) << 24);
837 #ifdef DRFLAC_HAS_BYTESWAP_INTRINSIC 838 #if defined(_MSC_VER) 839 return _byteswap_uint64(
n);
840 #elif defined(__GNUC__) || defined(__clang__) 841 return __builtin_bswap64(
n);
843 #error "This compiler does not support the byte swap intrinsic." 863 if (drflac__is_little_endian())
864 return drflac__swap_endian_uint16(
n);
875 if (drflac__is_little_endian())
876 return drflac__swap_endian_uint32(
n);
887 if (drflac__is_little_endian())
888 return drflac__swap_endian_uint64(
n);
900 if (!drflac__is_little_endian())
901 return drflac__swap_endian_uint32(
n);
911 result |= (
n & 0x7F000000) >> 3;
912 result |= (
n & 0x007F0000) >> 2;
913 result |= (
n & 0x00007F00) >> 1;
914 result |= (
n & 0x0000007F) >> 0;
921 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
922 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
923 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
924 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
925 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
926 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
927 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
928 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
929 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
930 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
931 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
932 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
933 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
934 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
935 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
936 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
940 0x0000, 0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011,
941 0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027, 0x0022,
942 0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D, 0x8077, 0x0072,
943 0x0050, 0x8055, 0x805F, 0x005A, 0x804B, 0x004E, 0x0044, 0x8041,
944 0x80C3, 0x00C6, 0x00CC, 0x80C9, 0x00D8, 0x80DD, 0x80D7, 0x00D2,
945 0x00F0, 0x80F5, 0x80FF, 0x00FA, 0x80EB, 0x00EE, 0x00E4, 0x80E1,
946 0x00A0, 0x80A5, 0x80AF, 0x00AA, 0x80BB, 0x00BE, 0x00B4, 0x80B1,
947 0x8093, 0x0096, 0x009C, 0x8099, 0x0088, 0x808D, 0x8087, 0x0082,
948 0x8183, 0x0186, 0x018C, 0x8189, 0x0198, 0x819D, 0x8197, 0x0192,
949 0x01B0, 0x81B5, 0x81BF, 0x01BA, 0x81AB, 0x01AE, 0x01A4, 0x81A1,
950 0x01E0, 0x81E5, 0x81EF, 0x01EA, 0x81FB, 0x01FE, 0x01F4, 0x81F1,
951 0x81D3, 0x01D6, 0x01DC, 0x81D9, 0x01C8, 0x81CD, 0x81C7, 0x01C2,
952 0x0140, 0x8145, 0x814F, 0x014A, 0x815B, 0x015E, 0x0154, 0x8151,
953 0x8173, 0x0176, 0x017C, 0x8179, 0x0168, 0x816D, 0x8167, 0x0162,
954 0x8123, 0x0126, 0x012C, 0x8129, 0x0138, 0x813D, 0x8137, 0x0132,
955 0x0110, 0x8115, 0x811F, 0x011A, 0x810B, 0x010E, 0x0104, 0x8101,
956 0x8303, 0x0306, 0x030C, 0x8309, 0x0318, 0x831D, 0x8317, 0x0312,
957 0x0330, 0x8335, 0x833F, 0x033A, 0x832B, 0x032E, 0x0324, 0x8321,
958 0x0360, 0x8365, 0x836F, 0x036A, 0x837B, 0x037E, 0x0374, 0x8371,
959 0x8353, 0x0356, 0x035C, 0x8359, 0x0348, 0x834D, 0x8347, 0x0342,
960 0x03C0, 0x83C5, 0x83CF, 0x03CA, 0x83DB, 0x03DE, 0x03D4, 0x83D1,
961 0x83F3, 0x03F6, 0x03FC, 0x83F9, 0x03E8, 0x83ED, 0x83E7, 0x03E2,
962 0x83A3, 0x03A6, 0x03AC, 0x83A9, 0x03B8, 0x83BD, 0x83B7, 0x03B2,
963 0x0390, 0x8395, 0x839F, 0x039A, 0x838B, 0x038E, 0x0384, 0x8381,
964 0x0280, 0x8285, 0x828F, 0x028A, 0x829B, 0x029E, 0x0294, 0x8291,
965 0x82B3, 0x02B6, 0x02BC, 0x82B9, 0x02A8, 0x82AD, 0x82A7, 0x02A2,
966 0x82E3, 0x02E6, 0x02EC, 0x82E9, 0x02F8, 0x82FD, 0x82F7, 0x02F2,
967 0x02D0, 0x82D5, 0x82DF, 0x02DA, 0x82CB, 0x02CE, 0x02C4, 0x82C1,
968 0x8243, 0x0246, 0x024C, 0x8249, 0x0258, 0x825D, 0x8257, 0x0252,
969 0x0270, 0x8275, 0x827F, 0x027A, 0x826B, 0x026E, 0x0264, 0x8261,
970 0x0220, 0x8225, 0x822F, 0x022A, 0x823B, 0x023E, 0x0234, 0x8231,
971 0x8213, 0x0216, 0x021C, 0x8219, 0x0208, 0x820D, 0x8207, 0x0202
976 return drflac__crc8_table[crc ^
data];
982 #ifdef DR_FLAC_NO_CRC 986 drflac_assert(
count <= 32);
992 for (
int i =
count-1; i >= 0; --i)
996 crc = ((crc << 1) | bit) ^
p;
998 crc = ((crc << 1) | bit);
1003 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F
1007 drflac_uint64 leftoverDataMask = leftoverDataMaskTable[leftoverBits];
1008 drflac_assert(
count <= 32);
1012 case 4: crc = drflac_crc8_byte(crc, (
drflac_uint8)((
data & (0xFF000000UL << leftoverBits)) >> (24 + leftoverBits)));
1013 case 3: crc = drflac_crc8_byte(crc, (
drflac_uint8)((
data & (0x00FF0000UL << leftoverBits)) >> (16 + leftoverBits)));
1014 case 2: crc = drflac_crc8_byte(crc, (
drflac_uint8)((
data & (0x0000FF00UL << leftoverBits)) >> ( 8 + leftoverBits)));
1015 case 1: crc = drflac_crc8_byte(crc, (
drflac_uint8)((
data & (0x000000FFUL << leftoverBits)) >> ( 0 + leftoverBits)));
1016 case 0:
if (leftoverBits > 0) crc = (crc << leftoverBits) ^ drflac__crc8_table[(crc >> (8 - leftoverBits)) ^ (
data & leftoverDataMask)];
1050 #ifdef DR_FLAC_NO_CRC 1054 drflac_assert(
count <= 64);
1060 for (
int i =
count-1; i >= 0; --i)
1064 r = ((
r << 1) | bit) ^
p;
1066 r = ((
r << 1) | bit);
1075 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F
1077 drflac_uint64 leftoverDataMask = leftoverDataMaskTable[leftoverBits];
1079 drflac_assert(
count <= 64);
1084 case 4: crc = drflac_crc16_byte(crc, (
drflac_uint8)((
data & (0xFF000000UL << leftoverBits)) >> (24 + leftoverBits)));
1085 case 3: crc = drflac_crc16_byte(crc, (
drflac_uint8)((
data & (0x00FF0000UL << leftoverBits)) >> (16 + leftoverBits)));
1086 case 2: crc = drflac_crc16_byte(crc, (
drflac_uint8)((
data & (0x0000FF00UL << leftoverBits)) >> ( 8 + leftoverBits)));
1087 case 1: crc = drflac_crc16_byte(crc, (
drflac_uint8)((
data & (0x000000FFUL << leftoverBits)) >> ( 0 + leftoverBits)));
1088 case 0:
if (leftoverBits > 0) crc = (crc << leftoverBits) ^ drflac__crc16_table[(crc >> (16 - leftoverBits)) ^ (
data & leftoverDataMask)];
1098 #ifdef DR_FLAC_NO_CRC 1102 drflac_assert(
count <= 64);
1109 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F
1111 drflac_uint64 leftoverDataMask = leftoverDataMaskTable[leftoverBits];
1113 drflac_assert(
count <= 64);
1126 case 0:
if (leftoverBits > 0) crc = (crc << leftoverBits) ^ drflac__crc16_table[(crc >> (16 - leftoverBits)) ^ (
data & leftoverDataMask)];
1136 return drflac_crc16__64bit(crc,
data,
count);
1138 return drflac_crc16__32bit(crc,
data,
count);
1144 #define drflac__be2host__cache_line drflac__be2host_64 1146 #define drflac__be2host__cache_line drflac__be2host_32 1157 #define DRFLAC_CACHE_L1_SIZE_BYTES(bs) (sizeof((bs)->cache)) 1158 #define DRFLAC_CACHE_L1_SIZE_BITS(bs) (sizeof((bs)->cache)*8) 1159 #define DRFLAC_CACHE_L1_BITS_REMAINING(bs) (DRFLAC_CACHE_L1_SIZE_BITS(bs) - ((bs)->consumedBits)) 1161 #define DRFLAC_CACHE_L1_SELECTION_MASK(_bitCount) (~(((drflac_uint64)-1LL) >> (_bitCount))) 1163 #define DRFLAC_CACHE_L1_SELECTION_MASK(_bitCount) (~(((drflac_uint32)-1) >> (_bitCount))) 1165 #define DRFLAC_CACHE_L1_SELECTION_SHIFT(bs, _bitCount) (DRFLAC_CACHE_L1_SIZE_BITS(bs) - (_bitCount)) 1166 #define DRFLAC_CACHE_L1_SELECT(bs, _bitCount) (((bs)->cache) & DRFLAC_CACHE_L1_SELECTION_MASK(_bitCount)) 1167 #define DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, _bitCount) (DRFLAC_CACHE_L1_SELECT((bs), _bitCount) >> DRFLAC_CACHE_L1_SELECTION_SHIFT((bs), _bitCount)) 1168 #define DRFLAC_CACHE_L2_SIZE_BYTES(bs) (sizeof((bs)->cacheL2)) 1169 #define DRFLAC_CACHE_L2_LINE_COUNT(bs) (DRFLAC_CACHE_L2_SIZE_BYTES(bs) / sizeof((bs)->cacheL2[0])) 1170 #define DRFLAC_CACHE_L2_LINES_REMAINING(bs) (DRFLAC_CACHE_L2_LINE_COUNT(bs) - (bs)->nextL2Line) 1173 #ifndef DR_FLAC_NO_CRC 1174 static DRFLAC_INLINE
void drflac__reset_crc16(
drflac_bs* bs)
1180 static DRFLAC_INLINE
void drflac__update_crc16(
drflac_bs* bs)
1189 drflac_assert((DRFLAC_CACHE_L1_BITS_REMAINING(bs) & 7) == 0);
1193 if (DRFLAC_CACHE_L1_BITS_REMAINING(bs) == 0)
1194 drflac__update_crc16(bs);
1211 size_t alignedL1LineCount;
1214 if (bs->
nextL2Line < DRFLAC_CACHE_L2_LINE_COUNT(bs))
1228 if (bytesRead == DRFLAC_CACHE_L2_SIZE_BYTES(bs))
1240 alignedL1LineCount = bytesRead / DRFLAC_CACHE_L1_SIZE_BYTES(bs);
1243 bs->
unalignedByteCount = bytesRead - (alignedL1LineCount * DRFLAC_CACHE_L1_SIZE_BYTES(bs));
1247 if (alignedL1LineCount > 0)
1250 size_t offset = DRFLAC_CACHE_L2_LINE_COUNT(bs) - alignedL1LineCount;
1251 for (i = alignedL1LineCount; i > 0; --i)
1260 bs->
nextL2Line = DRFLAC_CACHE_L2_LINE_COUNT(bs);
1268 #ifndef DR_FLAC_NO_CRC 1269 drflac__update_crc16(bs);
1273 if (drflac__reload_l1_cache_from_l2(bs))
1275 bs->
cache = drflac__be2host__cache_line(bs->
cache);
1277 #ifndef DR_FLAC_NO_CRC 1292 drflac_assert(bytesRead < DRFLAC_CACHE_L1_SIZE_BYTES(bs));
1296 bs->
cache &= DRFLAC_CACHE_L1_SELECTION_MASK(DRFLAC_CACHE_L1_SIZE_BITS(bs) - bs->
consumedBits);
1299 #ifndef DR_FLAC_NO_CRC 1306 static void drflac__reset_cache(
drflac_bs* bs)
1308 bs->
nextL2Line = DRFLAC_CACHE_L2_LINE_COUNT(bs);
1314 #ifndef DR_FLAC_NO_CRC 1323 drflac_assert(bs !=
NULL);
1324 drflac_assert(pResultOut !=
NULL);
1325 drflac_assert(bitCount > 0);
1326 drflac_assert(bitCount <= 32);
1330 if (!drflac__reload_cache(bs))
1334 if (bitCount <= DRFLAC_CACHE_L1_BITS_REMAINING(bs))
1336 if (bitCount < DRFLAC_CACHE_L1_SIZE_BITS(bs))
1338 *pResultOut = DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCount);
1340 bs->
cache <<= bitCount;
1349 drflac_uint32 bitCountHi = DRFLAC_CACHE_L1_BITS_REMAINING(bs);
1351 drflac_uint32 resultHi = DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCountHi);
1353 if (!drflac__reload_cache(bs))
1356 *pResultOut = (resultHi << bitCountLo) | DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCountLo);
1358 bs->
cache <<= bitCountLo;
1368 drflac_assert(bs !=
NULL);
1369 drflac_assert(pResult !=
NULL);
1370 drflac_assert(bitCount > 0);
1371 drflac_assert(bitCount <= 32);
1373 if (!drflac__read_uint32(bs, bitCount, &
result))
1376 signbit = ((
result >> (bitCount-1)) & 0x01);
1377 result |= (~signbit + 1) << bitCount;
1388 drflac_assert(bitCount <= 64);
1389 drflac_assert(bitCount > 32);
1391 if (!drflac__read_uint32(bs, bitCount - 32, &resultHi))
1394 if (!drflac__read_uint32(bs, 32, &resultLo))
1405 drflac_assert(bitCount <= 64);
1408 if (!drflac__read_uint64(bs, bitCount, &
result))
1412 result |= (~signbit + 1) << bitCount;
1423 drflac_assert(bs !=
NULL);
1424 drflac_assert(pResult !=
NULL);
1425 drflac_assert(bitCount > 0);
1426 drflac_assert(bitCount <= 16);
1428 if (!drflac__read_uint32(bs, bitCount, &
result))
1440 drflac_assert(bs !=
NULL);
1441 drflac_assert(pResult !=
NULL);
1442 drflac_assert(bitCount > 0);
1443 drflac_assert(bitCount <= 16);
1445 if (!drflac__read_int32(bs, bitCount, &
result))
1457 drflac_assert(bs !=
NULL);
1458 drflac_assert(pResult !=
NULL);
1459 drflac_assert(bitCount > 0);
1460 drflac_assert(bitCount <= 8);
1462 if (!drflac__read_uint32(bs, bitCount, &
result))
1473 drflac_assert(bs !=
NULL);
1474 drflac_assert(pResult !=
NULL);
1475 drflac_assert(bitCount > 0);
1476 drflac_assert(bitCount <= 8);
1478 if (!drflac__read_int32(bs, bitCount, &
result))
1488 if (bitsToSeek <= DRFLAC_CACHE_L1_BITS_REMAINING(bs))
1491 bs->
cache <<= bitsToSeek;
1496 bitsToSeek -= DRFLAC_CACHE_L1_BITS_REMAINING(bs);
1497 bs->
consumedBits += DRFLAC_CACHE_L1_BITS_REMAINING(bs);
1502 while (bitsToSeek >= DRFLAC_CACHE_L1_SIZE_BITS(bs))
1505 if (!drflac__read_uint64(bs, DRFLAC_CACHE_L1_SIZE_BITS(bs), &bin))
1507 bitsToSeek -= DRFLAC_CACHE_L1_SIZE_BITS(bs);
1510 while (bitsToSeek >= DRFLAC_CACHE_L1_SIZE_BITS(bs))
1513 if (!drflac__read_uint32(bs, DRFLAC_CACHE_L1_SIZE_BITS(bs), &bin))
1515 bitsToSeek -= DRFLAC_CACHE_L1_SIZE_BITS(bs);
1520 while (bitsToSeek >= 8)
1523 if (!drflac__read_uint8(bs, 8, &bin))
1532 if (!drflac__read_uint8(bs, (
drflac_uint32)bitsToSeek, &bin))
1537 drflac_assert(bitsToSeek == 0);
1545 drflac_assert(bs !=
NULL);
1549 if (!drflac__seek_bits(bs, DRFLAC_CACHE_L1_BITS_REMAINING(bs) & 7))
1556 #ifndef DR_FLAC_NO_CRC 1557 drflac__reset_crc16(bs);
1560 if (!drflac__read_uint8(bs, 8, &hi))
1566 if (!drflac__read_uint8(bs, 6, &lo))
1572 if (!drflac__seek_bits(bs, DRFLAC_CACHE_L1_BITS_REMAINING(bs) & 7))
1584 #if !defined(DR_FLAC_NO_SIMD) && defined(DRFLAC_HAS_LZCNT_INTRINSIC) 1585 #define DRFLAC_IMPLEMENT_CLZ_LZCNT 1587 #if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(DRFLAC_X64) || defined(DRFLAC_X86)) 1588 #define DRFLAC_IMPLEMENT_CLZ_MSVC 1598 1, 1, 1, 1, 1, 1, 1, 1
1605 if ((
x & 0xFFFFFFFF00000000ULL) == 0) {
n = 32;
x <<= 32; }
1606 if ((
x & 0xFFFF000000000000ULL) == 0) {
n += 16;
x <<= 16; }
1607 if ((
x & 0xFF00000000000000ULL) == 0) {
n += 8;
x <<= 8; }
1608 if ((
x & 0xF000000000000000ULL) == 0) {
n += 4;
x <<= 4; }
1610 if ((
x & 0xFFFF0000) == 0) {
n = 16;
x <<= 16; }
1611 if ((
x & 0xFF000000) == 0) {
n += 8;
x <<= 8; }
1612 if ((
x & 0xF0000000) == 0) {
n += 4;
x <<= 4; }
1614 n += clz_table_4[
x >> (
sizeof(
x)*8 - 4)];
1620 #ifdef DRFLAC_IMPLEMENT_CLZ_LZCNT 1621 static DRFLAC_INLINE
drflac_bool32 drflac__is_lzcnt_supported()
1624 #ifdef DRFLAC_HAS_LZCNT_INTRINSIC 1625 return drflac__gIsLZCNTSupported;
1633 #if defined(_MSC_VER) && !defined(__clang__) 1640 #if defined(__GNUC__) || defined(__clang__) 1648 #error "This compiler does not support the lzcnt intrinsic." 1654 #ifdef DRFLAC_IMPLEMENT_CLZ_MSVC 1659 _BitScanReverse64((
unsigned long*)&
n,
x);
1661 _BitScanReverse((
unsigned long*)&
n,
x);
1663 return sizeof(
x)*8 -
n - 1;
1670 #ifdef DRFLAC_IMPLEMENT_CLZ_LZCNT 1671 if (drflac__is_lzcnt_supported())
1672 return drflac__clz_lzcnt(
x);
1675 #ifdef DRFLAC_IMPLEMENT_CLZ_MSVC 1676 return drflac__clz_msvc(
x);
1678 return drflac__clz_software(
x);
1686 while (bs->
cache == 0)
1688 zeroCounter += (
drflac_uint32)DRFLAC_CACHE_L1_BITS_REMAINING(bs);
1689 if (!drflac__reload_cache(bs))
1693 setBitOffsetPlus1 = drflac__clz(bs->
cache);
1694 zeroCounter += setBitOffsetPlus1;
1695 setBitOffsetPlus1 += 1;
1698 bs->
cache <<= setBitOffsetPlus1;
1700 *pOffsetOut = zeroCounter + setBitOffsetPlus1 - 1;
1708 drflac_assert(bs !=
NULL);
1709 drflac_assert(offsetFromStart > 0);
1714 if (offsetFromStart > 0x7FFFFFFF)
1719 bytesRemaining -= 0x7FFFFFFF;
1721 while (bytesRemaining > 0x7FFFFFFF)
1725 bytesRemaining -= 0x7FFFFFFF;
1728 if (bytesRemaining > 0)
1741 drflac__reset_cache(bs);
1751 unsigned char utf8[7] = {0};
1754 drflac_assert(bs !=
NULL);
1755 drflac_assert(pNumberOut !=
NULL);
1759 if (!drflac__read_uint8(bs, 8, utf8))
1762 return DRFLAC_END_OF_STREAM;
1764 crc = drflac_crc8(crc, utf8[0], 8);
1766 if ((utf8[0] & 0x80) == 0)
1768 *pNumberOut = utf8[0];
1770 return DRFLAC_SUCCESS;
1773 if ((utf8[0] & 0xE0) == 0xC0)
1775 else if ((utf8[0] & 0xF0) == 0xE0)
1777 else if ((utf8[0] & 0xF8) == 0xF0)
1779 else if ((utf8[0] & 0xFC) == 0xF8)
1781 else if ((utf8[0] & 0xFE) == 0xFC)
1783 else if ((utf8[0] & 0xFF) == 0xFE)
1788 return DRFLAC_CRC_MISMATCH;
1792 drflac_assert(byteCount > 1);
1795 for (i = 1; i < byteCount; ++i)
1797 if (!drflac__read_uint8(bs, 8, utf8 + i))
1800 return DRFLAC_END_OF_STREAM;
1802 crc = drflac_crc8(crc, utf8[i], 8);
1809 return DRFLAC_SUCCESS;
1824 drflac_assert(
order <= 32);
1832 case 32: prediction += coefficients[31] * pDecodedSamples[-32];
1833 case 31: prediction += coefficients[30] * pDecodedSamples[-31];
1834 case 30: prediction += coefficients[29] * pDecodedSamples[-30];
1835 case 29: prediction += coefficients[28] * pDecodedSamples[-29];
1836 case 28: prediction += coefficients[27] * pDecodedSamples[-28];
1837 case 27: prediction += coefficients[26] * pDecodedSamples[-27];
1838 case 26: prediction += coefficients[25] * pDecodedSamples[-26];
1839 case 25: prediction += coefficients[24] * pDecodedSamples[-25];
1840 case 24: prediction += coefficients[23] * pDecodedSamples[-24];
1841 case 23: prediction += coefficients[22] * pDecodedSamples[-23];
1842 case 22: prediction += coefficients[21] * pDecodedSamples[-22];
1843 case 21: prediction += coefficients[20] * pDecodedSamples[-21];
1844 case 20: prediction += coefficients[19] * pDecodedSamples[-20];
1845 case 19: prediction += coefficients[18] * pDecodedSamples[-19];
1846 case 18: prediction += coefficients[17] * pDecodedSamples[-18];
1847 case 17: prediction += coefficients[16] * pDecodedSamples[-17];
1848 case 16: prediction += coefficients[15] * pDecodedSamples[-16];
1849 case 15: prediction += coefficients[14] * pDecodedSamples[-15];
1850 case 14: prediction += coefficients[13] * pDecodedSamples[-14];
1851 case 13: prediction += coefficients[12] * pDecodedSamples[-13];
1852 case 12: prediction += coefficients[11] * pDecodedSamples[-12];
1853 case 11: prediction += coefficients[10] * pDecodedSamples[-11];
1854 case 10: prediction += coefficients[ 9] * pDecodedSamples[-10];
1855 case 9: prediction += coefficients[ 8] * pDecodedSamples[- 9];
1856 case 8: prediction += coefficients[ 7] * pDecodedSamples[- 8];
1857 case 7: prediction += coefficients[ 6] * pDecodedSamples[- 7];
1858 case 6: prediction += coefficients[ 5] * pDecodedSamples[- 6];
1859 case 5: prediction += coefficients[ 4] * pDecodedSamples[- 5];
1860 case 4: prediction += coefficients[ 3] * pDecodedSamples[- 4];
1861 case 3: prediction += coefficients[ 2] * pDecodedSamples[- 3];
1862 case 2: prediction += coefficients[ 1] * pDecodedSamples[- 2];
1863 case 1: prediction += coefficients[ 0] * pDecodedSamples[- 1];
1872 drflac_assert(
order <= 32);
1879 #ifndef DRFLAC_64BIT 1882 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1883 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1884 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1885 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1886 prediction += coefficients[4] * (
drflac_int64)pDecodedSamples[-5];
1887 prediction += coefficients[5] * (
drflac_int64)pDecodedSamples[-6];
1888 prediction += coefficients[6] * (
drflac_int64)pDecodedSamples[-7];
1889 prediction += coefficients[7] * (
drflac_int64)pDecodedSamples[-8];
1891 else if (
order == 7)
1893 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1894 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1895 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1896 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1897 prediction += coefficients[4] * (
drflac_int64)pDecodedSamples[-5];
1898 prediction += coefficients[5] * (
drflac_int64)pDecodedSamples[-6];
1899 prediction += coefficients[6] * (
drflac_int64)pDecodedSamples[-7];
1901 else if (
order == 3)
1903 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1904 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1905 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1907 else if (
order == 6)
1909 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1910 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1911 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1912 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1913 prediction += coefficients[4] * (
drflac_int64)pDecodedSamples[-5];
1914 prediction += coefficients[5] * (
drflac_int64)pDecodedSamples[-6];
1916 else if (
order == 5)
1918 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1919 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1920 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1921 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1922 prediction += coefficients[4] * (
drflac_int64)pDecodedSamples[-5];
1924 else if (
order == 4)
1926 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1927 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1928 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1929 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1931 else if (
order == 12)
1933 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1934 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1935 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1936 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1937 prediction += coefficients[4] * (
drflac_int64)pDecodedSamples[-5];
1938 prediction += coefficients[5] * (
drflac_int64)pDecodedSamples[-6];
1939 prediction += coefficients[6] * (
drflac_int64)pDecodedSamples[-7];
1940 prediction += coefficients[7] * (
drflac_int64)pDecodedSamples[-8];
1941 prediction += coefficients[8] * (
drflac_int64)pDecodedSamples[-9];
1942 prediction += coefficients[9] * (
drflac_int64)pDecodedSamples[-10];
1943 prediction += coefficients[10] * (
drflac_int64)pDecodedSamples[-11];
1944 prediction += coefficients[11] * (
drflac_int64)pDecodedSamples[-12];
1946 else if (
order == 2)
1948 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1949 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1951 else if (
order == 1)
1953 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1955 else if (
order == 10)
1957 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1958 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1959 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1960 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1961 prediction += coefficients[4] * (
drflac_int64)pDecodedSamples[-5];
1962 prediction += coefficients[5] * (
drflac_int64)pDecodedSamples[-6];
1963 prediction += coefficients[6] * (
drflac_int64)pDecodedSamples[-7];
1964 prediction += coefficients[7] * (
drflac_int64)pDecodedSamples[-8];
1965 prediction += coefficients[8] * (
drflac_int64)pDecodedSamples[-9];
1966 prediction += coefficients[9] * (
drflac_int64)pDecodedSamples[-10];
1968 else if (
order == 9)
1970 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1971 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1972 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1973 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1974 prediction += coefficients[4] * (
drflac_int64)pDecodedSamples[-5];
1975 prediction += coefficients[5] * (
drflac_int64)pDecodedSamples[-6];
1976 prediction += coefficients[6] * (
drflac_int64)pDecodedSamples[-7];
1977 prediction += coefficients[7] * (
drflac_int64)pDecodedSamples[-8];
1978 prediction += coefficients[8] * (
drflac_int64)pDecodedSamples[-9];
1980 else if (
order == 11)
1982 prediction = coefficients[0] * (
drflac_int64)pDecodedSamples[-1];
1983 prediction += coefficients[1] * (
drflac_int64)pDecodedSamples[-2];
1984 prediction += coefficients[2] * (
drflac_int64)pDecodedSamples[-3];
1985 prediction += coefficients[3] * (
drflac_int64)pDecodedSamples[-4];
1986 prediction += coefficients[4] * (
drflac_int64)pDecodedSamples[-5];
1987 prediction += coefficients[5] * (
drflac_int64)pDecodedSamples[-6];
1988 prediction += coefficients[6] * (
drflac_int64)pDecodedSamples[-7];
1989 prediction += coefficients[7] * (
drflac_int64)pDecodedSamples[-8];
1990 prediction += coefficients[8] * (
drflac_int64)pDecodedSamples[-9];
1991 prediction += coefficients[9] * (
drflac_int64)pDecodedSamples[-10];
1992 prediction += coefficients[10] * (
drflac_int64)pDecodedSamples[-11];
1999 prediction += coefficients[
j] * (
drflac_int64)pDecodedSamples[-
j-1];
2010 case 32: prediction += coefficients[31] * (
drflac_int64)pDecodedSamples[-32];
2011 case 31: prediction += coefficients[30] * (
drflac_int64)pDecodedSamples[-31];
2012 case 30: prediction += coefficients[29] * (
drflac_int64)pDecodedSamples[-30];
2013 case 29: prediction += coefficients[28] * (
drflac_int64)pDecodedSamples[-29];
2014 case 28: prediction += coefficients[27] * (
drflac_int64)pDecodedSamples[-28];
2015 case 27: prediction += coefficients[26] * (
drflac_int64)pDecodedSamples[-27];
2016 case 26: prediction += coefficients[25] * (
drflac_int64)pDecodedSamples[-26];
2017 case 25: prediction += coefficients[24] * (
drflac_int64)pDecodedSamples[-25];
2018 case 24: prediction += coefficients[23] * (
drflac_int64)pDecodedSamples[-24];
2019 case 23: prediction += coefficients[22] * (
drflac_int64)pDecodedSamples[-23];
2020 case 22: prediction += coefficients[21] * (
drflac_int64)pDecodedSamples[-22];
2021 case 21: prediction += coefficients[20] * (
drflac_int64)pDecodedSamples[-21];
2022 case 20: prediction += coefficients[19] * (
drflac_int64)pDecodedSamples[-20];
2023 case 19: prediction += coefficients[18] * (
drflac_int64)pDecodedSamples[-19];
2024 case 18: prediction += coefficients[17] * (
drflac_int64)pDecodedSamples[-18];
2025 case 17: prediction += coefficients[16] * (
drflac_int64)pDecodedSamples[-17];
2026 case 16: prediction += coefficients[15] * (
drflac_int64)pDecodedSamples[-16];
2027 case 15: prediction += coefficients[14] * (
drflac_int64)pDecodedSamples[-15];
2028 case 14: prediction += coefficients[13] * (
drflac_int64)pDecodedSamples[-14];
2029 case 13: prediction += coefficients[12] * (
drflac_int64)pDecodedSamples[-13];
2030 case 12: prediction += coefficients[11] * (
drflac_int64)pDecodedSamples[-12];
2031 case 11: prediction += coefficients[10] * (
drflac_int64)pDecodedSamples[-11];
2032 case 10: prediction += coefficients[ 9] * (
drflac_int64)pDecodedSamples[-10];
2033 case 9: prediction += coefficients[ 8] * (
drflac_int64)pDecodedSamples[- 9];
2034 case 8: prediction += coefficients[ 7] * (
drflac_int64)pDecodedSamples[- 8];
2035 case 7: prediction += coefficients[ 6] * (
drflac_int64)pDecodedSamples[- 7];
2036 case 6: prediction += coefficients[ 5] * (
drflac_int64)pDecodedSamples[- 6];
2037 case 5: prediction += coefficients[ 4] * (
drflac_int64)pDecodedSamples[- 5];
2038 case 4: prediction += coefficients[ 3] * (
drflac_int64)pDecodedSamples[- 4];
2039 case 3: prediction += coefficients[ 2] * (
drflac_int64)pDecodedSamples[- 3];
2040 case 2: prediction += coefficients[ 1] * (
drflac_int64)pDecodedSamples[- 2];
2041 case 1: prediction += coefficients[ 0] * (
drflac_int64)pDecodedSamples[- 1];
2053 drflac_assert(bs !=
NULL);
2054 drflac_assert(
count > 0);
2055 drflac_assert(pSamplesOut !=
NULL);
2063 if (!drflac__read_uint8(bs, 1, &bit))
2075 if (!drflac__read_uint32(bs, riceParam, &decodedRice))
2081 decodedRice |= (zeroCounter << riceParam);
2082 if ((decodedRice & 0x01))
2083 decodedRice = ~(decodedRice >> 1);
2085 decodedRice = (decodedRice >> 1);
2088 if (bitsPerSample > 16)
2089 pSamplesOut[i] = decodedRice + drflac__calculate_prediction_64(
order, shift, coefficients, pSamplesOut + i);
2091 pSamplesOut[i] = decodedRice + drflac__calculate_prediction_32(
order, shift, coefficients, pSamplesOut + i);
2104 if (!drflac__read_uint8(bs, 1, &bit))
2116 if (!drflac__read_uint32(bs, riceParam, &decodedRice))
2122 *pZeroCounterOut = zeroCounter;
2123 *pRiceParamPartOut = decodedRice;
2133 drflac_cache_t riceParamMask = DRFLAC_CACHE_L1_SELECTION_MASK(riceParam);
2134 drflac_cache_t resultHiShift = DRFLAC_CACHE_L1_SIZE_BITS(bs) - riceParam;
2136 while (bs->
cache == 0) {
2137 zeroCounter += (
drflac_uint32)DRFLAC_CACHE_L1_BITS_REMAINING(bs);
2138 if (!drflac__reload_cache(bs))
2142 setBitOffsetPlus1 = drflac__clz(bs->
cache);
2143 zeroCounter += setBitOffsetPlus1;
2144 setBitOffsetPlus1 += 1;
2146 riceLength = setBitOffsetPlus1 + riceParam;
2148 if (riceLength < DRFLAC_CACHE_L1_BITS_REMAINING(bs))
2150 riceParamPart = (
drflac_uint32)((bs->
cache & (riceParamMask >> setBitOffsetPlus1)) >> (DRFLAC_CACHE_L1_SIZE_BITS(bs) - riceLength));
2153 bs->
cache <<= riceLength;
2161 if (setBitOffsetPlus1 < DRFLAC_CACHE_L1_SIZE_BITS(bs))
2162 bs->
cache <<= setBitOffsetPlus1;
2165 bitCountLo = bs->
consumedBits - DRFLAC_CACHE_L1_SIZE_BITS(bs);
2166 resultHi = bs->
cache & riceParamMask;
2168 if (bs->
nextL2Line < DRFLAC_CACHE_L2_LINE_COUNT(bs)) {
2169 #ifndef DR_FLAC_NO_CRC 2170 drflac__update_crc16(bs);
2174 #ifndef DR_FLAC_NO_CRC 2179 if (!drflac__reload_cache(bs)) {
2184 riceParamPart = (
drflac_uint32)((resultHi >> resultHiShift) | DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCountLo));
2187 bs->
cache <<= bitCountLo;
2190 *pZeroCounterOut = zeroCounter;
2191 *pRiceParamPartOut = riceParamPart;
2202 drflac_assert(bs !=
NULL);
2203 drflac_assert(
count > 0);
2204 drflac_assert(pSamplesOut !=
NULL);
2210 if (!drflac__read_rice_parts(bs, riceParam, &zeroCountPart, &riceParamPart))
2215 riceParamPart |= (zeroCountPart << riceParam);
2216 riceParamPart = (riceParamPart >> 1) ^
t[riceParamPart & 0x01];
2218 riceParamPart = (riceParamPart >> 1) ^ (~(riceParamPart & 0x01) + 1);
2222 if (bitsPerSample > 16)
2224 pSamplesOut[i] = riceParamPart + drflac__calculate_prediction_64(
order, shift, coefficients, pSamplesOut + i);
2228 pSamplesOut[i] = riceParamPart + drflac__calculate_prediction_32(
order, shift, coefficients, pSamplesOut + i);
2240 return drflac__decode_samples_with_residual__rice__reference(bs, bitsPerSample,
count, riceParam,
order, shift, coefficients, pSamplesOut);
2242 return drflac__decode_samples_with_residual__rice__simple(bs, bitsPerSample,
count, riceParam,
order, shift, coefficients, pSamplesOut);
2250 drflac_assert(bs !=
NULL);
2251 drflac_assert(
count > 0);
2253 for (i = 0; i <
count; ++i)
2257 if (!drflac__read_rice_parts(bs, riceParam, &zeroCountPart, &riceParamPart))
2267 drflac_assert(bs !=
NULL);
2268 drflac_assert(
count > 0);
2269 drflac_assert(unencodedBitsPerSample > 0 && unencodedBitsPerSample <= 32);
2270 drflac_assert(pSamplesOut !=
NULL);
2272 for (i = 0; i <
count; ++i)
2274 if (!drflac__read_int32(bs, unencodedBitsPerSample, pSamplesOut + i))
2277 if (bitsPerSample > 16)
2279 pSamplesOut[i] += drflac__calculate_prediction_64(
order, shift, coefficients, pSamplesOut + i);
2283 pSamplesOut[i] += drflac__calculate_prediction_32(
order, shift, coefficients, pSamplesOut + i);
2301 drflac_assert(bs !=
NULL);
2302 drflac_assert(blockSize != 0);
2303 drflac_assert(pDecodedSamples !=
NULL);
2305 if (!drflac__read_uint8(bs, 2, &residualMethod))
2308 if (residualMethod != DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE && residualMethod != DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2)
2312 pDecodedSamples +=
order;
2315 if (!drflac__read_uint8(bs, 4, &partitionOrder))
2320 if (partitionOrder > 8)
2324 if ((blockSize / (1 << partitionOrder)) <=
order)
2327 samplesInPartition = (blockSize / (1 << partitionOrder)) -
order;
2328 partitionsRemaining = (1 << partitionOrder);
2333 if (residualMethod == DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE)
2335 if (!drflac__read_uint8(bs, 4, &riceParam))
2337 if (riceParam == 16)
2340 else if (residualMethod == DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2)
2342 if (!drflac__read_uint8(bs, 5, &riceParam))
2344 if (riceParam == 32)
2348 if (riceParam != 0xFF)
2350 if (!drflac__decode_samples_with_residual__rice(bs, bitsPerSample, samplesInPartition, riceParam,
order, shift, coefficients, pDecodedSamples))
2355 unsigned char unencodedBitsPerSample = 0;
2356 if (!drflac__read_uint8(bs, 5, &unencodedBitsPerSample))
2359 if (!drflac__decode_samples_with_residual__unencoded(bs, bitsPerSample, samplesInPartition, unencodedBitsPerSample,
order, shift, coefficients, pDecodedSamples))
2363 pDecodedSamples += samplesInPartition;
2366 if (partitionsRemaining == 1)
2369 partitionsRemaining -= 1;
2371 if (partitionOrder != 0)
2372 samplesInPartition = blockSize / (1 << partitionOrder);
2388 drflac_assert(bs !=
NULL);
2389 drflac_assert(blockSize != 0);
2391 if (!drflac__read_uint8(bs, 2, &residualMethod))
2394 if (residualMethod != DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE && residualMethod != DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2)
2397 if (!drflac__read_uint8(bs, 4, &partitionOrder))
2400 samplesInPartition = (blockSize / (1 << partitionOrder)) -
order;
2401 partitionsRemaining = (1 << partitionOrder);
2405 if (residualMethod == DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE)
2407 if (!drflac__read_uint8(bs, 4, &riceParam))
2409 if (riceParam == 16)
2412 else if (residualMethod == DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
2413 if (!drflac__read_uint8(bs, 5, &riceParam))
2415 if (riceParam == 32)
2419 if (riceParam != 0xFF)
2421 if (!drflac__read_and_seek_residual__rice(bs, samplesInPartition, riceParam))
2426 unsigned char unencodedBitsPerSample = 0;
2427 if (!drflac__read_uint8(bs, 5, &unencodedBitsPerSample))
2430 if (!drflac__seek_bits(bs, unencodedBitsPerSample * samplesInPartition))
2434 if (partitionsRemaining == 1)
2437 partitionsRemaining -= 1;
2438 samplesInPartition = blockSize / (1 << partitionOrder);
2450 if (!drflac__read_int32(bs, bitsPerSample, &
sample))
2455 for (i = 0; i < blockSize; ++i)
2456 pDecodedSamples[i] =
sample;
2464 for (i = 0; i < blockSize; ++i)
2467 if (!drflac__read_int32(bs, bitsPerSample, &
sample))
2470 pDecodedSamples[i] =
sample;
2488 for (i = 0; i < lpcOrder; ++i)
2491 if (!drflac__read_int32(bs, bitsPerSample, &
sample))
2494 pDecodedSamples[i] =
sample;
2498 if (!drflac__decode_samples_with_residual(bs, bitsPerSample, blockSize, lpcOrder, 0, lpcCoefficientsTable[lpcOrder], pDecodedSamples))
2512 for (i = 0; i < lpcOrder; ++i)
2515 if (!drflac__read_int32(bs, bitsPerSample, &
sample))
2518 pDecodedSamples[i] =
sample;
2521 if (!drflac__read_uint8(bs, 4, &lpcPrecision))
2523 if (lpcPrecision == 15)
2528 if (!drflac__read_int8(bs, 5, &lpcShift))
2531 for (i = 0; i < lpcOrder; ++i)
2533 if (!drflac__read_int32(bs, lpcPrecision, coefficients + i))
2537 if (!drflac__decode_samples_with_residual(bs, bitsPerSample, blockSize, lpcOrder, lpcShift, coefficients, pDecodedSamples))
2546 const drflac_uint32 sampleRateTable[12] = {0, 88200, 176400, 192000, 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000};
2549 drflac_assert(bs !=
NULL);
2550 drflac_assert(header !=
NULL);
2564 if (!drflac__find_and_seek_to_next_sync_code(bs))
2567 if (!drflac__read_uint8(bs, 1, &
reserved))
2569 crc8 = drflac_crc8(crc8,
reserved, 1);
2571 if (!drflac__read_uint8(bs, 1, &blockingStrategy))
2573 crc8 = drflac_crc8(crc8, blockingStrategy, 1);
2575 if (!drflac__read_uint8(bs, 4, &blockSize))
2577 crc8 = drflac_crc8(crc8, blockSize, 4);
2579 if (!drflac__read_uint8(bs, 4, &sampleRate))
2581 crc8 = drflac_crc8(crc8, sampleRate, 4);
2583 if (!drflac__read_uint8(bs, 4, &channelAssignment))
2585 crc8 = drflac_crc8(crc8, channelAssignment, 4);
2587 if (!drflac__read_uint8(bs, 3, &bitsPerSample))
2589 crc8 = drflac_crc8(crc8, bitsPerSample, 3);
2591 if (!drflac__read_uint8(bs, 1, &
reserved))
2593 crc8 = drflac_crc8(crc8,
reserved, 1);
2595 isVariableBlockSize = blockingStrategy == 1;
2597 if (isVariableBlockSize)
2600 drflac_result
result = drflac__read_utf8_coded_number(bs, &sampleNumber, &crc8);
2601 if (
result != DRFLAC_SUCCESS)
2603 if (
result == DRFLAC_END_OF_STREAM)
2614 drflac_result
result = drflac__read_utf8_coded_number(bs, &frameNumber, &crc8);
2615 if (
result != DRFLAC_SUCCESS)
2617 if (
result == DRFLAC_END_OF_STREAM)
2629 else if (blockSize >= 2 && blockSize <= 5)
2630 header->
blockSize = 576 * (1 << (blockSize - 2));
2631 else if (blockSize == 6)
2633 if (!drflac__read_uint16(bs, 8, &header->
blockSize))
2635 crc8 = drflac_crc8(crc8, header->
blockSize, 8);
2638 else if (blockSize == 7)
2640 if (!drflac__read_uint16(bs, 16, &header->
blockSize))
2642 crc8 = drflac_crc8(crc8, header->
blockSize, 16);
2646 header->
blockSize = 256 * (1 << (blockSize - 8));
2648 if (sampleRate <= 11)
2649 header->
sampleRate = sampleRateTable[sampleRate];
2650 else if (sampleRate == 12)
2652 if (!drflac__read_uint32(bs, 8, &header->
sampleRate))
2654 crc8 = drflac_crc8(crc8, header->
sampleRate, 8);
2657 else if (sampleRate == 13)
2659 if (!drflac__read_uint32(bs, 16, &header->
sampleRate))
2661 crc8 = drflac_crc8(crc8, header->
sampleRate, 16);
2663 else if (sampleRate == 14)
2665 if (!drflac__read_uint32(bs, 16, &header->
sampleRate))
2667 crc8 = drflac_crc8(crc8, header->
sampleRate, 16);
2679 if (!drflac__read_uint8(bs, 8, &header->
crc8))
2682 #ifndef DR_FLAC_NO_CRC 2683 if (header->
crc8 != crc8)
2694 if (!drflac__read_uint8(bs, 8, &header))
2698 if ((header & 0x80) != 0)
2701 type = (header & 0x7E) >> 1;
2708 if ((
type & 0x20) != 0) {
2711 }
else if ((
type & 0x08) != 0) {
2723 if (pSubframe->
subframeType == DRFLAC_SUBFRAME_RESERVED)
2728 if ((header & 0x01) == 1)
2730 unsigned int wastedBitsPerSample = 0;
2731 if (!drflac__seek_past_next_set_bit(bs, &wastedBitsPerSample))
2742 drflac_assert(bs !=
NULL);
2745 pSubframe =
frame->subframes + subframeIndex;
2746 if (!drflac__read_subframe_header(bs, pSubframe))
2751 if ((
frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE ||
frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE) && subframeIndex == 1) {
2753 }
else if (
frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE && subframeIndex == 0) {
2763 case DRFLAC_SUBFRAME_CONSTANT:
2768 case DRFLAC_SUBFRAME_VERBATIM:
2773 case DRFLAC_SUBFRAME_FIXED:
2778 case DRFLAC_SUBFRAME_LPC:
2793 drflac_assert(bs !=
NULL);
2796 pSubframe =
frame->subframes + subframeIndex;
2797 if (!drflac__read_subframe_header(bs, pSubframe))
2802 if ((
frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE ||
frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE) && subframeIndex == 1) {
2804 }
else if (
frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE && subframeIndex == 0) {
2814 case DRFLAC_SUBFRAME_CONSTANT:
2820 case DRFLAC_SUBFRAME_VERBATIM:
2823 if (!drflac__seek_bits(bs, bitsToSeek))
2827 case DRFLAC_SUBFRAME_FIXED:
2830 if (!drflac__seek_bits(bs, bitsToSeek))
2833 if (!drflac__read_and_seek_residual(bs,
frame->header.blockSize, pSubframe->
lpcOrder))
2837 case DRFLAC_SUBFRAME_LPC:
2839 unsigned char lpcPrecision;
2841 if (!drflac__seek_bits(bs, bitsToSeek))
2844 if (!drflac__read_uint8(bs, 4, &lpcPrecision))
2846 if (lpcPrecision == 15)
2851 bitsToSeek = (pSubframe->
lpcOrder * lpcPrecision) + 5;
2852 if (!drflac__seek_bits(bs, bitsToSeek))
2855 if (!drflac__read_and_seek_residual(bs,
frame->header.blockSize, pSubframe->
lpcOrder))
2866 static DRFLAC_INLINE
drflac_uint8 drflac__get_channel_count_from_channel_assignment(
drflac_int8 channelAssignment)
2868 drflac_uint8 lookup[] = {1, 2, 3, 4, 5, 6, 7, 8, 2, 2, 2};
2870 drflac_assert(channelAssignment <= 10);
2871 return lookup[channelAssignment];
2874 static drflac_result drflac__decode_frame(
drflac* pFlac)
2879 int i, channelCount;
2886 return DRFLAC_ERROR;
2890 if (channelCount != (
int)pFlac->
channels)
2891 return DRFLAC_ERROR;
2893 for (i = 0; i < channelCount; ++i)
2896 return DRFLAC_ERROR;
2899 paddingSizeInBits = DRFLAC_CACHE_L1_BITS_REMAINING(&pFlac->
bs) & 7;
2900 if (paddingSizeInBits > 0)
2903 if (!drflac__read_uint8(&pFlac->
bs, paddingSizeInBits, &padding))
2904 return DRFLAC_END_OF_STREAM;
2907 #ifndef DR_FLAC_NO_CRC 2908 actualCRC16 = drflac__flush_crc16(&pFlac->
bs);
2910 if (!drflac__read_uint16(&pFlac->
bs, 16, &desiredCRC16))
2911 return DRFLAC_END_OF_STREAM;
2913 #ifndef DR_FLAC_NO_CRC 2914 if (actualCRC16 != desiredCRC16)
2915 return DRFLAC_CRC_MISMATCH;
2920 return DRFLAC_SUCCESS;
2923 static drflac_result drflac__seek_frame(
drflac* pFlac)
2925 #ifndef DR_FLAC_NO_CRC 2932 for (i = 0; i < channelCount; ++i)
2935 return DRFLAC_ERROR;
2939 if (!drflac__seek_bits(&pFlac->
bs, DRFLAC_CACHE_L1_BITS_REMAINING(&pFlac->
bs) & 7))
2940 return DRFLAC_ERROR;
2943 #ifndef DR_FLAC_NO_CRC 2944 actualCRC16 = drflac__flush_crc16(&pFlac->
bs);
2946 if (!drflac__read_uint16(&pFlac->
bs, 16, &desiredCRC16))
2947 return DRFLAC_END_OF_STREAM;
2949 #ifndef DR_FLAC_NO_CRC 2950 if (actualCRC16 != desiredCRC16)
2951 return DRFLAC_CRC_MISMATCH;
2954 return DRFLAC_SUCCESS;
2959 drflac_assert(pFlac !=
NULL);
2968 result = drflac__decode_frame(pFlac);
2969 if (
result != DRFLAC_SUCCESS)
2971 if (
result == DRFLAC_CRC_MISMATCH)
2983 unsigned int channelCount;
2986 drflac_assert(pFlac !=
NULL);
2991 if (firstSampleInFrame == 0)
2995 if (lastSampleInFrame > 0)
2996 lastSampleInFrame -= 1;
2998 if (pFirstSampleInFrameOut)
2999 *pFirstSampleInFrameOut = firstSampleInFrame;
3000 if (pLastSampleInFrameOut)
3001 *pLastSampleInFrameOut = lastSampleInFrame;
3008 drflac_assert(pFlac !=
NULL);
3016 static DRFLAC_INLINE drflac_result drflac__seek_to_next_frame(
drflac* pFlac)
3019 drflac_assert(pFlac !=
NULL);
3020 return drflac__seek_frame(pFlac);
3029 if (!drflac__seek_to_first_frame(pFlac))
3041 drflac__get_current_frame_sample_range(pFlac, &firstSampleInFrame, &lastSampleInFrame);
3043 sampleCountInThisFrame = (lastSampleInFrame - firstSampleInFrame) + 1;
3044 if (sampleIndex < (runningSampleCount + sampleCountInThisFrame))
3048 drflac_result
result = drflac__decode_frame(pFlac);
3049 if (
result == DRFLAC_SUCCESS)
3052 drflac_uint64 samplesToDecode = (size_t)(sampleIndex - runningSampleCount);
3053 if (samplesToDecode == 0)
3059 if (
result == DRFLAC_CRC_MISMATCH)
3068 drflac_result
result = drflac__seek_to_next_frame(pFlac);
3069 if (
result == DRFLAC_SUCCESS)
3070 runningSampleCount += sampleCountInThisFrame;
3073 if (
result == DRFLAC_CRC_MISMATCH)
3089 drflac_assert(pFlac !=
NULL);
3099 if (seekpointCount == 0)
3102 seekpointsRemaining = seekpointCount;
3103 while (seekpointsRemaining > 0)
3106 if (!drflac__read_uint64(&pFlac->
bs, 64, &seekpoint.
firstSample))
3108 if (!drflac__read_uint64(&pFlac->
bs, 64, &seekpoint.
frameOffset))
3110 if (!drflac__read_uint16(&pFlac->
bs, 16, &seekpoint.
sampleCount))
3118 closestSeekpoint = seekpoint;
3119 seekpointsRemaining -= 1;
3137 drflac__get_current_frame_sample_range(pFlac, &firstSampleInFrame, &lastSampleInFrame);
3139 sampleCountInThisFrame = (lastSampleInFrame - firstSampleInFrame) + 1;
3140 if (sampleIndex < (runningSampleCount + sampleCountInThisFrame))
3144 drflac_result
result = drflac__decode_frame(pFlac);
3146 if (
result == DRFLAC_SUCCESS)
3149 drflac_uint64 samplesToDecode = (size_t)(sampleIndex - runningSampleCount);
3150 if (samplesToDecode == 0)
3156 if (
result == DRFLAC_CRC_MISMATCH)
3165 drflac_result
result = drflac__seek_to_next_frame(pFlac);
3166 if (
result == DRFLAC_SUCCESS)
3167 runningSampleCount += sampleCountInThisFrame;
3170 if (
result == DRFLAC_CRC_MISMATCH)
3179 #ifndef DR_FLAC_NO_OGG 3191 } drflac_ogg_page_header;
3213 #ifndef DR_FLAC_NO_OGG 3216 drflac_ogg_page_header oggBosHeader;
3222 blockHeader = drflac__be2host_32(blockHeader);
3223 *isLastBlock = (blockHeader & (0x01 << 31)) >> 31;
3224 *blockType = (blockHeader & (0x7F << 24)) >> 24;
3225 *blockSize = (blockHeader & 0xFFFFFF);
3231 if (onRead(pUserData, &blockHeader, 4) != 4) {
3235 drflac__decode_block_header(blockHeader, isLastBlock, blockType, blockSize);
3247 if (onRead(pUserData, &blockSizes, 4) != 4)
3251 if (onRead(pUserData, &frameSizes, 6) != 6)
3255 if (onRead(pUserData, &importantProps, 8) != 8)
3259 if (onRead(pUserData,
md5,
sizeof(
md5)) !=
sizeof(
md5))
3262 blockSizes = drflac__be2host_32(blockSizes);
3263 frameSizes = drflac__be2host_64(frameSizes);
3264 importantProps = drflac__be2host_64(importantProps);
3266 pStreamInfo->
minBlockSize = (blockSizes & 0xFFFF0000) >> 16;
3274 drflac_copy_memory(pStreamInfo->
md5,
md5,
sizeof(
md5));
3287 drflac_assert(pFlac !=
NULL);
3296 if (!drflac__read_and_decode_block_header(pFlac->
bs.
onRead, pFlac->
bs.
pUserData, &isLastBlock, &blockType, &blockSize))
3298 runningFilePos += 4;
3310 void* pRawData = DRFLAC_MALLOC(blockSize);
3311 if (pRawData ==
NULL)
3315 DRFLAC_FREE(pRawData);
3326 DRFLAC_FREE(pRawData);
3332 seektablePos = runningFilePos;
3333 seektableSize = blockSize;
3338 void* pRawData = DRFLAC_MALLOC(blockSize);
3339 if (pRawData ==
NULL)
3343 DRFLAC_FREE(pRawData);
3353 for (iSeekpoint = 0; iSeekpoint <
metadata.data.seektable.seekpointCount; ++iSeekpoint) {
3362 DRFLAC_FREE(pRawData);
3370 const char* pRunningData;
3371 void* pRawData = DRFLAC_MALLOC(blockSize);
3372 if (pRawData ==
NULL)
3376 DRFLAC_FREE(pRawData);
3383 pRunningData = (
const char*)pRawData;
3384 metadata.data.vorbis_comment.vendorLength = drflac__le2host_32(*(
drflac_uint32*)pRunningData); pRunningData += 4;
3385 metadata.data.vorbis_comment.vendor = pRunningData; pRunningData +=
metadata.data.vorbis_comment.vendorLength;
3386 metadata.data.vorbis_comment.commentCount = drflac__le2host_32(*(
drflac_uint32*)pRunningData); pRunningData += 4;
3387 metadata.data.vorbis_comment.comments = pRunningData;
3390 DRFLAC_FREE(pRawData);
3398 const char* pRunningData;
3399 void* pRawData = DRFLAC_MALLOC(blockSize);
3400 if (pRawData ==
NULL)
3404 DRFLAC_FREE(pRawData);
3411 pRunningData = (
const char*)pRawData;
3412 drflac_copy_memory(
metadata.data.cuesheet.catalog, pRunningData, 128); pRunningData += 128;
3413 metadata.data.cuesheet.leadInSampleCount = drflac__be2host_64(*(
drflac_uint64*)pRunningData); pRunningData += 4;
3414 metadata.data.cuesheet.isCD = ((pRunningData[0] & 0x80) >> 7) != 0; pRunningData += 259;
3415 metadata.data.cuesheet.trackCount = pRunningData[0]; pRunningData += 1;
3419 DRFLAC_FREE(pRawData);
3427 const char* pRunningData;
3428 void* pRawData = DRFLAC_MALLOC(blockSize);
3429 if (pRawData ==
NULL)
3433 DRFLAC_FREE(pRawData);
3440 pRunningData = (
const char*)pRawData;
3442 metadata.data.picture.mimeLength = drflac__be2host_32(*(
drflac_uint32*)pRunningData); pRunningData += 4;
3443 metadata.data.picture.mime = pRunningData; pRunningData +=
metadata.data.picture.mimeLength;
3444 metadata.data.picture.descriptionLength = drflac__be2host_32(*(
drflac_uint32*)pRunningData); pRunningData += 4;
3445 metadata.data.picture.description = pRunningData;
3447 metadata.data.picture.height = drflac__be2host_32(*(
drflac_uint32*)pRunningData); pRunningData += 4;
3448 metadata.data.picture.colorDepth = drflac__be2host_32(*(
drflac_uint32*)pRunningData); pRunningData += 4;
3449 metadata.data.picture.indexColorCount = drflac__be2host_32(*(
drflac_uint32*)pRunningData); pRunningData += 4;
3450 metadata.data.picture.pictureDataSize = drflac__be2host_32(*(
drflac_uint32*)pRunningData); pRunningData += 4;
3454 DRFLAC_FREE(pRawData);
3489 void* pRawData = DRFLAC_MALLOC(blockSize);
3490 if (pRawData ==
NULL)
3494 DRFLAC_FREE(pRawData);
3502 DRFLAC_FREE(pRawData);
3514 runningFilePos += blockSize;
3539 if (!drflac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize))
3553 if (!drflac__read_next_frame_header(&pInit->bs, 0, &pInit->firstFrameHeader))
3556 if (pInit->firstFrameHeader.bitsPerSample == 0)
3559 pInit->sampleRate = pInit->firstFrameHeader.sampleRate;
3560 pInit->channels = drflac__get_channel_count_from_channel_assignment(pInit->firstFrameHeader.channelAssignment);
3561 pInit->bitsPerSample = pInit->firstFrameHeader.bitsPerSample;
3562 pInit->maxBlockSize = 65535;
3568 if (!drflac__read_streaminfo(onRead, pUserData, &streaminfo))
3573 pInit->channels = streaminfo.
channels;
3577 pInit->hasMetadataBlocks = !isLastBlock;
3584 metadata.data.streaminfo = streaminfo;
3592 #ifndef DR_FLAC_NO_OGG 3593 #define DRFLAC_OGG_MAX_PAGE_SIZE 65307 3594 #define DRFLAC_OGG_CAPTURE_PATTERN_CRC32 1605413199 3598 drflac_ogg_recover_on_crc_mismatch,
3599 drflac_ogg_fail_on_crc_mismatch
3600 } drflac_ogg_crc_mismatch_recovery;
3604 0x00000000
L, 0x04C11DB7
L, 0x09823B6E
L, 0x0D4326D9
L,
3605 0x130476DC
L, 0x17C56B6B
L, 0x1A864DB2
L, 0x1E475005
L,
3606 0x2608EDB8
L, 0x22C9F00F
L, 0x2F8AD6D6
L, 0x2B4BCB61
L,
3607 0x350C9B64
L, 0x31CD86D3
L, 0x3C8EA00A
L, 0x384FBDBD
L,
3608 0x4C11DB70
L, 0x48D0C6C7
L, 0x4593E01E
L, 0x4152FDA9
L,
3609 0x5F15ADAC
L, 0x5BD4B01B
L, 0x569796C2
L, 0x52568B75
L,
3610 0x6A1936C8
L, 0x6ED82B7F
L, 0x639B0DA6
L, 0x675A1011
L,
3611 0x791D4014
L, 0x7DDC5DA3
L, 0x709F7B7A
L, 0x745E66CD
L,
3612 0x9823B6E0
L, 0x9CE2AB57
L, 0x91A18D8E
L, 0x95609039
L,
3613 0x8B27C03C
L, 0x8FE6DD8B
L, 0x82A5FB52
L, 0x8664E6E5
L,
3614 0xBE2B5B58
L, 0xBAEA46EF
L, 0xB7A96036
L, 0xB3687D81
L,
3615 0xAD2F2D84
L, 0xA9EE3033
L, 0xA4AD16EA
L, 0xA06C0B5D
L,
3616 0xD4326D90
L, 0xD0F37027
L, 0xDDB056FE
L, 0xD9714B49
L,
3617 0xC7361B4C
L, 0xC3F706FB
L, 0xCEB42022
L, 0xCA753D95
L,
3618 0xF23A8028
L, 0xF6FB9D9F
L, 0xFBB8BB46
L, 0xFF79A6F1
L,
3619 0xE13EF6F4
L, 0xE5FFEB43
L, 0xE8BCCD9A
L, 0xEC7DD02D
L,
3620 0x34867077
L, 0x30476DC0
L, 0x3D044B19
L, 0x39C556AE
L,
3621 0x278206AB
L, 0x23431B1C
L, 0x2E003DC5
L, 0x2AC12072
L,
3622 0x128E9DCF
L, 0x164F8078
L, 0x1B0CA6A1
L, 0x1FCDBB16
L,
3623 0x018AEB13
L, 0x054BF6A4
L, 0x0808D07D
L, 0x0CC9CDCA
L,
3624 0x7897AB07
L, 0x7C56B6B0
L, 0x71159069
L, 0x75D48DDE
L,
3625 0x6B93DDDB
L, 0x6F52C06C
L, 0x6211E6B5
L, 0x66D0FB02
L,
3626 0x5E9F46BF
L, 0x5A5E5B08
L, 0x571D7DD1
L, 0x53DC6066
L,
3627 0x4D9B3063
L, 0x495A2DD4
L, 0x44190B0D
L, 0x40D816BA
L,
3628 0xACA5C697
L, 0xA864DB20
L, 0xA527FDF9
L, 0xA1E6E04E
L,
3629 0xBFA1B04B
L, 0xBB60ADFC
L, 0xB6238B25
L, 0xB2E29692
L,
3630 0x8AAD2B2F
L, 0x8E6C3698
L, 0x832F1041
L, 0x87EE0DF6
L,
3631 0x99A95DF3
L, 0x9D684044
L, 0x902B669D
L, 0x94EA7B2A
L,
3632 0xE0B41DE7
L, 0xE4750050
L, 0xE9362689
L, 0xEDF73B3E
L,
3633 0xF3B06B3B
L, 0xF771768C
L, 0xFA325055
L, 0xFEF34DE2
L,
3634 0xC6BCF05F
L, 0xC27DEDE8
L, 0xCF3ECB31
L, 0xCBFFD686
L,
3635 0xD5B88683
L, 0xD1799B34
L, 0xDC3ABDED
L, 0xD8FBA05A
L,
3636 0x690CE0EE
L, 0x6DCDFD59
L, 0x608EDB80
L, 0x644FC637
L,
3637 0x7A089632
L, 0x7EC98B85
L, 0x738AAD5C
L, 0x774BB0EB
L,
3638 0x4F040D56
L, 0x4BC510E1
L, 0x46863638
L, 0x42472B8F
L,
3639 0x5C007B8A
L, 0x58C1663D
L, 0x558240E4
L, 0x51435D53
L,
3640 0x251D3B9E
L, 0x21DC2629
L, 0x2C9F00F0
L, 0x285E1D47
L,
3641 0x36194D42
L, 0x32D850F5
L, 0x3F9B762C
L, 0x3B5A6B9B
L,
3642 0x0315D626
L, 0x07D4CB91
L, 0x0A97ED48
L, 0x0E56F0FF
L,
3643 0x1011A0FA
L, 0x14D0BD4D
L, 0x19939B94
L, 0x1D528623
L,
3644 0xF12F560E
L, 0xF5EE4BB9
L, 0xF8AD6D60
L, 0xFC6C70D7
L,
3645 0xE22B20D2
L, 0xE6EA3D65
L, 0xEBA91BBC
L, 0xEF68060B
L,
3646 0xD727BBB6
L, 0xD3E6A601
L, 0xDEA580D8
L, 0xDA649D6F
L,
3647 0xC423CD6A
L, 0xC0E2D0DD
L, 0xCDA1F604
L, 0xC960EBB3
L,
3648 0xBD3E8D7E
L, 0xB9FF90C9
L, 0xB4BCB610
L, 0xB07DABA7
L,
3649 0xAE3AFBA2
L, 0xAAFBE615
L, 0xA7B8C0CC
L, 0xA379DD7B
L,
3650 0x9B3660C6
L, 0x9FF77D71
L, 0x92B45BA8
L, 0x9675461F
L,
3651 0x8832161A
L, 0x8CF30BAD
L, 0x81B02D74
L, 0x857130C3
L,
3652 0x5D8A9099
L, 0x594B8D2E
L, 0x5408ABF7
L, 0x50C9B640
L,
3653 0x4E8EE645
L, 0x4A4FFBF2
L, 0x470CDD2B
L, 0x43CDC09C
L,
3654 0x7B827D21
L, 0x7F436096
L, 0x7200464F
L, 0x76C15BF8
L,
3655 0x68860BFD
L, 0x6C47164A
L, 0x61043093
L, 0x65C52D24
L,
3656 0x119B4BE9
L, 0x155A565E
L, 0x18197087
L, 0x1CD86D30
L,
3657 0x029F3D35
L, 0x065E2082
L, 0x0B1D065B
L, 0x0FDC1BEC
L,
3658 0x3793A651
L, 0x3352BBE6
L, 0x3E119D3F
L, 0x3AD08088
L,
3659 0x2497D08D
L, 0x2056CD3A
L, 0x2D15EBE3
L, 0x29D4F654
L,
3660 0xC5A92679
L, 0xC1683BCE
L, 0xCC2B1D17
L, 0xC8EA00A0
L,
3661 0xD6AD50A5
L, 0xD26C4D12
L, 0xDF2F6BCB
L, 0xDBEE767C
L,
3662 0xE3A1CBC1
L, 0xE760D676
L, 0xEA23F0AF
L, 0xEEE2ED18
L,
3663 0xF0A5BD1D
L, 0xF464A0AA
L, 0xF9278673
L, 0xFDE69BC4
L,
3664 0x89B8FD09
L, 0x8D79E0BE
L, 0x803AC667
L, 0x84FBDBD0
L,
3665 0x9ABC8BD5
L, 0x9E7D9662
L, 0x933EB0BB
L, 0x97FFAD0C
L,
3666 0xAFB010B1
L, 0xAB710D06
L, 0xA6322BDF
L, 0xA2F33668
L,
3667 0xBCB4666D
L, 0xB8757BDA
L, 0xB5365D03
L, 0xB1F740B4
L 3672 #ifndef DR_FLAC_NO_CRC 3714 static DRFLAC_INLINE
drflac_uint32 drflac_ogg__get_page_header_size(drflac_ogg_page_header* pHeader)
3716 return 27 + pHeader->segmentCount;
3719 static DRFLAC_INLINE
drflac_uint32 drflac_ogg__get_page_body_size(drflac_ogg_page_header* pHeader)
3724 for (i = 0; i < pHeader->segmentCount; ++i)
3725 pageBodySize += pHeader->segmentTable[i];
3727 return pageBodySize;
3735 drflac_assert(*pCRC32 == DRFLAC_OGG_CAPTURE_PATTERN_CRC32);
3737 if (onRead(pUserData,
data, 23) != 23)
3738 return DRFLAC_END_OF_STREAM;
3741 pHeader->structureVersion =
data[0];
3742 pHeader->headerType =
data[1];
3743 drflac_copy_memory(&pHeader->granulePosition, &
data[ 2], 8);
3744 drflac_copy_memory(&pHeader->serialNumber, &
data[10], 4);
3745 drflac_copy_memory(&pHeader->sequenceNumber, &
data[14], 4);
3746 drflac_copy_memory(&pHeader->checksum, &
data[18], 4);
3747 pHeader->segmentCount =
data[22];
3755 for (i = 0; i < 23; ++i)
3756 *pCRC32 = drflac_crc32_byte(*pCRC32,
data[i]);
3758 if (onRead(pUserData, pHeader->segmentTable, pHeader->segmentCount) != pHeader->segmentCount)
3759 return DRFLAC_END_OF_STREAM;
3761 *pBytesRead += pHeader->segmentCount;
3763 for (i = 0; i < pHeader->segmentCount; ++i)
3764 *pCRC32 = drflac_crc32_byte(*pCRC32, pHeader->segmentTable[i]);
3766 return DRFLAC_SUCCESS;
3775 if (onRead(pUserData,
id, 4) != 4)
3776 return DRFLAC_END_OF_STREAM;
3782 if (drflac_ogg__is_capture_pattern(
id))
3785 *pCRC32 = DRFLAC_OGG_CAPTURE_PATTERN_CRC32;
3787 result = drflac_ogg__read_page_header_after_capture_pattern(onRead, pUserData, pHeader, pBytesRead, pCRC32);
3788 if (
result == DRFLAC_SUCCESS)
3789 return DRFLAC_SUCCESS;
3791 if (
result == DRFLAC_CRC_MISMATCH)
3801 if (onRead(pUserData, &
id[3], 1) != 1)
3802 return DRFLAC_END_OF_STREAM;
3822 drflac_ogg_page_header bosPageHeader;
3823 drflac_ogg_page_header currentPageHeader;
3829 static size_t drflac_oggbs__read_physical(drflac_oggbs* oggbs,
void* bufferOut,
size_t bytesToRead)
3831 size_t bytesActuallyRead = oggbs->onRead(oggbs->pUserData, bufferOut, bytesToRead);
3832 oggbs->currentBytePos += bytesActuallyRead;
3834 return bytesActuallyRead;
3841 if (
offset <= 0x7FFFFFFF)
3845 oggbs->currentBytePos =
offset;
3853 oggbs->currentBytePos =
offset;
3860 while (
offset > 0x7FFFFFFF)
3864 oggbs->currentBytePos += 0x7FFFFFFF;
3870 oggbs->currentBytePos +=
offset;
3876 static drflac_bool32 drflac_oggbs__goto_next_page(drflac_oggbs* oggbs, drflac_ogg_crc_mismatch_recovery recoveryMethod)
3878 drflac_ogg_page_header header;
3880 #ifndef DR_FLAC_NO_CRC 3886 if (drflac_ogg__read_page_header(oggbs->onRead, oggbs->pUserData, &header, &bytesRead, &
crc32) != DRFLAC_SUCCESS)
3888 oggbs->currentBytePos += bytesRead;
3890 pageBodySize = drflac_ogg__get_page_body_size(&header);
3891 if (pageBodySize > DRFLAC_OGG_MAX_PAGE_SIZE)
3894 if (header.serialNumber != oggbs->serialNumber)
3903 if (drflac_oggbs__read_physical(oggbs, oggbs->pageData, pageBodySize) != pageBodySize)
3905 oggbs->pageDataSize = pageBodySize;
3907 #ifndef DR_FLAC_NO_CRC 3908 actualCRC32 = drflac_crc32_buffer(
crc32, oggbs->pageData, oggbs->pageDataSize);
3909 if (actualCRC32 != header.checksum)
3911 if (recoveryMethod == drflac_ogg_recover_on_crc_mismatch)
3917 drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch);
3922 oggbs->currentPageHeader = header;
3923 oggbs->bytesRemainingInPage = pageBodySize;
3930 static drflac_uint8 drflac_oggbs__get_current_segment_index(drflac_oggbs* oggbs,
drflac_uint8* pBytesRemainingInSeg)
3932 drflac_uint32 bytesConsumedInPage = drflac_ogg__get_page_body_size(&oggbs->currentPageHeader) - oggbs->bytesRemainingInPage;
3935 while (iByte < bytesConsumedInPage)
3937 drflac_uint8 segmentSize = oggbs->currentPageHeader.segmentTable[iSeg];
3938 if (iByte + segmentSize > bytesConsumedInPage)
3942 iByte += segmentSize;
3945 *pBytesRemainingInSeg = oggbs->currentPageHeader.segmentTable[iSeg] - (
drflac_uint8)(bytesConsumedInPage - iByte);
3949 static drflac_bool32 drflac_oggbs__seek_to_next_packet(drflac_oggbs* oggbs)
3956 drflac_uint8 iFirstSeg = drflac_oggbs__get_current_segment_index(oggbs, &bytesRemainingInSeg);
3958 drflac_uint32 bytesToEndOfPacketOrPage = bytesRemainingInSeg;
3959 for (
drflac_uint8 iSeg = iFirstSeg; iSeg < oggbs->currentPageHeader.segmentCount; ++iSeg) {
3960 drflac_uint8 segmentSize = oggbs->currentPageHeader.segmentTable[iSeg];
3961 if (segmentSize < 255)
3963 if (iSeg == oggbs->currentPageHeader.segmentCount-1)
3969 bytesToEndOfPacketOrPage += segmentSize;
3975 oggbs->bytesRemainingInPage -= bytesToEndOfPacketOrPage;
3981 if (!drflac_oggbs__goto_next_page(oggbs))
3985 if ((oggbs->currentPageHeader.headerType & 0x01) == 0)
3996 static drflac_bool32 drflac_oggbs__seek_to_next_frame(drflac_oggbs* oggbs)
4001 return drflac_oggbs__seek_to_next_packet(oggbs);
4005 static size_t drflac__on_read_ogg(
void* pUserData,
void* bufferOut,
size_t bytesToRead)
4007 size_t bytesRead = 0;
4009 drflac_oggbs* oggbs = (drflac_oggbs*)pUserData;
4011 drflac_assert(oggbs !=
NULL);
4016 while (bytesRead < bytesToRead)
4018 size_t bytesRemainingToRead = bytesToRead - bytesRead;
4020 if (oggbs->bytesRemainingInPage >= bytesRemainingToRead) {
4021 drflac_copy_memory(pRunningBufferOut, oggbs->pageData + (oggbs->pageDataSize - oggbs->bytesRemainingInPage), bytesRemainingToRead);
4022 bytesRead += bytesRemainingToRead;
4023 oggbs->bytesRemainingInPage -= (
drflac_uint32)bytesRemainingToRead;
4028 if (oggbs->bytesRemainingInPage > 0)
4030 drflac_copy_memory(pRunningBufferOut, oggbs->pageData + (oggbs->pageDataSize - oggbs->bytesRemainingInPage), oggbs->bytesRemainingInPage);
4031 bytesRead += oggbs->bytesRemainingInPage;
4032 pRunningBufferOut += oggbs->bytesRemainingInPage;
4033 oggbs->bytesRemainingInPage = 0;
4036 drflac_assert(bytesRemainingToRead > 0);
4037 if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch))
4046 int bytesSeeked = 0;
4047 drflac_oggbs* oggbs = (drflac_oggbs*)pUserData;
4049 drflac_assert(oggbs !=
NULL);
4058 if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_fail_on_crc_mismatch))
4066 while (bytesSeeked <
offset)
4068 int bytesRemainingToSeek =
offset - bytesSeeked;
4069 drflac_assert(bytesRemainingToSeek >= 0);
4071 if (oggbs->bytesRemainingInPage >= (
size_t)bytesRemainingToSeek)
4073 oggbs->bytesRemainingInPage -= bytesRemainingToSeek;
4078 if (oggbs->bytesRemainingInPage > 0)
4080 bytesSeeked += (int)oggbs->bytesRemainingInPage;
4081 oggbs->bytesRemainingInPage = 0;
4084 drflac_assert(bytesRemainingToSeek > 0);
4087 if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_fail_on_crc_mismatch))
4099 drflac_oggbs* oggbs = (drflac_oggbs*)pFlac->
_oggbs;
4106 oggbs->bytesRemainingInPage = 0;
4110 if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch)) {
4115 runningFrameBytePos = oggbs->currentBytePos - drflac_ogg__get_page_header_size(&oggbs->currentPageHeader) - oggbs->pageDataSize;
4116 if (oggbs->currentPageHeader.granulePosition*pFlac->
channels >= sampleIndex)
4121 if ((oggbs->currentPageHeader.headerType & 0x01) == 0)
4123 if (oggbs->currentPageHeader.segmentTable[0] >= 2)
4126 firstBytesInPage[0] = oggbs->pageData[0];
4127 firstBytesInPage[1] = oggbs->pageData[1];
4129 if ((firstBytesInPage[0] == 0xFF) && (firstBytesInPage[1] & 0xFC) == 0xF8)
4130 runningGranulePosition = oggbs->currentPageHeader.granulePosition*pFlac->
channels;
4144 if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch))
4149 runningSampleCount = runningGranulePosition;
4178 drflac__get_current_frame_sample_range(pFlac, &firstSampleInFrame, &lastSampleInFrame);
4180 sampleCountInThisFrame = (lastSampleInFrame - firstSampleInFrame) + 1;
4181 if (sampleIndex < (runningSampleCount + sampleCountInThisFrame)) {
4184 drflac_result
result = drflac__decode_frame(pFlac);
4185 if (
result == DRFLAC_SUCCESS) {
4187 drflac_uint64 samplesToDecode = (size_t)(sampleIndex - runningSampleCount);
4188 if (samplesToDecode == 0)
4194 if (
result == DRFLAC_CRC_MISMATCH)
4203 drflac_result
result = drflac__seek_to_next_frame(pFlac);
4204 if (
result == DRFLAC_SUCCESS)
4205 runningSampleCount += sampleCountInThisFrame;
4208 if (
result == DRFLAC_CRC_MISMATCH)
4222 drflac_ogg_page_header header;
4230 pInit->oggFirstBytePos = 0;
4232 if (drflac_ogg__read_page_header_after_capture_pattern(onRead, pUserData, &header, &bytesRead, &
crc32) != DRFLAC_SUCCESS)
4234 pInit->runningFilePos += bytesRead;
4240 if ((header.headerType & 0x02) == 0)
4244 pageBodySize = drflac_ogg__get_page_body_size(&header);
4245 if (pageBodySize == 51)
4252 if (onRead(pUserData, &packetType, 1) != 1)
4255 bytesRemainingInPage -= 1;
4256 if (packetType == 0x7F)
4260 if (onRead(pUserData, sig, 4) != 4)
4263 bytesRemainingInPage -= 4;
4264 if (sig[0] ==
'F' && sig[1] ==
'L' && sig[2] ==
'A' && sig[3] ==
'C') {
4267 if (onRead(pUserData, mappingVersion, 2) != 2)
4270 if (mappingVersion[0] != 1)
4279 if (onRead(pUserData, sig, 4) != 4)
4282 if (sig[0] ==
'f' && sig[1] ==
'L' && sig[2] ==
'a' && sig[3] ==
'C')
4289 if (!drflac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize))
4295 if (drflac__read_streaminfo(onRead, pUserData, &streaminfo)) {
4299 pInit->channels = streaminfo.
channels;
4303 pInit->hasMetadataBlocks = !isLastBlock;
4310 metadata.data.streaminfo = streaminfo;
4314 pInit->runningFilePos += pageBodySize;
4315 pInit->oggFirstBytePos = pInit->runningFilePos - 79;
4316 pInit->oggSerial = header.serialNumber;
4317 pInit->oggBosHeader = header;
4352 pInit->runningFilePos += pageBodySize;
4355 if (drflac_ogg__read_page_header(onRead, pUserData, &header, &bytesRead, &
crc32) != DRFLAC_SUCCESS)
4357 pInit->runningFilePos += bytesRead;
4377 drflac_zero_memory(pInit,
sizeof(*pInit));
4378 pInit->onRead = onRead;
4379 pInit->onSeek = onSeek;
4380 pInit->onMeta = onMeta;
4381 pInit->container = container;
4382 pInit->pUserData = pUserData;
4383 pInit->pUserDataMD = pUserDataMD;
4385 pInit->bs.onRead = onRead;
4386 pInit->bs.onSeek = onSeek;
4387 pInit->bs.pUserData = pUserData;
4388 drflac__reset_cache(&pInit->bs);
4397 if (onRead(pUserData,
id, 4) != 4)
4399 pInit->runningFilePos += 4;
4401 if (
id[0] ==
'I' &&
id[1] ==
'D' &&
id[2] ==
'3')
4407 if (onRead(pUserData, header, 6) != 6)
4409 pInit->runningFilePos += 6;
4412 drflac_copy_memory(&headerSize, header+2, 4);
4413 headerSize = drflac__unsynchsafe_32(drflac__be2host_32(headerSize));
4419 pInit->runningFilePos += headerSize;
4425 if (
id[0] ==
'f' &&
id[1] ==
'L' &&
id[2] ==
'a' &&
id[3] ==
'C') {
4426 return drflac__init_private__native(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
4428 #ifndef DR_FLAC_NO_OGG 4429 if (
id[0] ==
'O' &&
id[1] ==
'g' &&
id[2] ==
'g' &&
id[3] ==
'S') {
4430 return drflac__init_private__ogg(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
4438 return drflac__init_private__native(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
4439 #ifndef DR_FLAC_NO_OGG 4441 return drflac__init_private__ogg(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
4449 void drflac__init_from_info(
drflac* pFlac, drflac_init_info* pInit)
4451 drflac_assert(pFlac !=
NULL);
4452 drflac_assert(pInit !=
NULL);
4454 drflac_zero_memory(pFlac,
sizeof(*pFlac));
4455 pFlac->
bs = pInit->bs;
4456 pFlac->
onMeta = pInit->onMeta;
4468 drflac_init_info
init;
4474 #ifndef DRFLAC_NO_CPUID 4476 drflac__init_cpu_caps();
4479 if (!drflac__init_private(&
init, onRead, onSeek, onMeta, container, pUserData, pUserDataMD))
4490 allocationSize =
sizeof(
drflac);
4494 if ((
init.maxBlockSize % (DRFLAC_MAX_SIMD_VECTOR_SIZE /
sizeof(
drflac_int32))) == 0) {
4495 wholeSIMDVectorCountPerChannel = (
init.maxBlockSize / (DRFLAC_MAX_SIMD_VECTOR_SIZE /
sizeof(
drflac_int32)));
4497 wholeSIMDVectorCountPerChannel = (
init.maxBlockSize / (DRFLAC_MAX_SIMD_VECTOR_SIZE /
sizeof(
drflac_int32))) + 1;
4500 decodedSamplesAllocationSize = wholeSIMDVectorCountPerChannel * DRFLAC_MAX_SIMD_VECTOR_SIZE *
init.channels;
4502 allocationSize += decodedSamplesAllocationSize;
4503 allocationSize += DRFLAC_MAX_SIMD_VECTOR_SIZE;
4505 #ifndef DR_FLAC_NO_OGG 4508 allocationSize +=
sizeof(drflac_oggbs);
4511 pFlac = (
drflac*)DRFLAC_MALLOC(allocationSize);
4512 drflac__init_from_info(pFlac, &
init);
4515 #ifndef DR_FLAC_NO_OGG 4518 oggbs->onRead = onRead;
4519 oggbs->onSeek = onSeek;
4520 oggbs->pUserData = pUserData;
4521 oggbs->currentBytePos =
init.oggFirstBytePos;
4522 oggbs->firstBytePos =
init.oggFirstBytePos;
4523 oggbs->serialNumber =
init.oggSerial;
4524 oggbs->bosPageHeader =
init.oggBosHeader;
4525 oggbs->bytesRemainingInPage = 0;
4528 pFlac->
bs.
onRead = drflac__on_read_ogg;
4529 pFlac->
bs.
onSeek = drflac__on_seek_ogg;
4531 pFlac->
_oggbs = (
void*)oggbs;
4536 if (
init.hasMetadataBlocks)
4538 if (!drflac__read_and_decode_metadata(pFlac))
4547 if (!
init.hasStreamInfoBlock)
4552 drflac_result
result = drflac__decode_frame(pFlac);
4553 if (
result == DRFLAC_SUCCESS)
4556 if (
result == DRFLAC_CRC_MISMATCH)
4569 #ifndef DR_FLAC_NO_STDIO 4570 typedef void* drflac_file;
4572 #if defined(DR_FLAC_NO_WIN32_IO) || !defined(_WIN32) 4575 static size_t drflac__on_read_stdio(
void* pUserData,
void* bufferOut,
size_t bytesToRead)
4577 return fread(bufferOut, 1, bytesToRead, (
FILE*)pUserData);
4587 static drflac_file drflac__open_file_handle(
const char* filename)
4591 if (
fopen_s(&pFile, filename,
"rb") != 0) {
4595 pFile =
fopen(filename,
"rb");
4596 if (pFile ==
NULL) {
4601 return (drflac_file)pFile;
4604 static void drflac__close_file_handle(drflac_file
file)
4609 #include <windows.h> 4612 #ifndef INVALID_SET_FILE_POINTER 4613 #define INVALID_SET_FILE_POINTER ((DWORD)-1) 4616 static size_t drflac__on_read_stdio(
void* pUserData,
void* bufferOut,
size_t bytesToRead)
4620 drflac_assert(bytesToRead < 0xFFFFFFFF);
4622 ReadFile((HANDLE)pUserData, bufferOut, (DWORD)bytesToRead, &bytesRead,
NULL);
4624 return (
size_t)bytesRead;
4634 static drflac_file drflac__open_file_handle(
const char* filename)
4636 HANDLE hFile = CreateFileA(filename, FILE_GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
NULL);
4637 if (hFile == INVALID_HANDLE_VALUE) {
4641 return (drflac_file)hFile;
4644 static void drflac__close_file_handle(drflac_file
file)
4646 CloseHandle((HANDLE)
file);
4651 drflac* drflac_open_file(
const char* filename)
4653 drflac_file
file = drflac__open_file_handle(filename);
4659 if (pFlac ==
NULL) {
4660 drflac__close_file_handle(
file);
4669 drflac_file
file = drflac__open_file_handle(filename);
4675 if (pFlac ==
NULL) {
4676 drflac__close_file_handle(
file);
4684 static size_t drflac__on_read_memory(
void* pUserData,
void* bufferOut,
size_t bytesToRead)
4686 size_t bytesRemaining;
4688 drflac_assert(memoryStream !=
NULL);
4692 if (bytesToRead > bytesRemaining)
4693 bytesToRead = bytesRemaining;
4695 if (bytesToRead > 0)
4697 drflac_copy_memory(bufferOut, memoryStream->
data + memoryStream->
currentReadPos, bytesToRead);
4707 drflac_assert(memoryStream !=
NULL);
4732 memoryStream.
data = (
const unsigned char*)
data;
4735 pFlac =
drflac_open(drflac__on_read_memory, drflac__on_seek_memory, &memoryStream);
4742 #ifndef DR_FLAC_NO_OGG 4745 drflac_oggbs* oggbs = (drflac_oggbs*)pFlac->
_oggbs;
4762 memoryStream.
data = (
const unsigned char*)
data;
4766 pFlac = drflac_open_with_metadata_private(drflac__on_read_memory, drflac__on_seek_memory, onMeta,
drflac_container_unknown, &memoryStream, pUserData);
4773 #ifndef DR_FLAC_NO_OGG 4776 drflac_oggbs* oggbs = (drflac_oggbs*)pFlac->
_oggbs;
4796 return drflac_open_with_metadata_private(onRead, onSeek,
NULL, container, pUserData, pUserData);
4805 return drflac_open_with_metadata_private(onRead, onSeek, onMeta, container, pUserData, pUserData);
4810 if (pFlac ==
NULL) {
4814 #ifndef DR_FLAC_NO_STDIO 4817 if (pFlac->
bs.
onRead == drflac__on_read_stdio)
4818 drflac__close_file_handle((drflac_file)pFlac->
bs.
pUserData);
4820 #ifndef DR_FLAC_NO_OGG 4824 drflac_assert(pFlac->
bs.
onRead == drflac__on_read_ogg);
4825 drflac_oggbs* oggbs = (drflac_oggbs*)pFlac->
_oggbs;
4826 if (oggbs->onRead == drflac__on_read_stdio)
4827 drflac__close_file_handle((drflac_file)oggbs->pUserData);
4841 drflac_assert(samplesToRead < channelCount);
4844 while (samplesToRead > 0)
4848 drflac_uint64 channelIndex = samplesReadFromFrameSoFar % channelCount;
4850 drflac_uint64 nextSampleInFrame = samplesReadFromFrameSoFar / channelCount;
4852 int decodedSample = 0;
4855 case DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE:
4857 if (channelIndex == 0) {
4862 decodedSample =
left - side;
4866 case DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE:
4868 if (channelIndex == 0) {
4871 decodedSample = side +
right;
4877 case DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE:
4881 if (channelIndex == 0) {
4885 mid = (((
unsigned int)mid) << 1) | (side & 0x01);
4886 decodedSample = (mid + side) >> 1;
4891 mid = (((
unsigned int)mid) << 1) | (side & 0x01);
4892 decodedSample = (mid - side) >> 1;
4896 case DRFLAC_CHANNEL_ASSIGNMENT_INDEPENDENT:
4907 *bufferOut++ = decodedSample;
4921 while (samplesToRead > 0) {
4924 if (!drflac__read_and_decode_next_frame(pFlac))
4942 if (pFlac ==
NULL || samplesToRead == 0)
4945 if (bufferOut ==
NULL)
4946 return drflac__seek_forward_by_samples(pFlac, samplesToRead);
4948 while (samplesToRead > 0)
4953 if (!drflac__read_and_decode_next_frame(pFlac))
4961 unsigned int unusedBitsPerSample;
4966 drflac_uint64 misalignedSampleCount = samplesReadFromFrameSoFar % channelCount;
4967 if (misalignedSampleCount > 0)
4969 drflac_uint64 misalignedSamplesRead = drflac__read_s32__misaligned(pFlac, misalignedSampleCount, bufferOut);
4970 samplesRead += misalignedSamplesRead;
4971 samplesReadFromFrameSoFar += misalignedSamplesRead;
4972 bufferOut += misalignedSamplesRead;
4973 samplesToRead -= misalignedSamplesRead;
4976 alignedSampleCountPerChannel = samplesToRead / channelCount;
4980 firstAlignedSampleInFrame = samplesReadFromFrameSoFar / channelCount;
4985 case DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE:
4991 for (i = 0; i < alignedSampleCountPerChannel; ++i) {
4992 int left = pDecodedSamples0[i];
4993 int side = pDecodedSamples1[i];
5001 case DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE:
5007 for (i = 0; i < alignedSampleCountPerChannel; ++i) {
5008 int side = pDecodedSamples0[i];
5009 int right = pDecodedSamples1[i];
5017 case DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE:
5023 for (i = 0; i < alignedSampleCountPerChannel; ++i) {
5024 int side = pDecodedSamples1[i];
5025 int mid = (((
drflac_uint32)pDecodedSamples0[i]) << 1) | (side & 0x01);
5032 case DRFLAC_CHANNEL_ASSIGNMENT_INDEPENDENT:
5042 for (i = 0; i < alignedSampleCountPerChannel; ++i) {
5052 for (i = 0; i < alignedSampleCountPerChannel; ++i)
5055 for (
j = 0;
j < channelCount; ++
j)
5064 alignedSamplesRead = alignedSampleCountPerChannel * channelCount;
5065 samplesRead += alignedSamplesRead;
5066 samplesReadFromFrameSoFar += alignedSamplesRead;
5067 bufferOut += alignedSamplesRead;
5068 samplesToRead -= alignedSamplesRead;
5074 if (samplesToRead < pFlac->currentFrame.samplesRemaining) {
5075 excessSamplesRead = drflac__read_s32__misaligned(pFlac, samplesToRead, bufferOut);
5080 samplesRead += excessSamplesRead;
5081 samplesReadFromFrameSoFar += excessSamplesRead;
5082 bufferOut += excessSamplesRead;
5083 samplesToRead -= excessSamplesRead;
5096 while (samplesToRead > 0)
5101 if (samplesJustRead == 0)
5105 for (i = 0; i < samplesJustRead; ++i)
5108 totalSamplesRead += samplesJustRead;
5109 samplesToRead -= samplesJustRead;
5110 pBufferOut += samplesJustRead;
5113 return totalSamplesRead;
5121 while (samplesToRead > 0)
5126 if (samplesJustRead == 0)
5130 for (i = 0; i < samplesJustRead; ++i)
5131 pBufferOut[i] = (
float)(samples32[i] / 2147483648.0);
5133 totalSamplesRead += samplesJustRead;
5134 samplesToRead -= samplesJustRead;
5135 pBufferOut += samplesJustRead;
5138 return totalSamplesRead;
5151 if (sampleIndex == 0)
5152 return drflac__seek_to_first_frame(pFlac);
5161 #ifndef DR_FLAC_NO_OGG 5163 return drflac_ogg__seek_to_sample(pFlac, sampleIndex);
5168 if (!drflac__seek_to_sample__seek_table(pFlac, sampleIndex))
5169 return drflac__seek_to_sample__brute_force(pFlac, sampleIndex);
5181 #if defined(_MSC_VER) && _MSC_VER <= 1200 5183 #define SIZE_MAX ((drflac_uint64)0xFFFFFFFFFFFFFFFF) 5185 #define SIZE_MAX 0xFFFFFFFF 5190 #define DRFLAC_DEFINE_FULL_DECODE_AND_CLOSE(extension, type) \ 5191 static type* drflac__full_decode_and_close_ ## extension (drflac* pFlac, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalSampleCountOut)\ 5193 drflac_uint64 totalSampleCount; \ 5194 type* pSampleData = NULL; \ 5195 drflac_assert(pFlac != NULL); \ 5196 totalSampleCount = pFlac->totalSampleCount; \ 5197 if (totalSampleCount == 0) { \ 5198 type buffer[4096]; \ 5199 drflac_uint64 samplesRead; \ 5200 size_t sampleDataBufferSize = sizeof(buffer); \ 5201 pSampleData = (type*)DRFLAC_MALLOC(sampleDataBufferSize); \ 5202 if (pSampleData == NULL) \ 5204 while ((samplesRead = (drflac_uint64)drflac_read_##extension(pFlac, sizeof(buffer)/sizeof(buffer[0]), buffer)) > 0) { \ 5205 if (((totalSampleCount + samplesRead) * sizeof(type)) > sampleDataBufferSize) { \ 5206 type *pNewSampleData; \ 5207 sampleDataBufferSize *= 2; \ 5208 pNewSampleData = (type*)DRFLAC_REALLOC(pSampleData, sampleDataBufferSize); \ 5209 if (pNewSampleData == NULL) { \ 5210 DRFLAC_FREE(pSampleData); \ 5214 pSampleData = pNewSampleData; \ 5217 drflac_copy_memory(pSampleData + totalSampleCount, buffer, (size_t)(samplesRead*sizeof(type))); \ 5218 totalSampleCount += samplesRead; \ 5223 drflac_zero_memory(pSampleData + totalSampleCount, (size_t)(sampleDataBufferSize - totalSampleCount*sizeof(type))); \ 5225 drflac_uint64 dataSize = totalSampleCount * sizeof(type); \ 5226 if (dataSize > SIZE_MAX) { \ 5230 pSampleData = (type*)DRFLAC_MALLOC((size_t)dataSize); \ 5231 if (pSampleData == NULL) { \ 5235 totalSampleCount = drflac_read_##extension(pFlac, pFlac->totalSampleCount, pSampleData); \ 5238 if (sampleRateOut) *sampleRateOut = pFlac->sampleRate; \ 5239 if (channelsOut) *channelsOut = pFlac->channels; \ 5240 if (totalSampleCountOut) *totalSampleCountOut = totalSampleCount; \ 5242 drflac_close(pFlac); \ 5243 return pSampleData; \ 5246 drflac_close(pFlac); \ 5252 DRFLAC_DEFINE_FULL_DECODE_AND_CLOSE(
f32,
float)
5258 if (sampleRate) *sampleRate = 0;
5259 if (channels) *channels = 0;
5260 if (totalSampleCount) *totalSampleCount = 0;
5266 return drflac__full_decode_and_close_s32(pFlac, channels, sampleRate, totalSampleCount);
5273 if (sampleRate) *sampleRate = 0;
5274 if (channels) *channels = 0;
5275 if (totalSampleCount) *totalSampleCount = 0;
5281 return drflac__full_decode_and_close_s16(pFlac, channels, sampleRate, totalSampleCount);
5288 if (sampleRate) *sampleRate = 0;
5289 if (channels) *channels = 0;
5290 if (totalSampleCount) *totalSampleCount = 0;
5296 return drflac__full_decode_and_close_f32(pFlac, channels, sampleRate, totalSampleCount);
5299 #ifndef DR_FLAC_NO_STDIO 5300 drflac_int32* drflac_open_and_decode_file_s32(
const char* filename,
unsigned int* channels,
unsigned int* sampleRate,
drflac_uint64* totalSampleCount)
5303 if (sampleRate) *sampleRate = 0;
5304 if (channels) *channels = 0;
5305 if (totalSampleCount) *totalSampleCount = 0;
5307 pFlac = drflac_open_file(filename);
5311 return drflac__full_decode_and_close_s32(pFlac, channels, sampleRate, totalSampleCount);
5314 drflac_int16* drflac_open_and_decode_file_s16(
const char* filename,
unsigned int* channels,
unsigned int* sampleRate,
drflac_uint64* totalSampleCount)
5317 if (sampleRate) *sampleRate = 0;
5318 if (channels) *channels = 0;
5319 if (totalSampleCount) *totalSampleCount = 0;
5321 pFlac = drflac_open_file(filename);
5325 return drflac__full_decode_and_close_s16(pFlac, channels, sampleRate, totalSampleCount);
5328 float* drflac_open_and_decode_file_f32(
const char* filename,
unsigned int* channels,
unsigned int* sampleRate,
drflac_uint64* totalSampleCount)
5331 if (sampleRate) *sampleRate = 0;
5332 if (channels) *channels = 0;
5333 if (totalSampleCount) *totalSampleCount = 0;
5335 pFlac = drflac_open_file(filename);
5339 return drflac__full_decode_and_close_f32(pFlac, channels, sampleRate, totalSampleCount);
5347 if (sampleRate) *sampleRate = 0;
5348 if (channels) *channels = 0;
5349 if (totalSampleCount) *totalSampleCount = 0;
5355 return drflac__full_decode_and_close_s32(pFlac, channels, sampleRate, totalSampleCount);
5361 if (sampleRate) *sampleRate = 0;
5362 if (channels) *channels = 0;
5363 if (totalSampleCount) *totalSampleCount = 0;
5369 return drflac__full_decode_and_close_s16(pFlac, channels, sampleRate, totalSampleCount);
5375 if (sampleRate) *sampleRate = 0;
5376 if (channels) *channels = 0;
5377 if (totalSampleCount) *totalSampleCount = 0;
5383 return drflac__full_decode_and_close_f32(pFlac, channels, sampleRate, totalSampleCount);
5386 void drflac_free(
void* pSampleDataReturnedByOpenAndDecode)
5388 DRFLAC_FREE(pSampleDataReturnedByOpenAndDecode);
5405 const char* pComment;
5408 if (pCommentLengthOut) *pCommentLengthOut = 0;
5420 if (pCommentLengthOut) *pCommentLengthOut =
length;
drflac_uint32 seekpointCount
Definition: dr_flac.h:153
Definition: dr_flac.h:121
Definition: dr_flac.h:237
size_t unalignedByteCount
Definition: dr_flac.h:253
drflac_seek_origin
Definition: dr_flac.h:92
drflac_bool32 isCD
Definition: dr_flac.h:169
drflac_bool32 drflac_seek_to_sample(drflac *pFlac, drflac_uint64 sampleIndex)
drflac_uint64 drflac_read_s16(drflac *pFlac, drflac_uint64 samplesToRead, drflac_int16 *pBufferOut)
drflac_uint32 sampleRate
Definition: dr_flac.h:346
void drflac_free(void *p)
int32_t drflac_int32
Definition: dr_flac.h:14
drflac_uint32 drflac_cache_t
Definition: dr_flac.h:49
drflac_uint32 samplesRemaining
Definition: dr_flac.h:330
drflac_uint32 type
Definition: dr_flac.h:124
int32_t s32
32bit signed integer
Definition: gctypes.h:24
const void * pData
Definition: dr_flac.h:147
drflac_uint16 sampleCount
Definition: dr_flac.h:104
drflac_uint32 colorDepth
Definition: dr_flac.h:183
#define INLINE
Definition: retro_inline.h:35
drflac * drflac_open_with_metadata_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void *pUserData)
drflac_uint8 md5[16]
Definition: dr_flac.h:118
drflac__memory_stream memoryStream
Definition: dr_flac.h:382
#define DRFLAC_METADATA_BLOCK_TYPE_CUESHEET
Definition: dr_flac.h:58
const char * pRunningData
Definition: dr_flac.h:620
__asm__(".arm\n" ".align 4\n" ".globl co_switch_arm\n" ".globl _co_switch_arm\n" "co_switch_arm:\n" "_co_switch_arm:\n" " stmia r1!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, lr}\n" " ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, pc}\n")
static char * ReadFile(const char *filename, Allocator &allocator)
Definition: schematest.cpp:15
Definition: dr_flac.h:617
drflac_uint8 channelAssignment
Definition: dr_flac.h:313
drflac_uint32 dataSize
Definition: dr_flac.h:148
size_t currentReadPos
Definition: dr_flac.h:233
drflac_uint8 trackCount
Definition: dr_flac.h:170
Definition: dr_flac.h:296
drflac_uint32 sampleRate
Definition: dr_flac.h:306
Definition: ffmpeg_core.c:151
drflac_uint8 pExtraData[1]
Definition: dr_flac.h:395
float f32
Definition: gctypes.h:43
drflac_uint32 drflac_bool32
Definition: dr_flac.h:19
Definition: dr_flac.h:229
drflac * drflac_open_memory(const void *data, size_t dataSize)
Definition: libretro.h:2275
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
drflac_uint32 frameNumber
Definition: dr_flac.h:303
drflac_meta_proc onMeta
Definition: dr_flac.h:339
GLdouble GLdouble t
Definition: glext.h:6398
void * pUserDataMD
Definition: dr_flac.h:342
drflac_uint32 pictureDataSize
Definition: dr_flac.h:185
uint64_t drflac_uint64
Definition: dr_flac.h:17
drflac_uint8 bitsPerSample
Definition: dr_flac.h:353
drflac_uint32 nextL2Line
Definition: dr_flac.h:259
void(* drflac_meta_proc)(void *pUserData, drflac_metadata *pMetadata)
Definition: dr_flac.h:225
uint8_t drflac_uint8
Definition: dr_flac.h:11
#define SEEK_CUR
Definition: zconf.h:439
int unused
Definition: dr_flac.h:141
uint16_t drflac_uint16
Definition: dr_flac.h:13
#define DRFLAC_METADATA_BLOCK_TYPE_PADDING
Definition: dr_flac.h:54
drflac_uint8 bitsPerSample
Definition: dr_flac.h:116
Definition: dr_flac.h:336
void * pUserData
Definition: dr_flac.h:246
drflac * drflac_open(drflac_read_proc onRead, drflac_seek_proc onSeek, void *pUserData)
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
#define DRFLAC_METADATA_BLOCK_TYPE_SEEKTABLE
Definition: dr_flac.h:56
drflac_uint32 width
Definition: dr_flac.h:181
void drflac_close(drflac *pFlac)
drflac_uint16 maxBlockSize
Definition: dr_flac.h:111
drflac_int32 * drflac_open_and_decode_s32(drflac_read_proc onRead, drflac_seek_proc onSeek, void *pUserData, unsigned int *channels, unsigned int *sampleRate, drflac_uint64 *totalSampleCount)
drflac_uint32 vendorLength
Definition: dr_flac.h:159
void drflac_init_vorbis_comment_iterator(drflac_vorbis_comment_iterator *pIter, drflac_uint32 commentCount, const char *pComments)
char type[64]
Definition: chd_stream.c:63
drflac_uint64 totalSampleCount
Definition: dr_flac.h:361
GLdouble GLdouble right
Definition: glext.h:11766
Definition: dr_flac.h:108
drflac_uint32 minFrameSize
Definition: dr_flac.h:112
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
drflac_uint32 maxFrameSize
Definition: dr_flac.h:113
drflac * drflac_open_with_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void *pUserData)
drflac_int16 * drflac_open_and_decode_memory_s16(const void *data, size_t dataSize, unsigned int *channels, unsigned int *sampleRate, drflac_uint64 *totalSampleCount)
GLuint GLuint GLsizei count
Definition: glext.h:6292
size_t dataSize
Definition: dr_flac.h:232
drflac_uint64 firstSample
Definition: dr_flac.h:102
drflac_frame currentFrame
Definition: dr_flac.h:375
drflac_uint32 height
Definition: dr_flac.h:182
#define DRFLAC_METADATA_BLOCK_TYPE_APPLICATION
Definition: dr_flac.h:55
drflac_seek_proc onSeek
Definition: dr_flac.h:243
int16_t drflac_int16
Definition: dr_flac.h:12
drflac_uint32 consumedBits
Definition: dr_flac.h:262
#define NULL
Pointer to 0.
Definition: gctypes.h:65
GLenum type
Definition: glext.h:6233
int64_t drflac_int64
Definition: dr_flac.h:16
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Definition: pixman-arm-neon-asm.h:469
drflac_uint32 id
Definition: dr_flac.h:146
#define fclose
Definition: file_stream_transforms.h:53
drflac_uint64 firstFramePos
Definition: dr_flac.h:378
drflac_cache_t crc16Cache
Definition: dr_flac.h:272
Definition: dr_flac.h:100
drflac_uint8 crc8
Definition: dr_flac.h:319
#define SEEK_SET
Definition: zconf.h:438
void * _oggbs
Definition: dr_flac.h:389
drflac_uint32 sampleRate
Definition: dr_flac.h:114
drflac_uint64 frameOffset
Definition: dr_flac.h:103
drflac_uint32 commentCount
Definition: dr_flac.h:161
drflac_uint8 lpcOrder
Definition: dr_flac.h:285
#define DRFLAC_TRUE
Definition: dr_flac.h:20
drflac_uint32 crc16CacheIgnoredBytes
Definition: dr_flac.h:273
drflac_uint32 countRemaining
Definition: dr_flac.h:619
#define DRFLAC_METADATA_BLOCK_TYPE_PICTURE
Definition: dr_flac.h:59
char reserved[128]
Definition: scefiber.c:17
#define DRFLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT
Definition: dr_flac.h:57
drflac_cache_t cacheL2[DR_FLAC_BUFFER_SIZE/sizeof(drflac_cache_t)]
Definition: dr_flac.h:266
signed short int16_t
Definition: stdint.h:122
int8_t drflac_int8
Definition: dr_flac.h:10
drflac_uint8 bitsPerSample
Definition: dr_flac.h:316
Definition: chd_stream.c:62
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
const char * description
Definition: dr_flac.h:180
GLuint64EXT * result
Definition: glext.h:12211
float * drflac_open_and_decode_memory_f32(const void *data, size_t dataSize, unsigned int *channels, unsigned int *sampleRate, drflac_uint64 *totalSampleCount)
#define DR_FLAC_BUFFER_SIZE
Definition: dr_flac.h:28
GLuint GLdouble GLdouble GLint GLint order
Definition: glext.h:12101
drflac_container
Definition: dr_flac.h:85
#define md5
Definition: compat-1.3.h:2001
drflac_uint8 wastedBitsPerSample
Definition: dr_flac.h:282
const drflac_uint8 * data
Definition: dr_flac.h:231
drflac_cache_t unalignedCache
Definition: dr_flac.h:256
drflac_uint8 channels
Definition: dr_flac.h:115
drflac_uint32 seektableSize
Definition: dr_flac.h:371
const void * pRawData
Definition: dr_flac.h:130
GLfloat GLfloat p
Definition: glext.h:9809
drflac_bool32(* drflac_seek_proc)(void *pUserData, int offset, drflac_seek_origin origin)
Definition: dr_flac.h:216
const char * drflac_next_vorbis_comment(drflac_vorbis_comment_iterator *pIter, drflac_uint32 *pCommentLengthOut)
signed int int32_t
Definition: stdint.h:123
GLenum GLsizei dataSize
Definition: glext.h:12030
drflac_int32 * pDecodedSamples
Definition: dr_flac.h:386
drflac_uint16 blockSize
Definition: dr_flac.h:309
drflac_cache_t cache
Definition: dr_flac.h:267
drflac_int32 * pDecodedSamples
Definition: dr_flac.h:293
int16_t s16
16bit signed integer
Definition: gctypes.h:23
#define FILE
Definition: file_stream_transforms.h:35
drflac_container container
Definition: dr_flac.h:365
#define DRFLAC_FALSE
Definition: dr_flac.h:21
drflac_uint16 crc16
Definition: dr_flac.h:271
drflac_uint8 channels
Definition: dr_flac.h:350
uint32_t drflac_uint32
Definition: dr_flac.h:15
drflac_uint8 drflac_bool8
Definition: dr_flac.h:18
drflac * drflac_open_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_container container, void *pUserData)
drflac_streaminfo streaminfo
Definition: dr_flac.h:137
Definition: dr_flac.h:276
drflac_uint64 seektablePos
Definition: dr_flac.h:368
GLint j
Definition: nx_glsym.h:307
drflac_int32 * drflac_open_and_decode_memory_s32(const void *data, size_t dataSize, unsigned int *channels, unsigned int *sampleRate, drflac_uint64 *totalSampleCount)
const char * comments
Definition: dr_flac.h:162
drflac_uint8 subframeType
Definition: dr_flac.h:279
const char * mime
Definition: dr_flac.h:178
drflac_uint64 leadInSampleCount
Definition: dr_flac.h:168
signed __int64 int64_t
Definition: stdint.h:135
drflac_uint64 drflac_read_s32(drflac *pFlac, drflac_uint64 samplesToRead, drflac_int32 *pBufferOut)
unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len)
Definition: libz-crc32.c:70
drflac_uint32 descriptionLength
Definition: dr_flac.h:179
Ιστορικό Εικόνα Πληροφορίες Όλοι Οι Χρήστες Χειρίζονται Το Μενού Αριστερό Αναλογικό Αριστερό Αναλογικό Αριστερό Αναλογικό Y Αριστερό Αναλογικό Δεξί Αναλογικό X Δεξί Αναλογικό Δεξί Αναλογικό Y Δεξί Αναλογικό Σκανδάλη Όπλου Όπλο Aux A Όπλο Aux C Όπλο Select Όπλο D pad Κάτω Όπλο D pad Δεξιά Νεκρή Ζώνη Αναλογικού Σύνδεση Όλων Λήξη Χρόνου Σύνδεσης Hide Unbound Core Input Descriptors Κατάλογος Συσκευών Κατάλογος Ποντικιού Duty Cycle Keyboard Gamepad Mapping Enable Κουμπί D pad κάτω Κουμπί Κουμπί L(πίσω)" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_LEFT
const drflac_seekpoint * pSeekpoints
Definition: dr_flac.h:154
drflac_read_proc onRead
Definition: dr_flac.h:240
drflac_uint16 minBlockSize
Definition: dr_flac.h:110
drflac_uint32 mimeLength
Definition: dr_flac.h:177
#define fread
Definition: file_stream_transforms.h:56
drflac * drflac_open_memory_with_metadata(const void *data, size_t dataSize, drflac_meta_proc onMeta, void *pUserData)
drflac_uint32 rawDataSize
Definition: dr_flac.h:133
drflac_uint64 totalSampleCount
Definition: dr_flac.h:117
drflac_frame_header header
Definition: dr_flac.h:325
drflac_uint32 indexColorCount
Definition: dr_flac.h:184
#define fopen
Definition: file_stream_transforms.h:52
const drflac_uint8 * pTrackData
Definition: dr_flac.h:171
drflac_subframe subframes[8]
Definition: dr_flac.h:333
Definition: civetweb.c:1024
GLintptr offset
Definition: glext.h:6560
GLint left
Definition: glext.h:8393
GLbitfield flags
Definition: glext.h:7828
#define DRFLAC_METADATA_BLOCK_TYPE_INVALID
Definition: dr_flac.h:60
const char * vendor
Definition: dr_flac.h:160
drflac_int16 * drflac_open_and_decode_s16(drflac_read_proc onRead, drflac_seek_proc onSeek, void *pUserData, unsigned int *channels, unsigned int *sampleRate, drflac_uint64 *totalSampleCount)
drflac_bs bs
Definition: dr_flac.h:392
float * drflac_open_and_decode_f32(drflac_read_proc onRead, drflac_seek_proc onSeek, void *pUserData, unsigned int *channels, unsigned int *sampleRate, drflac_uint64 *totalSampleCount)
const drflac_uint8 * pPictureData
Definition: dr_flac.h:186
drflac_uint64 sampleNumber
Definition: dr_flac.h:300
size_t(* drflac_read_proc)(void *pUserData, void *pBufferOut, size_t bytesToRead)
Definition: dr_flac.h:203
unsigned short uint16_t
Definition: stdint.h:125
#define DRFLAC_METADATA_BLOCK_TYPE_STREAMINFO
Definition: dr_flac.h:53
unsigned __int64 uint64_t
Definition: stdint.h:136
GLenum GLuint GLenum GLsizei length
Definition: glext.h:6233
GLdouble n
Definition: glext.h:8396
unsigned char uint8_t
Definition: stdint.h:124
unsigned int uint32_t
Definition: stdint.h:126
int fopen_s(FILE **pFile, const char *filename, const char *mode)
Definition: StandAlone.cpp:1437
drflac_uint16 maxBlockSize
Definition: dr_flac.h:356
drflac_uint32 bitsPerSample
Definition: dr_flac.h:289
signed char int8_t
Definition: stdint.h:121
drflac_uint64 drflac_read_f32(drflac *pFlac, drflac_uint64 samplesToRead, float *pBufferOut)
#define fseek
Definition: file_stream_transforms.h:55
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld init[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
Definition: pixman-arm-neon-asm.h:600
Definition: dr_flac.h:322