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"
|
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
|
|
|
{
|
2009-06-09 21:46:05 +00:00
|
|
|
insertSetting(eVOLUME,new EncTtsSetting(this,EncTtsSetting::eDOUBLE,
|
|
|
|
tr("Volume:"),RbSettings::subValue("rbspeex",RbSettings::EncoderVolume),1.0,10.0));
|
|
|
|
insertSetting(eQUALITY,new EncTtsSetting(this,EncTtsSetting::eDOUBLE,
|
|
|
|
tr("Quality:"),RbSettings::subValue("rbspeex",RbSettings::EncoderQuality),0,10.0));
|
|
|
|
insertSetting(eCOMPLEXITY,new EncTtsSetting(this,EncTtsSetting::eINT,
|
|
|
|
tr("Complexity:"),RbSettings::subValue("rbspeex",RbSettings::EncoderComplexity),0,10));
|
|
|
|
insertSetting(eNARROWBAND,new EncTtsSetting(this,EncTtsSetting::eBOOL,
|
|
|
|
tr("Use Narrowband:"),RbSettings::subValue("rbspeex",RbSettings::EncoderNarrowBand)));
|
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
|
|
|
|
2012-01-06 19:19:32 +00:00
|
|
|
bool EncoderRbSpeex::start()
|
2007-12-14 20:09:44 +00:00
|
|
|
{
|
2009-06-09 21:46:05 +00:00
|
|
|
|
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();
|
|
|
|
complexity = RbSettings::subValue("rbspeex", RbSettings::EncoderComplexity).toInt();
|
|
|
|
volume = RbSettings::subValue("rbspeex", RbSettings::EncoderVolume).toDouble();
|
|
|
|
narrowband = RbSettings::subValue("rbspeex", RbSettings::EncoderNarrowBand).toBool();
|
2009-06-09 21:46:05 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
bool result=true;
|
|
|
|
// check config
|
2009-06-09 21:46:05 +00:00
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
if(RbSettings::subValue("rbspeex", RbSettings::EncoderVolume).toDouble() <= 0)
|
2007-12-14 20:09:44 +00:00
|
|
|
result =false;
|
2009-06-09 21:46:05 +00:00
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
if(RbSettings::subValue("rbspeex", RbSettings::EncoderQuality).toDouble() <= 0)
|
2007-12-14 20:09:44 +00:00
|
|
|
result =false;
|
2009-06-09 21:46:05 +00:00
|
|
|
|
2009-05-09 16:59:14 +00:00
|
|
|
if(RbSettings::subValue("rbspeex", RbSettings::EncoderComplexity).toInt() <= 0)
|
2007-12-14 20:09:44 +00:00
|
|
|
result =false;
|
2009-06-09 21:46:05 +00:00
|
|
|
|
2007-12-14 20:09:44 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|