MCPcopy Create free account
hub / github.com/zhuker/lamejs / copy_buffer

Method copy_buffer

src/main/java/mp3/BitStream.java:899–995  ·  view source on GitHub ↗

copy data out of the internal MP3 bit buffer into a user supplied unsigned char buffer. mp3data=0 indicates data in buffer is an id3tags and VBR tags mp3data=1 data is real mp3 frame data.

(final LameInternalFlags gfc,
			final byte[] buffer, final int bufferPos, final int size,
			final int mp3data)

Source from the content-addressed store, hash-verified

897 * </PRE>
898 */
899 public final int copy_buffer(final LameInternalFlags gfc,
900 final byte[] buffer, final int bufferPos, final int size,
901 final int mp3data) {
902 final int minimum = bufByteIdx + 1;
903 if (minimum <= 0)
904 return 0;
905 if (size != 0 && minimum > size) {
906 /* buffer is too small */
907 return -1;
908 }
909 System.arraycopy(buf, 0, buffer, bufferPos, minimum);
910 bufByteIdx = -1;
911 bufBitIdx = 0;
912
913 if (mp3data != 0) {
914 int[] crc = new int[1];
915 crc[0] = gfc.nMusicCRC;
916 vbr.updateMusicCRC(crc, buffer, bufferPos, minimum);
917 gfc.nMusicCRC = crc[0];
918
919 /**
920 * sum number of bytes belonging to the mp3 stream this info will be
921 * written into the Xing/LAME header for seeking
922 */
923 if (minimum > 0) {
924 gfc.VBR_seek_table.nBytesWritten += minimum;
925 }
926
927 if (gfc.decode_on_the_fly) { /* decode the frame */
928 float pcm_buf[][] = new float[2][1152];
929 int mp3_in = minimum;
930 int samples_out = -1;
931 int i;
932
933 /* re-synthesis to pcm. Repeat until we get a samples_out=0 */
934 while (samples_out != 0) {
935
936 samples_out = mpg.hip_decode1_unclipped(gfc.hip, buffer,
937 bufferPos, mp3_in, pcm_buf[0], pcm_buf[1]);
938 /*
939 * samples_out = 0: need more data to decode samples_out =
940 * -1: error. Lets assume 0 pcm output samples_out = number
941 * of samples output
942 */
943
944 /*
945 * set the lenght of the mp3 input buffer to zero, so that
946 * in the next iteration of the loop we will be querying
947 * mpglib about buffered data
948 */
949 mp3_in = 0;
950
951 if (samples_out == -1) {
952 /*
953 * error decoding. Not fatal, but might screw up the
954 * ReplayGain tag. What should we do? Ignore for now
955 */
956 samples_out = 0;

Callers 13

EncoderFunction · 0.80
LameFunction · 0.80
cFunction · 0.80
vFunction · 0.80
WFunction · 0.80
EncoderFunction · 0.80
LameFunction · 0.80
lame_encode_mp3_frameMethod · 0.80

Calls 3

updateMusicCRCMethod · 0.80
hip_decode1_unclippedMethod · 0.80
AnalyzeSamplesMethod · 0.80

Tested by

no test coverage detected