|
Lines 19-24
Link Here
|
| 19 |
*/ |
19 |
*/ |
| 20 |
|
20 |
|
| 21 |
#include "encoderflac.h" |
21 |
#include "encoderflac.h" |
|
|
22 |
#include "audiocd_flac_encoder.h" |
| 23 |
#include "encoderflacconfig.h" |
| 22 |
|
24 |
|
| 23 |
#ifdef HAVE_LIBFLAC |
25 |
#ifdef HAVE_LIBFLAC |
| 24 |
|
26 |
|
|
Lines 29-34
Link Here
|
| 29 |
#include <kconfig.h> |
31 |
#include <kconfig.h> |
| 30 |
#include <kdebug.h> |
32 |
#include <kdebug.h> |
| 31 |
|
33 |
|
|
|
34 |
#if !defined FLAC_API_VERSION_CURRENT || FLAC_API_VERSION_CURRENT < 8 |
| 35 |
#define LEGACY_FLAC |
| 36 |
#else |
| 37 |
#undef LEGACY_FLAC |
| 38 |
#endif |
| 32 |
|
39 |
|
| 33 |
extern "C" |
40 |
extern "C" |
| 34 |
{ |
41 |
{ |
|
Lines 38-43
Link Here
|
| 38 |
} |
45 |
} |
| 39 |
} |
46 |
} |
| 40 |
|
47 |
|
|
|
48 |
struct FLACSettings { |
| 49 |
bool verify; /**< -V */ |
| 50 |
bool subset; /**< --no-lax */ |
| 51 |
bool mid_side_stereo; /**< -m */ |
| 52 |
bool loose_mid_side_stereo; /**< -M */ |
| 53 |
uint blocksize; /**< -b */ |
| 54 |
uint max_lpc_order; /**< -l */ |
| 55 |
uint qlp_coef_prec; /**< -q */ |
| 56 |
bool qlp_coef_prec_search; /**< -p */ |
| 57 |
bool exhaustive_model_search; /**< -e */ |
| 58 |
uint min_residual_part_order; /**< -r */ |
| 59 |
uint max_residual_part_order; /**< -r */ |
| 60 |
}; |
| 61 |
|
| 62 |
static FLACSettings presets[] = { |
| 63 |
{ /* compression level 0 */ |
| 64 |
false, |
| 65 |
true, |
| 66 |
false, |
| 67 |
false, |
| 68 |
1152, |
| 69 |
0, |
| 70 |
0, |
| 71 |
false, |
| 72 |
false, |
| 73 |
2, |
| 74 |
2 |
| 75 |
}, |
| 76 |
{ /* compression level 1 */ |
| 77 |
false, |
| 78 |
true, |
| 79 |
false, |
| 80 |
true, |
| 81 |
1152, |
| 82 |
0, |
| 83 |
0, |
| 84 |
false, |
| 85 |
false, |
| 86 |
2, |
| 87 |
2 |
| 88 |
}, |
| 89 |
{ /* compression level 2 */ |
| 90 |
false, |
| 91 |
true, |
| 92 |
true, |
| 93 |
false, |
| 94 |
1152, |
| 95 |
0, |
| 96 |
0, |
| 97 |
false, |
| 98 |
false, |
| 99 |
0, |
| 100 |
3 |
| 101 |
}, |
| 102 |
{ /* compression level 3 */ |
| 103 |
false, |
| 104 |
true, |
| 105 |
false, |
| 106 |
false, |
| 107 |
4608, |
| 108 |
6, |
| 109 |
0, |
| 110 |
false, |
| 111 |
false, |
| 112 |
3, |
| 113 |
3 |
| 114 |
}, |
| 115 |
{ /* compression level 4 */ |
| 116 |
false, |
| 117 |
true, |
| 118 |
false, |
| 119 |
true, |
| 120 |
4608, |
| 121 |
8, |
| 122 |
0, |
| 123 |
false, |
| 124 |
false, |
| 125 |
3, |
| 126 |
3 |
| 127 |
}, |
| 128 |
{ /* compression level 5 */ |
| 129 |
false, |
| 130 |
true, |
| 131 |
true, |
| 132 |
false, |
| 133 |
4608, |
| 134 |
8, |
| 135 |
0, |
| 136 |
false, |
| 137 |
false, |
| 138 |
3, |
| 139 |
3 |
| 140 |
}, |
| 141 |
{ /* compression level 6 */ |
| 142 |
false, |
| 143 |
true, |
| 144 |
true, |
| 145 |
false, |
| 146 |
4608, |
| 147 |
8, |
| 148 |
0, |
| 149 |
false, |
| 150 |
false, |
| 151 |
0, |
| 152 |
4 |
| 153 |
}, |
| 154 |
{ /* compression level 7 */ |
| 155 |
false, |
| 156 |
true, |
| 157 |
true, |
| 158 |
false, |
| 159 |
4608, |
| 160 |
8, |
| 161 |
0, |
| 162 |
false, |
| 163 |
true, |
| 164 |
0, |
| 165 |
6 |
| 166 |
}, |
| 167 |
{ /* compression level 7 */ |
| 168 |
false, |
| 169 |
true, |
| 170 |
true, |
| 171 |
false, |
| 172 |
4608, |
| 173 |
12, |
| 174 |
0, |
| 175 |
false, |
| 176 |
true, |
| 177 |
0, |
| 178 |
6 |
| 179 |
} |
| 180 |
}; |
| 181 |
|
| 41 |
class EncoderFLAC::Private { |
182 |
class EncoderFLAC::Private { |
| 42 |
|
183 |
|
| 43 |
public: |
184 |
public: |
|
Lines 45-53
Link Here
|
| 45 |
FLAC__StreamMetadata** metadata; |
186 |
FLAC__StreamMetadata** metadata; |
| 46 |
KIO::SlaveBase* ioslave; |
187 |
KIO::SlaveBase* ioslave; |
| 47 |
unsigned long data; |
188 |
unsigned long data; |
|
|
189 |
|
| 190 |
void loadSettings(const FLACSettings& s); |
| 191 |
void loadPreset(uint preset); |
| 48 |
}; |
192 |
}; |
| 49 |
|
193 |
|
|
|
194 |
void EncoderFLAC::Private::loadSettings(const FLACSettings& s) |
| 195 |
{ |
| 196 |
FLAC__stream_encoder_set_verify(encoder, s.verify); |
| 197 |
FLAC__stream_encoder_set_streamable_subset(encoder, s.subset); |
| 198 |
|
| 199 |
FLAC__stream_encoder_set_do_mid_side_stereo(encoder, s.mid_side_stereo); |
| 200 |
FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, s.loose_mid_side_stereo); |
| 201 |
|
| 202 |
FLAC__stream_encoder_set_blocksize(encoder, s.blocksize); |
| 203 |
FLAC__stream_encoder_set_max_lpc_order(encoder, s.max_lpc_order); |
| 204 |
|
| 205 |
FLAC__stream_encoder_set_qlp_coeff_precision(encoder, s.qlp_coef_prec); |
| 206 |
FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, s.qlp_coef_prec_search); |
| 207 |
|
| 208 |
FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, s.exhaustive_model_search); |
| 209 |
FLAC__stream_encoder_set_min_residual_partition_order(encoder, s.min_residual_part_order); |
| 210 |
FLAC__stream_encoder_set_max_residual_partition_order(encoder, s.max_residual_part_order); |
| 211 |
} |
| 212 |
|
| 213 |
void EncoderFLAC::Private::loadPreset(uint preset) |
| 214 |
{ |
| 215 |
size_t max_preset = sizeof(presets) / sizeof(presets[0]); |
| 216 |
// Q_ASSERT(preset < max_preset); |
| 217 |
// be more tolerant ;-) |
| 218 |
if (preset >= max_preset) { |
| 219 |
preset = max_preset - 1; |
| 220 |
} |
| 221 |
loadSettings(presets[preset]); |
| 222 |
} |
| 223 |
|
| 224 |
#ifdef LEGACY_FLAC |
| 50 |
static FLAC__StreamEncoderWriteStatus WriteCallback(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) |
225 |
static FLAC__StreamEncoderWriteStatus WriteCallback(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) |
|
|
226 |
#else |
| 227 |
static FLAC__StreamEncoderWriteStatus WriteCallback(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data) |
| 228 |
#endif |
| 51 |
{ |
229 |
{ |
| 52 |
EncoderFLAC::Private *d = (EncoderFLAC::Private*)client_data; |
230 |
EncoderFLAC::Private *d = (EncoderFLAC::Private*)client_data; |
| 53 |
|
231 |
|
|
Lines 74-86
Link Here
|
| 74 |
static FLAC__SeekableStreamEncoderSeekStatus SeekCallback(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) |
252 |
static FLAC__SeekableStreamEncoderSeekStatus SeekCallback(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) |
| 75 |
{} ; */ |
253 |
{} ; */ |
| 76 |
|
254 |
|
|
|
255 |
#include <kglobal.h> |
| 256 |
#include <klocale.h> |
| 257 |
|
| 258 |
#include <qslider.h> |
| 77 |
|
259 |
|
| 78 |
|
260 |
|
| 79 |
|
261 |
|
| 80 |
EncoderFLAC::EncoderFLAC(KIO::SlaveBase *slave) : AudioCDEncoder(slave) { |
262 |
EncoderFLAC::EncoderFLAC(KIO::SlaveBase *slave) : AudioCDEncoder(slave) { |
| 81 |
d = new Private(); |
263 |
d = new Private(); |
| 82 |
d->ioslave = slave; |
264 |
d->ioslave = slave; |
| 83 |
d->encoder = 0; |
265 |
d->encoder = NULL; |
| 84 |
} |
266 |
} |
| 85 |
|
267 |
|
| 86 |
EncoderFLAC::~EncoderFLAC() { |
268 |
EncoderFLAC::~EncoderFLAC() { |
|
Lines 95-103
Link Here
|
| 95 |
return true; |
277 |
return true; |
| 96 |
} |
278 |
} |
| 97 |
|
279 |
|
| 98 |
void EncoderFLAC::loadSettings() { |
280 |
QWidget* EncoderFLAC::getConfigureWidget(KConfigSkeleton** manager) const { |
| 99 |
// config->setGroup("FLAC"); |
281 |
(*manager) = Settings::self(); |
|
|
282 |
KGlobal::locale()->insertCatalogue("audiocd_encoder_flac"); |
| 283 |
EncoderFlacConfig *config = new EncoderFlacConfig(); |
| 284 |
config->kcfg_compression_level->setValue(5); |
| 285 |
return config; |
| 286 |
} |
| 100 |
|
287 |
|
|
|
288 |
void EncoderFLAC::loadSettings() { |
| 289 |
kdDebug(7117) << "EncoderFLAC::loadSettings() called"<< endl; |
| 290 |
Settings *settings = Settings::self(); |
| 291 |
// make sure we deal with the _current_ config. |
| 292 |
// unfortunately current (3.4.x) kconfig machinery doesn't |
| 293 |
// guaranty that config changes will be delivered to all |
| 294 |
// currently running applications. This makes hard to predict |
| 295 |
// what config values will be used for pre-loaded konqueror instances |
| 296 |
settings->readConfig(); |
| 297 |
d->loadPreset(settings->compression_level()); |
| 101 |
} |
298 |
} |
| 102 |
|
299 |
|
| 103 |
// Estimate size to be 5/8 of uncompresed size. |
300 |
// Estimate size to be 5/8 of uncompresed size. |
|
Lines 109-130
Link Here
|
| 109 |
long EncoderFLAC::readInit(long size) { |
306 |
long EncoderFLAC::readInit(long size) { |
| 110 |
kdDebug(7117) << "EncoderFLAC::readInit() called"<< endl; |
307 |
kdDebug(7117) << "EncoderFLAC::readInit() called"<< endl; |
| 111 |
d->data = 0; |
308 |
d->data = 0; |
|
|
309 |
#ifdef LEGACY_FLAC |
| 112 |
FLAC__stream_encoder_set_write_callback(d->encoder, WriteCallback); |
310 |
FLAC__stream_encoder_set_write_callback(d->encoder, WriteCallback); |
| 113 |
FLAC__stream_encoder_set_metadata_callback(d->encoder, MetadataCallback); |
311 |
FLAC__stream_encoder_set_metadata_callback(d->encoder, MetadataCallback); |
| 114 |
FLAC__stream_encoder_set_client_data(d->encoder, d); |
312 |
FLAC__stream_encoder_set_client_data(d->encoder, d); |
|
|
313 |
#endif |
| 314 |
|
| 315 |
// make sure we loaded the most recent settings |
| 316 |
loadSettings(); |
| 115 |
|
317 |
|
| 116 |
// The options match approximely those of flac compression-level-3 |
|
|
| 117 |
FLAC__stream_encoder_set_do_mid_side_stereo(d->encoder, true); |
| 118 |
FLAC__stream_encoder_set_loose_mid_side_stereo(d->encoder, true); // flac -M |
| 119 |
FLAC__stream_encoder_set_max_lpc_order(d->encoder, 6); // flac -l6 |
| 120 |
FLAC__stream_encoder_set_min_residual_partition_order(d->encoder, 3); |
| 121 |
FLAC__stream_encoder_set_max_residual_partition_order(d->encoder, 3); // flac -r3,3 |
| 122 |
FLAC__stream_encoder_set_blocksize(d->encoder, 4608); |
| 123 |
FLAC__stream_encoder_set_streamable_subset(d->encoder, true); |
| 124 |
if (size > 0) |
318 |
if (size > 0) |
| 125 |
FLAC__stream_encoder_set_total_samples_estimate(d->encoder, size/4); |
319 |
FLAC__stream_encoder_set_total_samples_estimate(d->encoder, size/4); |
| 126 |
|
320 |
|
| 127 |
FLAC__stream_encoder_init(d->encoder); |
321 |
#ifdef LEGACY_FLAC |
|
|
322 |
if(FLAC__stream_encoder_init(d->encoder) != FLAC__STREAM_ENCODER_OK) |
| 323 |
; // really should handle an init failure |
| 324 |
#else |
| 325 |
if(FLAC__stream_encoder_init_stream(d->encoder, WriteCallback, NULL, NULL, MetadataCallback, d) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) |
| 326 |
; // really should handle an init failure |
| 327 |
#endif |
| 128 |
return d->data; |
328 |
return d->data; |
| 129 |
} |
329 |
} |
| 130 |
|
330 |
|