本文整理汇总了C++中DB_decoder_t::open方法的典型用法代码示例。如果您正苦于以下问题:C++ DB_decoder_t::open方法的具体用法?C++ DB_decoder_t::open怎么用?C++ DB_decoder_t::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB_decoder_t
的用法示例。
在下文中一共展示了DB_decoder_t::open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
int
convert (DB_playItem_t *it, const char *outfolder, const char *outfile, int output_bps, int output_is_float, int preserve_folder_structure, const char *root_folder, ddb_encoder_preset_t *encoder_preset, ddb_dsp_preset_t *dsp_preset, int *abort) {
if (deadbeef->pl_get_item_duration (it) <= 0) {
deadbeef->pl_lock ();
const char *fname = deadbeef->pl_find_meta (it, ":URI");
fprintf (stderr, "converter: stream %s doesn't have finite length, skipped\n", fname);
deadbeef->pl_unlock ();
return -1;
}
char *path = outfolder[0] ? strdupa (outfolder) : strdupa (getenv("HOME"));
if (!check_dir (path, 0755)) {
fprintf (stderr, "converter: failed to create output folder: %s\n", outfolder);
return -1;
}
int err = -1;
FILE *enc_pipe = NULL;
FILE *temp_file = NULL;
DB_decoder_t *dec = NULL;
DB_fileinfo_t *fileinfo = NULL;
char out[PATH_MAX] = ""; // full path to output file
char input_file_name[PATH_MAX] = "";
dec = (DB_decoder_t *)deadbeef->plug_get_for_id (deadbeef->pl_find_meta (it, ":DECODER"));
if (dec) {
fileinfo = dec->open (0);
if (fileinfo && dec->init (fileinfo, DB_PLAYITEM (it)) != 0) {
deadbeef->pl_lock ();
fprintf (stderr, "converter: failed to decode file %s\n", deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
goto error;
}
if (fileinfo) {
if (output_bps == -1) {
output_bps = fileinfo->fmt.bps;
output_is_float = fileinfo->fmt.is_float;
}
get_output_path (it, outfolder, outfile, encoder_preset, out, sizeof (out));
if (encoder_preset->method == DDB_ENCODER_METHOD_FILE) {
const char *tmp = getenv ("TMPDIR");
if (!tmp) {
tmp = "/tmp";
}
snprintf (input_file_name, sizeof (input_file_name), "%s/ddbconvXXXXXX", tmp);
mktemp (input_file_name);
strcat (input_file_name, ".wav");
}
else {
strcpy (input_file_name, "-");
}
char enc[2000];
memset (enc, 0, sizeof (enc));
// formatting: %o = outfile, %i = infile
char *e = encoder_preset->encoder;
char *o = enc;
*o = 0;
int len = sizeof (enc);
while (e && *e) {
if (len <= 0) {
fprintf (stderr, "converter: failed to assemble encoder command line - buffer is not big enough, try to shorten your parameters. max allowed length is %u characters\n", (unsigned)sizeof (enc));
goto error;
}
if (e[0] == '%' && e[1]) {
if (e[1] == 'o') {
int l = snprintf (o, len, "\"%s\"", out);
o += l;
len -= l;
}
else if (e[1] == 'i') {
int l = snprintf (o, len, "\"%s\"", input_file_name);
o += l;
len -= l;
}
else {
strncpy (o, e, 2);
o += 2;
len -= 2;
}
e += 2;
}
else {
*o++ = *e++;
*o = 0;
len--;
}
}
fprintf (stderr, "converter: will encode using: %s\n", enc[0] ? enc : "internal RIFF WAVE writer");
if (!encoder_preset->encoder[0]) {
// write to wave file
temp_file = fopen (out, "w+b");
if (!temp_file) {
fprintf (stderr, "converter: failed to open output wave file %s\n", out);
goto error;
}
//.........这里部分代码省略.........
示例2: if
int
convert (DB_playItem_t *it, const char *out, int output_bps, int output_is_float, ddb_encoder_preset_t *encoder_preset, ddb_dsp_preset_t *dsp_preset, int *abort) {
char *buffer = NULL;
char *dspbuffer = NULL;
if (deadbeef->pl_get_item_duration (it) <= 0) {
deadbeef->pl_lock ();
fprintf (stderr, "converter: stream %s doesn't have finite length, skipped\n", deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
return -1;
}
int err = -1;
FILE *enc_pipe = NULL;
int temp_file = -1;
DB_decoder_t *dec = NULL;
DB_fileinfo_t *fileinfo = NULL;
char input_file_name[PATH_MAX] = "";
deadbeef->pl_lock ();
dec = (DB_decoder_t *)deadbeef->plug_get_for_id (deadbeef->pl_find_meta (it, ":DECODER"));
deadbeef->pl_unlock ();
if (dec) {
fileinfo = dec->open (0);
if (fileinfo && dec->init (fileinfo, DB_PLAYITEM (it)) != 0) {
deadbeef->pl_lock ();
fprintf (stderr, "converter: failed to decode file %s\n", deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
goto error;
}
if (fileinfo) {
if (output_bps == -1) {
output_bps = fileinfo->fmt.bps;
output_is_float = fileinfo->fmt.is_float;
}
char *final_path = strdupa (out);
char *sep = strrchr (final_path, '/');
if (sep) {
*sep = 0;
if (!check_dir (final_path, 0755)) {
fprintf (stderr, "converter: failed to create output folder: %s\n", final_path);
goto error;
}
}
if (encoder_preset->method == DDB_ENCODER_METHOD_FILE) {
const char *tmp = getenv ("TMPDIR");
if (!tmp) {
tmp = "/tmp";
}
snprintf (input_file_name, sizeof (input_file_name), "%s/ddbconvXXXXXX", tmp);
char *res = mktemp (input_file_name);
strcat (input_file_name, ".wav");
}
else {
strcpy (input_file_name, "-");
}
char enc[2000];
memset (enc, 0, sizeof (enc));
char escaped_out[PATH_MAX];
escape_filepath (out, escaped_out, sizeof (escaped_out));
// formatting: %o = outfile, %i = infile
char *e = encoder_preset->encoder;
char *o = enc;
*o = 0;
int len = sizeof (enc);
while (e && *e) {
if (len <= 0) {
fprintf (stderr, "converter: failed to assemble encoder command line - buffer is not big enough, try to shorten your parameters. max allowed length is %u characters\n", (unsigned)sizeof (enc));
goto error;
}
if (e[0] == '%' && e[1]) {
if (e[1] == 'o') {
int l = snprintf (o, len, "\"%s\"", escaped_out);
o += l;
len -= l;
}
else if (e[1] == 'i') {
int l = snprintf (o, len, "\"%s\"", input_file_name);
o += l;
len -= l;
}
else {
strncpy (o, e, 2);
o += 2;
len -= 2;
}
e += 2;
}
else {
*o++ = *e++;
*o = 0;
len--;
}
}
fprintf (stderr, "converter: will encode using: %s\n", enc[0] ? enc : "internal RIFF WAVE writer");
//.........这里部分代码省略.........
示例3: malloc
void
rg_calc_thread(void *ctx) {
DB_decoder_t *dec = NULL;
DB_fileinfo_t *fileinfo = NULL;
char *buffer = NULL;
char *bufferf = NULL;
track_state_t *st = (track_state_t *)ctx;
if (st->settings->pabort && *(st->settings->pabort)) {
return;
}
if (deadbeef->pl_get_item_duration (st->settings->tracks[st->track_index]) <= 0) {
st->settings->results[st->track_index].scan_result = DDB_RG_SCAN_RESULT_INVALID_FILE;
return;
}
deadbeef->pl_lock ();
dec = (DB_decoder_t *)deadbeef->plug_get_for_id (deadbeef->pl_find_meta (st->settings->tracks[st->track_index], ":DECODER"));
deadbeef->pl_unlock ();
if (dec) {
fileinfo = dec->open (DDB_DECODER_HINT_RAW_SIGNAL);
if (fileinfo && dec->init (fileinfo, DB_PLAYITEM (st->settings->tracks[st->track_index])) != 0) {
st->settings->results[st->track_index].scan_result = DDB_RG_SCAN_RESULT_FILE_NOT_FOUND;
goto error;
}
if (fileinfo) {
st->gain_state[st->track_index] = ebur128_init(fileinfo->fmt.channels, fileinfo->fmt.samplerate, EBUR128_MODE_I);
st->peak_state[st->track_index] = ebur128_init(fileinfo->fmt.channels, fileinfo->fmt.samplerate, EBUR128_MODE_SAMPLE_PEAK);
// speaker mask mapping from WAV to EBUR128
static const int chmap[18] = {
EBUR128_LEFT,
EBUR128_RIGHT,
EBUR128_CENTER,
EBUR128_UNUSED,
EBUR128_LEFT_SURROUND,
EBUR128_RIGHT_SURROUND,
EBUR128_LEFT_SURROUND,
EBUR128_RIGHT_SURROUND,
EBUR128_CENTER,
EBUR128_LEFT_SURROUND,
EBUR128_RIGHT_SURROUND,
EBUR128_CENTER,
EBUR128_LEFT_SURROUND,
EBUR128_CENTER,
EBUR128_RIGHT_SURROUND,
EBUR128_LEFT_SURROUND,
EBUR128_CENTER,
EBUR128_RIGHT_SURROUND,
};
uint32_t channelmask = fileinfo->fmt.channelmask;
// first 18 speaker positions are known, the rest will be marked as UNUSED
int ch = 0;
for (int i = 0; i < 32 && ch < fileinfo->fmt.channels; i++) {
if (i < 18) {
if (channelmask & (1<<i))
{
ebur128_set_channel (st->gain_state[st->track_index], ch, chmap[i]);
ebur128_set_channel (st->peak_state[st->track_index], ch, chmap[i]);
ch++;
}
}
else {
ebur128_set_channel (st->gain_state[st->track_index], ch, EBUR128_UNUSED);
ebur128_set_channel (st->peak_state[st->track_index], ch, EBUR128_UNUSED);
ch++;
}
}
int samplesize = fileinfo->fmt.channels * fileinfo->fmt.bps / 8;
int bs = 2000 * samplesize;
ddb_waveformat_t fmt;
buffer = malloc (bs);
if (!fileinfo->fmt.is_float) {
bufferf = malloc (2000 * sizeof (float) * fileinfo->fmt.channels);
memcpy (&fmt, &fileinfo->fmt, sizeof (fmt));
fmt.bps = 32;
fmt.is_float = 1;
}
else {
bufferf = buffer;
}
int eof = 0;
for (;;) {
if (eof) {
break;
}
if (st->settings->pabort && *(st->settings->pabort)) {
break;
//.........这里部分代码省略.........