idtag.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:3k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*
  2.   Copyright (c) 2005, The Musepack Development Team
  3.   All rights reserved.
  4.   Redistribution and use in source and binary forms, with or without
  5.   modification, are permitted provided that the following conditions are
  6.   met:
  7.   * Redistributions of source code must retain the above copyright
  8.   notice, this list of conditions and the following disclaimer.
  9.   * Redistributions in binary form must reproduce the above
  10.   copyright notice, this list of conditions and the following
  11.   disclaimer in the documentation and/or other materials provided
  12.   with the distribution.
  13.   * Neither the name of the The Musepack Development Team nor the
  14.   names of its contributors may be used to endorse or promote
  15.   products derived from this software without specific prior
  16.   written permission.
  17.   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18.   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19.   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20.   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21.   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22.   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23.   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24.   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25.   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26.   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27.   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /// file idtag.c
  30. /// Rudimentary id3tag handling routines, just enough to skip id3v2 tags,
  31. /// if present.
  32. #include "musepack/musepack.h"
  33. #include "musepack/internal.h"
  34. mpc_int32_t
  35. JumpID3v2 (mpc_reader* r) {
  36.     unsigned char  tmp [10];
  37.     mpc_uint32_t   Unsynchronisation;   // ID3v2.4-flag
  38.     mpc_uint32_t   ExtHeaderPresent;    // ID3v2.4-flag
  39.     mpc_uint32_t   ExperimentalFlag;    // ID3v2.4-flag
  40.     mpc_uint32_t   FooterPresent;       // ID3v2.4-flag
  41.     mpc_int32_t    ret;
  42.     // seek to first byte of mpc data
  43.     if (!r->seek (r->data, 0)) {
  44.         return 0;  
  45.     }
  46.     
  47.     r->read(r->data, tmp, sizeof(tmp));
  48.     // check id3-tag
  49.     if ( 0 != memcmp ( tmp, "ID3", 3) )
  50.         return 0;
  51.     // read flags
  52.     Unsynchronisation = tmp[5] & 0x80;
  53.     ExtHeaderPresent  = tmp[5] & 0x40;
  54.     ExperimentalFlag  = tmp[5] & 0x20;
  55.     FooterPresent     = tmp[5] & 0x10;
  56.     if ( tmp[5] & 0x0F )
  57.         return -1;              // not (yet???) allowed
  58.     if ( (tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80 )
  59.         return -1;              // not allowed
  60.     // read HeaderSize (syncsave: 4 * $0xxxxxxx = 28 significant bits)
  61.     ret  = tmp[6] << 21;
  62.     ret += tmp[7] << 14;
  63.     ret += tmp[8] <<  7;
  64.     ret += tmp[9]      ;
  65.     ret += 10;
  66.     if ( FooterPresent )
  67.         ret += 10;
  68.     return ret;
  69. }