| 89 | } |
| 90 | |
| 91 | void xs_mp3_decode(xsMachine *the) |
| 92 | { |
| 93 | xsMP3 mp3 = xsmcGetHostData(xsThis); |
| 94 | void *data; |
| 95 | xsUnsignedValue count; |
| 96 | |
| 97 | if (!mp3) |
| 98 | xsUnknownError("closed"); |
| 99 | |
| 100 | xsmcGetBufferWritable(xsArg(1), (void *)&mp3->outputBuffer, &count); |
| 101 | if ((kMP3SamplesPerFrame * sizeof(int16_t)) > count) |
| 102 | xsUnknownError("output too small"); |
| 103 | mp3->outputBufferPosition = 0; |
| 104 | |
| 105 | xsmcGetBufferReadable(xsArg(0), &data, &count); |
| 106 | mad_stream_buffer(&mp3->stream, data, count); // count includes MAD_BUFFER_GUARD |
| 107 | |
| 108 | mad_frame_decode(&mp3->frame, &mp3->stream); |
| 109 | |
| 110 | enum mad_flow result = mad_synth_frame(&mp3->synth, &mp3->frame, output, mp3); |
| 111 | if (MAD_FLOW_BREAK == result) |
| 112 | xsUnknownError("break"); |
| 113 | |
| 114 | if (!mp3->stream.this_frame || !mp3->stream.next_frame) |
| 115 | return; |
| 116 | |
| 117 | xsmcSetInteger(xsResult, mp3->outputBufferPosition / sizeof(int16_t)); |
| 118 | xsmcSet(xsArg(1), xsID_samples, xsResult); |
| 119 | xsmcSetInteger(xsResult, mp3->stream.next_frame - mp3->stream.this_frame); |
| 120 | } |
nothing calls this directly
no test coverage detected