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