interface.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. * interface.c
  3. *
  4. * Copyright (C) 1999-2012 The L.A.M.E. project
  5. *
  6. * Initially written by Michael Hipp, see also AUTHORS and README.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. * Boston, MA 02111-1307, USA.
  22. */
  23. /* $Id: interface.c,v 1.69 2017/09/06 15:07:30 robert Exp $ */
  24. #ifdef HAVE_CONFIG_H
  25. # include <config.h>
  26. #endif
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include "common.h"
  30. #include "interface.h"
  31. #include "tabinit.h"
  32. #include "layer3.h"
  33. #include "lame.h"
  34. #include "machine.h"
  35. #include "VbrTag.h"
  36. #include "decode_i386.h"
  37. #include "layer1.h"
  38. #include "layer2.h"
  39. #ifdef WITH_DMALLOC
  40. #include <dmalloc.h>
  41. #endif
  42. extern void lame_report_def(const char* format, va_list args);
  43. /* #define HIP_DEBUG */
  44. int
  45. InitMP3(PMPSTR mp)
  46. {
  47. hip_init_tables_layer1();
  48. hip_init_tables_layer2();
  49. hip_init_tables_layer3();
  50. if (mp) {
  51. memset(mp, 0, sizeof(MPSTR));
  52. mp->framesize = 0;
  53. mp->num_frames = 0;
  54. mp->enc_delay = -1;
  55. mp->enc_padding = -1;
  56. mp->vbr_header = 0;
  57. mp->header_parsed = 0;
  58. mp->side_parsed = 0;
  59. mp->data_parsed = 0;
  60. mp->free_format = 0;
  61. mp->old_free_format = 0;
  62. mp->ssize = 0;
  63. mp->dsize = 0;
  64. mp->fsizeold = -1;
  65. mp->bsize = 0;
  66. mp->head = mp->tail = NULL;
  67. mp->fr.single = -1;
  68. mp->bsnum = 0;
  69. mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
  70. mp->bitindex = 0;
  71. mp->synth_bo = 1;
  72. mp->sync_bitstream = 1;
  73. mp->report_dbg = &lame_report_def;
  74. mp->report_err = &lame_report_def;
  75. mp->report_msg = &lame_report_def;
  76. }
  77. make_decode_tables(32767);
  78. return 1;
  79. }
  80. void
  81. ExitMP3(PMPSTR mp)
  82. {
  83. if (mp) {
  84. struct buf *b, *bn;
  85. b = mp->tail;
  86. while (b) {
  87. free(b->pnt);
  88. bn = b->next;
  89. free(b);
  90. b = bn;
  91. }
  92. }
  93. }
  94. static struct buf *
  95. addbuf(PMPSTR mp, unsigned char *buf, int size)
  96. {
  97. struct buf *nbuf;
  98. nbuf = (struct buf *) malloc(sizeof(struct buf));
  99. if (!nbuf) {
  100. lame_report_fnc(mp->report_err, "hip: addbuf() Out of memory!\n");
  101. return NULL;
  102. }
  103. nbuf->pnt = (unsigned char *) malloc((size_t) size);
  104. if (!nbuf->pnt) {
  105. free(nbuf);
  106. return NULL;
  107. }
  108. nbuf->size = size;
  109. memcpy(nbuf->pnt, buf, (size_t) size);
  110. nbuf->next = NULL;
  111. nbuf->prev = mp->head;
  112. nbuf->pos = 0;
  113. if (!mp->tail) {
  114. mp->tail = nbuf;
  115. }
  116. else {
  117. mp->head->next = nbuf;
  118. }
  119. mp->head = nbuf;
  120. mp->bsize += size;
  121. return nbuf;
  122. }
  123. void
  124. remove_buf(PMPSTR mp)
  125. {
  126. struct buf *buf = mp->tail;
  127. mp->tail = buf->next;
  128. if (mp->tail)
  129. mp->tail->prev = NULL;
  130. else {
  131. mp->tail = mp->head = NULL;
  132. }
  133. free(buf->pnt);
  134. free(buf);
  135. }
  136. static int
  137. read_buf_byte(PMPSTR mp)
  138. {
  139. unsigned int b;
  140. int pos;
  141. pos = mp->tail->pos;
  142. while (pos >= mp->tail->size) {
  143. remove_buf(mp);
  144. if (!mp->tail) {
  145. lame_report_fnc(mp->report_err, "hip: Fatal error! tried to read past mp buffer\n");
  146. exit(1);
  147. }
  148. pos = mp->tail->pos;
  149. }
  150. b = mp->tail->pnt[pos];
  151. mp->bsize--;
  152. mp->tail->pos++;
  153. return b;
  154. }
  155. static void
  156. read_head(PMPSTR mp)
  157. {
  158. unsigned long head;
  159. head = read_buf_byte(mp);
  160. head <<= 8;
  161. head |= read_buf_byte(mp);
  162. head <<= 8;
  163. head |= read_buf_byte(mp);
  164. head <<= 8;
  165. head |= read_buf_byte(mp);
  166. mp->header = head;
  167. }
  168. static void
  169. copy_mp(PMPSTR mp, int size, unsigned char *ptr)
  170. {
  171. int len = 0;
  172. while (len < size && mp->tail) {
  173. int nlen;
  174. int blen = mp->tail->size - mp->tail->pos;
  175. if ((size - len) <= blen) {
  176. nlen = size - len;
  177. }
  178. else {
  179. nlen = blen;
  180. }
  181. memcpy(ptr + len, mp->tail->pnt + mp->tail->pos, (size_t) nlen);
  182. len += nlen;
  183. mp->tail->pos += nlen;
  184. mp->bsize -= nlen;
  185. if (mp->tail->pos == mp->tail->size) {
  186. remove_buf(mp);
  187. }
  188. }
  189. }
  190. /* number of bytes needed by GetVbrTag to parse header */
  191. #define XING_HEADER_SIZE 194
  192. /*
  193. traverse mp data structure without changing it
  194. (just like sync_buffer)
  195. pull out Xing bytes
  196. call vbr header check code from LAME
  197. if we find a header, parse it and also compute the VBR header size
  198. if no header, do nothing.
  199. bytes = number of bytes before MPEG header. skip this many bytes
  200. before starting to read
  201. return value: number of bytes in VBR header, including syncword
  202. */
  203. static int
  204. check_vbr_header(PMPSTR mp, int bytes)
  205. {
  206. int i, pos;
  207. struct buf *buf = mp->tail;
  208. unsigned char xing[XING_HEADER_SIZE];
  209. VBRTAGDATA pTagData;
  210. pos = buf->pos;
  211. /* skip to valid header */
  212. for (i = 0; i < bytes; ++i) {
  213. while (pos >= buf->size) {
  214. buf = buf->next;
  215. if (!buf)
  216. return -1; /* fatal error */
  217. pos = buf->pos;
  218. }
  219. ++pos;
  220. }
  221. /* now read header */
  222. for (i = 0; i < XING_HEADER_SIZE; ++i) {
  223. while (pos >= buf->size) {
  224. buf = buf->next;
  225. if (!buf)
  226. return -1; /* fatal error */
  227. pos = buf->pos;
  228. }
  229. xing[i] = buf->pnt[pos];
  230. ++pos;
  231. }
  232. /* check first bytes for Xing header */
  233. mp->vbr_header = GetVbrTag(&pTagData, xing);
  234. if (mp->vbr_header) {
  235. mp->num_frames = pTagData.frames;
  236. mp->enc_delay = pTagData.enc_delay;
  237. mp->enc_padding = pTagData.enc_padding;
  238. /* lame_report_fnc(mp->report_msg,"hip: delays: %i %i \n",mp->enc_delay,mp->enc_padding); */
  239. /* lame_report_fnc(mp->report_msg,"hip: Xing VBR header dectected. MP3 file has %i frames\n", pTagData.frames); */
  240. if (pTagData.headersize < 1)
  241. return 1;
  242. return pTagData.headersize;
  243. }
  244. return 0;
  245. }
  246. static int
  247. sync_buffer(PMPSTR mp, int free_match)
  248. {
  249. /* traverse mp structure without modifying pointers, looking
  250. * for a frame valid header.
  251. * if free_format, valid header must also have the same
  252. * samplerate.
  253. * return number of bytes in mp, before the header
  254. * return -1 if header is not found
  255. */
  256. unsigned int b[4] = { 0, 0, 0, 0 };
  257. int i, h, pos;
  258. struct buf *buf = mp->tail;
  259. if (!buf)
  260. return -1;
  261. pos = buf->pos;
  262. for (i = 0; i < mp->bsize; i++) {
  263. /* get 4 bytes */
  264. b[0] = b[1];
  265. b[1] = b[2];
  266. b[2] = b[3];
  267. while (pos >= buf->size) {
  268. buf = buf->next;
  269. if (!buf) {
  270. return -1;
  271. /* not enough data to read 4 bytes */
  272. }
  273. pos = buf->pos;
  274. }
  275. b[3] = buf->pnt[pos];
  276. ++pos;
  277. if (i >= 3) {
  278. struct frame *fr = &mp->fr;
  279. unsigned long head;
  280. head = b[0];
  281. head <<= 8;
  282. head |= b[1];
  283. head <<= 8;
  284. head |= b[2];
  285. head <<= 8;
  286. head |= b[3];
  287. h = head_check(head, fr->lay);
  288. if (h && free_match) {
  289. /* just to be even more thorough, match the sample rate */
  290. int mode, stereo, sampling_frequency, mpeg25, lsf;
  291. if (head & (1 << 20)) {
  292. lsf = (head & (1 << 19)) ? 0x0 : 0x1;
  293. mpeg25 = 0;
  294. }
  295. else {
  296. lsf = 1;
  297. mpeg25 = 1;
  298. }
  299. mode = ((head >> 6) & 0x3);
  300. stereo = (mode == MPG_MD_MONO) ? 1 : 2;
  301. if (mpeg25)
  302. sampling_frequency = 6 + ((head >> 10) & 0x3);
  303. else
  304. sampling_frequency = ((head >> 10) & 0x3) + (lsf * 3);
  305. h = ((stereo == fr->stereo) && (lsf == fr->lsf) && (mpeg25 == fr->mpeg25) &&
  306. (sampling_frequency == fr->sampling_frequency));
  307. }
  308. if (h) {
  309. return i - 3;
  310. }
  311. }
  312. }
  313. return -1;
  314. }
  315. void
  316. decode_reset(PMPSTR mp)
  317. {
  318. #if 0
  319. remove_buf(mp);
  320. /* start looking for next frame */
  321. /* mp->fsizeold = mp->framesize; */
  322. mp->fsizeold = -1;
  323. mp->old_free_format = mp->free_format;
  324. mp->framesize = 0;
  325. mp->header_parsed = 0;
  326. mp->side_parsed = 0;
  327. mp->data_parsed = 0;
  328. mp->sync_bitstream = 1; /* TODO check if this is right */
  329. #else
  330. InitMP3(mp); /* Less error prone to just to reinitialise. */
  331. #endif
  332. }
  333. int
  334. audiodata_precedesframes(PMPSTR mp)
  335. {
  336. if (mp->fr.lay == 3)
  337. return layer3_audiodata_precedesframes(mp);
  338. else
  339. return 0; /* For Layer 1 & 2 the audio data starts at the frame that describes it, so no audio data precedes. */
  340. }
  341. static int
  342. decodeMP3_clipchoice(PMPSTR mp, unsigned char *in, int isize, char *out, int *done,
  343. int (*synth_1to1_mono_ptr) (PMPSTR, real *, unsigned char *, int *),
  344. int (*synth_1to1_ptr) (PMPSTR, real *, int, unsigned char *, int *))
  345. {
  346. int i, iret, bits, bytes;
  347. if (in && isize && addbuf(mp, in, isize) == NULL)
  348. return MP3_ERR;
  349. /* First decode header */
  350. if (!mp->header_parsed) {
  351. if (mp->fsizeold == -1 || mp->sync_bitstream) {
  352. int vbrbytes;
  353. mp->sync_bitstream = 0;
  354. /* This is the very first call. sync with anything */
  355. /* bytes= number of bytes before header */
  356. bytes = sync_buffer(mp, 0);
  357. /* now look for Xing VBR header */
  358. if (mp->bsize >= bytes + XING_HEADER_SIZE) {
  359. /* vbrbytes = number of bytes in entire vbr header */
  360. vbrbytes = check_vbr_header(mp, bytes);
  361. }
  362. else {
  363. /* not enough data to look for Xing header */
  364. #ifdef HIP_DEBUG
  365. lame_report_fnc(mp->report_dbg, "hip: not enough data to look for Xing header\n");
  366. #endif
  367. return MP3_NEED_MORE;
  368. }
  369. if (mp->vbr_header) {
  370. /* do we have enough data to parse entire Xing header? */
  371. if (bytes + vbrbytes > mp->bsize) {
  372. /* lame_report_fnc(mp->report_err,"hip: not enough data to parse entire Xing header\n"); */
  373. return MP3_NEED_MORE;
  374. }
  375. /* read in Xing header. Buffer data in case it
  376. * is used by a non zero main_data_begin for the next
  377. * frame, but otherwise dont decode Xing header */
  378. #ifdef HIP_DEBUG
  379. lame_report_fnc(mp->report_dbg, "hip: found xing header, skipping %i bytes\n", vbrbytes + bytes);
  380. #endif
  381. for (i = 0; i < vbrbytes + bytes; ++i)
  382. read_buf_byte(mp);
  383. /* now we need to find another syncword */
  384. /* just return and make user send in more data */
  385. return MP3_NEED_MORE;
  386. }
  387. }
  388. else {
  389. /* match channels, samplerate, etc, when syncing */
  390. bytes = sync_buffer(mp, 1);
  391. }
  392. /* buffer now synchronized */
  393. if (bytes < 0) {
  394. /* lame_report_fnc(mp->report_err,"hip: need more bytes %d\n", bytes); */
  395. return MP3_NEED_MORE;
  396. }
  397. if (bytes > 0) {
  398. /* there were some extra bytes in front of header.
  399. * bitstream problem, but we are now resynced
  400. * should try to buffer previous data in case new
  401. * frame has nonzero main_data_begin, but we need
  402. * to make sure we do not overflow buffer
  403. */
  404. int size;
  405. if (mp->fsizeold != -1) {
  406. lame_report_fnc(mp->report_err, "hip: bitstream problem, resyncing skipping %d bytes...\n", bytes);
  407. }
  408. mp->old_free_format = 0;
  409. #if 1
  410. /* FIXME: correct ??? */
  411. mp->sync_bitstream = 1;
  412. #endif
  413. /* skip some bytes, buffer the rest */
  414. size = (int) (mp->wordpointer - (mp->bsspace[mp->bsnum] + 512));
  415. if (size > MAXFRAMESIZE) {
  416. /* wordpointer buffer is trashed. probably cant recover, but try anyway */
  417. lame_report_fnc(mp->report_err, "hip: wordpointer trashed. size=%i (%i) bytes=%i \n",
  418. size, MAXFRAMESIZE, bytes);
  419. size = 0;
  420. mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
  421. }
  422. /* buffer contains 'size' data right now
  423. we want to add 'bytes' worth of data, but do not
  424. exceed MAXFRAMESIZE, so we through away 'i' bytes */
  425. i = (size + bytes) - MAXFRAMESIZE;
  426. for (; i > 0; --i) {
  427. --bytes;
  428. read_buf_byte(mp);
  429. }
  430. copy_mp(mp, bytes, mp->wordpointer);
  431. mp->fsizeold += bytes;
  432. }
  433. read_head(mp);
  434. if (!decode_header(mp, &mp->fr, mp->header))
  435. return MP3_ERR;
  436. mp->header_parsed = 1;
  437. mp->framesize = mp->fr.framesize;
  438. mp->free_format = (mp->framesize == 0);
  439. if (mp->fr.lsf)
  440. mp->ssize = (mp->fr.stereo == 1) ? 9 : 17;
  441. else
  442. mp->ssize = (mp->fr.stereo == 1) ? 17 : 32;
  443. if (mp->fr.error_protection)
  444. mp->ssize += 2;
  445. mp->bsnum = 1 - mp->bsnum; /* toggle buffer */
  446. mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
  447. mp->bitindex = 0;
  448. /* for very first header, never parse rest of data */
  449. if (mp->fsizeold == -1) {
  450. #ifdef HIP_DEBUG
  451. lame_report_fnc(mp->report_dbg, "hip: not parsing the rest of the data of the first header\n");
  452. #endif
  453. return MP3_NEED_MORE;
  454. }
  455. } /* end of header parsing block */
  456. /* now decode side information */
  457. if (!mp->side_parsed) {
  458. /* Layer 3 only */
  459. if (mp->fr.lay == 3) {
  460. if (mp->bsize < mp->ssize)
  461. return MP3_NEED_MORE;
  462. copy_mp(mp, mp->ssize, mp->wordpointer);
  463. if (mp->fr.error_protection)
  464. getbits(mp, 16);
  465. bits = decode_layer3_sideinfo(mp);
  466. /* bits = actual number of bits needed to parse this frame */
  467. /* can be negative, if all bits needed are in the reservoir */
  468. if (bits < 0)
  469. bits = 0;
  470. /* read just as many bytes as necessary before decoding */
  471. mp->dsize = (bits + 7) / 8;
  472. if (!mp->free_format) {
  473. /* do not read more than framsize data */
  474. int framesize = mp->fr.framesize - mp->ssize;
  475. if (mp->dsize > framesize) {
  476. lame_report_fnc(mp->report_err,
  477. "hip: error audio data exceeds framesize by %d bytes\n",
  478. mp->dsize - framesize);
  479. mp->dsize = framesize;
  480. }
  481. }
  482. #ifdef HIP_DEBUG
  483. lame_report_fnc(mp->report_dbg,
  484. "hip: %d bits needed to parse layer III frame, number of bytes to read before decoding dsize = %d\n",
  485. bits, mp->dsize);
  486. #endif
  487. /* this will force mpglib to read entire frame before decoding */
  488. /* mp->dsize= mp->framesize - mp->ssize; */
  489. }
  490. else {
  491. /* Layers 1 and 2 */
  492. /* check if there is enough input data */
  493. if (mp->fr.framesize > mp->bsize)
  494. return MP3_NEED_MORE;
  495. /* takes care that the right amount of data is copied into wordpointer */
  496. mp->dsize = mp->fr.framesize;
  497. mp->ssize = 0;
  498. }
  499. mp->side_parsed = 1;
  500. }
  501. /* now decode main data */
  502. iret = MP3_NEED_MORE;
  503. if (!mp->data_parsed) {
  504. if (mp->dsize > mp->bsize) {
  505. return MP3_NEED_MORE;
  506. }
  507. copy_mp(mp, mp->dsize, mp->wordpointer);
  508. *done = 0;
  509. /*do_layer3(&mp->fr,(unsigned char *) out,done); */
  510. switch (mp->fr.lay) {
  511. case 1:
  512. if (mp->fr.error_protection)
  513. getbits(mp, 16);
  514. if (decode_layer1_frame(mp, (unsigned char *) out, done) < 0)
  515. return MP3_ERR;
  516. break;
  517. case 2:
  518. if (mp->fr.error_protection)
  519. getbits(mp, 16);
  520. decode_layer2_frame(mp, (unsigned char *) out, done);
  521. break;
  522. case 3:
  523. decode_layer3_frame(mp, (unsigned char *) out, done, synth_1to1_mono_ptr, synth_1to1_ptr);
  524. break;
  525. default:
  526. lame_report_fnc(mp->report_err, "hip: invalid layer %d\n", mp->fr.lay);
  527. }
  528. mp->wordpointer = mp->bsspace[mp->bsnum] + 512 + mp->ssize + mp->dsize;
  529. mp->data_parsed = 1;
  530. iret = MP3_OK;
  531. }
  532. /* remaining bits are ancillary data, or reservoir for next frame
  533. * If free format, scan stream looking for next frame to determine
  534. * mp->framesize */
  535. if (mp->free_format) {
  536. if (mp->old_free_format) {
  537. /* free format. bitrate must not vary */
  538. mp->framesize = mp->fsizeold_nopadding + (mp->fr.padding);
  539. }
  540. else {
  541. bytes = sync_buffer(mp, 1);
  542. if (bytes < 0)
  543. return iret;
  544. mp->framesize = bytes + mp->ssize + mp->dsize;
  545. mp->fsizeold_nopadding = mp->framesize - mp->fr.padding;
  546. #if 0
  547. lame_report_fnc(mp->report_dbg,"hip: freeformat bitstream: estimated bitrate=%ikbs \n",
  548. 8*(4+mp->framesize)*freqs[mp->fr.sampling_frequency]/
  549. (1000*576*(2-mp->fr.lsf)));
  550. #endif
  551. }
  552. }
  553. /* buffer the ancillary data and reservoir for next frame */
  554. bytes = mp->framesize - (mp->ssize + mp->dsize);
  555. if (bytes > mp->bsize) {
  556. return iret;
  557. }
  558. if (bytes > 0) {
  559. int size;
  560. #if 1
  561. /* FIXME: while loop OK ??? */
  562. while (bytes > 512) {
  563. read_buf_byte(mp);
  564. bytes--;
  565. mp->framesize--;
  566. }
  567. #endif
  568. copy_mp(mp, bytes, mp->wordpointer);
  569. mp->wordpointer += bytes;
  570. size = (int) (mp->wordpointer - (mp->bsspace[mp->bsnum] + 512));
  571. if (size > MAXFRAMESIZE) {
  572. lame_report_fnc(mp->report_err, "hip: fatal error. MAXFRAMESIZE not large enough.\n");
  573. }
  574. }
  575. /* the above frame is completely parsed. start looking for next frame */
  576. mp->fsizeold = mp->framesize;
  577. mp->old_free_format = mp->free_format;
  578. mp->framesize = 0;
  579. mp->header_parsed = 0;
  580. mp->side_parsed = 0;
  581. mp->data_parsed = 0;
  582. return iret;
  583. }
  584. int
  585. decodeMP3(PMPSTR mp, unsigned char *in, int isize, char *out, int osize, int *done)
  586. {
  587. if (osize < 4608) {
  588. lame_report_fnc(mp->report_err, "hip: Insufficient memory for decoding buffer %d\n", osize);
  589. return MP3_ERR;
  590. }
  591. /* passing pointers to the functions which clip the samples */
  592. return decodeMP3_clipchoice(mp, in, isize, out, done, synth_1to1_mono, synth_1to1);
  593. }
  594. int
  595. decodeMP3_unclipped(PMPSTR mp, unsigned char *in, int isize, char *out, int osize, int *done)
  596. {
  597. /* we forbid input with more than 1152 samples per channel for output in unclipped mode */
  598. if (osize < (int) (1152 * 2 * sizeof(real))) {
  599. lame_report_fnc(mp->report_err, "hip: out space too small for unclipped mode\n");
  600. return MP3_ERR;
  601. }
  602. /* passing pointers to the functions which don't clip the samples */
  603. return decodeMP3_clipchoice(mp, in, isize, out, done, synth_1to1_mono_unclipped,
  604. synth_1to1_unclipped);
  605. }