1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/* This file is part of the KDE project
* Copyright (C) 2002 Shane Wright <me@shanewright.co.uk>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include <config.h>
#include "tdefile_au.h"
#include <kprocess.h>
#include <klocale.h>
#include <kgenericfactory.h>
#include <kstringvalidator.h>
#include <kdebug.h>
#include <tqdict.h>
#include <tqvalidator.h>
#include <tqcstring.h>
#include <tqfile.h>
#include <tqdatetime.h>
#if !defined(__osf__)
#include <inttypes.h>
#else
typedef unsigned long uint32_t;
typedef unsigned short uint16_t;
#endif
typedef KGenericFactory<KAuPlugin> AuFactory;
K_EXPORT_COMPONENT_FACTORY(tdefile_au, AuFactory( "tdefile_au" ))
KAuPlugin::KAuPlugin(TQObject *parent, const char *name,
const TQStringList &args)
: KFilePlugin(parent, name, args)
{
KFileMimeTypeInfo* info = addMimeTypeInfo( "audio/basic" );
KFileMimeTypeInfo::GroupInfo* group = 0L;
group = addGroupInfo(info, "Technical", i18n("Technical Details"));
KFileMimeTypeInfo::ItemInfo* item;
item = addItemInfo(group, "Length", i18n("Length"), TQVariant::Int);
setSuffix(item, "s");
item = addItemInfo(group, "Sample Rate", i18n("Sample Rate"), TQVariant::Int);
setSuffix(item, "Hz");
item = addItemInfo(group, "Channels", i18n("Channels"), TQVariant::Int);
item = addItemInfo(group, "Encoding", i18n("Encoding"), TQVariant::String);
}
bool KAuPlugin::readInfo( KFileMetaInfo& info, uint what)
{
// the file signature, wants to be tidier...
const char fsig[] = { 0x2e, 0x73, 0x6e, 0x64 };
// a dword buffer for input
char inbuf[4];
// some vars for the file properties
uint32_t datasize;
uint32_t encoding;
uint32_t samplerate;
uint32_t channels;
uint16_t bytespersample;
if ( info.path().isEmpty() ) // remote file
return false;
TQFile file(info.path());
if (!file.open(IO_ReadOnly))
{
kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl;
return false;
}
TQDataStream dstream(&file);
// AU files are big-endian
dstream.setByteOrder(TQDataStream::BigEndian);
// Read and verify the signature
dstream.readRawBytes(inbuf, 4);
if (memcmp(fsig, inbuf, 4))
return false;
// skip unwanted bits
file.at(8);
// grab the bits we want
dstream >> datasize;
dstream >> encoding;
dstream >> samplerate;
dstream >> channels;
// add the info
KFileMetaInfoGroup group = appendGroup(info, "Technical");
appendItem(group, "Sample Rate", (uint) samplerate);
appendItem(group, "Channels", (uint) channels);
// work out the encoding
switch (encoding) {
case 1 :
appendItem(group, "Encoding", i18n("8-bit ISDN u-law"));
bytespersample = 1;
break;
case 2 :
appendItem(group, "Encoding", i18n("8-bit linear PCM [REF-PCM]"));
bytespersample = 1;
break;
case 3 :
appendItem(group, "Encoding", i18n("16-bit linear PCM"));
bytespersample = 2;
break;
case 4 :
appendItem(group, "Encoding", i18n("24-bit linear PCM"));
bytespersample = 3;
break;
case 5 :
appendItem(group, "Encoding", i18n("32-bit linear PCM"));
bytespersample = 4;
break;
case 6 :
appendItem(group, "Encoding", i18n("32-bit IEEE floating point"));
bytespersample = 4;
break;
case 7 :
appendItem(group, "Encoding", i18n("64-bit IEEE floating point"));
bytespersample = 8;
break;
case 23 :
appendItem(group, "Encoding", i18n("8-bit ISDN u-law compressed"));
bytespersample = 1;
break;
default :
appendItem(group, "Encoding", i18n("Unknown"));
bytespersample = 0;
}
// work out length from bytespersample + channels + size
if ((channels > 0) && (datasize > 0) && (datasize != 0xFFFFFFFF) && (bytespersample > 0) && (samplerate > 0)) {
uint32_t length = datasize / channels / bytespersample / samplerate;
appendItem(group, "Length", (uint) length);
} else {
appendItem(group, "Length", "???");
}
return true;
}
#include "tdefile_au.moc"
|