aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-12-13 17:41:10 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-12-13 17:41:10 +0000
commit0910b79d3e3287886d9d0796c2c4c3ed822e97bc (patch)
tree26f85e0e47cca0316bd9fe6e51ff73c967dde092
parenta55ba50ce1f08d80962cac410ded386cfeaa682d (diff)
downloadqmmp-0910b79d3e3287886d9d0796c2c4c3ed822e97bc.tar.gz
qmmp-0910b79d3e3287886d9d0796c2c4c3ed822e97bc.tar.bz2
qmmp-0910b79d3e3287886d9d0796c2c4c3ed822e97bc.zip
added replay gain api
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1444 90c681e8-e032-0410-971d-27865f9a5e38
-rw-r--r--src/qmmp/replaygain.cpp62
-rw-r--r--src/qmmp/replaygain.h47
-rw-r--r--src/qmmp/volumecontrol.cpp2
3 files changed, 110 insertions, 1 deletions
diff --git a/src/qmmp/replaygain.cpp b/src/qmmp/replaygain.cpp
new file mode 100644
index 000000000..876797593
--- /dev/null
+++ b/src/qmmp/replaygain.cpp
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * 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; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <math.h>
+#include "replaygain.h"
+
+ReplayGain::ReplayGain()
+{
+ m_freq = 0;
+ m_chan = 0;
+ m_bits = 0;
+ m_scale = 0;
+}
+
+void ReplayGain::configure(quint32 freq, int chan, int bits)
+{
+ m_bits = bits;
+}
+
+void ReplayGain::setReplayGainInfo(const ReplayGainInfo &info)
+{
+ m_info = info;
+ m_scale = pow(10.0, (info.trackGain()/20) * info.trackPeak());
+}
+
+void ReplayGain::applyReplayGain(char *data, qint64 size)
+{
+ size = size*8/m_bits;
+ if(m_bits == 16)
+ {
+ for (qint64 i = 0; i < size; i++)
+ ((short*)data)[i]*= m_scale;
+
+ }
+ else if(m_bits == 8)
+ {
+ for (qint64 i = 0; i < size; i++)
+ ((char*)data)[i]*= m_scale;
+ }
+ else if(m_bits == 32)
+ {
+ for (qint64 i = 0; i < size; i++)
+ ((qint32*)data)[i]*= m_scale;
+ }
+}
diff --git a/src/qmmp/replaygain.h b/src/qmmp/replaygain.h
new file mode 100644
index 000000000..67f52243b
--- /dev/null
+++ b/src/qmmp/replaygain.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * 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; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef REPLAYGAIN_H
+#define REPLAYGAIN_H
+
+#include <QtGlobal>
+#include "replaygaininfo.h"
+
+/*!
+ * @author Ilya Kotov <forkotov02@hotmail.ru>
+ */
+class ReplayGain
+{
+public:
+ ReplayGain();
+
+ void configure(quint32 freq, int chan, int bits);
+ void setReplayGainInfo(const ReplayGainInfo &info);
+ void applyReplayGain(char *data, qint64 size);
+
+private:
+ quint32 m_freq;
+ int m_chan;
+ int m_bits;
+ ReplayGainInfo m_info;
+ double m_scale;
+};
+
+#endif // REPLAYGAIN_H
diff --git a/src/qmmp/volumecontrol.cpp b/src/qmmp/volumecontrol.cpp
index d2d768f58..2e6379104 100644
--- a/src/qmmp/volumecontrol.cpp
+++ b/src/qmmp/volumecontrol.cpp
@@ -170,7 +170,7 @@ void SoftwareVolume::changeVolume(uchar *data, qint64 size, int chan, int bits)
}
else
{
- for (qint64 i = 0; i < size/4; i++)
+ for (qint64 i = 0; i < size; i++)
((qint32*)data)[i]*= qMax(m_scaleRight, m_scaleLeft);
}
}