diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-15 21:04:28 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-24 18:05:53 +0100 |
commit | c876d3bbefe0dc00c27ca0c12d29da5874946962 (patch) | |
tree | 69f468a185a369b01998314bc3ecc19b70f4fcaa /utils/rbutilqt/base/encoderrbspeex.cpp | |
parent | 6c6f0757d7a902feb293be165d1490c42bc8e7ad (diff) | |
download | rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.tar.gz rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.zip |
rbutil: Merge rbutil with utils folder.
rbutil uses several components from the utils folder, and can be
considered part of utils too. Having it in a separate folder is an
arbitrary split that doesn't help anymore these days, so merge them.
This also allows other utils to easily use libtools.make without the
need to navigate to a different folder.
Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21
Diffstat (limited to 'utils/rbutilqt/base/encoderrbspeex.cpp')
-rw-r--r-- | utils/rbutilqt/base/encoderrbspeex.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/encoderrbspeex.cpp b/utils/rbutilqt/base/encoderrbspeex.cpp new file mode 100644 index 0000000000..2bee66028a --- /dev/null +++ b/utils/rbutilqt/base/encoderrbspeex.cpp | |||
@@ -0,0 +1,119 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Wenger | ||
10 | * | ||
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. | ||
13 | * | ||
14 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
15 | * KIND, either express or implied. | ||
16 | * | ||
17 | ****************************************************************************/ | ||
18 | |||
19 | #include <QtCore> | ||
20 | #include "encoderrbspeex.h" | ||
21 | #include "rbsettings.h" | ||
22 | #include "rbspeex.h" | ||
23 | #include "Logger.h" | ||
24 | |||
25 | EncoderRbSpeex::EncoderRbSpeex(QObject *parent) : EncoderBase(parent) | ||
26 | { | ||
27 | |||
28 | } | ||
29 | |||
30 | void EncoderRbSpeex::generateSettings() | ||
31 | { | ||
32 | loadSettings(); | ||
33 | insertSetting(eVOLUME, new EncTtsSetting(this, EncTtsSetting::eDOUBLE, | ||
34 | tr("Volume:"), volume, 0.0, 2.0)); | ||
35 | insertSetting(eQUALITY, new EncTtsSetting(this, EncTtsSetting::eDOUBLE, | ||
36 | tr("Quality:"), quality, 0, 10.0)); | ||
37 | insertSetting(eCOMPLEXITY, new EncTtsSetting(this, EncTtsSetting::eINT, | ||
38 | tr("Complexity:"), complexity, 0, 10)); | ||
39 | insertSetting(eNARROWBAND,new EncTtsSetting(this, EncTtsSetting::eBOOL, | ||
40 | tr("Use Narrowband:"), narrowband)); | ||
41 | } | ||
42 | |||
43 | void EncoderRbSpeex::saveSettings() | ||
44 | { | ||
45 | //save settings in user config | ||
46 | RbSettings::setSubValue("rbspeex",RbSettings::EncoderVolume, | ||
47 | getSetting(eVOLUME)->current().toDouble()); | ||
48 | RbSettings::setSubValue("rbspeex",RbSettings::EncoderQuality, | ||
49 | getSetting(eQUALITY)->current().toDouble()); | ||
50 | RbSettings::setSubValue("rbspeex",RbSettings::EncoderComplexity, | ||
51 | getSetting(eCOMPLEXITY)->current().toInt()); | ||
52 | RbSettings::setSubValue("rbspeex",RbSettings::EncoderNarrowBand, | ||
53 | getSetting(eNARROWBAND)->current().toBool()); | ||
54 | |||
55 | RbSettings::sync(); | ||
56 | } | ||
57 | |||
58 | |||
59 | void EncoderRbSpeex::loadSettings(void) | ||
60 | { | ||
61 | // try to get config from settings | ||
62 | quality = RbSettings::subValue("rbspeex", RbSettings::EncoderQuality).toDouble(); | ||
63 | if(quality < 0) { | ||
64 | quality = 8.0; | ||
65 | } | ||
66 | complexity = RbSettings::subValue("rbspeex", RbSettings::EncoderComplexity).toInt(); | ||
67 | volume = RbSettings::subValue("rbspeex", RbSettings::EncoderVolume).toDouble(); | ||
68 | narrowband = RbSettings::subValue("rbspeex", RbSettings::EncoderNarrowBand).toBool(); | ||
69 | } | ||
70 | |||
71 | |||
72 | bool EncoderRbSpeex::start() | ||
73 | { | ||
74 | |||
75 | // make sure configuration parameters are set. | ||
76 | loadSettings(); | ||
77 | return true; | ||
78 | } | ||
79 | |||
80 | bool EncoderRbSpeex::encode(QString input,QString output) | ||
81 | { | ||
82 | LOG_INFO() << "Encoding " << input << " to "<< output; | ||
83 | char errstr[512]; | ||
84 | |||
85 | FILE *fin,*fout; | ||
86 | if ((fin = fopen(input.toLocal8Bit(), "rb")) == nullptr) { | ||
87 | LOG_ERROR() << "Error: could not open input file\n"; | ||
88 | return false; | ||
89 | } | ||
90 | if ((fout = fopen(output.toLocal8Bit(), "wb")) == nullptr) { | ||
91 | LOG_ERROR() << "Error: could not open output file\n"; | ||
92 | fclose(fin); | ||
93 | return false; | ||
94 | } | ||
95 | |||
96 | int ret = encode_file(fin, fout, quality, complexity, narrowband, volume, | ||
97 | errstr, sizeof(errstr)); | ||
98 | fclose(fout); | ||
99 | fclose(fin); | ||
100 | |||
101 | if (!ret) { | ||
102 | /* Attempt to delete unfinished output */ | ||
103 | LOG_ERROR() << "Error:" << errstr; | ||
104 | QFile(output).remove(); | ||
105 | return false; | ||
106 | } | ||
107 | return true; | ||
108 | } | ||
109 | |||
110 | bool EncoderRbSpeex::configOk() | ||
111 | { | ||
112 | // check config. Make sure current settings are loaded. | ||
113 | loadSettings(); | ||
114 | if(volume <= 0 || quality <= 0 || complexity <= 0) | ||
115 | return false; | ||
116 | else | ||
117 | return true; | ||
118 | } | ||
119 | |||