private int lame_decode_initfile(Stream fd, MP3Data mp3data, Enc enc) { var buf = new byte[100]; var pcm_l = new short[1152]; var pcm_r = new short[1152]; var freeformat = false; if (hip != null) { mpg.hip_decode_exit(hip); } hip = mpg.hip_decode_init(); var len = 4; if (fd.Position + len > fd.Length) { return(-1); } fd.Read(buf, 0, len); if (buf[0] == (sbyte)'I' && buf[1] == (sbyte)'D' && buf[2] == (sbyte)'3') { len = 6; try { fd.Read(buf, 0, len); } catch (IOException e) { return(-1); } buf[2] &= 127; buf[3] &= 127; buf[4] &= 127; buf[5] &= 127; len = (((((buf[2] << 7) + buf[3]) << 7) + buf[4]) << 7) + buf[5]; try { fd.Seek(len, SeekOrigin.Current); } catch (IOException e) { return(-1); } len = 4; try { fd.Read(buf, 0, len); } catch (IOException e) { return(-1); } } if (check_aid(buf)) { try { fd.Read(buf, 0, 2); } catch (IOException e) { return(-1); } var aid_header = (buf[0] & 0xff) + 256 * (buf[1] & 0xff); try { fd.Seek(aid_header - 6, SeekOrigin.Current); } catch (IOException e) { return(-1); } try { fd.Read(buf, 0, len); } catch (IOException e) { return(-1); } } len = 4; while (!is_syncword_mp123(buf)) { int i; for (i = 0; i < len - 1; i++) { buf[i] = buf[i + 1]; } try { fd.Read(buf, len - 1, 1); } catch (IOException e) { return(-1); } } if ((buf[2] & 0xf0) == 0) { freeformat = true; } var ret = mpg.hip_decode1_headersB(hip, buf, len, pcm_l, pcm_r, mp3data, enc, false); if (-1 == ret) { return(-1); } while (!mp3data.header_parsed) { try { fd.Read(buf, 0, buf.Length); } catch (IOException e) { return(-1); } ret = mpg.hip_decode1_headersB(hip, buf, buf.Length, pcm_l, pcm_r, mp3data, enc, false); if (-1 == ret) { return(-1); } } if (mp3data.bitrate == 0 && !freeformat) { return(lame_decode_initfile(fd, mp3data, enc)); } if (mp3data.totalframes > 0) { } else { mp3data.nsamp = -1; } return(0); }
private int lame_decode_initfile(FileStream fd, MP3Data mp3data, Enc enc) { var buf = new byte[100]; var pcm_l = new short[1152]; var pcm_r = new short[1152]; var freeformat = false; if (hip != null) { mpg.hip_decode_exit(hip); } hip = mpg.hip_decode_init(); var len = 4; try { fd.Read(buf, 0, len); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } if (buf[0] == (sbyte)'I' && buf[1] == (sbyte)'D' && buf[2] == (sbyte)'3') { if (parse.silent < 10) { Console.WriteLine( "ID3v2 found. " + "Be aware that the ID3 tag is currently lost when transcoding."); } len = 6; try { fd.Read(buf, 0, len); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } buf[2] &= 127; buf[3] &= 127; buf[4] &= 127; buf[5] &= 127; len = (((((buf[2] << 7) + buf[3]) << 7) + buf[4]) << 7) + buf[5]; try { fd.Seek(len, SeekOrigin.Current); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } len = 4; try { fd.Read(buf, 0, len); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } } if (check_aid(buf)) { try { fd.Read(buf, 0, 2); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } var aid_header = (buf[0] & 0xff) + 256 * (buf[1] & 0xff); if (parse.silent < 10) { Console.Write("Album ID found. length={0:D} \n", aid_header); } try { fd.Seek(aid_header - 6, SeekOrigin.Current); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } try { fd.Read(buf, 0, len); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } } len = 4; while (!is_syncword_mp123(buf)) { int i; for (i = 0; i < len - 1; i++) { buf[i] = buf[i + 1]; } try { fd.Read(buf, len - 1, 1); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } } if ((buf[2] & 0xf0) == 0) { if (parse.silent < 10) { Console.WriteLine("Input file is freeformat."); } freeformat = true; } var ret = mpg.hip_decode1_headersB(hip, buf, len, pcm_l, pcm_r, mp3data, enc); if (-1 == ret) { return(-1); } while (!mp3data.header_parsed) { try { fd.Read(buf, 0, 1024); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(-1); } ret = mpg.hip_decode1_headersB(hip, buf, buf.Length, pcm_l, pcm_r, mp3data, enc); if (-1 == ret) { return(-1); } } if (mp3data.bitrate == 0 && !freeformat) { if (parse.silent < 10) { Console.Error.WriteLine("fail to sync..."); } return(lame_decode_initfile(fd, mp3data, enc)); } if (mp3data.totalframes > 0) { } else { mp3data.nsamp = -1; } return(0); }