Fix advanced EQ menu
[maemo-rb.git] / rbutil / rbutilqt / base / encoderrbspeex.cpp
blobb5b516ec871b50dd5ea50f20ff25a1d3a0fbcfca
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QtCore>
20 #include "encoderrbspeex.h"
21 #include "rbsettings.h"
22 #include "rbspeex.h"
24 EncoderRbSpeex::EncoderRbSpeex(QObject *parent) : EncoderBase(parent)
29 void EncoderRbSpeex::generateSettings()
31 loadSettings();
32 insertSetting(eVOLUME, new EncTtsSetting(this, EncTtsSetting::eDOUBLE,
33 tr("Volume:"), volume, 1.0, 10.0));
34 insertSetting(eQUALITY, new EncTtsSetting(this, EncTtsSetting::eDOUBLE,
35 tr("Quality:"), quality, 0, 10.0));
36 insertSetting(eCOMPLEXITY, new EncTtsSetting(this, EncTtsSetting::eINT,
37 tr("Complexity:"), complexity, 0, 10));
38 insertSetting(eNARROWBAND,new EncTtsSetting(this, EncTtsSetting::eBOOL,
39 tr("Use Narrowband:"), narrowband));
42 void EncoderRbSpeex::saveSettings()
44 //save settings in user config
45 RbSettings::setSubValue("rbspeex",RbSettings::EncoderVolume,
46 getSetting(eVOLUME)->current().toDouble());
47 RbSettings::setSubValue("rbspeex",RbSettings::EncoderQuality,
48 getSetting(eQUALITY)->current().toDouble());
49 RbSettings::setSubValue("rbspeex",RbSettings::EncoderComplexity,
50 getSetting(eCOMPLEXITY)->current().toInt());
51 RbSettings::setSubValue("rbspeex",RbSettings::EncoderNarrowBand,
52 getSetting(eNARROWBAND)->current().toBool());
54 RbSettings::sync();
58 void EncoderRbSpeex::loadSettings(void)
60 // try to get config from settings
61 quality = RbSettings::subValue("rbspeex", RbSettings::EncoderQuality).toDouble();
62 if(quality < 0) {
63 quality = 8.0;
65 complexity = RbSettings::subValue("rbspeex", RbSettings::EncoderComplexity).toInt();
66 volume = RbSettings::subValue("rbspeex", RbSettings::EncoderVolume).toDouble();
67 narrowband = RbSettings::subValue("rbspeex", RbSettings::EncoderNarrowBand).toBool();
71 bool EncoderRbSpeex::start()
74 // make sure configuration parameters are set.
75 loadSettings();
76 return true;
79 bool EncoderRbSpeex::encode(QString input,QString output)
81 qDebug() << "[RbSpeex] Encoding " << input << " to "<< output;
82 char errstr[512];
84 FILE *fin,*fout;
85 if ((fin = fopen(input.toLocal8Bit(), "rb")) == NULL) {
86 qDebug() << "[RbSpeex] Error: could not open input file\n";
87 return false;
89 if ((fout = fopen(output.toLocal8Bit(), "wb")) == NULL) {
90 qDebug() << "[RbSpeex] Error: could not open output file\n";
91 fclose(fin);
92 return false;
95 int ret = encode_file(fin, fout, quality, complexity, narrowband, volume,
96 errstr, sizeof(errstr));
97 fclose(fout);
98 fclose(fin);
100 if (!ret) {
101 /* Attempt to delete unfinished output */
102 qDebug() << "[RbSpeex] Error:" << errstr;
103 QFile(output).remove();
104 return false;
106 return true;
109 bool EncoderRbSpeex::configOk()
111 // check config. Make sure current settings are loaded.
112 loadSettings();
113 if(volume <= 0 || quality <= 0 || complexity <= 0)
114 return false;
115 else
116 return true;