21 #include <QLatin1Char> 23 #include <QTextStream> 32 :m_fir(true), m_rate(0), m_coeff(), m_delay()
40 for (
unsigned int i = 0; i <
count(); i++) {
64 s += QString::number(
m_rate);
65 s += QLatin1Char(
',');
66 s +=
_((
m_fir) ?
"fir" :
"iir");
67 s += QLatin1Char(
',') + QString::number(
count());
69 for (
unsigned int i = 0; i <
count(); i++) {
70 s += QLatin1Char(
',');
71 s += QString::number(
m_delay[i]);
72 s += QLatin1Char(
',');
73 s += QString::number(
m_coeff[i]);
81 unsigned int oldnum =
count();
82 if (newnum == oldnum)
return oldnum;
92 while (oldnum < newnum) {
139 QString
name(filename);
140 Q_ASSERT(name.length());
141 if (!name.length())
return;
143 if (name.lastIndexOf(
_(
".filter")) !=
Kwave::toInt(name.length() - 7))
144 name.append(
_(
".filter"));
147 file.open(QIODevice::WriteOnly);
148 QTextStream out(&file);
150 out << ((
m_fir) ?
"FIR " :
"IIR ") <<
count() << endl;
151 for (
unsigned int i = 0; i <
count(); i++) {
164 unsigned int linenr = 0;
166 QFile file(filename);
167 file.open(QIODevice::ReadOnly);
168 QTextStream in(&file);
171 while (!in.atEnd()) {
172 line = in.readLine().simplified();
175 if (line.isEmpty() || line.isNull())
continue;
176 if ((line[0] == QLatin1Char(
'#')) || (line[0] == QLatin1Char(
'/')))
180 m_fir = line.startsWith(
_(
"FIR "));
181 qDebug(
"Filter::load(): fir = %d",
m_fir);
184 unsigned int order = line.remove(0,4).toUInt(&ok);
187 qDebug(
"Filter::load(): order = %d", order);
191 while (!in.atEnd()) {
192 line = in.readLine().simplified();
195 if (line.isEmpty() || line.isNull())
continue;
196 if ((line[0] == QLatin1Char(
'#')) || (line[0] == QLatin1Char(
'/')))
199 int spacepos = line.indexOf(QLatin1Char(
' '));
201 if (ok)
m_delay[i] = line.left(spacepos).toUInt(&ok);
202 line.remove(0, spacepos);
203 if (ok)
m_coeff[i] = line.toDouble(&ok);
208 qDebug(
"Filter::load(%s): syntax error in line %d",
209 DBG(filename), linenr);
QVector< double > m_coeff
double coeff(unsigned int index)
unsigned int delay(unsigned int index)
void save(const QString &filename)
void setDelay(unsigned int index, unsigned int newval)
void load(const QString &filename)
unsigned int resize(unsigned int newnum)
void setCoeff(unsigned int index, double newval)
const QString & nextParam()