1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
20 #include "encoderrbspeex.h"
21 #include "rbsettings.h"
24 EncoderRbSpeex::EncoderRbSpeex(QObject
*parent
) : EncoderBase(parent
)
29 void EncoderRbSpeex::generateSettings()
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());
58 void EncoderRbSpeex::loadSettings(void)
60 // try to get config from settings
61 quality
= RbSettings::subValue("rbspeex", RbSettings::EncoderQuality
).toDouble();
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.
79 bool EncoderRbSpeex::encode(QString input
,QString output
)
81 qDebug() << "[RbSpeex] Encoding " << input
<< " to "<< output
;
85 if ((fin
= fopen(input
.toLocal8Bit(), "rb")) == NULL
) {
86 qDebug() << "[RbSpeex] Error: could not open input file\n";
89 if ((fout
= fopen(output
.toLocal8Bit(), "wb")) == NULL
) {
90 qDebug() << "[RbSpeex] Error: could not open output file\n";
95 int ret
= encode_file(fin
, fout
, quality
, complexity
, narrowband
, volume
,
96 errstr
, sizeof(errstr
));
101 /* Attempt to delete unfinished output */
102 qDebug() << "[RbSpeex] Error:" << errstr
;
103 QFile(output
).remove();
109 bool EncoderRbSpeex::configOk()
111 // check config. Make sure current settings are loaded.
113 if(volume
<= 0 || quality
<= 0 || complexity
<= 0)