<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o = "urn:schemas-microsoft-com:office:office"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.5730.13" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=140023509-05092011><FONT face=Arial
color=#0000ff size=2>Hi all. I'm picking up this old thread I started a while
ago because I've now done some more changes.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=140023509-05092011><FONT face=Arial
color=#0000ff size=2>Since then we've discovered some MP3 files were detected as
invalid after my previous patch.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=140023509-05092011><FONT face=Arial
color=#0000ff size=2>This was because the MP3 files were inside a WAV container
and didn't contain any tags. These additional changes fix
that:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=140023509-05092011><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=140023509-05092011>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-spacerun: yes"> </SPAN></SPAN><SPAN
style="FONT-SIZE: 10pt; COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">//if no tag
was found at all, make sure this is a valid MP3 file by checking the MP3
header</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-spacerun: yes"> </SPAN></SPAN><B><SPAN
style="FONT-SIZE: 10pt; COLOR: #7f0055; FONT-FAMILY: 'Courier New'">if</SPAN></B><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">
(!d->hasID3v2 && ! d->hasID3v1 && !d->hasAPE)
{</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 1"> </SPAN></SPAN><SPAN
style="FONT-SIZE: 10pt; COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">//goto the
beginning of the file and read the header</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 1">
</SPAN>seek(0);</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 1"> </SPAN>MPEG::Header
header(readBlock(4));</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 1"> </SPAN></SPAN><B><SPAN
style="FONT-SIZE: 10pt; COLOR: #7f0055; FONT-FAMILY: 'Courier New'">bool</SPAN></B><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> valid =
header.isValid();</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 1"> </SPAN></SPAN><SPAN
style="FONT-SIZE: 10pt; COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">//if still
not valid then maybe the MP3 stream is in a WAV container?...</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 1"> </SPAN></SPAN><B><SPAN
style="FONT-SIZE: 10pt; COLOR: #7f0055; FONT-FAMILY: 'Courier New'">if</SPAN></B><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (!valid)
{</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 2">
</SPAN>RIFF::WAV::File* wav = </SPAN><B><SPAN
style="FONT-SIZE: 10pt; COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></B><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">
RIFF::WAV::File(name(), readProperties, propertiesStyle);</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 2">
</SPAN>valid = wav->isValid();</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 2">
</SPAN></SPAN><SPAN
style="FONT-SIZE: 10pt; COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">//now test
to make sure this isn't a WAV file renamed to MP3...</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 2">
</SPAN></SPAN><B><SPAN
style="FONT-SIZE: 10pt; COLOR: #7f0055; FONT-FAMILY: 'Courier New'">if</SPAN></B><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> (valid)
{</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 3">
</SPAN></SPAN><SPAN
style="FONT-SIZE: 10pt; COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">//current
position will be the beginning of the "data" chunk</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 3">
</SPAN></SPAN><B><SPAN
style="FONT-SIZE: 10pt; COLOR: #7f0055; FONT-FAMILY: 'Courier New'">long</SPAN></B><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> pos =
wav->tell();</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 3">
</SPAN></SPAN><SPAN
style="FONT-SIZE: 10pt; COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">//we need to
seek over the chunk id ("data") and the chunk size (4 bytes)</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 3">
</SPAN>wav->seek(pos + 8);</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 3">
</SPAN>MPEG::Header header(wav->readBlock(4));</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 3">
</SPAN>valid = header.isValid();</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 2">
</SPAN>}</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 2">
</SPAN></SPAN><B><SPAN
style="FONT-SIZE: 10pt; COLOR: #7f0055; FONT-FAMILY: 'Courier New'">delete</SPAN></B><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">
wav;</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 1"> </SPAN>}</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-tab-count: 1">
</SPAN>setValid(valid);</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
style="mso-spacerun: yes"> </SPAN>}</SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"></SPAN> </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
class=140023509-05092011><FONT face=Arial color=#0000ff>Does anyone know a
better way of handling MP3 validity?</FONT></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
class=140023509-05092011></SPAN></SPAN> </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
class=140023509-05092011><FONT face=Arial
color=#0000ff>Regards,</FONT></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"><SPAN
class=140023509-05092011><FONT face=Arial
color=#0000ff>David</FONT></SPAN></SPAN><SPAN
style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"></SPAN></P></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> David Place
[mailto:David.Place@tomtom.com] <BR><B>Sent:</B> 03 June 2011
17:19<BR><B>To:</B> taglib-devel@kde.org<BR><B>Subject:</B> Detection of valid
audio files<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2>Hi, one of the
requirements we have here is to detect if an audio file is valid or not. E.g: if
an EXE file was renamed to .MP3, we need to know that it's bad! I've tested
this on several of the supported file formats and the behaviour of TagLib
seems to vary. Sometimes FileRef.IsNull() is true, sometimes I have to check the
Tag() pointer and even sometimes I need to check the audioProperties() pointer.
However, with MP3 files, the results from a valid MP3 file without any tags
(ID3v1, ID3v2 & APE) and an invalid MP3 file are the same so I can't detect
if it's truely a valid MP3 file or not. Even the audioProperties() gives me
results.</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2>I have found a way
around this by a small modification to 'mpegfile.cpp' in
MPEG::File::read:</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2></FONT><FONT
face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-spacerun: yes"> </SPAN><SPAN style="COLOR: green">//if no tag
was found at all, make sure this is a valid MP3 file by checking the MP3
header</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-spacerun: yes"> </SPAN><SPAN style="COLOR: blue">if</SPAN>
(!d->hasID3v2 && ! d->hasID3v1 && !d->hasAPE)
{<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-tab-count: 1"> </SPAN><SPAN
style="COLOR: green">//goto the beginning of the file and read the
header</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-tab-count: 1">
</SPAN>seek(0);<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-tab-count: 1">
</SPAN>MPEG::Header header(readBlock(4));<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-tab-count: 1">
</SPAN>setValid(header.isValid());<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN
style="FONT-SIZE: 9.5pt; FONT-FAMILY: Consolas; mso-bidi-font-family: Consolas"><SPAN
style="mso-spacerun: yes"> </SPAN>}<o:p></o:p></SPAN></P></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2>So after the tags
have tried to be read, if no tags could be read, check the MPEG header. This
seems ok to me providing the first 4 bytes of the file would ALWAYS be the start
of an MPEG header for valid MP3 file.</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial size=2>Is this approach any
good?</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2>David</FONT></SPAN></DIV>
<DIV><SPAN class=763415815-03062011><FONT face=Arial
size=2></FONT></SPAN> </DIV></BODY></HTML>