RetroArch
dr_mp3.h
Go to the documentation of this file.
1 #ifndef dr_mp3_h
2 #define dr_mp3_h
3 
4 #define DR_MP3_NO_STDIO
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 #include <retro_inline.h>
13 
24 #define DRMP3_TRUE 1
25 #define DRMP3_FALSE 0
26 
27 #define DRMP3_MAX_SAMPLES_PER_FRAME (1152*2)
28 
29 
30 /* Low Level Push API
31  * ================== */
32 typedef struct
33 {
35  int channels;
36  int hz;
37  int layer;
40 
41 typedef struct
42 {
43  float mdct_overlap[2][9*32];
44  float qmf_state[15*2*32];
45  int reserv;
47  unsigned char header[4];
48  unsigned char reserv_buf[511];
49 } drmp3dec;
50 
51 /* Initializes a low level decoder. */
52 void drmp3dec_init(drmp3dec *dec);
53 
54 /* Reads a frame from a low level decoder. */
55 int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes, short *pcm, drmp3dec_frame_info *info);
56 
57 
58 /* Main API (Pull API)
59  * ===================*/
60 
61 typedef struct drmp3_src drmp3_src;
62 typedef drmp3_uint64 (* drmp3_src_read_proc)(drmp3_src* pSRC, drmp3_uint64 frameCount, void* pFramesOut, void* pUserData); /* Returns the number of frames that were read. */
63 
64 typedef enum
65 {
69 
70 #define DRMP3_SRC_CACHE_SIZE_IN_FRAMES 512
71 typedef struct
72 {
74  float pCachedFrames[2 * DRMP3_SRC_CACHE_SIZE_IN_FRAMES];
78 
79 typedef struct
80 {
85  drmp3_uint32 cacheSizeInFrames; /* The number of frames to read from the client at a time. */
87 
88 struct drmp3_src
89 {
92  void* pUserData;
93  float bin[256];
94  drmp3_src_cache cache; /* <-- For simplifying and optimizing client -> memory reading. */
95  union
96  {
97  struct
98  {
99  float alpha;
102  } linear;
103  } algo;
104 };
105 
106 typedef enum
107 {
111 
112 /* Callback for when data is read. Return value is the number of bytes actually read.
113  *
114  * pUserData [in] The user data that was passed to drmp3_init(), drmp3_open() and family.
115  * pBufferOut [out] The output buffer.
116  * bytesToRead [in] The number of bytes to read.
117  *
118  * Returns the number of bytes actually read.
119  *
120  * A return value of less than bytesToRead indicates the end of the stream. Do _not_ return from this callback until
121  * either the entire bytesToRead is filled or you have reached the end of the stream.
122  */
123 typedef size_t (* drmp3_read_proc)(void* pUserData, void* pBufferOut, size_t bytesToRead);
124 
125 /* Callback for when data needs to be seeked.
126  *
127  * pUserData [in] The user data that was passed to drmp3_init(), drmp3_open() and family.
128  * offset [in] The number of bytes to move, relative to the origin. Will never be negative.
129  * origin [in] The origin of the seek - the current position or the start of the stream.
130  *
131  * Returns whether or not the seek was successful.
132  *
133  * Whether or not it is relative to the beginning or current position is determined by the "origin" parameter which
134  * will be either drmp3_seek_origin_start or drmp3_seek_origin_current.
135  */
136 typedef drmp3_bool32 (* drmp3_seek_proc)(void* pUserData, int offset, drmp3_seek_origin origin);
137 
138 typedef struct
139 {
142 } drmp3_config;
143 
144 typedef struct
145 {
152  void* pUserData;
153  drmp3_uint32 frameChannels; /* The number of channels in the currently loaded MP3 frame. Internal use only. */
154  drmp3_uint32 frameSampleRate; /* The sample rate of the currently loaded MP3 frame. Internal use only */
159  size_t dataSize;
160  size_t dataCapacity;
163  struct
164  {
166  size_t dataSize;
168  } memory; /* Only used for decoders that were opened against a block of memory. */
169 } drmp3;
170 
171 /* Initializes an MP3 decoder.
172  *
173  * onRead [in] The function to call when data needs to be read from the client.
174  * onSeek [in] The function to call when the read position of the client data needs to move.
175  * pUserData [in, optional] A pointer to application defined data that will be passed to onRead and onSeek.
176  *
177  * Returns true if successful; false otherwise.
178  *
179  * Close the loader with drmp3_uninit().
180  *
181  * See also: drmp3_init_file(), drmp3_init_memory(), drmp3_uninit()
182  */
183 drmp3_bool32 drmp3_init(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, const drmp3_config* pConfig);
184 
185 /* Initializes an MP3 decoder from a block of memory.
186  *
187  * This does not create a copy of the data. It is up to the application to ensure the buffer remains valid for
188  * the lifetime of the drmp3 object.
189  *
190  * The buffer should contain the contents of the entire MP3 file.
191  */
192 drmp3_bool32 drmp3_init_memory(drmp3* pMP3, const void* pData, size_t dataSize, const drmp3_config* pConfig);
193 
194 #ifndef DR_MP3_NO_STDIO
195 /* Initializes an MP3 decoder from a file.
196  *
197  * This holds the internal FILE object until drmp3_uninit() is called. Keep this in mind if you're caching drmp3
198  * objects because the operating system may restrict the number of file handles an application can have open at
199  * any given time.
200  */
201 drmp3_bool32 drmp3_init_file(drmp3* pMP3, const char* filePath, const drmp3_config* pConfig);
202 #endif
203 
204 /* Uninitializes an MP3 decoder. */
205 void drmp3_uninit(drmp3* pMP3);
206 
207 /* Reads PCM frames as interleaved 32-bit IEEE floating point PCM.
208  *
209  * Note that framesToRead specifies the number of PCM frames to read, _not_ the number of MP3 frames.
210  */
211 drmp3_uint64 drmp3_read_f32(drmp3* pMP3, drmp3_uint64 framesToRead, float* pBufferOut);
212 
213 /* Seeks to a specific frame.
214  *
215  * Note that this is _not_ an MP3 frame, but rather a PCM frame.
216  */
218 
219 
220 /* Opens an decodes an entire MP3 stream as a single operation.
221  *
222  * pConfig is both an input and output. On input it contains what you want. On output it contains what you got.
223  *
224  * Free the returned pointer with drmp3_free().
225  */
226 float* drmp3_open_and_decode_f32(drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount);
227 float* drmp3_open_and_decode_memory_f32(const void* pData, size_t dataSize, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount);
228 #ifndef DR_MP3_NO_STDIO
229 float* drmp3_open_and_decode_file_f32(const char* filePath, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount);
230 #endif
231 
232 /* Frees any memory that was allocated by a public drmp3 API. */
233 void drmp3_free(void* p);
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 #endif /* dr_mp3_h */
239 
240 
241 /*
242  *
243  * IMPLEMENTATION
244  *
245  */
246 #ifdef DR_MP3_IMPLEMENTATION
247 #include <stdlib.h>
248 #include <string.h>
249 #include <stdint.h>
250 #include <limits.h> /* For INT_MAX */
251 
252 #define DRMP3_MAX_FREE_FORMAT_FRAME_SIZE 2304 /* more than ISO spec's */
253 #define DRMP3_MAX_FRAME_SYNC_MATCHES 10
254 
255 #define DRMP3_MAX_L3_FRAME_PAYLOAD_BYTES DRMP3_MAX_FREE_FORMAT_FRAME_SIZE /* MUST be >= 320000/8/32000*1152 = 1440 */
256 
257 #define DRMP3_MAX_BITRESERVOIR_BYTES 511
258 #define DRMP3_SHORT_BLOCK_TYPE 2
259 #define DRMP3_STOP_BLOCK_TYPE 3
260 #define DRMP3_MODE_MONO 3
261 #define DRMP3_MODE_JOINT_STEREO 1
262 #define DRMP3_HDR_SIZE 4
263 #define DRMP3_HDR_IS_MONO(h) (((h[3]) & 0xC0) == 0xC0)
264 #define DRMP3_HDR_IS_MS_STEREO(h) (((h[3]) & 0xE0) == 0x60)
265 #define DRMP3_HDR_IS_FREE_FORMAT(h) (((h[2]) & 0xF0) == 0)
266 #define DRMP3_HDR_IS_CRC(h) (!((h[1]) & 1))
267 #define DRMP3_HDR_TEST_PADDING(h) ((h[2]) & 0x2)
268 #define DRMP3_HDR_TEST_MPEG1(h) ((h[1]) & 0x8)
269 #define DRMP3_HDR_TEST_NOT_MPEG25(h) ((h[1]) & 0x10)
270 #define DRMP3_HDR_TEST_I_STEREO(h) ((h[3]) & 0x10)
271 #define DRMP3_HDR_TEST_MS_STEREO(h) ((h[3]) & 0x20)
272 #define DRMP3_HDR_GET_STEREO_MODE(h) (((h[3]) >> 6) & 3)
273 #define DRMP3_HDR_GET_STEREO_MODE_EXT(h) (((h[3]) >> 4) & 3)
274 #define DRMP3_HDR_GET_LAYER(h) (((h[1]) >> 1) & 3)
275 #define DRMP3_HDR_GET_BITRATE(h) ((h[2]) >> 4)
276 #define DRMP3_HDR_GET_SAMPLE_RATE(h) (((h[2]) >> 2) & 3)
277 #define DRMP3_HDR_GET_MY_SAMPLE_RATE(h) (DRMP3_HDR_GET_SAMPLE_RATE(h) + (((h[1] >> 3) & 1) + ((h[1] >> 4) & 1))*3)
278 #define DRMP3_HDR_IS_FRAME_576(h) ((h[1] & 14) == 2)
279 #define DRMP3_HDR_IS_LAYER_1(h) ((h[1] & 6) == 6)
280 
281 #define DRMP3_BITS_DEQUANTIZER_OUT -1
282 #define DRMP3_MAX_SCF (255 + DRMP3_BITS_DEQUANTIZER_OUT*4 - 210)
283 #define DRMP3_MAX_SCFI ((DRMP3_MAX_SCF + 3) & ~3)
284 
285 #define DRMP3_MIN(a, b) ((a) > (b) ? (b) : (a))
286 #define DRMP3_MAX(a, b) ((a) < (b) ? (b) : (a))
287 
288 #if !defined(DR_MP3_NO_SIMD)
289 
290 #if !defined(DR_MP3_ONLY_SIMD) && (defined(_M_X64) || defined(_M_ARM64) || defined(__x86_64__) || defined(__aarch64__))
291 /* x64 always have SSE2, arm64 always have neon, no need for generic code */
292 #define DR_MP3_ONLY_SIMD
293 #endif
294 
295 #if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) || ((defined(__i386__) || defined(__x86_64__)) && defined(__SSE2__))
296 #if defined(_MSC_VER)
297 #include <intrin.h>
298 #endif
299 #include <immintrin.h>
300 #define DRMP3_HAVE_SSE 1
301 #define DRMP3_HAVE_SIMD 1
302 #define DRMP3_VSTORE _mm_storeu_ps
303 #define DRMP3_VLD _mm_loadu_ps
304 #define DRMP3_VSET _mm_set1_ps
305 #define DRMP3_VADD _mm_add_ps
306 #define DRMP3_VSUB _mm_sub_ps
307 #define DRMP3_VMUL _mm_mul_ps
308 #define DRMP3_VMAC(a, x, y) _mm_add_ps(a, _mm_mul_ps(x, y))
309 #define DRMP3_VMSB(a, x, y) _mm_sub_ps(a, _mm_mul_ps(x, y))
310 #define DRMP3_VMUL_S(x, s) _mm_mul_ps(x, _mm_set1_ps(s))
311 #define DRMP3_VREV(x) _mm_shuffle_ps(x, x, _MM_SHUFFLE(0, 1, 2, 3))
312 typedef __m128 drmp3_f4;
313 #if defined(_MSC_VER) || defined(DR_MP3_ONLY_SIMD)
314 #define drmp3_cpuid __cpuid
315 #else
316 static INLINE __attribute__((always_inline)) void drmp3_cpuid(int CPUInfo[], const int InfoType)
317 {
318 #if defined(__PIC__)
319  __asm__ __volatile__(
320 #if defined(__x86_64__)
321  "push %%rbx\n"
322  "cpuid\n"
323  "xchgl %%ebx, %1\n"
324  "pop %%rbx\n"
325 #else
326  "xchgl %%ebx, %1\n"
327  "cpuid\n"
328  "xchgl %%ebx, %1\n"
329 #endif
330  : "=a" (CPUInfo[0]), "=r" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3])
331  : "a" (InfoType));
332 #else
333  __asm__ __volatile__(
334  "cpuid"
335  : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3])
336  : "a" (InfoType));
337 #endif
338 }
339 #endif
340 static int drmp3_have_simd()
341 {
342 #ifdef DR_MP3_ONLY_SIMD
343  return 1;
344 #else
345  static int g_have_simd;
346  int CPUInfo[4];
347 #ifdef MINIMP3_TEST
348  static int g_counter;
349  if (g_counter++ > 100)
350  goto test_nosimd;
351 #endif
352  if (g_have_simd)
353  return g_have_simd - 1;
354  drmp3_cpuid(CPUInfo, 0);
355  if (CPUInfo[0] > 0)
356  {
357  drmp3_cpuid(CPUInfo, 1);
358  g_have_simd = (CPUInfo[3] & (1 << 26)) + 1; /* SSE2 */
359  return g_have_simd - 1;
360  }
361 #ifdef MINIMP3_TEST
362 test_nosimd:
363 #endif
364  g_have_simd = 1;
365  return 0;
366 #endif
367 }
368 #elif defined(__ARM_NEON) || defined(__aarch64__)
369 #include <arm_neon.h>
370 #define DRMP3_HAVE_SIMD 1
371 #define DRMP3_VSTORE vst1q_f32
372 #define DRMP3_VLD vld1q_f32
373 #define DRMP3_VSET vmovq_n_f32
374 #define DRMP3_VADD vaddq_f32
375 #define DRMP3_VSUB vsubq_f32
376 #define DRMP3_VMUL vmulq_f32
377 #define DRMP3_VMAC(a, x, y) vmlaq_f32(a, x, y)
378 #define DRMP3_VMSB(a, x, y) vmlsq_f32(a, x, y)
379 #define DRMP3_VMUL_S(x, s) vmulq_f32(x, vmovq_n_f32(s))
380 #define DRMP3_VREV(x) vcombine_f32(vget_high_f32(vrev64q_f32(x)), vget_low_f32(vrev64q_f32(x)))
381 typedef float32x4_t drmp3_f4;
382 static int drmp3_have_simd()
383 { /* TODO: detect neon for !DR_MP3_ONLY_SIMD */
384  return 1;
385 }
386 #else
387 #define DRMP3_HAVE_SIMD 0
388 #ifdef DR_MP3_ONLY_SIMD
389 #error DR_MP3_ONLY_SIMD used, but SSE/NEON not enabled
390 #endif
391 #endif
392 
393 #else
394 
395 #define DRMP3_HAVE_SIMD 0
396 
397 #endif
398 
399 typedef struct
400 {
401  const drmp3_uint8 *buf;
402  int pos;
403  int limit;
404 } drmp3_bs;
405 
406 typedef struct
407 {
408  drmp3_uint8 total_bands;
409  drmp3_uint8 stereo_bands;
410  drmp3_uint8 bitalloc[64];
411  drmp3_uint8 scfcod[64];
412  float scf[3*64];
413 } drmp3_L12_scale_info;
414 
415 typedef struct
416 {
417  drmp3_uint8 tab_offset;
418  drmp3_uint8 code_tab_width;
419  drmp3_uint8 band_count;
420 } drmp3_L12_subband_alloc;
421 
422 typedef struct
423 {
424  const drmp3_uint8 *sfbtab;
425  drmp3_uint16 part_23_length;
426  drmp3_uint16 big_values;
427  drmp3_uint16 scalefac_compress;
428  drmp3_uint8 global_gain;
429  drmp3_uint8 block_type;
430  drmp3_uint8 mixed_block_flag;
431  drmp3_uint8 n_long_sfb;
432  drmp3_uint8 n_short_sfb;
433  drmp3_uint8 table_select[3];
434  drmp3_uint8 region_count[3];
435  drmp3_uint8 subblock_gain[3];
436  drmp3_uint8 preflag;
437  drmp3_uint8 scalefac_scale;
438  drmp3_uint8 count1_table;
439  drmp3_uint8 scfsi;
440 } drmp3_L3_gr_info;
441 
442 typedef struct
443 {
444  drmp3_bs bs;
445  drmp3_uint8 maindata[DRMP3_MAX_BITRESERVOIR_BYTES + DRMP3_MAX_L3_FRAME_PAYLOAD_BYTES];
446  drmp3_L3_gr_info gr_info[4];
447  float grbuf[2][576];
448  float scf[40];
449  drmp3_uint8 ist_pos[2][39];
450  float syn[18 + 15][2*32];
451 } drmp3dec_scratch;
452 
453 static void drmp3_bs_init(drmp3_bs *bs, const drmp3_uint8 *data, int bytes)
454 {
455  bs->buf = data;
456  bs->pos = 0;
457  bs->limit = bytes*8;
458 }
459 
460 static drmp3_uint32 drmp3_bs_get_bits(drmp3_bs *bs, int n)
461 {
462  drmp3_uint32 next, cache = 0, s = bs->pos & 7;
463  int shl = n + s;
464  const drmp3_uint8 *p = bs->buf + (bs->pos >> 3);
465  if ((bs->pos += n) > bs->limit)
466  return 0;
467  next = *p++ & (255 >> s);
468  while ((shl -= 8) > 0)
469  {
470  cache |= next << shl;
471  next = *p++;
472  }
473  return cache | (next >> -shl);
474 }
475 
476 static int drmp3_hdr_valid(const drmp3_uint8 *h)
477 {
478  return h[0] == 0xff &&
479  ((h[1] & 0xF0) == 0xf0 || (h[1] & 0xFE) == 0xe2) &&
480  (DRMP3_HDR_GET_LAYER(h) != 0) &&
481  (DRMP3_HDR_GET_BITRATE(h) != 15) &&
482  (DRMP3_HDR_GET_SAMPLE_RATE(h) != 3);
483 }
484 
485 static int drmp3_hdr_compare(const drmp3_uint8 *h1, const drmp3_uint8 *h2)
486 {
487  return drmp3_hdr_valid(h2) &&
488  ((h1[1] ^ h2[1]) & 0xFE) == 0 &&
489  ((h1[2] ^ h2[2]) & 0x0C) == 0 &&
490  !(DRMP3_HDR_IS_FREE_FORMAT(h1) ^ DRMP3_HDR_IS_FREE_FORMAT(h2));
491 }
492 
493 static unsigned drmp3_hdr_bitrate_kbps(const drmp3_uint8 *h)
494 {
495  static const drmp3_uint8 halfrate[2][3][15] = {
496  { { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,16,24,28,32,40,48,56,64,72,80,88,96,112,128 } },
497  { { 0,16,20,24,28,32,40,48,56,64,80,96,112,128,160 }, { 0,16,24,28,32,40,48,56,64,80,96,112,128,160,192 }, { 0,16,32,48,64,80,96,112,128,144,160,176,192,208,224 } },
498  };
499  return 2*halfrate[!!DRMP3_HDR_TEST_MPEG1(h)][DRMP3_HDR_GET_LAYER(h) - 1][DRMP3_HDR_GET_BITRATE(h)];
500 }
501 
502 static unsigned drmp3_hdr_sample_rate_hz(const drmp3_uint8 *h)
503 {
504  static const unsigned g_hz[3] = { 44100, 48000, 32000 };
505  return g_hz[DRMP3_HDR_GET_SAMPLE_RATE(h)] >> (int)!DRMP3_HDR_TEST_MPEG1(h) >> (int)!DRMP3_HDR_TEST_NOT_MPEG25(h);
506 }
507 
508 static unsigned drmp3_hdr_frame_samples(const drmp3_uint8 *h)
509 {
510  return DRMP3_HDR_IS_LAYER_1(h) ? 384 : (1152 >> (int)DRMP3_HDR_IS_FRAME_576(h));
511 }
512 
513 static int drmp3_hdr_frame_bytes(const drmp3_uint8 *h, int free_format_size)
514 {
515  int frame_bytes = drmp3_hdr_frame_samples(h)*drmp3_hdr_bitrate_kbps(h)*125/drmp3_hdr_sample_rate_hz(h);
516  if (DRMP3_HDR_IS_LAYER_1(h))
517  {
518  frame_bytes &= ~3; /* slot align */
519  }
520  return frame_bytes ? frame_bytes : free_format_size;
521 }
522 
523 static int drmp3_hdr_padding(const drmp3_uint8 *h)
524 {
525  return DRMP3_HDR_TEST_PADDING(h) ? (DRMP3_HDR_IS_LAYER_1(h) ? 4 : 1) : 0;
526 }
527 
528 #ifndef DR_MP3_ONLY_MP3
529 static const drmp3_L12_subband_alloc *drmp3_L12_subband_alloc_table(const drmp3_uint8 *hdr, drmp3_L12_scale_info *sci)
530 {
531  const drmp3_L12_subband_alloc *alloc;
532  int mode = DRMP3_HDR_GET_STEREO_MODE(hdr);
533  int nbands, stereo_bands = (mode == DRMP3_MODE_MONO) ? 0 : (mode == DRMP3_MODE_JOINT_STEREO) ? (DRMP3_HDR_GET_STEREO_MODE_EXT(hdr) << 2) + 4 : 32;
534 
535  if (DRMP3_HDR_IS_LAYER_1(hdr))
536  {
537  static const drmp3_L12_subband_alloc g_alloc_L1[] = { { 76, 4, 32 } };
538  alloc = g_alloc_L1;
539  nbands = 32;
540  } else if (!DRMP3_HDR_TEST_MPEG1(hdr))
541  {
542  static const drmp3_L12_subband_alloc g_alloc_L2M2[] = { { 60, 4, 4 }, { 44, 3, 7 }, { 44, 2, 19 } };
543  alloc = g_alloc_L2M2;
544  nbands = 30;
545  } else
546  {
547  static const drmp3_L12_subband_alloc g_alloc_L2M1[] = { { 0, 4, 3 }, { 16, 4, 8 }, { 32, 3, 12 }, { 40, 2, 7 } };
548  int sample_rate_idx = DRMP3_HDR_GET_SAMPLE_RATE(hdr);
549  unsigned kbps = drmp3_hdr_bitrate_kbps(hdr) >> (int)(mode != DRMP3_MODE_MONO);
550  if (!kbps) /* free-format */
551  {
552  kbps = 192;
553  }
554 
555  alloc = g_alloc_L2M1;
556  nbands = 27;
557  if (kbps < 56)
558  {
559  static const drmp3_L12_subband_alloc g_alloc_L2M1_lowrate[] = { { 44, 4, 2 }, { 44, 3, 10 } };
560  alloc = g_alloc_L2M1_lowrate;
561  nbands = sample_rate_idx == 2 ? 12 : 8;
562  } else if (kbps >= 96 && sample_rate_idx != 1)
563  {
564  nbands = 30;
565  }
566  }
567 
568  sci->total_bands = (drmp3_uint8)nbands;
569  sci->stereo_bands = (drmp3_uint8)DRMP3_MIN(stereo_bands, nbands);
570 
571  return alloc;
572 }
573 
574 static void drmp3_L12_read_scalefactors(drmp3_bs *bs, drmp3_uint8 *pba, drmp3_uint8 *scfcod, int bands, float *scf)
575 {
576  static const float g_deq_L12[18*3] = {
577 #define DRMP3_DQ(x) 9.53674316e-07f/x, 7.56931807e-07f/x, 6.00777173e-07f/x
578  DRMP3_DQ(3),DRMP3_DQ(7),DRMP3_DQ(15),DRMP3_DQ(31),DRMP3_DQ(63),DRMP3_DQ(127),DRMP3_DQ(255),DRMP3_DQ(511),DRMP3_DQ(1023),DRMP3_DQ(2047),DRMP3_DQ(4095),DRMP3_DQ(8191),DRMP3_DQ(16383),DRMP3_DQ(32767),DRMP3_DQ(65535),DRMP3_DQ(3),DRMP3_DQ(5),DRMP3_DQ(9)
579  };
580  int i, m;
581  for (i = 0; i < bands; i++)
582  {
583  float s = 0;
584  int ba = *pba++;
585  int mask = ba ? 4 + ((19 >> scfcod[i]) & 3) : 0;
586  for (m = 4; m; m >>= 1)
587  {
588  if (mask & m)
589  {
590  int b = drmp3_bs_get_bits(bs, 6);
591  s = g_deq_L12[ba*3 - 6 + b % 3]*(1 << 21 >> b/3);
592  }
593  *scf++ = s;
594  }
595  }
596 }
597 
598 static void drmp3_L12_read_scale_info(const drmp3_uint8 *hdr, drmp3_bs *bs, drmp3_L12_scale_info *sci)
599 {
600  static const drmp3_uint8 g_bitalloc_code_tab[] = {
601  0,17, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16,
602  0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,16,
603  0,17,18, 3,19,4,5,16,
604  0,17,18,16,
605  0,17,18,19, 4,5,6, 7,8, 9,10,11,12,13,14,15,
606  0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,14,
607  0, 2, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16
608  };
609  const drmp3_L12_subband_alloc *subband_alloc = drmp3_L12_subband_alloc_table(hdr, sci);
610 
611  int i, k = 0, ba_bits = 0;
612  const drmp3_uint8 *ba_code_tab = g_bitalloc_code_tab;
613 
614  for (i = 0; i < sci->total_bands; i++)
615  {
616  drmp3_uint8 ba;
617  if (i == k)
618  {
619  k += subband_alloc->band_count;
620  ba_bits = subband_alloc->code_tab_width;
621  ba_code_tab = g_bitalloc_code_tab + subband_alloc->tab_offset;
622  subband_alloc++;
623  }
624  ba = ba_code_tab[drmp3_bs_get_bits(bs, ba_bits)];
625  sci->bitalloc[2*i] = ba;
626  if (i < sci->stereo_bands)
627  {
628  ba = ba_code_tab[drmp3_bs_get_bits(bs, ba_bits)];
629  }
630  sci->bitalloc[2*i + 1] = sci->stereo_bands ? ba : 0;
631  }
632 
633  for (i = 0; i < 2*sci->total_bands; i++)
634  {
635  sci->scfcod[i] = (drmp3_uint8)(sci->bitalloc[i] ? DRMP3_HDR_IS_LAYER_1(hdr) ? 2 : drmp3_bs_get_bits(bs, 2) : 6);
636  }
637 
638  drmp3_L12_read_scalefactors(bs, sci->bitalloc, sci->scfcod, sci->total_bands*2, sci->scf);
639 
640  for (i = sci->stereo_bands; i < sci->total_bands; i++)
641  {
642  sci->bitalloc[2*i + 1] = 0;
643  }
644 }
645 
646 static int drmp3_L12_dequantize_granule(float *grbuf, drmp3_bs *bs, drmp3_L12_scale_info *sci, int group_size)
647 {
648  int i, j, k, choff = 576;
649  for (j = 0; j < 4; j++)
650  {
651  float *dst = grbuf + group_size*j;
652  for (i = 0; i < 2*sci->total_bands; i++)
653  {
654  int ba = sci->bitalloc[i];
655  if (ba != 0)
656  {
657  if (ba < 17)
658  {
659  int half = (1 << (ba - 1)) - 1;
660  for (k = 0; k < group_size; k++)
661  {
662  dst[k] = (float)((int)drmp3_bs_get_bits(bs, ba) - half);
663  }
664  } else
665  {
666  unsigned mod = (2 << (ba - 17)) + 1; /* 3, 5, 9 */
667  unsigned code = drmp3_bs_get_bits(bs, mod + 2 - (mod >> 3)); /* 5, 7, 10 */
668  for (k = 0; k < group_size; k++, code /= mod)
669  {
670  dst[k] = (float)((int)(code % mod - mod/2));
671  }
672  }
673  }
674  dst += choff;
675  choff = 18 - choff;
676  }
677  }
678  return group_size*4;
679 }
680 
681 static void drmp3_L12_apply_scf_384(drmp3_L12_scale_info *sci, const float *scf, float *dst)
682 {
683  int i, k;
684  memcpy(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*sizeof(float));
685  for (i = 0; i < sci->total_bands; i++, dst += 18, scf += 6)
686  {
687  for (k = 0; k < 12; k++)
688  {
689  dst[k + 0] *= scf[0];
690  dst[k + 576] *= scf[3];
691  }
692  }
693 }
694 #endif
695 
696 static int drmp3_L3_read_side_info(drmp3_bs *bs, drmp3_L3_gr_info *gr, const drmp3_uint8 *hdr)
697 {
698  static const drmp3_uint8 g_scf_long[9][23] = {
699  { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
700  { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
701  { 12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2,0 },
702  { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
703  { 6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36,0 },
704  { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
705  { 4,4,4,4,4,4,6,6,8,8,10,12,16,20,24,28,34,42,50,54,76,158,0 },
706  { 4,4,4,4,4,4,6,6,6,8,10,12,16,18,22,28,34,40,46,54,54,192,0 },
707  { 4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102,26,0 }
708  };
709  static const drmp3_uint8 g_scf_short[9][40] = {
710  { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
711  { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
712  { 8,8,8,8,8,8,8,8,8,12,12,12,16,16,16,20,20,20,24,24,24,28,28,28,36,36,36,2,2,2,2,2,2,2,2,2,26,26,26,0 },
713  { 4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,8,8,8,10,10,10,14,14,14,18,18,18,26,26,26,32,32,32,42,42,42,18,18,18,0 },
714  { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,32,32,32,44,44,44,12,12,12,0 },
715  { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
716  { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,22,22,22,30,30,30,56,56,56,0 },
717  { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,10,10,10,12,12,12,14,14,14,16,16,16,20,20,20,26,26,26,66,66,66,0 },
718  { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,12,12,12,16,16,16,20,20,20,26,26,26,34,34,34,42,42,42,12,12,12,0 }
719  };
720  static const drmp3_uint8 g_scf_mixed[9][40] = {
721  { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
722  { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
723  { 12,12,12,4,4,4,8,8,8,12,12,12,16,16,16,20,20,20,24,24,24,28,28,28,36,36,36,2,2,2,2,2,2,2,2,2,26,26,26,0 },
724  { 6,6,6,6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,14,14,14,18,18,18,26,26,26,32,32,32,42,42,42,18,18,18,0 },
725  { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,32,32,32,44,44,44,12,12,12,0 },
726  { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
727  { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,22,22,22,30,30,30,56,56,56,0 },
728  { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,6,6,6,10,10,10,12,12,12,14,14,14,16,16,16,20,20,20,26,26,26,66,66,66,0 },
729  { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,8,8,8,12,12,12,16,16,16,20,20,20,26,26,26,34,34,34,42,42,42,12,12,12,0 }
730  };
731 
732  unsigned tables, scfsi = 0;
733  int main_data_begin, part_23_sum = 0;
734  int sr_idx = DRMP3_HDR_GET_MY_SAMPLE_RATE(hdr);
735  int gr_count = DRMP3_HDR_IS_MONO(hdr) ? 1 : 2;
736 
737  if (DRMP3_HDR_TEST_MPEG1(hdr))
738  {
739  gr_count *= 2;
740  main_data_begin = drmp3_bs_get_bits(bs, 9);
741  scfsi = drmp3_bs_get_bits(bs, 7 + gr_count);
742  } else
743  {
744  main_data_begin = drmp3_bs_get_bits(bs, 8 + gr_count) >> gr_count;
745  }
746 
747  do
748  {
749  if (DRMP3_HDR_IS_MONO(hdr))
750  {
751  scfsi <<= 4;
752  }
753  gr->part_23_length = (drmp3_uint16)drmp3_bs_get_bits(bs, 12);
754  part_23_sum += gr->part_23_length;
755  gr->big_values = (drmp3_uint16)drmp3_bs_get_bits(bs, 9);
756  if (gr->big_values > 288)
757  {
758  return -1;
759  }
760  gr->global_gain = (drmp3_uint8)drmp3_bs_get_bits(bs, 8);
761  gr->scalefac_compress = (drmp3_uint16)drmp3_bs_get_bits(bs, DRMP3_HDR_TEST_MPEG1(hdr) ? 4 : 9);
762  gr->sfbtab = g_scf_long[sr_idx];
763  gr->n_long_sfb = 22;
764  gr->n_short_sfb = 0;
765  if (drmp3_bs_get_bits(bs, 1))
766  {
767  gr->block_type = (drmp3_uint8)drmp3_bs_get_bits(bs, 2);
768  if (!gr->block_type)
769  {
770  return -1;
771  }
772  gr->mixed_block_flag = (drmp3_uint8)drmp3_bs_get_bits(bs, 1);
773  gr->region_count[0] = 7;
774  gr->region_count[1] = 255;
775  if (gr->block_type == DRMP3_SHORT_BLOCK_TYPE)
776  {
777  scfsi &= 0x0F0F;
778  if (!gr->mixed_block_flag)
779  {
780  gr->region_count[0] = 8;
781  gr->sfbtab = g_scf_short[sr_idx];
782  gr->n_long_sfb = 0;
783  gr->n_short_sfb = 39;
784  } else
785  {
786  gr->sfbtab = g_scf_mixed[sr_idx];
787  gr->n_long_sfb = DRMP3_HDR_TEST_MPEG1(hdr) ? 8 : 6;
788  gr->n_short_sfb = 30;
789  }
790  }
791  tables = drmp3_bs_get_bits(bs, 10);
792  tables <<= 5;
793  gr->subblock_gain[0] = (drmp3_uint8)drmp3_bs_get_bits(bs, 3);
794  gr->subblock_gain[1] = (drmp3_uint8)drmp3_bs_get_bits(bs, 3);
795  gr->subblock_gain[2] = (drmp3_uint8)drmp3_bs_get_bits(bs, 3);
796  } else
797  {
798  gr->block_type = 0;
799  gr->mixed_block_flag = 0;
800  tables = drmp3_bs_get_bits(bs, 15);
801  gr->region_count[0] = (drmp3_uint8)drmp3_bs_get_bits(bs, 4);
802  gr->region_count[1] = (drmp3_uint8)drmp3_bs_get_bits(bs, 3);
803  gr->region_count[2] = 255;
804  }
805  gr->table_select[0] = (drmp3_uint8)(tables >> 10);
806  gr->table_select[1] = (drmp3_uint8)((tables >> 5) & 31);
807  gr->table_select[2] = (drmp3_uint8)((tables) & 31);
808  gr->preflag = (drmp3_uint8)(DRMP3_HDR_TEST_MPEG1(hdr) ? drmp3_bs_get_bits(bs, 1) : (gr->scalefac_compress >= 500));
809  gr->scalefac_scale = (drmp3_uint8)drmp3_bs_get_bits(bs, 1);
810  gr->count1_table = (drmp3_uint8)drmp3_bs_get_bits(bs, 1);
811  gr->scfsi = (drmp3_uint8)((scfsi >> 12) & 15);
812  scfsi <<= 4;
813  gr++;
814  } while(--gr_count);
815 
816  if (part_23_sum + bs->pos > bs->limit + main_data_begin*8)
817  {
818  return -1;
819  }
820 
821  return main_data_begin;
822 }
823 
824 static void drmp3_L3_read_scalefactors(drmp3_uint8 *scf, drmp3_uint8 *ist_pos, const drmp3_uint8 *scf_size, const drmp3_uint8 *scf_count, drmp3_bs *bitbuf, int scfsi)
825 {
826  int i, k;
827  for (i = 0; i < 4 && scf_count[i]; i++, scfsi *= 2)
828  {
829  int cnt = scf_count[i];
830  if (scfsi & 8)
831  {
832  memcpy(scf, ist_pos, cnt);
833  } else
834  {
835  int bits = scf_size[i];
836  if (!bits)
837  {
838  memset(scf, 0, cnt);
839  memset(ist_pos, 0, cnt);
840  } else
841  {
842  int max_scf = (scfsi < 0) ? (1 << bits) - 1 : -1;
843  for (k = 0; k < cnt; k++)
844  {
845  int s = drmp3_bs_get_bits(bitbuf, bits);
846  ist_pos[k] = (drmp3_uint8)(s == max_scf ? -1 : s);
847  scf[k] = (drmp3_uint8)s;
848  }
849  }
850  }
851  ist_pos += cnt;
852  scf += cnt;
853  }
854  scf[0] = scf[1] = scf[2] = 0;
855 }
856 
857 static float drmp3_L3_ldexp_q2(float y, int exp_q2)
858 {
859  static const float g_expfrac[4] = { 9.31322575e-10f,7.83145814e-10f,6.58544508e-10f,5.53767716e-10f };
860  int e;
861  do
862  {
863  e = DRMP3_MIN(30*4, exp_q2);
864  y *= g_expfrac[e & 3]*(1 << 30 >> (e >> 2));
865  } while ((exp_q2 -= e) > 0);
866  return y;
867 }
868 
869 static void drmp3_L3_decode_scalefactors(const drmp3_uint8 *hdr, drmp3_uint8 *ist_pos, drmp3_bs *bs, const drmp3_L3_gr_info *gr, float *scf, int ch)
870 {
871  static const drmp3_uint8 g_scf_partitions[3][28] = {
872  { 6,5,5, 5,6,5,5,5,6,5, 7,3,11,10,0,0, 7, 7, 7,0, 6, 6,6,3, 8, 8,5,0 },
873  { 8,9,6,12,6,9,9,9,6,9,12,6,15,18,0,0, 6,15,12,0, 6,12,9,6, 6,18,9,0 },
874  { 9,9,6,12,9,9,9,9,9,9,12,6,18,18,0,0,12,12,12,0,12, 9,9,6,15,12,9,0 }
875  };
876  const drmp3_uint8 *scf_partition = g_scf_partitions[!!gr->n_short_sfb + !gr->n_long_sfb];
877  drmp3_uint8 scf_size[4], iscf[40];
878  int i, scf_shift = gr->scalefac_scale + 1, gain_exp, scfsi = gr->scfsi;
879  float gain;
880 
881  if (DRMP3_HDR_TEST_MPEG1(hdr))
882  {
883  static const drmp3_uint8 g_scfc_decode[16] = { 0,1,2,3, 12,5,6,7, 9,10,11,13, 14,15,18,19 };
884  int part = g_scfc_decode[gr->scalefac_compress];
885  scf_size[1] = scf_size[0] = (drmp3_uint8)(part >> 2);
886  scf_size[3] = scf_size[2] = (drmp3_uint8)(part & 3);
887  } else
888  {
889  static const drmp3_uint8 g_mod[6*4] = { 5,5,4,4,5,5,4,1,4,3,1,1,5,6,6,1,4,4,4,1,4,3,1,1 };
890  int k, modprod, sfc, ist = DRMP3_HDR_TEST_I_STEREO(hdr) && ch;
891  sfc = gr->scalefac_compress >> ist;
892  for (k = ist*3*4; sfc >= 0; sfc -= modprod, k += 4)
893  {
894  for (modprod = 1, i = 3; i >= 0; i--)
895  {
896  scf_size[i] = (drmp3_uint8)(sfc / modprod % g_mod[k + i]);
897  modprod *= g_mod[k + i];
898  }
899  }
900  scf_partition += k;
901  scfsi = -16;
902  }
903  drmp3_L3_read_scalefactors(iscf, ist_pos, scf_size, scf_partition, bs, scfsi);
904 
905  if (gr->n_short_sfb)
906  {
907  int sh = 3 - scf_shift;
908  for (i = 0; i < gr->n_short_sfb; i += 3)
909  {
910  iscf[gr->n_long_sfb + i + 0] += gr->subblock_gain[0] << sh;
911  iscf[gr->n_long_sfb + i + 1] += gr->subblock_gain[1] << sh;
912  iscf[gr->n_long_sfb + i + 2] += gr->subblock_gain[2] << sh;
913  }
914  } else if (gr->preflag)
915  {
916  static const drmp3_uint8 g_preamp[10] = { 1,1,1,1,2,2,3,3,3,2 };
917  for (i = 0; i < 10; i++)
918  {
919  iscf[11 + i] += g_preamp[i];
920  }
921  }
922 
923  gain_exp = gr->global_gain + DRMP3_BITS_DEQUANTIZER_OUT*4 - 210 - (DRMP3_HDR_IS_MS_STEREO(hdr) ? 2 : 0);
924  gain = drmp3_L3_ldexp_q2(1 << (DRMP3_MAX_SCFI/4), DRMP3_MAX_SCFI - gain_exp);
925  for (i = 0; i < (int)(gr->n_long_sfb + gr->n_short_sfb); i++)
926  {
927  scf[i] = drmp3_L3_ldexp_q2(gain, iscf[i] << scf_shift);
928  }
929 }
930 
931 static float drmp3_L3_pow_43(int x)
932 {
933  static const float g_pow43[129] = {
934  0,1,2.519842f,4.326749f,6.349604f,8.549880f,10.902724f,13.390518f,16.000000f,18.720754f,21.544347f,24.463781f,27.473142f,30.567351f,33.741992f,36.993181f,40.317474f,43.711787f,47.173345f,50.699631f,54.288352f,57.937408f,61.644865f,65.408941f,69.227979f,73.100443f,77.024898f,81.000000f,85.024491f,89.097188f,93.216975f,97.382800f,101.593667f,105.848633f,110.146801f,114.487321f,118.869381f,123.292209f,127.755065f,132.257246f,136.798076f,141.376907f,145.993119f,150.646117f,155.335327f,160.060199f,164.820202f,169.614826f,174.443577f,179.305980f,184.201575f,189.129918f,194.090580f,199.083145f,204.107210f,209.162385f,214.248292f,219.364564f,224.510845f,229.686789f,234.892058f,240.126328f,245.389280f,250.680604f,256.000000f,261.347174f,266.721841f,272.123723f,277.552547f,283.008049f,288.489971f,293.998060f,299.532071f,305.091761f,310.676898f,316.287249f,321.922592f,327.582707f,333.267377f,338.976394f,344.709550f,350.466646f,356.247482f,362.051866f,367.879608f,373.730522f,379.604427f,385.501143f,391.420496f,397.362314f,403.326427f,409.312672f,415.320884f,421.350905f,427.402579f,433.475750f,439.570269f,445.685987f,451.822757f,457.980436f,464.158883f,470.357960f,476.577530f,482.817459f,489.077615f,495.357868f,501.658090f,507.978156f,514.317941f,520.677324f,527.056184f,533.454404f,539.871867f,546.308458f,552.764065f,559.238575f,565.731879f,572.243870f,578.774440f,585.323483f,591.890898f,598.476581f,605.080431f,611.702349f,618.342238f,625.000000f,631.675540f,638.368763f,645.079578f
935  };
936  float frac;
937  int sign, mult = 256;
938 
939  if (x < 129)
940  {
941  return g_pow43[x];
942  }
943 
944  if (x < 1024)
945  {
946  mult = 16;
947  x <<= 3;
948  }
949 
950  sign = 2*x & 64;
951  frac = (float)((x & 63) - sign) / ((x & ~63) + sign);
952  return g_pow43[(x + sign) >> 6]*(1.f + frac*((4.f/3) + frac*(2.f/9)))*mult;
953 }
954 
955 static void drmp3_L3_huffman(float *dst, drmp3_bs *bs, const drmp3_L3_gr_info *gr_info, const float *scf, int layer3gr_limit)
956 {
957  static const float g_pow43_signed[32] = { 0,0,1,-1,2.519842f,-2.519842f,4.326749f,-4.326749f,6.349604f,-6.349604f,8.549880f,-8.549880f,10.902724f,-10.902724f,13.390518f,-13.390518f,16.000000f,-16.000000f,18.720754f,-18.720754f,21.544347f,-21.544347f,24.463781f,-24.463781f,27.473142f,-27.473142f,30.567351f,-30.567351f,33.741992f,-33.741992f,36.993181f,-36.993181f };
958  static const drmp3_int16 tab0[32] = { 0, };
959  static const drmp3_int16 tab1[] = { 785,785,785,785,784,784,784,784,513,513,513,513,513,513,513,513,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256 };
960  static const drmp3_int16 tab2[] = { -255,1313,1298,1282,785,785,785,785,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,290,288 };
961  static const drmp3_int16 tab3[] = { -255,1313,1298,1282,769,769,769,769,529,529,529,529,529,529,529,529,528,528,528,528,528,528,528,528,512,512,512,512,512,512,512,512,290,288 };
962  static const drmp3_int16 tab5[] = { -253,-318,-351,-367,785,785,785,785,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,819,818,547,547,275,275,275,275,561,560,515,546,289,274,288,258 };
963  static const drmp3_int16 tab6[] = { -254,-287,1329,1299,1314,1312,1057,1057,1042,1042,1026,1026,784,784,784,784,529,529,529,529,529,529,529,529,769,769,769,769,768,768,768,768,563,560,306,306,291,259 };
964  static const drmp3_int16 tab7[] = { -252,-413,-477,-542,1298,-575,1041,1041,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-383,-399,1107,1092,1106,1061,849,849,789,789,1104,1091,773,773,1076,1075,341,340,325,309,834,804,577,577,532,532,516,516,832,818,803,816,561,561,531,531,515,546,289,289,288,258 };
965  static const drmp3_int16 tab8[] = { -252,-429,-493,-559,1057,1057,1042,1042,529,529,529,529,529,529,529,529,784,784,784,784,769,769,769,769,512,512,512,512,512,512,512,512,-382,1077,-415,1106,1061,1104,849,849,789,789,1091,1076,1029,1075,834,834,597,581,340,340,339,324,804,833,532,532,832,772,818,803,817,787,816,771,290,290,290,290,288,258 };
966  static const drmp3_int16 tab9[] = { -253,-349,-414,-447,-463,1329,1299,-479,1314,1312,1057,1057,1042,1042,1026,1026,785,785,785,785,784,784,784,784,769,769,769,769,768,768,768,768,-319,851,821,-335,836,850,805,849,341,340,325,336,533,533,579,579,564,564,773,832,578,548,563,516,321,276,306,291,304,259 };
967  static const drmp3_int16 tab10[] = { -251,-572,-733,-830,-863,-879,1041,1041,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-511,-527,-543,1396,1351,1381,1366,1395,1335,1380,-559,1334,1138,1138,1063,1063,1350,1392,1031,1031,1062,1062,1364,1363,1120,1120,1333,1348,881,881,881,881,375,374,359,373,343,358,341,325,791,791,1123,1122,-703,1105,1045,-719,865,865,790,790,774,774,1104,1029,338,293,323,308,-799,-815,833,788,772,818,803,816,322,292,307,320,561,531,515,546,289,274,288,258 };
968  static const drmp3_int16 tab11[] = { -251,-525,-605,-685,-765,-831,-846,1298,1057,1057,1312,1282,785,785,785,785,784,784,784,784,769,769,769,769,512,512,512,512,512,512,512,512,1399,1398,1383,1367,1382,1396,1351,-511,1381,1366,1139,1139,1079,1079,1124,1124,1364,1349,1363,1333,882,882,882,882,807,807,807,807,1094,1094,1136,1136,373,341,535,535,881,775,867,822,774,-591,324,338,-671,849,550,550,866,864,609,609,293,336,534,534,789,835,773,-751,834,804,308,307,833,788,832,772,562,562,547,547,305,275,560,515,290,290 };
969  static const drmp3_int16 tab12[] = { -252,-397,-477,-557,-622,-653,-719,-735,-750,1329,1299,1314,1057,1057,1042,1042,1312,1282,1024,1024,785,785,785,785,784,784,784,784,769,769,769,769,-383,1127,1141,1111,1126,1140,1095,1110,869,869,883,883,1079,1109,882,882,375,374,807,868,838,881,791,-463,867,822,368,263,852,837,836,-543,610,610,550,550,352,336,534,534,865,774,851,821,850,805,593,533,579,564,773,832,578,578,548,548,577,577,307,276,306,291,516,560,259,259 };
970  static const drmp3_int16 tab13[] = { -250,-2107,-2507,-2764,-2909,-2974,-3007,-3023,1041,1041,1040,1040,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-767,-1052,-1213,-1277,-1358,-1405,-1469,-1535,-1550,-1582,-1614,-1647,-1662,-1694,-1726,-1759,-1774,-1807,-1822,-1854,-1886,1565,-1919,-1935,-1951,-1967,1731,1730,1580,1717,-1983,1729,1564,-1999,1548,-2015,-2031,1715,1595,-2047,1714,-2063,1610,-2079,1609,-2095,1323,1323,1457,1457,1307,1307,1712,1547,1641,1700,1699,1594,1685,1625,1442,1442,1322,1322,-780,-973,-910,1279,1278,1277,1262,1276,1261,1275,1215,1260,1229,-959,974,974,989,989,-943,735,478,478,495,463,506,414,-1039,1003,958,1017,927,942,987,957,431,476,1272,1167,1228,-1183,1256,-1199,895,895,941,941,1242,1227,1212,1135,1014,1014,490,489,503,487,910,1013,985,925,863,894,970,955,1012,847,-1343,831,755,755,984,909,428,366,754,559,-1391,752,486,457,924,997,698,698,983,893,740,740,908,877,739,739,667,667,953,938,497,287,271,271,683,606,590,712,726,574,302,302,738,736,481,286,526,725,605,711,636,724,696,651,589,681,666,710,364,467,573,695,466,466,301,465,379,379,709,604,665,679,316,316,634,633,436,436,464,269,424,394,452,332,438,363,347,408,393,448,331,422,362,407,392,421,346,406,391,376,375,359,1441,1306,-2367,1290,-2383,1337,-2399,-2415,1426,1321,-2431,1411,1336,-2447,-2463,-2479,1169,1169,1049,1049,1424,1289,1412,1352,1319,-2495,1154,1154,1064,1064,1153,1153,416,390,360,404,403,389,344,374,373,343,358,372,327,357,342,311,356,326,1395,1394,1137,1137,1047,1047,1365,1392,1287,1379,1334,1364,1349,1378,1318,1363,792,792,792,792,1152,1152,1032,1032,1121,1121,1046,1046,1120,1120,1030,1030,-2895,1106,1061,1104,849,849,789,789,1091,1076,1029,1090,1060,1075,833,833,309,324,532,532,832,772,818,803,561,561,531,560,515,546,289,274,288,258 };
971  static const drmp3_int16 tab15[] = { -250,-1179,-1579,-1836,-1996,-2124,-2253,-2333,-2413,-2477,-2542,-2574,-2607,-2622,-2655,1314,1313,1298,1312,1282,785,785,785,785,1040,1040,1025,1025,768,768,768,768,-766,-798,-830,-862,-895,-911,-927,-943,-959,-975,-991,-1007,-1023,-1039,-1055,-1070,1724,1647,-1103,-1119,1631,1767,1662,1738,1708,1723,-1135,1780,1615,1779,1599,1677,1646,1778,1583,-1151,1777,1567,1737,1692,1765,1722,1707,1630,1751,1661,1764,1614,1736,1676,1763,1750,1645,1598,1721,1691,1762,1706,1582,1761,1566,-1167,1749,1629,767,766,751,765,494,494,735,764,719,749,734,763,447,447,748,718,477,506,431,491,446,476,461,505,415,430,475,445,504,399,460,489,414,503,383,474,429,459,502,502,746,752,488,398,501,473,413,472,486,271,480,270,-1439,-1455,1357,-1471,-1487,-1503,1341,1325,-1519,1489,1463,1403,1309,-1535,1372,1448,1418,1476,1356,1462,1387,-1551,1475,1340,1447,1402,1386,-1567,1068,1068,1474,1461,455,380,468,440,395,425,410,454,364,467,466,464,453,269,409,448,268,432,1371,1473,1432,1417,1308,1460,1355,1446,1459,1431,1083,1083,1401,1416,1458,1445,1067,1067,1370,1457,1051,1051,1291,1430,1385,1444,1354,1415,1400,1443,1082,1082,1173,1113,1186,1066,1185,1050,-1967,1158,1128,1172,1097,1171,1081,-1983,1157,1112,416,266,375,400,1170,1142,1127,1065,793,793,1169,1033,1156,1096,1141,1111,1155,1080,1126,1140,898,898,808,808,897,897,792,792,1095,1152,1032,1125,1110,1139,1079,1124,882,807,838,881,853,791,-2319,867,368,263,822,852,837,866,806,865,-2399,851,352,262,534,534,821,836,594,594,549,549,593,593,533,533,848,773,579,579,564,578,548,563,276,276,577,576,306,291,516,560,305,305,275,259 };
972  static const drmp3_int16 tab16[] = { -251,-892,-2058,-2620,-2828,-2957,-3023,-3039,1041,1041,1040,1040,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-511,-527,-543,-559,1530,-575,-591,1528,1527,1407,1526,1391,1023,1023,1023,1023,1525,1375,1268,1268,1103,1103,1087,1087,1039,1039,1523,-604,815,815,815,815,510,495,509,479,508,463,507,447,431,505,415,399,-734,-782,1262,-815,1259,1244,-831,1258,1228,-847,-863,1196,-879,1253,987,987,748,-767,493,493,462,477,414,414,686,669,478,446,461,445,474,429,487,458,412,471,1266,1264,1009,1009,799,799,-1019,-1276,-1452,-1581,-1677,-1757,-1821,-1886,-1933,-1997,1257,1257,1483,1468,1512,1422,1497,1406,1467,1496,1421,1510,1134,1134,1225,1225,1466,1451,1374,1405,1252,1252,1358,1480,1164,1164,1251,1251,1238,1238,1389,1465,-1407,1054,1101,-1423,1207,-1439,830,830,1248,1038,1237,1117,1223,1148,1236,1208,411,426,395,410,379,269,1193,1222,1132,1235,1221,1116,976,976,1192,1162,1177,1220,1131,1191,963,963,-1647,961,780,-1663,558,558,994,993,437,408,393,407,829,978,813,797,947,-1743,721,721,377,392,844,950,828,890,706,706,812,859,796,960,948,843,934,874,571,571,-1919,690,555,689,421,346,539,539,944,779,918,873,932,842,903,888,570,570,931,917,674,674,-2575,1562,-2591,1609,-2607,1654,1322,1322,1441,1441,1696,1546,1683,1593,1669,1624,1426,1426,1321,1321,1639,1680,1425,1425,1305,1305,1545,1668,1608,1623,1667,1592,1638,1666,1320,1320,1652,1607,1409,1409,1304,1304,1288,1288,1664,1637,1395,1395,1335,1335,1622,1636,1394,1394,1319,1319,1606,1621,1392,1392,1137,1137,1137,1137,345,390,360,375,404,373,1047,-2751,-2767,-2783,1062,1121,1046,-2799,1077,-2815,1106,1061,789,789,1105,1104,263,355,310,340,325,354,352,262,339,324,1091,1076,1029,1090,1060,1075,833,833,788,788,1088,1028,818,818,803,803,561,561,531,531,816,771,546,546,289,274,288,258 };
973  static const drmp3_int16 tab24[] = { -253,-317,-381,-446,-478,-509,1279,1279,-811,-1179,-1451,-1756,-1900,-2028,-2189,-2253,-2333,-2414,-2445,-2511,-2526,1313,1298,-2559,1041,1041,1040,1040,1025,1025,1024,1024,1022,1007,1021,991,1020,975,1019,959,687,687,1018,1017,671,671,655,655,1016,1015,639,639,758,758,623,623,757,607,756,591,755,575,754,559,543,543,1009,783,-575,-621,-685,-749,496,-590,750,749,734,748,974,989,1003,958,988,973,1002,942,987,957,972,1001,926,986,941,971,956,1000,910,985,925,999,894,970,-1071,-1087,-1102,1390,-1135,1436,1509,1451,1374,-1151,1405,1358,1480,1420,-1167,1507,1494,1389,1342,1465,1435,1450,1326,1505,1310,1493,1373,1479,1404,1492,1464,1419,428,443,472,397,736,526,464,464,486,457,442,471,484,482,1357,1449,1434,1478,1388,1491,1341,1490,1325,1489,1463,1403,1309,1477,1372,1448,1418,1433,1476,1356,1462,1387,-1439,1475,1340,1447,1402,1474,1324,1461,1371,1473,269,448,1432,1417,1308,1460,-1711,1459,-1727,1441,1099,1099,1446,1386,1431,1401,-1743,1289,1083,1083,1160,1160,1458,1445,1067,1067,1370,1457,1307,1430,1129,1129,1098,1098,268,432,267,416,266,400,-1887,1144,1187,1082,1173,1113,1186,1066,1050,1158,1128,1143,1172,1097,1171,1081,420,391,1157,1112,1170,1142,1127,1065,1169,1049,1156,1096,1141,1111,1155,1080,1126,1154,1064,1153,1140,1095,1048,-2159,1125,1110,1137,-2175,823,823,1139,1138,807,807,384,264,368,263,868,838,853,791,867,822,852,837,866,806,865,790,-2319,851,821,836,352,262,850,805,849,-2399,533,533,835,820,336,261,578,548,563,577,532,532,832,772,562,562,547,547,305,275,560,515,290,290,288,258 };
974  static const drmp3_uint8 tab32[] = { 130,162,193,209,44,28,76,140,9,9,9,9,9,9,9,9,190,254,222,238,126,94,157,157,109,61,173,205};
975  static const drmp3_uint8 tab33[] = { 252,236,220,204,188,172,156,140,124,108,92,76,60,44,28,12 };
976  static const drmp3_int16 * const tabindex[2*16] = { tab0,tab1,tab2,tab3,tab0,tab5,tab6,tab7,tab8,tab9,tab10,tab11,tab12,tab13,tab0,tab15,tab16,tab16,tab16,tab16,tab16,tab16,tab16,tab16,tab24,tab24,tab24,tab24,tab24,tab24,tab24,tab24 };
977  static const drmp3_uint8 g_linbits[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,6,8,10,13,4,5,6,7,8,9,11,13 };
978 
979 #define DRMP3_PEEK_BITS(n) (bs_cache >> (32 - n))
980 #define DRMP3_FLUSH_BITS(n) { bs_cache <<= (n); bs_sh += (n); }
981 #define DRMP3_CHECK_BITS while (bs_sh >= 0) { bs_cache |= (drmp3_uint32)*bs_next_ptr++ << bs_sh; bs_sh -= 8; }
982 #define DRMP3_BSPOS ((bs_next_ptr - bs->buf)*8 - 24 + bs_sh)
983 
984  float one = 0.0f;
985  int ireg = 0, big_val_cnt = gr_info->big_values;
986  const drmp3_uint8 *sfb = gr_info->sfbtab;
987  const drmp3_uint8 *bs_next_ptr = bs->buf + bs->pos/8;
988  drmp3_uint32 bs_cache = (((bs_next_ptr[0]*256u + bs_next_ptr[1])*256u + bs_next_ptr[2])*256u + bs_next_ptr[3]) << (bs->pos & 7);
989  int pairs_to_decode, np, bs_sh = (bs->pos & 7) - 8;
990  bs_next_ptr += 4;
991 
992  while (big_val_cnt > 0)
993  {
994  int tab_num = gr_info->table_select[ireg];
995  int sfb_cnt = gr_info->region_count[ireg++];
996  const short *codebook = tabindex[tab_num];
997  int linbits = g_linbits[tab_num];
998  do
999  {
1000  np = *sfb++ / 2;
1001  pairs_to_decode = DRMP3_MIN(big_val_cnt, np);
1002  one = *scf++;
1003  do
1004  {
1005  int j, w = 5;
1006  int leaf = codebook[DRMP3_PEEK_BITS(w)];
1007  while (leaf < 0)
1008  {
1009  DRMP3_FLUSH_BITS(w);
1010  w = leaf & 7;
1011  leaf = codebook[DRMP3_PEEK_BITS(w) - (leaf >> 3)];
1012  }
1013  DRMP3_FLUSH_BITS(leaf >> 8);
1014 
1015  for (j = 0; j < 2; j++, dst++, leaf >>= 4)
1016  {
1017  int lsb = leaf & 0x0F;
1018  if (lsb == 15 && linbits)
1019  {
1020  lsb += DRMP3_PEEK_BITS(linbits);
1021  DRMP3_FLUSH_BITS(linbits);
1022  DRMP3_CHECK_BITS;
1023  *dst = one*drmp3_L3_pow_43(lsb)*((int32_t)bs_cache < 0 ? -1: 1);
1024  } else
1025  {
1026  *dst = g_pow43_signed[lsb*2 + (bs_cache >> 31)]*one;
1027  }
1028  DRMP3_FLUSH_BITS(lsb ? 1 : 0);
1029  }
1030  DRMP3_CHECK_BITS;
1031  } while (--pairs_to_decode);
1032  } while ((big_val_cnt -= np) > 0 && --sfb_cnt >= 0);
1033  }
1034 
1035  for (np = 1 - big_val_cnt;; dst += 4)
1036  {
1037  const drmp3_uint8 *codebook_count1 = (gr_info->count1_table) ? tab33 : tab32;
1038  int leaf = codebook_count1[DRMP3_PEEK_BITS(4)];
1039  if (!(leaf & 8))
1040  {
1041  leaf = codebook_count1[(leaf >> 3) + (bs_cache << 4 >> (32 - (leaf & 3)))];
1042  }
1043  DRMP3_FLUSH_BITS(leaf & 7);
1044  if (DRMP3_BSPOS > layer3gr_limit)
1045  {
1046  break;
1047  }
1048 #define DRMP3_RELOAD_SCALEFACTOR if (!--np) { np = *sfb++/2; if (!np) break; one = *scf++; }
1049 #define DRMP3_DEQ_COUNT1(s) if (leaf & (128 >> s)) { dst[s] = ((drmp3_int32)bs_cache < 0) ? -one : one; DRMP3_FLUSH_BITS(1) }
1050  DRMP3_RELOAD_SCALEFACTOR;
1051  DRMP3_DEQ_COUNT1(0);
1052  DRMP3_DEQ_COUNT1(1);
1053  DRMP3_RELOAD_SCALEFACTOR;
1054  DRMP3_DEQ_COUNT1(2);
1055  DRMP3_DEQ_COUNT1(3);
1056  DRMP3_CHECK_BITS;
1057  }
1058 
1059  bs->pos = layer3gr_limit;
1060 }
1061 
1062 static void drmp3_L3_midside_stereo(float *left, int n)
1063 {
1064  int i = 0;
1065  float *right = left + 576;
1066 #if DRMP3_HAVE_SIMD
1067  if (drmp3_have_simd()) for (; i < n - 3; i += 4)
1068  {
1069  drmp3_f4 vl = DRMP3_VLD(left + i);
1070  drmp3_f4 vr = DRMP3_VLD(right + i);
1071  DRMP3_VSTORE(left + i, DRMP3_VADD(vl, vr));
1072  DRMP3_VSTORE(right + i, DRMP3_VSUB(vl, vr));
1073  }
1074 #endif
1075  for (; i < n; i++)
1076  {
1077  float a = left[i];
1078  float b = right[i];
1079  left[i] = a + b;
1080  right[i] = a - b;
1081  }
1082 }
1083 
1084 static void drmp3_L3_intensity_stereo_band(float *left, int n, float kl, float kr)
1085 {
1086  int i;
1087  for (i = 0; i < n; i++)
1088  {
1089  left[i + 576] = left[i]*kr;
1090  left[i] = left[i]*kl;
1091  }
1092 }
1093 
1094 static void drmp3_L3_stereo_top_band(const float *right, const drmp3_uint8 *sfb, int nbands, int max_band[3])
1095 {
1096  int i, k;
1097 
1098  max_band[0] = max_band[1] = max_band[2] = -1;
1099 
1100  for (i = 0; i < nbands; i++)
1101  {
1102  for (k = 0; k < sfb[i]; k += 2)
1103  {
1104  if (right[k] != 0 || right[k + 1] != 0)
1105  {
1106  max_band[i % 3] = i;
1107  break;
1108  }
1109  }
1110  right += sfb[i];
1111  }
1112 }
1113 
1114 static void drmp3_L3_stereo_process(float *left, const drmp3_uint8 *ist_pos, const drmp3_uint8 *sfb, const drmp3_uint8 *hdr, int max_band[3], int mpeg2_sh)
1115 {
1116  static const float g_pan[7*2] = { 0,1,0.21132487f,0.78867513f,0.36602540f,0.63397460f,0.5f,0.5f,0.63397460f,0.36602540f,0.78867513f,0.21132487f,1,0 };
1117  unsigned i, max_pos = DRMP3_HDR_TEST_MPEG1(hdr) ? 7 : 64;
1118 
1119  for (i = 0; sfb[i]; i++)
1120  {
1121  unsigned ipos = ist_pos[i];
1122  if ((int)i > max_band[i % 3] && ipos < max_pos)
1123  {
1124  float kl, kr, s = DRMP3_HDR_TEST_MS_STEREO(hdr) ? 1.41421356f : 1;
1125  if (DRMP3_HDR_TEST_MPEG1(hdr))
1126  {
1127  kl = g_pan[2*ipos];
1128  kr = g_pan[2*ipos + 1];
1129  } else
1130  {
1131  kl = 1;
1132  kr = drmp3_L3_ldexp_q2(1, (ipos + 1) >> 1 << mpeg2_sh);
1133  if (ipos & 1)
1134  {
1135  kl = kr;
1136  kr = 1;
1137  }
1138  }
1139  drmp3_L3_intensity_stereo_band(left, sfb[i], kl*s, kr*s);
1140  } else if (DRMP3_HDR_TEST_MS_STEREO(hdr))
1141  {
1142  drmp3_L3_midside_stereo(left, sfb[i]);
1143  }
1144  left += sfb[i];
1145  }
1146 }
1147 
1148 static void drmp3_L3_intensity_stereo(float *left, drmp3_uint8 *ist_pos, const drmp3_L3_gr_info *gr, const drmp3_uint8 *hdr)
1149 {
1150  int max_band[3], n_sfb = gr->n_long_sfb + gr->n_short_sfb;
1151  int i, max_blocks = gr->n_short_sfb ? 3 : 1;
1152 
1153  drmp3_L3_stereo_top_band(left + 576, gr->sfbtab, n_sfb, max_band);
1154  if (gr->n_long_sfb)
1155  {
1156  max_band[0] = max_band[1] = max_band[2] = DRMP3_MAX(DRMP3_MAX(max_band[0], max_band[1]), max_band[2]);
1157  }
1158  for (i = 0; i < max_blocks; i++)
1159  {
1160  int default_pos = DRMP3_HDR_TEST_MPEG1(hdr) ? 3 : 0;
1161  int itop = n_sfb - max_blocks + i;
1162  int prev = itop - max_blocks;
1163  ist_pos[itop] = (drmp3_uint8)(max_band[i] >= prev ? default_pos : ist_pos[prev]);
1164  }
1165  drmp3_L3_stereo_process(left, ist_pos, gr->sfbtab, hdr, max_band, gr[1].scalefac_compress&1);
1166 }
1167 
1168 static void drmp3_L3_reorder(float *grbuf, float *scratch, const drmp3_uint8 *sfb)
1169 {
1170  int i, len;
1171  float *src = grbuf, *dst = scratch;
1172 
1173  for (;0 != (len = *sfb); sfb += 3, src += 2*len)
1174  {
1175  for (i = 0; i < len; i++, src++)
1176  {
1177  *dst++ = src[0*len];
1178  *dst++ = src[1*len];
1179  *dst++ = src[2*len];
1180  }
1181  }
1182  memcpy(grbuf, scratch, (dst - scratch)*sizeof(float));
1183 }
1184 
1185 static void drmp3_L3_antialias(float *grbuf, int nbands)
1186 {
1187  static const float g_aa[2][8] = {
1188  {0.85749293f,0.88174200f,0.94962865f,0.98331459f,0.99551782f,0.99916056f,0.99989920f,0.99999316f},
1189  {0.51449576f,0.47173197f,0.31337745f,0.18191320f,0.09457419f,0.04096558f,0.01419856f,0.00369997f}
1190  };
1191 
1192  for (; nbands > 0; nbands--, grbuf += 18)
1193  {
1194  int i = 0;
1195 #if DRMP3_HAVE_SIMD
1196  if (drmp3_have_simd()) for (; i < 8; i += 4)
1197  {
1198  drmp3_f4 vu = DRMP3_VLD(grbuf + 18 + i);
1199  drmp3_f4 vd = DRMP3_VLD(grbuf + 14 - i);
1200  drmp3_f4 vc0 = DRMP3_VLD(g_aa[0] + i);
1201  drmp3_f4 vc1 = DRMP3_VLD(g_aa[1] + i);
1202  vd = DRMP3_VREV(vd);
1203  DRMP3_VSTORE(grbuf + 18 + i, DRMP3_VSUB(DRMP3_VMUL(vu, vc0), DRMP3_VMUL(vd, vc1)));
1204  vd = DRMP3_VADD(DRMP3_VMUL(vu, vc1), DRMP3_VMUL(vd, vc0));
1205  DRMP3_VSTORE(grbuf + 14 - i, DRMP3_VREV(vd));
1206  }
1207 #endif
1208 #ifndef DR_MP3_ONLY_SIMD
1209  for(; i < 8; i++)
1210  {
1211  float u = grbuf[18 + i];
1212  float d = grbuf[17 - i];
1213  grbuf[18 + i] = u*g_aa[0][i] - d*g_aa[1][i];
1214  grbuf[17 - i] = u*g_aa[1][i] + d*g_aa[0][i];
1215  }
1216 #endif
1217  }
1218 }
1219 
1220 static void drmp3_L3_dct3_9(float *y)
1221 {
1222  float s0, s1, s2, s3, s4, s5, s6, s7, s8, t0, t2, t4;
1223 
1224  s0 = y[0]; s2 = y[2]; s4 = y[4]; s6 = y[6]; s8 = y[8];
1225  t0 = s0 + s6*0.5f;
1226  s0 -= s6;
1227  t4 = (s4 + s2)*0.93969262f;
1228  t2 = (s8 + s2)*0.76604444f;
1229  s6 = (s4 - s8)*0.17364818f;
1230  s4 += s8 - s2;
1231 
1232  s2 = s0 - s4*0.5f;
1233  y[4] = s4 + s0;
1234  s8 = t0 - t2 + s6;
1235  s0 = t0 - t4 + t2;
1236  s4 = t0 + t4 - s6;
1237 
1238  s1 = y[1]; s3 = y[3]; s5 = y[5]; s7 = y[7];
1239 
1240  s3 *= 0.86602540f;
1241  t0 = (s5 + s1)*0.98480775f;
1242  t4 = (s5 - s7)*0.34202014f;
1243  t2 = (s1 + s7)*0.64278761f;
1244  s1 = (s1 - s5 - s7)*0.86602540f;
1245 
1246  s5 = t0 - s3 - t2;
1247  s7 = t4 - s3 - t0;
1248  s3 = t4 + s3 - t2;
1249 
1250  y[0] = s4 - s7;
1251  y[1] = s2 + s1;
1252  y[2] = s0 - s3;
1253  y[3] = s8 + s5;
1254  y[5] = s8 - s5;
1255  y[6] = s0 + s3;
1256  y[7] = s2 - s1;
1257  y[8] = s4 + s7;
1258 }
1259 
1260 static void drmp3_L3_imdct36(float *grbuf, float *overlap, const float *window, int nbands)
1261 {
1262  int i, j;
1263  static const float g_twid9[18] = {
1264  0.73727734f,0.79335334f,0.84339145f,0.88701083f,0.92387953f,0.95371695f,0.97629601f,0.99144486f,0.99904822f,0.67559021f,0.60876143f,0.53729961f,0.46174861f,0.38268343f,0.30070580f,0.21643961f,0.13052619f,0.04361938f
1265  };
1266 
1267  for (j = 0; j < nbands; j++, grbuf += 18, overlap += 9)
1268  {
1269  float co[9], si[9];
1270  co[0] = -grbuf[0];
1271  si[0] = grbuf[17];
1272  for (i = 0; i < 4; i++)
1273  {
1274  si[8 - 2*i] = grbuf[4*i + 1] - grbuf[4*i + 2];
1275  co[1 + 2*i] = grbuf[4*i + 1] + grbuf[4*i + 2];
1276  si[7 - 2*i] = grbuf[4*i + 4] - grbuf[4*i + 3];
1277  co[2 + 2*i] = -(grbuf[4*i + 3] + grbuf[4*i + 4]);
1278  }
1279  drmp3_L3_dct3_9(co);
1280  drmp3_L3_dct3_9(si);
1281 
1282  si[1] = -si[1];
1283  si[3] = -si[3];
1284  si[5] = -si[5];
1285  si[7] = -si[7];
1286 
1287  i = 0;
1288 
1289 #if DRMP3_HAVE_SIMD
1290  if (drmp3_have_simd()) for (; i < 8; i += 4)
1291  {
1292  drmp3_f4 vovl = DRMP3_VLD(overlap + i);
1293  drmp3_f4 vc = DRMP3_VLD(co + i);
1294  drmp3_f4 vs = DRMP3_VLD(si + i);
1295  drmp3_f4 vr0 = DRMP3_VLD(g_twid9 + i);
1296  drmp3_f4 vr1 = DRMP3_VLD(g_twid9 + 9 + i);
1297  drmp3_f4 vw0 = DRMP3_VLD(window + i);
1298  drmp3_f4 vw1 = DRMP3_VLD(window + 9 + i);
1299  drmp3_f4 vsum = DRMP3_VADD(DRMP3_VMUL(vc, vr1), DRMP3_VMUL(vs, vr0));
1300  DRMP3_VSTORE(overlap + i, DRMP3_VSUB(DRMP3_VMUL(vc, vr0), DRMP3_VMUL(vs, vr1)));
1301  DRMP3_VSTORE(grbuf + i, DRMP3_VSUB(DRMP3_VMUL(vovl, vw0), DRMP3_VMUL(vsum, vw1)));
1302  vsum = DRMP3_VADD(DRMP3_VMUL(vovl, vw1), DRMP3_VMUL(vsum, vw0));
1303  DRMP3_VSTORE(grbuf + 14 - i, DRMP3_VREV(vsum));
1304  }
1305 #endif
1306  for (; i < 9; i++)
1307  {
1308  float ovl = overlap[i];
1309  float sum = co[i]*g_twid9[9 + i] + si[i]*g_twid9[0 + i];
1310  overlap[i] = co[i]*g_twid9[0 + i] - si[i]*g_twid9[9 + i];
1311  grbuf[i] = ovl*window[0 + i] - sum*window[9 + i];
1312  grbuf[17 - i] = ovl*window[9 + i] + sum*window[0 + i];
1313  }
1314  }
1315 }
1316 
1317 static void drmp3_L3_idct3(float x0, float x1, float x2, float *dst)
1318 {
1319  float m1 = x1*0.86602540f;
1320  float a1 = x0 - x2*0.5f;
1321  dst[1] = x0 + x2;
1322  dst[0] = a1 + m1;
1323  dst[2] = a1 - m1;
1324 }
1325 
1326 static void drmp3_L3_imdct12(float *x, float *dst, float *overlap)
1327 {
1328  static const float g_twid3[6] = { 0.79335334f,0.92387953f,0.99144486f, 0.60876143f,0.38268343f,0.13052619f };
1329  float co[3], si[3];
1330  int i;
1331 
1332  drmp3_L3_idct3(-x[0], x[6] + x[3], x[12] + x[9], co);
1333  drmp3_L3_idct3(x[15], x[12] - x[9], x[6] - x[3], si);
1334  si[1] = -si[1];
1335 
1336  for (i = 0; i < 3; i++)
1337  {
1338  float ovl = overlap[i];
1339  float sum = co[i]*g_twid3[3 + i] + si[i]*g_twid3[0 + i];
1340  overlap[i] = co[i]*g_twid3[0 + i] - si[i]*g_twid3[3 + i];
1341  dst[i] = ovl*g_twid3[2 - i] - sum*g_twid3[5 - i];
1342  dst[5 - i] = ovl*g_twid3[5 - i] + sum*g_twid3[2 - i];
1343  }
1344 }
1345 
1346 static void drmp3_L3_imdct_short(float *grbuf, float *overlap, int nbands)
1347 {
1348  for (;nbands > 0; nbands--, overlap += 9, grbuf += 18)
1349  {
1350  float tmp[18];
1351  memcpy(tmp, grbuf, sizeof(tmp));
1352  memcpy(grbuf, overlap, 6*sizeof(float));
1353  drmp3_L3_imdct12(tmp, grbuf + 6, overlap + 6);
1354  drmp3_L3_imdct12(tmp + 1, grbuf + 12, overlap + 6);
1355  drmp3_L3_imdct12(tmp + 2, overlap, overlap + 6);
1356  }
1357 }
1358 
1359 static void drmp3_L3_change_sign(float *grbuf)
1360 {
1361  int b, i;
1362  for (b = 0, grbuf += 18; b < 32; b += 2, grbuf += 36)
1363  for (i = 1; i < 18; i += 2)
1364  grbuf[i] = -grbuf[i];
1365 }
1366 
1367 static void drmp3_L3_imdct_gr(float *grbuf, float *overlap, unsigned block_type, unsigned n_long_bands)
1368 {
1369  static const float g_mdct_window[2][18] = {
1370  { 0.99904822f,0.99144486f,0.97629601f,0.95371695f,0.92387953f,0.88701083f,0.84339145f,0.79335334f,0.73727734f,0.04361938f,0.13052619f,0.21643961f,0.30070580f,0.38268343f,0.46174861f,0.53729961f,0.60876143f,0.67559021f },
1371  { 1,1,1,1,1,1,0.99144486f,0.92387953f,0.79335334f,0,0,0,0,0,0,0.13052619f,0.38268343f,0.60876143f }
1372  };
1373  if (n_long_bands)
1374  {
1375  drmp3_L3_imdct36(grbuf, overlap, g_mdct_window[0], n_long_bands);
1376  grbuf += 18*n_long_bands;
1377  overlap += 9*n_long_bands;
1378  }
1379  if (block_type == DRMP3_SHORT_BLOCK_TYPE)
1380  drmp3_L3_imdct_short(grbuf, overlap, 32 - n_long_bands);
1381  else
1382  drmp3_L3_imdct36(grbuf, overlap, g_mdct_window[block_type == DRMP3_STOP_BLOCK_TYPE], 32 - n_long_bands);
1383 }
1384 
1385 static void drmp3_L3_save_reservoir(drmp3dec *h, drmp3dec_scratch *s)
1386 {
1387  int pos = (s->bs.pos + 7)/8u;
1388  int remains = s->bs.limit/8u - pos;
1389  if (remains > DRMP3_MAX_BITRESERVOIR_BYTES)
1390  {
1391  pos += remains - DRMP3_MAX_BITRESERVOIR_BYTES;
1392  remains = DRMP3_MAX_BITRESERVOIR_BYTES;
1393  }
1394  if (remains > 0)
1395  {
1396  memmove(h->reserv_buf, s->maindata + pos, remains);
1397  }
1398  h->reserv = remains;
1399 }
1400 
1401 static int drmp3_L3_restore_reservoir(drmp3dec *h, drmp3_bs *bs, drmp3dec_scratch *s, int main_data_begin)
1402 {
1403  int frame_bytes = (bs->limit - bs->pos)/8;
1404  int bytes_have = DRMP3_MIN(h->reserv, main_data_begin);
1405  memcpy(s->maindata, h->reserv_buf + DRMP3_MAX(0, h->reserv - main_data_begin), DRMP3_MIN(h->reserv, main_data_begin));
1406  memcpy(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes);
1407  drmp3_bs_init(&s->bs, s->maindata, bytes_have + frame_bytes);
1408  return h->reserv >= main_data_begin;
1409 }
1410 
1411 static void drmp3_L3_decode(drmp3dec *h, drmp3dec_scratch *s, drmp3_L3_gr_info *gr_info, int nch)
1412 {
1413  int ch;
1414 
1415  for (ch = 0; ch < nch; ch++)
1416  {
1417  int layer3gr_limit = s->bs.pos + gr_info[ch].part_23_length;
1418  drmp3_L3_decode_scalefactors(h->header, s->ist_pos[ch], &s->bs, gr_info + ch, s->scf, ch);
1419  drmp3_L3_huffman(s->grbuf[ch], &s->bs, gr_info + ch, s->scf, layer3gr_limit);
1420  }
1421 
1422  if (DRMP3_HDR_TEST_I_STEREO(h->header))
1423  {
1424  drmp3_L3_intensity_stereo(s->grbuf[0], s->ist_pos[1], gr_info, h->header);
1425  } else if (DRMP3_HDR_IS_MS_STEREO(h->header))
1426  {
1427  drmp3_L3_midside_stereo(s->grbuf[0], 576);
1428  }
1429 
1430  for (ch = 0; ch < nch; ch++, gr_info++)
1431  {
1432  int aa_bands = 31;
1433  int n_long_bands = (gr_info->mixed_block_flag ? 2 : 0) << (int)(DRMP3_HDR_GET_MY_SAMPLE_RATE(h->header) == 2);
1434 
1435  if (gr_info->n_short_sfb)
1436  {
1437  aa_bands = n_long_bands - 1;
1438  drmp3_L3_reorder(s->grbuf[ch] + n_long_bands*18, s->syn[0], gr_info->sfbtab + gr_info->n_long_sfb);
1439  }
1440 
1441  drmp3_L3_antialias(s->grbuf[ch], aa_bands);
1442  drmp3_L3_imdct_gr(s->grbuf[ch], h->mdct_overlap[ch], gr_info->block_type, n_long_bands);
1443  drmp3_L3_change_sign(s->grbuf[ch]);
1444  }
1445 }
1446 
1447 static void drmp3d_DCT_II(float *grbuf, int n)
1448 {
1449  static const float g_sec[24] = {
1450  10.19000816f,0.50060302f,0.50241929f,3.40760851f,0.50547093f,0.52249861f,2.05778098f,0.51544732f,0.56694406f,1.48416460f,0.53104258f,0.64682180f,1.16943991f,0.55310392f,0.78815460f,0.97256821f,0.58293498f,1.06067765f,0.83934963f,0.62250412f,1.72244716f,0.74453628f,0.67480832f,5.10114861f
1451  };
1452  int i, k = 0;
1453 #if DRMP3_HAVE_SIMD
1454  if (drmp3_have_simd()) for (; k < n; k += 4)
1455  {
1456  drmp3_f4 t[4][8], *x;
1457  float *y = grbuf + k;
1458 
1459  for (x = t[0], i = 0; i < 8; i++, x++)
1460  {
1461  drmp3_f4 x0 = DRMP3_VLD(&y[i*18]);
1462  drmp3_f4 x1 = DRMP3_VLD(&y[(15 - i)*18]);
1463  drmp3_f4 x2 = DRMP3_VLD(&y[(16 + i)*18]);
1464  drmp3_f4 x3 = DRMP3_VLD(&y[(31 - i)*18]);
1465  drmp3_f4 t0 = DRMP3_VADD(x0, x3);
1466  drmp3_f4 t1 = DRMP3_VADD(x1, x2);
1467  drmp3_f4 t2 = DRMP3_VMUL_S(DRMP3_VSUB(x1, x2), g_sec[3*i + 0]);
1468  drmp3_f4 t3 = DRMP3_VMUL_S(DRMP3_VSUB(x0, x3), g_sec[3*i + 1]);
1469  x[0] = DRMP3_VADD(t0, t1);
1470  x[8] = DRMP3_VMUL_S(DRMP3_VSUB(t0, t1), g_sec[3*i + 2]);
1471  x[16] = DRMP3_VADD(t3, t2);
1472  x[24] = DRMP3_VMUL_S(DRMP3_VSUB(t3, t2), g_sec[3*i + 2]);
1473  }
1474  for (x = t[0], i = 0; i < 4; i++, x += 8)
1475  {
1476  drmp3_f4 x0 = x[0], x1 = x[1], x2 = x[2], x3 = x[3], x4 = x[4], x5 = x[5], x6 = x[6], x7 = x[7], xt;
1477  xt = DRMP3_VSUB(x0, x7); x0 = DRMP3_VADD(x0, x7);
1478  x7 = DRMP3_VSUB(x1, x6); x1 = DRMP3_VADD(x1, x6);
1479  x6 = DRMP3_VSUB(x2, x5); x2 = DRMP3_VADD(x2, x5);
1480  x5 = DRMP3_VSUB(x3, x4); x3 = DRMP3_VADD(x3, x4);
1481  x4 = DRMP3_VSUB(x0, x3); x0 = DRMP3_VADD(x0, x3);
1482  x3 = DRMP3_VSUB(x1, x2); x1 = DRMP3_VADD(x1, x2);
1483  x[0] = DRMP3_VADD(x0, x1);
1484  x[4] = DRMP3_VMUL_S(DRMP3_VSUB(x0, x1), 0.70710677f);
1485  x5 = DRMP3_VADD(x5, x6);
1486  x6 = DRMP3_VMUL_S(DRMP3_VADD(x6, x7), 0.70710677f);
1487  x7 = DRMP3_VADD(x7, xt);
1488  x3 = DRMP3_VMUL_S(DRMP3_VADD(x3, x4), 0.70710677f);
1489  x5 = DRMP3_VSUB(x5, DRMP3_VMUL_S(x7, 0.198912367f)); /* rotate by PI/8 */
1490  x7 = DRMP3_VADD(x7, DRMP3_VMUL_S(x5, 0.382683432f));
1491  x5 = DRMP3_VSUB(x5, DRMP3_VMUL_S(x7, 0.198912367f));
1492  x0 = DRMP3_VSUB(xt, x6); xt = DRMP3_VADD(xt, x6);
1493  x[1] = DRMP3_VMUL_S(DRMP3_VADD(xt, x7), 0.50979561f);
1494  x[2] = DRMP3_VMUL_S(DRMP3_VADD(x4, x3), 0.54119611f);
1495  x[3] = DRMP3_VMUL_S(DRMP3_VSUB(x0, x5), 0.60134488f);
1496  x[5] = DRMP3_VMUL_S(DRMP3_VADD(x0, x5), 0.89997619f);
1497  x[6] = DRMP3_VMUL_S(DRMP3_VSUB(x4, x3), 1.30656302f);
1498  x[7] = DRMP3_VMUL_S(DRMP3_VSUB(xt, x7), 2.56291556f);
1499  }
1500 
1501  if (k > n - 3)
1502  {
1503 #if DRMP3_HAVE_SSE
1504 #define DRMP3_VSAVE2(i, v) _mm_storel_pi((__m64 *)(void*)&y[i*18], v)
1505 #else
1506 #define DRMP3_VSAVE2(i, v) vst1_f32((float32_t *)&y[i*18], vget_low_f32(v))
1507 #endif
1508  for (i = 0; i < 7; i++, y += 4*18)
1509  {
1510  drmp3_f4 s = DRMP3_VADD(t[3][i], t[3][i + 1]);
1511  DRMP3_VSAVE2(0, t[0][i]);
1512  DRMP3_VSAVE2(1, DRMP3_VADD(t[2][i], s));
1513  DRMP3_VSAVE2(2, DRMP3_VADD(t[1][i], t[1][i + 1]));
1514  DRMP3_VSAVE2(3, DRMP3_VADD(t[2][1 + i], s));
1515  }
1516  DRMP3_VSAVE2(0, t[0][7]);
1517  DRMP3_VSAVE2(1, DRMP3_VADD(t[2][7], t[3][7]));
1518  DRMP3_VSAVE2(2, t[1][7]);
1519  DRMP3_VSAVE2(3, t[3][7]);
1520  } else
1521  {
1522 #define DRMP3_VSAVE4(i, v) DRMP3_VSTORE(&y[i*18], v)
1523  for (i = 0; i < 7; i++, y += 4*18)
1524  {
1525  drmp3_f4 s = DRMP3_VADD(t[3][i], t[3][i + 1]);
1526  DRMP3_VSAVE4(0, t[0][i]);
1527  DRMP3_VSAVE4(1, DRMP3_VADD(t[2][i], s));
1528  DRMP3_VSAVE4(2, DRMP3_VADD(t[1][i], t[1][i + 1]));
1529  DRMP3_VSAVE4(3, DRMP3_VADD(t[2][1 + i], s));
1530  }
1531  DRMP3_VSAVE4(0, t[0][7]);
1532  DRMP3_VSAVE4(1, DRMP3_VADD(t[2][7], t[3][7]));
1533  DRMP3_VSAVE4(2, t[1][7]);
1534  DRMP3_VSAVE4(3, t[3][7]);
1535  }
1536  } else
1537 #endif
1538 #ifdef DR_MP3_ONLY_SIMD
1539  {}
1540 #else
1541  for (; k < n; k++)
1542  {
1543  float t[4][8], *x, *y = grbuf + k;
1544 
1545  for (x = t[0], i = 0; i < 8; i++, x++)
1546  {
1547  float x0 = y[i*18];
1548  float x1 = y[(15 - i)*18];
1549  float x2 = y[(16 + i)*18];
1550  float x3 = y[(31 - i)*18];
1551  float t0 = x0 + x3;
1552  float t1 = x1 + x2;
1553  float t2 = (x1 - x2)*g_sec[3*i + 0];
1554  float t3 = (x0 - x3)*g_sec[3*i + 1];
1555  x[0] = t0 + t1;
1556  x[8] = (t0 - t1)*g_sec[3*i + 2];
1557  x[16] = t3 + t2;
1558  x[24] = (t3 - t2)*g_sec[3*i + 2];
1559  }
1560  for (x = t[0], i = 0; i < 4; i++, x += 8)
1561  {
1562  float x0 = x[0], x1 = x[1], x2 = x[2], x3 = x[3], x4 = x[4], x5 = x[5], x6 = x[6], x7 = x[7], xt;
1563  xt = x0 - x7; x0 += x7;
1564  x7 = x1 - x6; x1 += x6;
1565  x6 = x2 - x5; x2 += x5;
1566  x5 = x3 - x4; x3 += x4;
1567  x4 = x0 - x3; x0 += x3;
1568  x3 = x1 - x2; x1 += x2;
1569  x[0] = x0 + x1;
1570  x[4] = (x0 - x1)*0.70710677f;
1571  x5 = x5 + x6;
1572  x6 = (x6 + x7)*0.70710677f;
1573  x7 = x7 + xt;
1574  x3 = (x3 + x4)*0.70710677f;
1575  x5 -= x7*0.198912367f; /* rotate by PI/8 */
1576  x7 += x5*0.382683432f;
1577  x5 -= x7*0.198912367f;
1578  x0 = xt - x6; xt += x6;
1579  x[1] = (xt + x7)*0.50979561f;
1580  x[2] = (x4 + x3)*0.54119611f;
1581  x[3] = (x0 - x5)*0.60134488f;
1582  x[5] = (x0 + x5)*0.89997619f;
1583  x[6] = (x4 - x3)*1.30656302f;
1584  x[7] = (xt - x7)*2.56291556f;
1585 
1586  }
1587  for (i = 0; i < 7; i++, y += 4*18)
1588  {
1589  y[0*18] = t[0][i];
1590  y[1*18] = t[2][i] + t[3][i] + t[3][i + 1];
1591  y[2*18] = t[1][i] + t[1][i + 1];
1592  y[3*18] = t[2][i + 1] + t[3][i] + t[3][i + 1];
1593  }
1594  y[0*18] = t[0][7];
1595  y[1*18] = t[2][7] + t[3][7];
1596  y[2*18] = t[1][7];
1597  y[3*18] = t[3][7];
1598  }
1599 #endif
1600 }
1601 
1602 static short drmp3d_scale_pcm(float sample)
1603 {
1604  int s;
1605  if (sample > 32767.0) return (short) 32767;
1606  if (sample < -32768.0) return (short)-32768;
1607  s = (int)(sample + .5f);
1608  s -= (s < 0); /* away from zero, to be compliant */
1609  if (s > 32767) return (short) 32767;
1610  if (s < -32768) return (short)-32768;
1611  return (short)s;
1612 }
1613 
1614 static void drmp3d_synth_pair(short *pcm, int nch, const float *z)
1615 {
1616  float a;
1617  a = (z[14*64] - z[ 0]) * 29;
1618  a += (z[ 1*64] + z[13*64]) * 213;
1619  a += (z[12*64] - z[ 2*64]) * 459;
1620  a += (z[ 3*64] + z[11*64]) * 2037;
1621  a += (z[10*64] - z[ 4*64]) * 5153;
1622  a += (z[ 5*64] + z[ 9*64]) * 6574;
1623  a += (z[ 8*64] - z[ 6*64]) * 37489;
1624  a += z[ 7*64] * 75038;
1625  pcm[0] = drmp3d_scale_pcm(a);
1626 
1627  z += 2;
1628  a = z[14*64] * 104;
1629  a += z[12*64] * 1567;
1630  a += z[10*64] * 9727;
1631  a += z[ 8*64] * 64019;
1632  a += z[ 6*64] * -9975;
1633  a += z[ 4*64] * -45;
1634  a += z[ 2*64] * 146;
1635  a += z[ 0*64] * -5;
1636  pcm[16*nch] = drmp3d_scale_pcm(a);
1637 }
1638 
1639 static void drmp3d_synth(float *xl, short *dstl, int nch, float *lins)
1640 {
1641  int i;
1642  float *xr = xl + 576*(nch - 1);
1643  short *dstr = dstl + (nch - 1);
1644 
1645  static const float g_win[] = {
1646  -1,26,-31,208,218,401,-519,2063,2000,4788,-5517,7134,5959,35640,-39336,74992,
1647  -1,24,-35,202,222,347,-581,2080,1952,4425,-5879,7640,5288,33791,-41176,74856,
1648  -1,21,-38,196,225,294,-645,2087,1893,4063,-6237,8092,4561,31947,-43006,74630,
1649  -1,19,-41,190,227,244,-711,2085,1822,3705,-6589,8492,3776,30112,-44821,74313,
1650  -1,17,-45,183,228,197,-779,2075,1739,3351,-6935,8840,2935,28289,-46617,73908,
1651  -1,16,-49,176,228,153,-848,2057,1644,3004,-7271,9139,2037,26482,-48390,73415,
1652  -2,14,-53,169,227,111,-919,2032,1535,2663,-7597,9389,1082,24694,-50137,72835,
1653  -2,13,-58,161,224,72,-991,2001,1414,2330,-7910,9592,70,22929,-51853,72169,
1654  -2,11,-63,154,221,36,-1064,1962,1280,2006,-8209,9750,-998,21189,-53534,71420,
1655  -2,10,-68,147,215,2,-1137,1919,1131,1692,-8491,9863,-2122,19478,-55178,70590,
1656  -3,9,-73,139,208,-29,-1210,1870,970,1388,-8755,9935,-3300,17799,-56778,69679,
1657  -3,8,-79,132,200,-57,-1283,1817,794,1095,-8998,9966,-4533,16155,-58333,68692,
1658  -4,7,-85,125,189,-83,-1356,1759,605,814,-9219,9959,-5818,14548,-59838,67629,
1659  -4,7,-91,117,177,-106,-1428,1698,402,545,-9416,9916,-7154,12980,-61289,66494,
1660  -5,6,-97,111,163,-127,-1498,1634,185,288,-9585,9838,-8540,11455,-62684,65290
1661  };
1662  float *zlin = lins + 15*64;
1663  const float *w = g_win;
1664 
1665  zlin[4*15] = xl[18*16];
1666  zlin[4*15 + 1] = xr[18*16];
1667  zlin[4*15 + 2] = xl[0];
1668  zlin[4*15 + 3] = xr[0];
1669 
1670  zlin[4*31] = xl[1 + 18*16];
1671  zlin[4*31 + 1] = xr[1 + 18*16];
1672  zlin[4*31 + 2] = xl[1];
1673  zlin[4*31 + 3] = xr[1];
1674 
1675  drmp3d_synth_pair(dstr, nch, lins + 4*15 + 1);
1676  drmp3d_synth_pair(dstr + 32*nch, nch, lins + 4*15 + 64 + 1);
1677  drmp3d_synth_pair(dstl, nch, lins + 4*15);
1678  drmp3d_synth_pair(dstl + 32*nch, nch, lins + 4*15 + 64);
1679 
1680 #if DRMP3_HAVE_SIMD
1681  if (drmp3_have_simd()) for (i = 14; i >= 0; i--)
1682  {
1683 #define DRMP3_VLOAD(k) drmp3_f4 w0 = DRMP3_VSET(*w++); drmp3_f4 w1 = DRMP3_VSET(*w++); drmp3_f4 vz = DRMP3_VLD(&zlin[4*i - 64*k]); drmp3_f4 vy = DRMP3_VLD(&zlin[4*i - 64*(15 - k)]);
1684 #define DRMP3_V0(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0)) ; a = DRMP3_VSUB(DRMP3_VMUL(vz, w0), DRMP3_VMUL(vy, w1)); }
1685 #define DRMP3_V1(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(b, DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0))); a = DRMP3_VADD(a, DRMP3_VSUB(DRMP3_VMUL(vz, w0), DRMP3_VMUL(vy, w1))); }
1686 #define DRMP3_V2(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(b, DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0))); a = DRMP3_VADD(a, DRMP3_VSUB(DRMP3_VMUL(vy, w1), DRMP3_VMUL(vz, w0))); }
1687  drmp3_f4 a, b;
1688  zlin[4*i] = xl[18*(31 - i)];
1689  zlin[4*i + 1] = xr[18*(31 - i)];
1690  zlin[4*i + 2] = xl[1 + 18*(31 - i)];
1691  zlin[4*i + 3] = xr[1 + 18*(31 - i)];
1692  zlin[4*i + 64] = xl[1 + 18*(1 + i)];
1693  zlin[4*i + 64 + 1] = xr[1 + 18*(1 + i)];
1694  zlin[4*i - 64 + 2] = xl[18*(1 + i)];
1695  zlin[4*i - 64 + 3] = xr[18*(1 + i)];
1696 
1697  DRMP3_V0(0) DRMP3_V2(1) DRMP3_V1(2) DRMP3_V2(3) DRMP3_V1(4) DRMP3_V2(5) DRMP3_V1(6) DRMP3_V2(7)
1698 
1699  {
1700 #if DRMP3_HAVE_SSE
1701  static const drmp3_f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f };
1702  static const drmp3_f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f };
1703  __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, g_max), g_min)),
1704  _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, g_max), g_min)));
1705  dstr[(15 - i)*nch] = (short)_mm_extract_epi16(pcm8, 1);
1706  dstr[(17 + i)*nch] = (short)_mm_extract_epi16(pcm8, 5);
1707  dstl[(15 - i)*nch] = (short)_mm_extract_epi16(pcm8, 0);
1708  dstl[(17 + i)*nch] = (short)_mm_extract_epi16(pcm8, 4);
1709  dstr[(47 - i)*nch] = (short)_mm_extract_epi16(pcm8, 3);
1710  dstr[(49 + i)*nch] = (short)_mm_extract_epi16(pcm8, 7);
1711  dstl[(47 - i)*nch] = (short)_mm_extract_epi16(pcm8, 2);
1712  dstl[(49 + i)*nch] = (short)_mm_extract_epi16(pcm8, 6);
1713 #else
1714  int16x4_t pcma, pcmb;
1715  a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
1716  b = DRMP3_VADD(b, DRMP3_VSET(0.5f));
1717  pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, DRMP3_VSET(0)))));
1718  pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, DRMP3_VSET(0)))));
1719  vst1_lane_s16(dstr + (15 - i)*nch, pcma, 1);
1720  vst1_lane_s16(dstr + (17 + i)*nch, pcmb, 1);
1721  vst1_lane_s16(dstl + (15 - i)*nch, pcma, 0);
1722  vst1_lane_s16(dstl + (17 + i)*nch, pcmb, 0);
1723  vst1_lane_s16(dstr + (47 - i)*nch, pcma, 3);
1724  vst1_lane_s16(dstr + (49 + i)*nch, pcmb, 3);
1725  vst1_lane_s16(dstl + (47 - i)*nch, pcma, 2);
1726  vst1_lane_s16(dstl + (49 + i)*nch, pcmb, 2);
1727 #endif
1728  }
1729  } else
1730 #endif
1731 #ifdef DR_MP3_ONLY_SIMD
1732  {}
1733 #else
1734  for (i = 14; i >= 0; i--)
1735  {
1736 #define DRMP3_LOAD(k) float w0 = *w++; float w1 = *w++; float *vz = &zlin[4*i - k*64]; float *vy = &zlin[4*i - (15 - k)*64];
1737 #define DRMP3_S0(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] = vz[j]*w1 + vy[j]*w0, a[j] = vz[j]*w0 - vy[j]*w1; }
1738 #define DRMP3_S1(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vz[j]*w0 - vy[j]*w1; }
1739 #define DRMP3_S2(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vy[j]*w1 - vz[j]*w0; }
1740  float a[4], b[4];
1741 
1742  zlin[4*i] = xl[18*(31 - i)];
1743  zlin[4*i + 1] = xr[18*(31 - i)];
1744  zlin[4*i + 2] = xl[1 + 18*(31 - i)];
1745  zlin[4*i + 3] = xr[1 + 18*(31 - i)];
1746  zlin[4*(i + 16)] = xl[1 + 18*(1 + i)];
1747  zlin[4*(i + 16) + 1] = xr[1 + 18*(1 + i)];
1748  zlin[4*(i - 16) + 2] = xl[18*(1 + i)];
1749  zlin[4*(i - 16) + 3] = xr[18*(1 + i)];
1750 
1751  DRMP3_S0(0) DRMP3_S2(1) DRMP3_S1(2) DRMP3_S2(3) DRMP3_S1(4) DRMP3_S2(5) DRMP3_S1(6) DRMP3_S2(7)
1752 
1753  dstr[(15 - i)*nch] = drmp3d_scale_pcm(a[1]);
1754  dstr[(17 + i)*nch] = drmp3d_scale_pcm(b[1]);
1755  dstl[(15 - i)*nch] = drmp3d_scale_pcm(a[0]);
1756  dstl[(17 + i)*nch] = drmp3d_scale_pcm(b[0]);
1757  dstr[(47 - i)*nch] = drmp3d_scale_pcm(a[3]);
1758  dstr[(49 + i)*nch] = drmp3d_scale_pcm(b[3]);
1759  dstl[(47 - i)*nch] = drmp3d_scale_pcm(a[2]);
1760  dstl[(49 + i)*nch] = drmp3d_scale_pcm(b[2]);
1761  }
1762 #endif
1763 }
1764 
1765 static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int nch, short *pcm, float *lins)
1766 {
1767  int i;
1768  for (i = 0; i < nch; i++)
1769  {
1770  drmp3d_DCT_II(grbuf + 576*i, nbands);
1771  }
1772 
1773  memcpy(lins, qmf_state, sizeof(float)*15*64);
1774 
1775  for (i = 0; i < nbands; i += 2)
1776  {
1777  drmp3d_synth(grbuf + i, pcm + 32*nch*i, nch, lins + i*64);
1778  }
1779 #ifndef DR_MP3_NONSTANDARD_BUT_LOGICAL
1780  if (nch == 1)
1781  {
1782  for (i = 0; i < 15*64; i += 2)
1783  {
1784  qmf_state[i] = lins[nbands*64 + i];
1785  }
1786  } else
1787 #endif
1788  {
1789  memcpy(qmf_state, lins + nbands*64, sizeof(float)*15*64);
1790  }
1791 }
1792 
1793 static int drmp3d_match_frame(const drmp3_uint8 *hdr, int mp3_bytes, int frame_bytes)
1794 {
1795  int i, nmatch;
1796  for (i = 0, nmatch = 0; nmatch < DRMP3_MAX_FRAME_SYNC_MATCHES; nmatch++)
1797  {
1798  i += drmp3_hdr_frame_bytes(hdr + i, frame_bytes) + drmp3_hdr_padding(hdr + i);
1799  if (i + DRMP3_HDR_SIZE > mp3_bytes)
1800  return nmatch > 0;
1801  if (!drmp3_hdr_compare(hdr, hdr + i))
1802  return 0;
1803  }
1804  return 1;
1805 }
1806 
1807 static int drmp3d_find_frame(const drmp3_uint8 *mp3, int mp3_bytes, int *free_format_bytes, int *ptr_frame_bytes)
1808 {
1809  int i, k;
1810  for (i = 0; i < mp3_bytes - DRMP3_HDR_SIZE; i++, mp3++)
1811  {
1812  if (drmp3_hdr_valid(mp3))
1813  {
1814  int frame_bytes = drmp3_hdr_frame_bytes(mp3, *free_format_bytes);
1815  int frame_and_padding = frame_bytes + drmp3_hdr_padding(mp3);
1816 
1817  for (k = DRMP3_HDR_SIZE; !frame_bytes && k < DRMP3_MAX_FREE_FORMAT_FRAME_SIZE && i + 2*k < mp3_bytes - DRMP3_HDR_SIZE; k++)
1818  {
1819  if (drmp3_hdr_compare(mp3, mp3 + k))
1820  {
1821  int fb = k - drmp3_hdr_padding(mp3);
1822  int nextfb = fb + drmp3_hdr_padding(mp3 + k);
1823  if (i + k + nextfb + DRMP3_HDR_SIZE > mp3_bytes || !drmp3_hdr_compare(mp3, mp3 + k + nextfb))
1824  continue;
1825  frame_and_padding = k;
1826  frame_bytes = fb;
1827  *free_format_bytes = fb;
1828  }
1829  }
1830 
1831  if ((frame_bytes && i + frame_and_padding <= mp3_bytes &&
1832  drmp3d_match_frame(mp3, mp3_bytes - i, frame_bytes)) ||
1833  (!i && frame_and_padding == mp3_bytes))
1834  {
1835  *ptr_frame_bytes = frame_and_padding;
1836  return i;
1837  }
1838  *free_format_bytes = 0;
1839  }
1840  }
1841  *ptr_frame_bytes = 0;
1842  return i;
1843 }
1844 
1845 void drmp3dec_init(drmp3dec *dec)
1846 {
1847  dec->header[0] = 0;
1848 }
1849 
1850 int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes, short *pcm, drmp3dec_frame_info *info)
1851 {
1852  int i = 0, igr, frame_size = 0, success = 1;
1853  const drmp3_uint8 *hdr;
1854  drmp3_bs bs_frame[1];
1855  drmp3dec_scratch scratch;
1856 
1857  if (mp3_bytes > 4 && dec->header[0] == 0xff && drmp3_hdr_compare(dec->header, mp3))
1858  {
1859  frame_size = drmp3_hdr_frame_bytes(mp3, dec->free_format_bytes) + drmp3_hdr_padding(mp3);
1860  if (frame_size != mp3_bytes && (frame_size + DRMP3_HDR_SIZE > mp3_bytes || !drmp3_hdr_compare(mp3, mp3 + frame_size)))
1861  {
1862  frame_size = 0;
1863  }
1864  }
1865  if (!frame_size)
1866  {
1867  memset(dec, 0, sizeof(drmp3dec));
1868  i = drmp3d_find_frame(mp3, mp3_bytes, &dec->free_format_bytes, &frame_size);
1869  if (!frame_size || i + frame_size > mp3_bytes)
1870  {
1871  info->frame_bytes = i;
1872  return 0;
1873  }
1874  }
1875 
1876  hdr = mp3 + i;
1877  memcpy(dec->header, hdr, DRMP3_HDR_SIZE);
1878  info->frame_bytes = i + frame_size;
1879  info->channels = DRMP3_HDR_IS_MONO(hdr) ? 1 : 2;
1880  info->hz = drmp3_hdr_sample_rate_hz(hdr);
1881  info->layer = 4 - DRMP3_HDR_GET_LAYER(hdr);
1882  info->bitrate_kbps = drmp3_hdr_bitrate_kbps(hdr);
1883 
1884  drmp3_bs_init(bs_frame, hdr + DRMP3_HDR_SIZE, frame_size - DRMP3_HDR_SIZE);
1885  if (DRMP3_HDR_IS_CRC(hdr))
1886  {
1887  drmp3_bs_get_bits(bs_frame, 16);
1888  }
1889 
1890  if (info->layer == 3)
1891  {
1892  int main_data_begin = drmp3_L3_read_side_info(bs_frame, scratch.gr_info, hdr);
1893  if (main_data_begin < 0 || bs_frame->pos > bs_frame->limit)
1894  {
1895  drmp3dec_init(dec);
1896  return 0;
1897  }
1898  success = drmp3_L3_restore_reservoir(dec, bs_frame, &scratch, main_data_begin);
1899  if (success)
1900  {
1901  for (igr = 0; igr < (DRMP3_HDR_TEST_MPEG1(hdr) ? 2 : 1); igr++, pcm += 576*info->channels)
1902  {
1903  memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
1904  drmp3_L3_decode(dec, &scratch, scratch.gr_info + igr*info->channels, info->channels);
1905  drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 18, info->channels, pcm, scratch.syn[0]);
1906  }
1907  }
1908  drmp3_L3_save_reservoir(dec, &scratch);
1909  } else
1910  {
1911 #ifdef DR_MP3_ONLY_MP3
1912  return 0;
1913 #else
1914  drmp3_L12_scale_info sci[1];
1915  drmp3_L12_read_scale_info(hdr, bs_frame, sci);
1916 
1917  memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
1918  for (i = 0, igr = 0; igr < 3; igr++)
1919  {
1920  if (12 == (i += drmp3_L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci, info->layer | 1)))
1921  {
1922  i = 0;
1923  drmp3_L12_apply_scf_384(sci, sci->scf + igr, scratch.grbuf[0]);
1924  drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 12, info->channels, pcm, scratch.syn[0]);
1925  memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
1926  pcm += 384*info->channels;
1927  }
1928  if (bs_frame->pos > bs_frame->limit)
1929  {
1930  drmp3dec_init(dec);
1931  return 0;
1932  }
1933  }
1934 #endif
1935  }
1936  return success*drmp3_hdr_frame_samples(dec->header);
1937 }
1938 
1939 
1940 
1941 
1942 /*
1943  *
1944  * Main Public API
1945  *
1946  */
1947 
1948 /* Options. */
1949 #ifndef DR_MP3_DEFAULT_CHANNELS
1950 #define DR_MP3_DEFAULT_CHANNELS 2
1951 #endif
1952 #ifndef DR_MP3_DEFAULT_SAMPLE_RATE
1953 #define DR_MP3_DEFAULT_SAMPLE_RATE 44100
1954 #endif
1955 
1956 /* Standard library stuff. */
1957 #ifndef DRMP3_ASSERT
1958 #include <assert.h>
1959 #define DRMP3_ASSERT(expression) assert(expression)
1960 #endif
1961 #ifndef DRMP3_COPY_MEMORY
1962 #define DRMP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
1963 #endif
1964 #ifndef DRMP3_ZERO_MEMORY
1965 #define DRMP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
1966 #endif
1967 #define DRMP3_ZERO_OBJECT(p) DRMP3_ZERO_MEMORY((p), sizeof(*(p)))
1968 #ifndef DRMP3_MALLOC
1969 #define DRMP3_MALLOC(sz) malloc((sz))
1970 #endif
1971 #ifndef DRMP3_REALLOC
1972 #define DRMP3_REALLOC(p, sz) realloc((p), (sz))
1973 #endif
1974 #ifndef DRMP3_FREE
1975 #define DRMP3_FREE(p) free((p))
1976 #endif
1977 
1978 #define drmp3_assert DRMP3_ASSERT
1979 #define drmp3_copy_memory DRMP3_COPY_MEMORY
1980 #define drmp3_zero_memory DRMP3_ZERO_MEMORY
1981 #define drmp3_zero_object DRMP3_ZERO_OBJECT
1982 #define drmp3_malloc DRMP3_MALLOC
1983 #define drmp3_realloc DRMP3_REALLOC
1984 
1985 #define drmp3_countof(x) (sizeof(x) / sizeof(x[0]))
1986 #define drmp3_max(x, y) (((x) > (y)) ? (x) : (y))
1987 #define drmp3_min(x, y) (((x) < (y)) ? (x) : (y))
1988 
1989 #define DRMP3_DATA_CHUNK_SIZE 16384 /* The size in bytes of each chunk of data to read from the MP3 stream. minimp3 recommends 16K. */
1990 
1991 static INLINE float drmp3_mix_f32(float x, float y, float a)
1992 {
1993  return x*(1-a) + y*a;
1994 }
1995 
1996 static void drmp3_blend_f32(float* pOut, float* pInA, float* pInB, float factor, drmp3_uint32 channels)
1997 {
1998  uint32_t i;
1999  for (i = 0; i < channels; ++i)
2000  pOut[i] = drmp3_mix_f32(pInA[i], pInB[i], factor);
2001 }
2002 
2003 void drmp3_src_cache_init(drmp3_src* pSRC, drmp3_src_cache* pCache)
2004 {
2005  drmp3_assert(pSRC != NULL);
2006  drmp3_assert(pCache != NULL);
2007 
2008  pCache->pSRC = pSRC;
2009  pCache->cachedFrameCount = 0;
2010  pCache->iNextFrame = 0;
2011 }
2012 
2013 drmp3_uint64 drmp3_src_cache_read_frames(drmp3_src_cache* pCache, drmp3_uint64 frameCount, float* pFramesOut)
2014 {
2015  drmp3_uint32 channels;
2016  drmp3_uint64 totalFramesRead = 0;
2017 
2018  drmp3_assert(pCache != NULL);
2019  drmp3_assert(pCache->pSRC != NULL);
2020  drmp3_assert(pCache->pSRC->onRead != NULL);
2021  drmp3_assert(frameCount > 0);
2022  drmp3_assert(pFramesOut != NULL);
2023 
2024  channels = pCache->pSRC->config.channels;
2025 
2026  while (frameCount > 0)
2027  {
2028  drmp3_uint32 framesToReadFromClient;
2029  /* If there's anything in memory go ahead and copy that over first. */
2030  drmp3_uint64 framesRemainingInMemory = pCache->cachedFrameCount - pCache->iNextFrame;
2031  drmp3_uint64 framesToReadFromMemory = frameCount;
2032  if (framesToReadFromMemory > framesRemainingInMemory)
2033  framesToReadFromMemory = framesRemainingInMemory;
2034 
2035  drmp3_copy_memory(pFramesOut, pCache->pCachedFrames + pCache->iNextFrame*channels, (drmp3_uint32)(framesToReadFromMemory * channels * sizeof(float)));
2036  pCache->iNextFrame += (drmp3_uint32)framesToReadFromMemory;
2037 
2038  totalFramesRead += framesToReadFromMemory;
2039  frameCount -= framesToReadFromMemory;
2040  if (frameCount == 0)
2041  break;
2042 
2043 
2044  /* At this point there are still more frames to read from the client, so we'll need to reload the cache with fresh data. */
2045  drmp3_assert(frameCount > 0);
2046  pFramesOut += framesToReadFromMemory * channels;
2047 
2048  pCache->iNextFrame = 0;
2049  pCache->cachedFrameCount = 0;
2050 
2051  framesToReadFromClient = drmp3_countof(pCache->pCachedFrames) / pCache->pSRC->config.channels;
2052  if (framesToReadFromClient > pCache->pSRC->config.cacheSizeInFrames)
2053  framesToReadFromClient = pCache->pSRC->config.cacheSizeInFrames;
2054 
2055  pCache->cachedFrameCount = (drmp3_uint32)pCache->pSRC->onRead(pCache->pSRC, framesToReadFromClient, pCache->pCachedFrames, pCache->pSRC->pUserData);
2056 
2057 
2058  /* Get out of this loop if nothing was able to be retrieved. */
2059  if (pCache->cachedFrameCount == 0)
2060  break;
2061  }
2062 
2063  return totalFramesRead;
2064 }
2065 
2066 
2067 drmp3_uint64 drmp3_src_read_frames_passthrough(drmp3_src* pSRC, drmp3_uint64 frameCount, void* pFramesOut, drmp3_bool32 flush);
2068 drmp3_uint64 drmp3_src_read_frames_linear(drmp3_src* pSRC, drmp3_uint64 frameCount, void* pFramesOut, drmp3_bool32 flush);
2069 
2070 drmp3_bool32 drmp3_src_init(const drmp3_src_config* pConfig, drmp3_src_read_proc onRead, void* pUserData, drmp3_src* pSRC)
2071 {
2072  if (pSRC == NULL) return DRMP3_FALSE;
2073  drmp3_zero_object(pSRC);
2074 
2075  if (pConfig == NULL || onRead == NULL) return DRMP3_FALSE;
2076  if (pConfig->channels == 0 || pConfig->channels > 2) return DRMP3_FALSE;
2077 
2078  pSRC->config = *pConfig;
2079  pSRC->onRead = onRead;
2080  pSRC->pUserData = pUserData;
2081 
2084 
2085  drmp3_src_cache_init(pSRC, &pSRC->cache);
2086  return DRMP3_TRUE;
2087 }
2088 
2089 drmp3_bool32 drmp3_src_set_input_sample_rate(drmp3_src* pSRC, drmp3_uint32 sampleRateIn)
2090 {
2091  if (pSRC == NULL) return DRMP3_FALSE;
2092 
2093  /* Must have a sample rate of > 0. */
2094  if (sampleRateIn == 0)
2095  return DRMP3_FALSE;
2096 
2097  pSRC->config.sampleRateIn = sampleRateIn;
2098  return DRMP3_TRUE;
2099 }
2100 
2101 drmp3_bool32 drmp3_src_set_output_sample_rate(drmp3_src* pSRC, drmp3_uint32 sampleRateOut)
2102 {
2103  if (pSRC == NULL) return DRMP3_FALSE;
2104 
2105  /* Must have a sample rate of > 0. */
2106  if (sampleRateOut == 0)
2107  return DRMP3_FALSE;
2108 
2109  pSRC->config.sampleRateOut = sampleRateOut;
2110  return DRMP3_TRUE;
2111 }
2112 
2113 drmp3_uint64 drmp3_src_read_frames_ex(drmp3_src* pSRC, drmp3_uint64 frameCount, void* pFramesOut, drmp3_bool32 flush)
2114 {
2115  drmp3_src_algorithm algorithm;
2116  if (pSRC == NULL || frameCount == 0 || pFramesOut == NULL) return 0;
2117 
2118  algorithm = pSRC->config.algorithm;
2119 
2120  /* Always use passthrough if the sample rates are the same. */
2121  if (pSRC->config.sampleRateIn == pSRC->config.sampleRateOut)
2122  algorithm = drmp3_src_algorithm_none;
2123 
2124  /* Could just use a function pointer instead of a switch for this... */
2125  switch (algorithm)
2126  {
2127  case drmp3_src_algorithm_none: return drmp3_src_read_frames_passthrough(pSRC, frameCount, pFramesOut, flush);
2128  case drmp3_src_algorithm_linear: return drmp3_src_read_frames_linear(pSRC, frameCount, pFramesOut, flush);
2129  default: return 0;
2130  }
2131 }
2132 
2133 drmp3_uint64 drmp3_src_read_frames(drmp3_src* pSRC, drmp3_uint64 frameCount, void* pFramesOut)
2134 {
2135  return drmp3_src_read_frames_ex(pSRC, frameCount, pFramesOut, DRMP3_FALSE);
2136 }
2137 
2138 drmp3_uint64 drmp3_src_read_frames_passthrough(drmp3_src* pSRC, drmp3_uint64 frameCount, void* pFramesOut, drmp3_bool32 flush)
2139 {
2140  drmp3_assert(pSRC != NULL);
2141  drmp3_assert(frameCount > 0);
2142  drmp3_assert(pFramesOut != NULL);
2143 
2144  (void)flush; /* Passthrough need not care about flushing. */
2145  return pSRC->onRead(pSRC, frameCount, pFramesOut, pSRC->pUserData);
2146 }
2147 
2148 drmp3_uint64 drmp3_src_read_frames_linear(drmp3_src* pSRC, drmp3_uint64 frameCount, void* pFramesOut, drmp3_bool32 flush)
2149 {
2150  float factor;
2151  drmp3_uint64 totalFramesRead = 0;
2152 
2153  drmp3_assert(pSRC != NULL);
2154  drmp3_assert(frameCount > 0);
2155  drmp3_assert(pFramesOut != NULL);
2156 
2157  /* For linear SRC, the bin is only 2 frames: 1 prior, 1 future. */
2158 
2159  /* Load the bin if necessary. */
2160  if (!pSRC->algo.linear.isPrevFramesLoaded)
2161  {
2162  drmp3_uint64 framesRead = drmp3_src_cache_read_frames(&pSRC->cache, 1, pSRC->bin);
2163  if (framesRead == 0)
2164  return 0;
2165  pSRC->algo.linear.isPrevFramesLoaded = DRMP3_TRUE;
2166  }
2167  if (!pSRC->algo.linear.isNextFramesLoaded)
2168  {
2169  drmp3_uint64 framesRead = drmp3_src_cache_read_frames(&pSRC->cache, 1, pSRC->bin + pSRC->config.channels);
2170  if (framesRead == 0)
2171  return 0;
2172  pSRC->algo.linear.isNextFramesLoaded = DRMP3_TRUE;
2173  }
2174 
2175  factor = (float)pSRC->config.sampleRateIn / pSRC->config.sampleRateOut;
2176 
2177  while (frameCount > 0)
2178  {
2179  drmp3_uint32 i;
2180  drmp3_uint32 framesToReadFromClient;
2181  /* The bin is where the previous and next frames are located. */
2182  float* pPrevFrame = pSRC->bin;
2183  float* pNextFrame = pSRC->bin + pSRC->config.channels;
2184 
2185  drmp3_blend_f32((float*)pFramesOut, pPrevFrame, pNextFrame, pSRC->algo.linear.alpha, pSRC->config.channels);
2186 
2187  pSRC->algo.linear.alpha += factor;
2188 
2189  /* The new alpha value is how we determine whether or not we need to read fresh frames. */
2190  framesToReadFromClient = (drmp3_uint32)pSRC->algo.linear.alpha;
2191  pSRC->algo.linear.alpha = pSRC->algo.linear.alpha - framesToReadFromClient;
2192 
2193  for (i = 0; i < framesToReadFromClient; ++i)
2194  {
2195  drmp3_uint32 j;
2196  drmp3_uint64 framesRead;
2197  for (j = 0; j < pSRC->config.channels; ++j)
2198  pPrevFrame[j] = pNextFrame[j];
2199 
2200  framesRead = drmp3_src_cache_read_frames(&pSRC->cache, 1, pNextFrame);
2201  if (framesRead == 0)
2202  {
2203  drmp3_uint32 j;
2204  for (j = 0; j < pSRC->config.channels; ++j)
2205  pNextFrame[j] = 0;
2206 
2207  if (pSRC->algo.linear.isNextFramesLoaded)
2208  pSRC->algo.linear.isNextFramesLoaded = DRMP3_FALSE;
2209  else
2210  {
2211  if (flush)
2212  pSRC->algo.linear.isPrevFramesLoaded = DRMP3_FALSE;
2213  }
2214 
2215  break;
2216  }
2217  }
2218 
2219  pFramesOut = (drmp3_uint8*)pFramesOut + (1 * pSRC->config.channels * sizeof(float));
2220  frameCount -= 1;
2221  totalFramesRead += 1;
2222 
2223  /* If there's no frames available we need to get out of this loop. */
2224  if (!pSRC->algo.linear.isNextFramesLoaded && (!flush || !pSRC->algo.linear.isPrevFramesLoaded))
2225  break;
2226  }
2227 
2228  return totalFramesRead;
2229 }
2230 
2231 
2232 
2233 static drmp3_bool32 drmp3_decode_next_frame(drmp3* pMP3)
2234 {
2235  drmp3_assert(pMP3 != NULL);
2236  drmp3_assert(pMP3->onRead != NULL);
2237 
2238  if (pMP3->atEnd)
2239  return DRMP3_FALSE;
2240 
2241  do
2242  {
2244  drmp3_uint32 samplesRead;
2245 
2246  /* minimp3 recommends doing data submission in 16K chunks. If we don't have at least 16K bytes available, get more. */
2247  if (pMP3->dataSize < DRMP3_DATA_CHUNK_SIZE)
2248  {
2249  size_t bytesRead;
2250 
2251  if (pMP3->dataCapacity < DRMP3_DATA_CHUNK_SIZE)
2252  {
2253  drmp3_uint8* pNewData = NULL;
2254  pMP3->dataCapacity = DRMP3_DATA_CHUNK_SIZE;
2255 
2256  pNewData = (drmp3_uint8*)
2257  drmp3_realloc(pMP3->pData, pMP3->dataCapacity);
2258  if (pNewData == NULL)
2259  return DRMP3_FALSE; /* Out of memory. */
2260 
2261  pMP3->pData = pNewData;
2262  }
2263 
2264  bytesRead = pMP3->onRead(pMP3->pUserData, pMP3->pData + pMP3->dataSize, (pMP3->dataCapacity - pMP3->dataSize));
2265  if (bytesRead == 0)
2266  {
2267  pMP3->atEnd = DRMP3_TRUE;
2268  return DRMP3_FALSE; /* No data. */
2269  }
2270 
2271  pMP3->dataSize += bytesRead;
2272  }
2273 
2274  if (pMP3->dataSize > INT_MAX)
2275  {
2276  pMP3->atEnd = DRMP3_TRUE;
2277  return DRMP3_FALSE; /* File too big. */
2278  }
2279 
2280  samplesRead = drmp3dec_decode_frame(&pMP3->decoder, pMP3->pData, (int)pMP3->dataSize, pMP3->frames, &info); /* <-- Safe size_t -> int conversion thanks to the check above. */
2281  if (samplesRead != 0)
2282  {
2283  size_t i;
2284  size_t leftoverDataSize = (pMP3->dataSize - (size_t)info.frame_bytes);
2285  for (i = 0; i < leftoverDataSize; ++i)
2286  pMP3->pData[i] = pMP3->pData[i + (size_t)info.frame_bytes];
2287 
2288  pMP3->dataSize = leftoverDataSize;
2289  pMP3->framesConsumed = 0;
2290  pMP3->framesRemaining = samplesRead;
2291  pMP3->frameChannels = info.channels;
2292  pMP3->frameSampleRate = info.hz;
2293  drmp3_src_set_input_sample_rate(&pMP3->src, pMP3->frameSampleRate);
2294  break;
2295  }
2296  else
2297  {
2298  size_t bytesRead;
2299  /* Need more data. minimp3 recommends doing data submission in 16K chunks. */
2300  if (pMP3->dataCapacity == pMP3->dataSize)
2301  {
2302  drmp3_uint8 *pNewData = NULL;
2303  /* No room. Expand. */
2304  pMP3->dataCapacity += DRMP3_DATA_CHUNK_SIZE;
2305 
2306  pNewData = (drmp3_uint8*)drmp3_realloc(pMP3->pData, pMP3->dataCapacity);
2307  if (pNewData == NULL)
2308  return DRMP3_FALSE; /* Out of memory. */
2309 
2310  pMP3->pData = pNewData;
2311  }
2312 
2313  /* Fill in a chunk. */
2314  bytesRead = pMP3->onRead(pMP3->pUserData, pMP3->pData + pMP3->dataSize, (pMP3->dataCapacity - pMP3->dataSize));
2315  if (bytesRead == 0)
2316  {
2317  pMP3->atEnd = DRMP3_TRUE;
2318  return DRMP3_FALSE; /* Error reading more data. */
2319  }
2320 
2321  pMP3->dataSize += bytesRead;
2322  }
2323  } while (DRMP3_TRUE);
2324 
2325  return DRMP3_TRUE;
2326 }
2327 
2328 static drmp3_uint64 drmp3_read_src(drmp3_src* pSRC, drmp3_uint64 frameCount, void* pFramesOut, void* pUserData)
2329 {
2330  float* pFramesOutF;
2331  drmp3_uint32 totalFramesRead = 0;
2332  drmp3* pMP3 = (drmp3*)pUserData;
2333 
2334  drmp3_assert(pMP3 != NULL);
2335  drmp3_assert(pMP3->onRead != NULL);
2336 
2337  pFramesOutF = (float*)pFramesOut;
2338 
2339  while (frameCount > 0)
2340  {
2341  /* Read from the in-memory buffer first. */
2342  while (pMP3->framesRemaining > 0 && frameCount > 0)
2343  {
2344  if (pMP3->frameChannels == 1)
2345  {
2346  if (pMP3->channels == 1)
2347  {
2348  /* Mono -> Mono. */
2349  pFramesOutF[0] = pMP3->frames[pMP3->framesConsumed] / 32768.0f;
2350  } else {
2351  /* Mono -> Stereo. */
2352  pFramesOutF[0] = pMP3->frames[pMP3->framesConsumed] / 32768.0f;
2353  pFramesOutF[1] = pMP3->frames[pMP3->framesConsumed] / 32768.0f;
2354  }
2355  } else {
2356  if (pMP3->channels == 1)
2357  {
2358  /* Stereo -> Mono */
2359  float sample = 0;
2360  sample += pMP3->frames[(pMP3->framesConsumed*pMP3->frameChannels)+0] / 32768.0f;
2361  sample += pMP3->frames[(pMP3->framesConsumed*pMP3->frameChannels)+1] / 32768.0f;
2362  pFramesOutF[0] = sample * 0.5f;
2363  } else {
2364  /* Stereo -> Stereo */
2365  pFramesOutF[0] = pMP3->frames[(pMP3->framesConsumed*pMP3->frameChannels)+0] / 32768.0f;
2366  pFramesOutF[1] = pMP3->frames[(pMP3->framesConsumed*pMP3->frameChannels)+1] / 32768.0f;
2367  }
2368  }
2369 
2370  pMP3->framesConsumed += 1;
2371  pMP3->framesRemaining -= 1;
2372  frameCount -= 1;
2373  totalFramesRead += 1;
2374  pFramesOutF += pSRC->config.channels;
2375  }
2376 
2377  if (frameCount == 0)
2378  break;
2379 
2380  drmp3_assert(pMP3->framesRemaining == 0);
2381 
2382  /* At this point we have exhausted our in-memory buffer so we need to re-fill. Note that the sample rate may have changed
2383  * at this point which means we'll also need to update our sample rate conversion pipeline. */
2384  if (!drmp3_decode_next_frame(pMP3))
2385  break;
2386  }
2387 
2388  return totalFramesRead;
2389 }
2390 
2391 drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, const drmp3_config* pConfig)
2392 {
2394  drmp3_src_config srcConfig;
2395 
2396  drmp3_assert(pMP3 != NULL);
2397  drmp3_assert(onRead != NULL);
2398 
2399  /* This function assumes the output object has already been reset to 0. Do not do that here, otherwise things will break. */
2400  drmp3dec_init(&pMP3->decoder);
2401 
2402  /* The config can be null in which case we use defaults. */
2403  if (pConfig != NULL)
2404  config = *pConfig;
2405  else
2406  drmp3_zero_object(&config);
2407 
2408  pMP3->channels = config.outputChannels;
2409  if (pMP3->channels == 0)
2410  pMP3->channels = DR_MP3_DEFAULT_CHANNELS;
2411 
2412  /* Cannot have more than 2 channels. */
2413  if (pMP3->channels > 2)
2414  pMP3->channels = 2;
2415 
2416  pMP3->sampleRate = config.outputSampleRate;
2417  if (pMP3->sampleRate == 0)
2418  pMP3->sampleRate = DR_MP3_DEFAULT_SAMPLE_RATE;
2419 
2420  pMP3->onRead = onRead;
2421  pMP3->onSeek = onSeek;
2422  pMP3->pUserData = pUserData;
2423 
2424  /* We need a sample rate converter for converting the sample rate from the MP3 frames to the requested output sample rate. */
2425  drmp3_zero_object(&srcConfig);
2426  srcConfig.sampleRateIn = DR_MP3_DEFAULT_SAMPLE_RATE;
2427  srcConfig.sampleRateOut = pMP3->sampleRate;
2428  srcConfig.channels = pMP3->channels;
2430  if (!drmp3_src_init(&srcConfig, drmp3_read_src, pMP3, &pMP3->src))
2431  return DRMP3_FALSE;
2432 
2433  /* Decode the first frame to confirm that it is indeed a valid MP3 stream. */
2434  if (!drmp3_decode_next_frame(pMP3))
2435  return DRMP3_FALSE; /* Not a valid MP3 stream. */
2436 
2437  return DRMP3_TRUE;
2438 }
2439 
2440 drmp3_bool32 drmp3_init(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, const drmp3_config* pConfig)
2441 {
2442  if (pMP3 == NULL || onRead == NULL)
2443  return DRMP3_FALSE;
2444 
2445  drmp3_zero_object(pMP3);
2446  return drmp3_init_internal(pMP3, onRead, onSeek, pUserData, pConfig);
2447 }
2448 
2449 
2450 static size_t drmp3__on_read_memory(void* pUserData, void* pBufferOut, size_t bytesToRead)
2451 {
2452  size_t bytesRemaining;
2453  drmp3* pMP3 = (drmp3*)pUserData;
2454  drmp3_assert(pMP3 != NULL);
2455  drmp3_assert(pMP3->memory.dataSize >= pMP3->memory.currentReadPos);
2456 
2457  bytesRemaining = pMP3->memory.dataSize - pMP3->memory.currentReadPos;
2458  if (bytesToRead > bytesRemaining)
2459  bytesToRead = bytesRemaining;
2460 
2461  if (bytesToRead > 0)
2462  {
2463  drmp3_copy_memory(pBufferOut, pMP3->memory.pData + pMP3->memory.currentReadPos, bytesToRead);
2464  pMP3->memory.currentReadPos += bytesToRead;
2465  }
2466 
2467  return bytesToRead;
2468 }
2469 
2470 static drmp3_bool32 drmp3__on_seek_memory(void* pUserData, int byteOffset, drmp3_seek_origin origin)
2471 {
2472  drmp3* pMP3 = (drmp3*)pUserData;
2473  drmp3_assert(pMP3 != NULL);
2474 
2475  if (origin == drmp3_seek_origin_current)
2476  {
2477  if (byteOffset > 0)
2478  {
2479  if (pMP3->memory.currentReadPos + byteOffset > pMP3->memory.dataSize)
2480  byteOffset = (int)(pMP3->memory.dataSize - pMP3->memory.currentReadPos); /* Trying to seek too far forward. */
2481  }
2482  else
2483  {
2484  if (pMP3->memory.currentReadPos < (size_t)-byteOffset)
2485  byteOffset = -(int)pMP3->memory.currentReadPos; /* Trying to seek too far backwards. */
2486  }
2487 
2488  /* This will never underflow thanks to the clamps above. */
2489  pMP3->memory.currentReadPos += byteOffset;
2490  } else {
2491  if ((drmp3_uint32)byteOffset <= pMP3->memory.dataSize)
2492  pMP3->memory.currentReadPos = byteOffset;
2493  else
2494  pMP3->memory.currentReadPos = pMP3->memory.dataSize; /* Trying to seek too far forward. */
2495  }
2496 
2497  return DRMP3_TRUE;
2498 }
2499 
2500 drmp3_bool32 drmp3_init_memory(drmp3* pMP3, const void* pData, size_t dataSize, const drmp3_config* pConfig)
2501 {
2502  if (pMP3 == NULL)
2503  return DRMP3_FALSE;
2504 
2505  drmp3_zero_object(pMP3);
2506 
2507  if (pData == NULL || dataSize == 0)
2508  return DRMP3_FALSE;
2509 
2510  pMP3->memory.pData = (const drmp3_uint8*)pData;
2511  pMP3->memory.dataSize = dataSize;
2512  pMP3->memory.currentReadPos = 0;
2513 
2514  return drmp3_init_internal(pMP3, drmp3__on_read_memory, drmp3__on_seek_memory, pMP3, pConfig);
2515 }
2516 
2517 
2518 #ifndef DR_MP3_NO_STDIO
2519 #include <stdio.h>
2520 
2521 static size_t drmp3__on_read_stdio(void* pUserData, void* pBufferOut, size_t bytesToRead)
2522 {
2523  return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
2524 }
2525 
2526 static drmp3_bool32 drmp3__on_seek_stdio(void* pUserData, int offset, drmp3_seek_origin origin)
2527 {
2528  return fseek((FILE*)pUserData, offset, (origin == drmp3_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
2529 }
2530 
2531 drmp3_bool32 drmp3_init_file(drmp3* pMP3, const char* filePath, const drmp3_config* pConfig)
2532 {
2533  FILE* pFile;
2534 #if defined(_MSC_VER) && _MSC_VER >= 1400
2535  if (fopen_s(&pFile, filePath, "rb") != 0)
2536  return DRMP3_FALSE;
2537 #else
2538  pFile = fopen(filePath, "rb");
2539  if (pFile == NULL)
2540  return DRMP3_FALSE;
2541 #endif
2542 
2543  return drmp3_init(pMP3, drmp3__on_read_stdio, drmp3__on_seek_stdio, (void*)pFile, pConfig);
2544 }
2545 #endif
2546 
2547 void drmp3_uninit(drmp3* pMP3)
2548 {
2549  if (pMP3 == NULL) return;
2550 
2551 #ifndef DR_MP3_NO_STDIO
2552  if (pMP3->onRead == drmp3__on_read_stdio)
2553  fclose((FILE*)pMP3->pUserData);
2554 #endif
2555 
2556  drmp3_free(pMP3->pData);
2557 }
2558 
2559 drmp3_uint64 drmp3_read_f32(drmp3* pMP3, drmp3_uint64 framesToRead, float* pBufferOut)
2560 {
2561  drmp3_uint64 totalFramesRead = 0;
2562  if (pMP3 == NULL || pMP3->onRead == NULL) return 0;
2563 
2564  if (pBufferOut == NULL)
2565  {
2566  float temp[4096];
2567  while (framesToRead > 0)
2568  {
2569  drmp3_uint64 framesJustRead;
2570  drmp3_uint64 framesToReadRightNow = sizeof(temp)/sizeof(temp[0]) / pMP3->channels;
2571  if (framesToReadRightNow > framesToRead)
2572  framesToReadRightNow = framesToRead;
2573 
2574  framesJustRead = drmp3_read_f32(pMP3, framesToReadRightNow, temp);
2575  if (framesJustRead == 0)
2576  break;
2577 
2578  framesToRead -= framesJustRead;
2579  totalFramesRead += framesJustRead;
2580  }
2581  } else {
2582  totalFramesRead = drmp3_src_read_frames_ex(&pMP3->src, framesToRead, pBufferOut, DRMP3_TRUE);
2583  }
2584 
2585  return totalFramesRead;
2586 }
2587 
2589 {
2590  drmp3_uint64 framesRead;
2591 
2592  if (pMP3 == NULL || pMP3->onSeek == NULL) return DRMP3_FALSE;
2593 
2594  /* Seek to the start of the stream to begin with. */
2595  if (!pMP3->onSeek(pMP3->pUserData, 0, drmp3_seek_origin_start))
2596  return DRMP3_FALSE;
2597 
2598  /* Clear any cached data. */
2599  pMP3->framesConsumed = 0;
2600  pMP3->framesRemaining = 0;
2601  pMP3->dataSize = 0;
2602  pMP3->atEnd = DRMP3_FALSE;
2603 
2604  /* TODO: Optimize.
2605  *
2606  * This is inefficient. We simply read frames from the start of the stream. */
2607  framesRead = drmp3_read_f32(pMP3, frameIndex, NULL);
2608  if (framesRead != frameIndex)
2609  return DRMP3_FALSE;
2610 
2611  return DRMP3_TRUE;
2612 }
2613 
2614 
2615 
2616 float* drmp3__full_decode_and_close_f32(drmp3* pMP3, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount)
2617 {
2618  drmp3_uint64 totalFramesRead = 0;
2619  drmp3_uint64 framesCapacity = 0;
2620  float* pFrames = NULL;
2621 
2622  float temp[4096];
2623 
2624  drmp3_assert(pMP3 != NULL);
2625 
2626  for (;;)
2627  {
2628  drmp3_uint64 framesToReadRightNow = drmp3_countof(temp) / pMP3->channels;
2629  drmp3_uint64 framesJustRead = drmp3_read_f32(pMP3, framesToReadRightNow, temp);
2630  if (framesJustRead == 0)
2631  break;
2632 
2633  /* Reallocate the output buffer if there's not enough room. */
2634  if (framesCapacity < totalFramesRead + framesJustRead)
2635  {
2636  float* pNewFrames;
2637  drmp3_uint64 newFramesBufferSize;
2638 
2639  framesCapacity *= 2;
2640  if (framesCapacity < totalFramesRead + framesJustRead)
2641  framesCapacity = totalFramesRead + framesJustRead;
2642 
2643  newFramesBufferSize = framesCapacity*pMP3->channels*sizeof(float);
2644  if (newFramesBufferSize > SIZE_MAX)
2645  break;
2646 
2647  pNewFrames = (float*)drmp3_realloc(pFrames, (size_t)newFramesBufferSize);
2648  if (pNewFrames == NULL)
2649  {
2650  drmp3_free(pFrames);
2651  break;
2652  }
2653 
2654  pFrames = pNewFrames;
2655  }
2656 
2657  drmp3_copy_memory(pFrames + totalFramesRead*pMP3->channels, temp, (size_t)(framesJustRead*pMP3->channels*sizeof(float)));
2658  totalFramesRead += framesJustRead;
2659 
2660  /* If the number of frames we asked for is less that what we actually read it means we've reached the end. */
2661  if (framesJustRead != framesToReadRightNow)
2662  break;
2663  }
2664 
2665  if (pConfig != NULL)
2666  {
2667  pConfig->outputChannels = pMP3->channels;
2668  pConfig->outputSampleRate = pMP3->sampleRate;
2669  }
2670 
2671  drmp3_uninit(pMP3);
2672 
2673  if (pTotalFrameCount) *pTotalFrameCount = totalFramesRead;
2674  return pFrames;
2675 }
2676 
2677 float* drmp3_open_and_decode_f32(drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount)
2678 {
2679  drmp3 mp3;
2680  if (!drmp3_init(&mp3, onRead, onSeek, pUserData, pConfig))
2681  return NULL;
2682 
2683  return drmp3__full_decode_and_close_f32(&mp3, pConfig, pTotalFrameCount);
2684 }
2685 
2686 float* drmp3_open_and_decode_memory_f32(const void* pData, size_t dataSize, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount)
2687 {
2688  drmp3 mp3;
2689  if (!drmp3_init_memory(&mp3, pData, dataSize, pConfig))
2690  return NULL;
2691 
2692  return drmp3__full_decode_and_close_f32(&mp3, pConfig, pTotalFrameCount);
2693 }
2694 
2695 #ifndef DR_MP3_NO_STDIO
2696 float* drmp3_open_and_decode_file_f32(const char* filePath, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount)
2697 {
2698  drmp3 mp3;
2699  if (!drmp3_init_file(&mp3, filePath, pConfig))
2700  return NULL;
2701 
2702  return drmp3__full_decode_and_close_f32(&mp3, pConfig, pTotalFrameCount);
2703 }
2704 #endif
2705 
2706 void drmp3_free(void* p)
2707 {
2708  DRMP3_FREE(p);
2709 }
2710 
2711 #endif /*DR_MP3_IMPLEMENTATION*/
2712 
2713 /*
2714 This is free and unencumbered software released into the public domain.
2715 
2716 Anyone is free to copy, modify, publish, use, compile, sell, or
2717 distribute this software, either in source code form or as a compiled
2718 binary, for any purpose, commercial or non-commercial, and by any
2719 means.
2720 
2721 In jurisdictions that recognize copyright laws, the author or authors
2722 of this software dedicate any and all copyright interest in the
2723 software to the public domain. We make this dedication for the benefit
2724 of the public at large and to the detriment of our heirs and
2725 successors. We intend this dedication to be an overt act of
2726 relinquishment in perpetuity of all present and future rights to this
2727 software under copyright law.
2728 
2729 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2730 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2731 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2732 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
2733 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2734 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2735 OTHER DEALINGS IN THE SOFTWARE.
2736 
2737 For more information, please refer to <http://unlicense.org/>
2738 */
2739 
2740 /*
2741  https://github.com/lieff/minimp3
2742  To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide.
2743  This software is distributed without any warranty.
2744  See <http://creativecommons.org/publicdomain/zero/1.0/>.
2745 */
drmp3_uint32 framesConsumed
Definition: dr_mp3.h:155
Definition: dr_mp3.h:108
drmp3_src src
Definition: dr_mp3.h:158
drmp3_bool32 drmp3_init_memory(drmp3 *pMP3, const void *pData, size_t dataSize, const drmp3_config *pConfig)
GLenum mode
Definition: glext.h:6857
#define INLINE
Definition: retro_inline.h:35
drmp3_uint64(* drmp3_src_read_proc)(drmp3_src *pSRC, drmp3_uint64 frameCount, void *pFramesOut, void *pUserData)
Definition: dr_mp3.h:62
drmp3_read_proc onRead
Definition: dr_mp3.h:150
Definition: dr_mp3.h:71
static const size_t frame_size
Definition: switch_thread_audio.c:42
__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")
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:8418
#define DRMP3_TRUE
Definition: dr_mp3.h:24
GLfixed GLfixed x2
Definition: glsym_gl.h:1051
Definition: libretro.h:2275
unsigned char header[4]
Definition: dr_mp3.h:47
int64_t drmp3_int64
Definition: dr_mp3.h:20
struct drmp3::@70 memory
GLdouble GLdouble t
Definition: glext.h:6398
int reserv
Definition: dr_mp3.h:45
GLenum GLsizei len
Definition: glext.h:7389
Definition: dr_mp3.h:138
int8_t s8
8bit signed integer
Definition: gctypes.h:22
Definition: tinyalsa.c:749
size_t currentReadPos
Definition: dr_mp3.h:167
GLint limit
Definition: glext.h:11233
#define SEEK_CUR
Definition: zconf.h:439
GLfloat f
Definition: glext.h:8207
Definition: dr_mp3.h:88
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 &reg2 endm macro vzip8 reg2 vzip d d &reg2 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 endif[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
Definition: pixman-arm-neon-asm.h:543
drmp3dec_frame_info frameInfo
Definition: dr_mp3.h:147
int8_t drmp3_int8
Definition: dr_mp3.h:14
int layer
Definition: dr_mp3.h:37
float * drmp3_open_and_decode_f32(drmp3_read_proc onRead, drmp3_seek_proc onSeek, void *pUserData, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount)
Definition: dr_mp3.h:41
drmp3_uint64 drmp3_read_f32(drmp3 *pMP3, drmp3_uint64 framesToRead, float *pBufferOut)
#define next(ls)
Definition: llex.c:32
GLdouble s
Definition: glext.h:6390
const struct retro_game_info * info
Definition: libretro.h:2121
GLdouble GLdouble z
Definition: glext.h:6514
drmp3_uint32 frameChannels
Definition: dr_mp3.h:153
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
uint64_t drmp3_uint64
Definition: dr_mp3.h:21
Definition: dr_mp3.h:109
Definition: ibxm.h:9
drmp3_src_algorithm algorithm
Definition: dr_mp3.h:84
GLdouble GLdouble right
Definition: glext.h:11766
bool success(size_t len)
Definition: peglib.h:475
drmp3_bool32 atEnd
Definition: dr_mp3.h:162
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
drmp3_bool32(* drmp3_seek_proc)(void *pUserData, int offset, drmp3_seek_origin origin)
Definition: dr_mp3.h:136
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
float pCachedFrames[2 *DRMP3_SRC_CACHE_SIZE_IN_FRAMES]
Definition: dr_mp3.h:74
int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes, short *pcm, drmp3dec_frame_info *info)
Definition: dr_mp3.h:79
drmp3_uint32 cachedFrameCount
Definition: dr_mp3.h:75
void * pUserData
Definition: dr_mp3.h:152
drmp3_uint32 channels
Definition: dr_mp3.h:83
drmp3_uint32 sampleRateIn
Definition: dr_mp3.h:81
#define NULL
Pointer to 0.
Definition: gctypes.h:65
drmp3dec decoder
Definition: dr_mp3.h:146
drmp3_uint32 channels
Definition: dr_mp3.h:148
#define fclose
Definition: file_stream_transforms.h:53
drmp3_uint32 framesRemaining
Definition: dr_mp3.h:156
uint8_t drmp3_uint8
Definition: dr_mp3.h:15
drmp3_bool32 isNextFramesLoaded
Definition: dr_mp3.h:101
Definition: dr_mp3.h:67
Definition: dr_mp3.h:144
void * pUserData
Definition: dr_mp3.h:92
const drmp3_uint8 * pData
Definition: dr_mp3.h:165
#define SEEK_SET
Definition: zconf.h:438
int bitrate_kbps
Definition: dr_mp3.h:38
float bin[256]
Definition: dr_mp3.h:93
drmp3_uint32 outputChannels
Definition: dr_mp3.h:140
drmp3_bool32 isPrevFramesLoaded
Definition: dr_mp3.h:100
int frame_bytes
Definition: dr_mp3.h:34
#define DRMP3_FALSE
Definition: dr_mp3.h:25
int hz
Definition: dr_mp3.h:36
drmp3_bool32 drmp3_init(drmp3 *pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void *pUserData, const drmp3_config *pConfig)
signed short int16_t
Definition: stdint.h:122
drmp3_uint32 frameSampleRate
Definition: dr_mp3.h:154
uint32_t drmp3_uint32
Definition: dr_mp3.h:19
float alpha
Definition: dr_mp3.h:99
GLint GLint GLint GLint GLint GLint y
Definition: glext.h:6295
GLenum src
Definition: glext.h:6980
static struct frame frames[2]
Definition: ffmpeg_core.c:162
GLenum GLint GLuint mask
Definition: glext.h:6668
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
Definition: deflate.c:120
drmp3_seek_proc onSeek
Definition: dr_mp3.h:151
Definition: inftrees.h:27
struct drmp3_src::@68::@69 linear
drmp3_src * pSRC
Definition: dr_mp3.h:73
未知的編譯器 設備已從連接口上移開 文件已存在。儲存到備份至緩衝區 連接來自: 公開地址 設定光碟機裡光碟 你已離開遊戲 這個核心模擬器不支援不同系統的網路連線對打 輸入連線遊戲服務器的密碼: s 已斷開連線 已離開連線遊戲模式 連線遊戲人數已滿 連線遊戲對方 s 已暫停 使用模擬器硬體渲染私人內容時可避免硬體在各frames時的狀態改變 調整選單顯示的相關設定。 以延遲和視訊撕裂為代價換取高性能,當且僅當能 n 達到全速模擬時使用。 自動偵測 容量 連接到連接口 對不起,錯誤發生:模擬器核心未請求內容,無法加入連線遊戲。 密碼 用戶名 帳戶列表終端 成就列表 添加遊戲內容 導入遊戲內容 詢問 塊幀 聲音驅動程式 啟用聲音 渦輪 盲區 聲音最大採樣間隔 動態聲音碼率控制間隔 聲音 SaveRAM自動儲存間隔 自動戴入重映射文件 返回 訊息 向下滾動 開始 切換選單 確認 退出 默認值 切換選單 啟用藍牙服務 緩沖目錄 相機驅動程式 執行金手指修改 金手指文件 另存金手指文件 描述 鎖定 非官方測試成就 未鎖定 設定 設定 退出時進行詢問 遊戲內容數據庫目錄 歷史記錄數量 快捷選單 下載目錄 核心計數器 核心訊息 分類 核心名稱 許可證 支持的擴展 系統名稱 戴入核心 核心 自動解壓下載的檔案 核心更新程序 指針目錄 自定義比率 選擇數據庫 選擇文件並探測核心< 默認 > 沒有找到文件夾。 Disk Cycle Tray Status 光碟索引 不關心 下載核心…… 啟用DPI覆蓋 驅動 載入前檢查韌體 BIOS是否存在 動態壁紙目錄 選單項懸停顏色 取消 顯示幀率 幀率限制 自動戴入遊戲內容特定的核心選項 遊戲選項文件 聲音 視訊故障排除 基本選單控制 戴入遊戲內容 什麼是「核心」? 歷史 圖像 訊息 所有用戶都能控制選單 左搖桿Y 右搖桿X 右搖桿Y Gun Trigger Gun Aux A Gun Aux C Gun Select Gun D pad Down Gun D pad Right 輸入軸閾值 綁定全部 綁定超時時間 顯示輸入描述標籤 設備類型 Turbo占空比 鍵盤控制器映射啟用 下十字鍵 左十字鍵 右十字鍵 開始鍵 Mouse Mouse Mouse Wheel Down Wheel Right 最大用戶數 金手指索引 金手指開關 下一張光碟 啟用熱鍵 快進切換 切換全營幕 切換遊戲焦距 切換選單 靜音開關 切換營幕鍵盤 切換暫停 重置遊戲 儲存狀態 下一個Shader 慢動作 存檔槽 音量 顯示覆層 輪詢類型行為 稍晚 優先前置觸摸 啟用綁定重映射 輸入 啟用觸摸 Turbo區間 內部存儲狀態 手柄驅動 簡體中文 荷蘭語 世界語 德語 日語 波蘭語 葡萄牙語 西班牙語 Arabic 核心目錄 核心日誌級別 使用核心戴入壓縮包 載入遊戲內容 允許使用位置 日誌 主選單 選單顏色主題 藍灰色 綠色 紅色 底部不透明度 選單驅動 選單文件瀏覽器 Horizontal Animation 選單壁紙 丟失 鼠標支持 音樂 環繞式導航 連線遊戲 連線遊戲延遲幀數 啟用連線遊戲 作為遊戲主機 服務器地址 啟用連線遊戲客戶端 服務器密碼 連線遊戲無狀態模式 啟用連線遊戲旁觀者 連線遊戲使用NAT穿透技術 網路命令端口 網路遊戲控制器 網路 無 沒有可顯示的成就。 沒有可用的核心。 沒有可用的核心選項。 沒有可用的歷史記錄。 沒有條目。 未發現網路。 沒有遊戲列表。 沒有找到設定。 關 連線更新器 營幕覆層 營幕通知 OSK覆層目錄 自動戴入最佳的覆層 覆層不透明度 覆層縮放比例 使用PAL60模式 當選單激活時暫停 性能計數器 遊戲列表目錄 觸控支援 現在 退出 RetroArch BBFC 分級 多人遊戲支持 描述 Edge雜誌發行 Edge雜誌評論 增強硬件 經銷商 MD5 起源 出版方 發售年份 系列 啟動遊戲內容 重啟 錄影輸出目錄 錄影設定 啟用錄影 使用輸出目錄 戴入重映射文件 儲存遊戲重映射文件 重啟 繼續 Retro鍵盤 RetroPad w Analog 啟用回溯 回溯 設定目錄 右側搖桿 啟用SAMBA文件共享服務 自動索引儲存狀態 自動儲存狀態 既時存檔縮圖 儲存核心覆寫 儲存新設定 存檔 掃瞄文件 營幕截圖目錄 搜索: 設定 Shader Shader效果 Simple Snow 顯示高級設定 關機 排序文件夾中的存檔 啟用SSH遠程終端服務 啟動遠程的RetroPad 狀態存儲槽 標準輸入流命令 暫停屏保程序 系統 BIOS目錄 支持 編譯日期 Cocoa 支持 CoreText 支持 顯示器度量DPI DirectSound 支持 動態鏈接庫支持 EGL 支持 FFmpeg 支持 STB TrueType 支持 前端名稱 Git版本 HLSL 支持 KMS EGL 支持 Libusb 支持 網路控制台支持 OpenAL 支持 OpenGL 支持 OpenVG 支持 覆層支持 已充滿電 放電中 PulseAudio 支持 BMP RetroRating 等級 RoarAudio 支持 RSound 支持 SDL2 支持 SDL1 支持 多線程支持 Video4Linux2 支持 Vulkan 支持 X11 支持 XVideo 支持 截取營幕 縮略圖 縮略圖更新程序 截屏 顯示時間日期 真 UI Companion Start On Boot 無法讀取壓縮的文件。 撤銷儲存狀態 更新程序 更新自動設定檔案 更新金手指 更新數據庫 更新 Lakka 更新Slang Shader效果文件 用戶界面 用戶 使用內建媒體播放器 允許旋轉 畫面比例選項 Crop 禁用桌面元素 視訊驅動 視訊濾鏡目錄 強制畫面比例 幀延時 視訊Gamma 啟用GPU截屏 強制GPU同步幀數 顯示器索引 刷新率 Set Display Reported Refresh Rate 窗口縮放量 視訊 Shader渲染遍數 戴入Shader預設 儲存核心預設 啟用硬件共享上下文 啟用軟件過濾器 視訊 降低閃爍 自定義畫面寬度 自定義畫面Y 垂直同步 窗口寬度 Wi Fi驅動 選單透明度因子 自定義 Monochrome Systematic Pixel Retrosystem 選單顏色主題 深色 鐵藍色 傳統紅 樸素 火山紅 選單縮放因子 顯示歷史頁 顯示圖像頁 顯示設定頁 Menu Layout 是 打開或關閉成就。更多內容請訪問 為測試目的而打開或關閉非官方成就和 或測試版特性。 修改驅動設定。 修改核心設定。 修改顯示覆蓋、鍵盤覆蓋和營幕通知的設定。 修改存檔設定。 修改用戶界面設定。 修改你的隱私設定。 修改遊戲列表設定。 下載且 或者掃瞄遊戲內容,並將其加入你的收藏中。 啟用或者禁止藍牙。 修改設定文件的默認設定。 CPU擁有的核心總數。 設定熱鍵選項。 調整遊戲控制器、鍵盤和鼠標的設定。 啟用或禁止向控制台打印日誌。 在局域網內搜索並連接聯網遊戲的主機。 下載並更新RetroArch的附加插件和組件。 管理操作系統層級的服務。 阻止系統激活營幕保護程序。 在幀與幀之間插入黑色的中間幀,通常用於消除在 n n 的鬼影。 設定當開啟「強制GPU同步」時CPU可以預先GPU多少幀。 選擇將要使用哪一個顯示器。 The refresh rate as reported by the display driver 掃瞄無線網路並且建立連接。 磁碟已加入 載入 shader 取消靜音。 自動設定文件儲存成功。 自動儲存狀態至 啟用通訊埠上的指令介面 無法推斷新的設定路徑,使用當前時間。 與已知的magic numbers比較 未設定設定目錄,無法儲存新的設定。 內容的CRC32s不同。無法使用不同的遊戲。 核心不支持儲存狀態。 無法找到磁碟 無法找到有效的數據軌 無法讀取內容文件 無法讀取視訊狀態 Custom timing given 解壓縮失敗。 無法找到任何有效的內容位置 已關閉 正在下載 錯誤 Libretro core 但程式未找到可載入內容 無法儲存 core options 檔案 無法儲存預置 shader 正在解壓 無法儲存設定到 無法讓觀眾加入 無法載入 shader 創建目錄失敗。 從客戶端獲取暱稱失敗 載入內容失敗 無法戴入 overlay 打開libretro核心失敗 無法接收連線端的資訊 無法接收主控端的暱稱 無法接收主控端 SRAM 資料 移除臨時文件失敗 即時存檔儲存失敗 發送暱稱尺寸失敗 發送暱稱至主控端失敗 聲音驅動啟動失敗,將在無聲音模式下繼續啟動。 建用錄製視訊失敗 還原載入即時存檔失敗 還原取消靜音失敗 未找到文件 找到磁碟標籤 找到最後一個狀態槽 幀 錯誤的磁碟索引 打開遊戲焦點 Libretro core is hardware rendered Must use post shaded recording as well 輸入金手指 目前檔案 接口 可移除的儲存空間 字節 兆字節 為libretro而設計的前端 戴入狀態從槽 一個或多個固件文件丟失 正在讀取歷史文件 內存 視訊格式看起來使用了不同的序列化版本。很有可能失敗。 停止視訊錄製。 沒有內容,啟動虛擬核心。 沒有戴入任何存檔。 覆蓋儲存成功。 RetroArch 接收完畢 錄製到 重新轉向 save file to Remap file 儲存成功 移除臨時內容文件 重啟錄製由於驅動器重新初始化。 Reverting savefile directory to 正在回溯。 初始化回放緩存失敗 回放功能關閉 到達回放緩存末端 儲存狀態至槽 成功儲存至 存檔中 已完成對文件夾的掃瞄 Several patches are explicitly defined
Definition: msg_hash_cht.h:2214
struct config_s config
GLfloat GLfloat p
Definition: glext.h:9809
signed int int32_t
Definition: stdint.h:123
GLenum GLsizei dataSize
Definition: glext.h:12030
drmp3_src_config config
Definition: dr_mp3.h:90
void drmp3_uninit(drmp3 *pMP3)
#define SIZE_MAX
Definition: stdint.h:252
int channels
Definition: dr_mp3.h:35
size_t dataSize
Definition: dr_mp3.h:159
Definition: nk_menu.h:45
#define FILE
Definition: file_stream_transforms.h:35
f32 a1
Definition: gx_regdef.h:5095
int16_t drmp3_int16
Definition: dr_mp3.h:16
drmp3_uint32 cacheSizeInFrames
Definition: dr_mp3.h:85
Definition: ibxm.h:14
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:11836
union drmp3_src::@68 algo
size_t dataCapacity
Definition: dr_mp3.h:160
#define DRMP3_SRC_CACHE_SIZE_IN_FRAMES
Definition: dr_mp3.h:70
drmp3_bool32 drmp3_seek_to_frame(drmp3 *pMP3, drmp3_uint64 frameIndex)
drmp3_src_read_proc onRead
Definition: dr_mp3.h:91
int32_t drmp3_int32
Definition: dr_mp3.h:18
GLint j
Definition: nx_glsym.h:307
void drmp3dec_init(drmp3dec *dec)
size_t(* drmp3_read_proc)(void *pUserData, void *pBufferOut, size_t bytesToRead)
Definition: dr_mp3.h:123
def sign()
Definition: build.py:201
int free_format_bytes
Definition: dr_mp3.h:46
signed __int64 int64_t
Definition: stdint.h:135
float * drmp3_open_and_decode_memory_f32(const void *pData, size_t dataSize, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount)
void drmp3_free(void *p)
Definition: dr_mp3.h:32
#define fread
Definition: file_stream_transforms.h:56
drmp3_uint8 drmp3_bool8
Definition: dr_mp3.h:22
GLenum GLenum dst
Definition: glext.h:6980
#define fopen
Definition: file_stream_transforms.h:52
#define __attribute__(Spec)
Definition: glslang_tab.cpp:647
drmp3_uint32 drmp3_bool32
Definition: dr_mp3.h:23
float qmf_state[15 *2 *32]
Definition: dr_mp3.h:44
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6742
drmp3_int16 frames[DRMP3_MAX_SAMPLES_PER_FRAME]
Definition: dr_mp3.h:157
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:8390
GLintptr offset
Definition: glext.h:6560
GLint left
Definition: glext.h:8393
#define DRMP3_MAX_SAMPLES_PER_FRAME
Definition: dr_mp3.h:27
drmp3_uint8 * pData
Definition: dr_mp3.h:161
drmp3_src_algorithm
Definition: dr_mp3.h:64
drmp3_uint32 outputSampleRate
Definition: dr_mp3.h:141
drmp3_seek_origin
Definition: dr_mp3.h:106
unsigned short uint16_t
Definition: stdint.h:125
void * memset(void *b, int c, size_t len)
Definition: string.c:7
unsigned __int64 uint64_t
Definition: stdint.h:136
GLdouble n
Definition: glext.h:8396
unsigned char uint8_t
Definition: stdint.h:124
unsigned int uint32_t
Definition: stdint.h:126
uint16_t drmp3_uint16
Definition: dr_mp3.h:17
int fopen_s(FILE **pFile, const char *filename, const char *mode)
Definition: StandAlone.cpp:1437
const GLfloat * m
Definition: glext.h:11755
drmp3_uint32 iNextFrame
Definition: dr_mp3.h:76
signed char int8_t
Definition: stdint.h:121
Definition: dr_mp3.h:66
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844
#define fseek
Definition: file_stream_transforms.h:55
drmp3_src_cache cache
Definition: dr_mp3.h:94
void * memcpy(void *dst, const void *src, size_t len)
Definition: string.c:26
drmp3_uint32 sampleRate
Definition: dr_mp3.h:149
drmp3_uint32 sampleRateOut
Definition: dr_mp3.h:82