1
1
/* flac - Command-line FLAC encoder/decoder
2
* Copyright (C) 2002,2003,2004,2005 Josh Coalson
2
* Copyright (C) 2002,2003,2004,2005,2006,2007 Josh Coalson
4
4
* This program is free software; you can redistribute it and/or
5
5
* modify it under the terms of the GNU General Public License
24
24
#include "FLAC/assert.h"
25
#include "FLAC/metadata.h"
26
27
#include <stdarg.h>
27
29
#include <stdlib.h>
28
30
#include <string.h>
32
const char *CHANNEL_MASK_TAG = "WAVEFORMATEXTENSIBLE_CHANNEL_MASK";
30
34
int flac__utils_verbosity_ = 2;
32
36
static FLAC__bool local__parse_uint64_(const char *s, FLAC__uint64 *value)
68
72
ret = (double)i * 60.;
70
/* parse [0-9]*[.]?[0-9]* i.e. a sign-less rational number */
71
if(strspn(s, "1234567890.") != strlen(s))
74
/* parse [0-9]*[.,]?[0-9]* i.e. a sign-less rational number (. or , OK for fractional seconds, to support different locales) */
75
if(strspn(s, "1234567890.,") != strlen(s))
74
const char *p = strchr(s, '.');
75
if(p && 0 != strchr(++p, '.'))
78
const char *p = strpbrk(s, ".,");
79
if(p && 0 != strpbrk(++p, ".,"))
116
* @@@ this only works with sorted cuesheets (the spec strongly recommends but
120
* this only works with sorted cuesheets (the spec strongly recommends but
117
121
* does not require sorted cuesheets). but if it's not sorted, picking a
118
122
* nearest cue point has no significance.
270
274
until_spec->value.samples = total_samples;
277
FLAC__bool flac__utils_set_channel_mask_tag(FLAC__StreamMetadata *object, FLAC__uint32 channel_mask)
279
FLAC__StreamMetadata_VorbisComment_Entry entry = { 0, 0 };
282
FLAC__ASSERT(object);
283
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
284
FLAC__ASSERT(strlen(CHANNEL_MASK_TAG+1+2+16+1) <= sizeof(tag)); /* +1 for =, +2 for 0x, +16 for digits, +1 for NUL */
285
entry.entry = (FLAC__byte*)tag;
286
#if defined _MSC_VER || defined __MINGW32__
287
if((entry.length = _snprintf(tag, sizeof(tag), "%s=0x%04X", CHANNEL_MASK_TAG, (unsigned)channel_mask)) >= sizeof(tag))
289
if((entry.length = snprintf(tag, sizeof(tag), "%s=0x%04X", CHANNEL_MASK_TAG, (unsigned)channel_mask)) >= sizeof(tag))
292
if(!FLAC__metadata_object_vorbiscomment_replace_comment(object, entry, /*all=*/true, /*copy=*/true))
297
FLAC__bool flac__utils_get_channel_mask_tag(const FLAC__StreamMetadata *object, FLAC__uint32 *channel_mask)
302
FLAC__ASSERT(object);
303
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
304
if(0 > (offset = FLAC__metadata_object_vorbiscomment_find_entry_from(object, /*offset=*/0, CHANNEL_MASK_TAG)))
306
if(object->data.vorbis_comment.comments[offset].length < strlen(CHANNEL_MASK_TAG)+4)
308
if(0 == (p = strchr((const char *)object->data.vorbis_comment.comments[offset].entry, '='))) /* should never happen, but just in case */
310
if(strncmp(p, "=0x", 3))
312
if(sscanf(p+3, "%x", &val) != 1)