2007-12-14 20:09:44 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-06 19:19:32 +00:00
|
|
|
#include <QtCore>
|
|
|
|
#include "encoderrbspeex.h"
|
2009-05-09 16:59:14 +00:00
|
|
|
#include "rbsettings.h"
|
2012-01-08 11:49:57 +00:00
|
|
|
#include "rbspeex.h"
|
2007-12-14 20:09:44 +00:00
|
|
|
|
2012-01-06 19:19:32 +00:00
|
|
|
EncoderRbSpeex::EncoderRbSpeex(QObject *parent) : EncoderBase(parent)
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2009-06-09 21:46:05 +00:00
|
|
|
|
2007-12-14 20:09:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-06 19:19:32 +00:00
|
|
|
void EncoderRbSpeex::generateSettings()
|
2009-04-29 21:27:01 +00:00
|
|
|
{
|
2012-01-29 14:36:30 +00:00
|
|
|
loadSettings();
|
|
|
|
insertSetting(eVOLUME, new EncTtsSetting(this, EncTtsSetting::eDOUBLE,
|
2013-03-07 19:38:31 +00:00
|
|
|
tr("Volume:"), volume, 0.0, 2.0));
|
2012-01-29 14:36:30 +00:00
|
|
|
insertSetting(eQUALITY, new EncTtsSetting(this, EncTtsSetting::eDOUBLE,
|
|
|
|
tr("Quality:"), quality, 0, 10.0));
|
|
|
|
insertSetting(eCOMPLEXITY, new EncTtsSetting(this, EncTtsSetting::eINT,
|
|
|
|
tr("Complexity:"), complexity, 0, 10));
|
|
|
|
insertSetting(eNARROWBAND,new EncTtsSetting(this, EncTtsSetting::eBOOL,
|
|
|
|
tr("Use Narrowband:"), narrowband));
|
2009-04-29 21:27:01 +00:00
|
|
|
}
|
|
|
|
|
2012-01-06 19:19:32 +00:00
|
|
|
void EncoderRbSpeex::saveSettings()
|
2009-04-29 21:27:01 +00:00
|
|
|
{
|
|
|
|
//save settings in user config
|
2009-06-09 21:46:05 +00:00
|
|
|
RbSettings::setSubValue("rbspeex",RbSettings::EncoderVolume,
|
|
|
|
getSetting(eVOLUME)->current().toDouble());
|
|
|
|
RbSettings::setSubValue("rbspeex",RbSettings::EncoderQuality,
|
|
|
|
getSetting(eQUALITY)->current().toDouble());
|
|
|
|
RbSettings::setSubValue("rbspeex",RbSettings::EncoderComplexity,
|
|
|
|
getSetting(eCOMPLEXITY)->current().toInt());
|
|
|
|
RbSettings::setSubValue("rbspeex",RbSettings::EncoderNarrowBand,
|
|
|
|
getSetting(eNARROWBAND)->current().toBool());
|
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
RbSettings::sync();
|
2009-04-29 21:27:01 +00:00
|
|
|
}
|
2007-12-14 20:09:44 +00:00
|
|
|
|
2009-06-09 21:46:05 +00:00
|
|
|
|
2012-01-29 14:36:30 +00:00
|
|
|
void EncoderRbSpeex::loadSettings(void)
|
|
|
|
{
|
2007-12-14 20:09:44 +00:00
|
|
|
// try to get config from settings
|
2009-05-09 16:59:14 +00:00
|
|
|
quality = RbSettings::subValue("rbspeex", RbSettings::EncoderQuality).toDouble();
|
2012-01-29 14:36:30 +00:00
|
|
|
if(quality < 0) {
|
|
|
|
quality = 8.0;
|
|
|
|
}
|
2009-05-09 16:59:14 +00:00
|
|
|
complexity = RbSettings::subValue("rbspeex", RbSettings::EncoderComplexity).toInt();
|
|
|
|
volume = RbSettings::subValue("rbspeex", RbSettings::EncoderVolume).toDouble();
|
|
|
|
narrowband = RbSettings::subValue("rbspeex", RbSettings::EncoderNarrowBand).toBool();
|
2012-01-29 14:36:30 +00:00
|
|
|
}
|
2009-06-09 21:46:05 +00:00
|
|
|
|
2007-12-14 20:09:44 +00:00
|
|
|
|
2012-01-29 14:36:30 +00:00
|
|
|
bool EncoderRbSpeex::start()
|
|
|
|
{
|
|
|
|
|
|
|
|
// make sure configuration parameters are set.
|
|
|
|
loadSettings();
|
2007-12-14 20:09:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-06 19:19:32 +00:00
|
|
|
bool EncoderRbSpeex::encode(QString input,QString output)
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2010-06-04 21:22:25 +00:00
|
|
|
qDebug() << "[RbSpeex] Encoding " << input << " to "<< output;
|
2007-12-14 20:09:44 +00:00
|
|
|
char errstr[512];
|
2009-06-09 21:46:05 +00:00
|
|
|
|
2007-12-14 20:09:44 +00:00
|
|
|
FILE *fin,*fout;
|
2008-02-25 22:02:55 +00:00
|
|
|
if ((fin = fopen(input.toLocal8Bit(), "rb")) == NULL) {
|
2010-06-04 21:22:25 +00:00
|
|
|
qDebug() << "[RbSpeex] Error: could not open input file\n";
|
2007-12-14 20:09:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-02-25 22:02:55 +00:00
|
|
|
if ((fout = fopen(output.toLocal8Bit(), "wb")) == NULL) {
|
2010-06-04 21:22:25 +00:00
|
|
|
qDebug() << "[RbSpeex] Error: could not open output file\n";
|
2010-04-01 22:06:52 +00:00
|
|
|
fclose(fin);
|
2007-12-14 20:09:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = encode_file(fin, fout, quality, complexity, narrowband, volume,
|
|
|
|
errstr, sizeof(errstr));
|
|
|
|
fclose(fout);
|
|
|
|
fclose(fin);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
/* Attempt to delete unfinished output */
|
2010-06-04 21:22:25 +00:00
|
|
|
qDebug() << "[RbSpeex] Error:" << errstr;
|
2007-12-14 20:09:44 +00:00
|
|
|
QFile(output).remove();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-06 19:19:32 +00:00
|
|
|
bool EncoderRbSpeex::configOk()
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2012-01-29 14:36:30 +00:00
|
|
|
// check config. Make sure current settings are loaded.
|
|
|
|
loadSettings();
|
|
|
|
if(volume <= 0 || quality <= 0 || complexity <= 0)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
2007-12-14 20:09:44 +00:00
|
|
|
}
|
|
|
|
|