From: Josh Coalson Date: Tue, 27 Aug 2002 05:36:09 +0000 (+0000) Subject: big rework X-Git-Tag: 1.2.0~1593 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5cc55f31297159009b05bd78fe9514fcb98b866;p=platform%2Fupstream%2Fflac.git big rework --- diff --git a/src/plugin_common/Makefile.am b/src/plugin_common/Makefile.am index 56f759b..bd9256b 100644 --- a/src/plugin_common/Makefile.am +++ b/src/plugin_common/Makefile.am @@ -9,11 +9,17 @@ noinst_LIBRARIES = libplugin-common.a noinst_HEADERS = \ all.h \ canonical_tag.h \ - dither.h + charset.h \ + dither.h \ + id3v1.h \ + id3v2.h libplugin_common_a_SOURCES = \ canonical_tag.c \ - dither.c + charset.c \ + dither.c \ + id3v1.c \ + id3v2.c EXTRA_DIST = \ Makefile.lite \ diff --git a/src/plugin_common/Makefile.lite b/src/plugin_common/Makefile.lite index 253d2d9..32a624e 100644 --- a/src/plugin_common/Makefile.lite +++ b/src/plugin_common/Makefile.lite @@ -7,7 +7,9 @@ INCLUDES = -I../../include OBJS = \ canonical_tag.o \ - dither.o + charset.o \ + dither.o \ + id3v1.o include ../../build/lib.mk diff --git a/src/plugin_common/Makefile.vc b/src/plugin_common/Makefile.vc index 11f3127..c8de6ad 100644 --- a/src/plugin_common/Makefile.vc +++ b/src/plugin_common/Makefile.vc @@ -10,7 +10,9 @@ C_FILES= \ canonical_tag.c \ - dither.c + charset.c \ + dither.c \ + id3v1.c OBJS= $(C_FILES:.c=.obj) diff --git a/src/plugin_common/all.h b/src/plugin_common/all.h index a8e7927..def39c0 100644 --- a/src/plugin_common/all.h +++ b/src/plugin_common/all.h @@ -1,10 +1,6 @@ /* plugin_common - Routines common to several plugins * Copyright (C) 2002 Josh Coalson * - * dithering routine derived from (other GPLed source): - * mad - MPEG audio decoder - * Copyright (C) 2000-2001 Robert Leslie - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 @@ -24,6 +20,10 @@ #define FLAC__PLUGIN_COMMON__ALL_H #include "canonical_tag.h" +#include "charset.h" #include "dither.h" +#include "id3v1.h" +#include "id3v2.h" +#include "locale_hack.h" #endif diff --git a/src/plugin_common/canonical_tag.c b/src/plugin_common/canonical_tag.c index fc05e9b..d647035 100644 --- a/src/plugin_common/canonical_tag.c +++ b/src/plugin_common/canonical_tag.c @@ -1,10 +1,6 @@ /* plugin_common - Routines common to several plugins * Copyright (C) 2002 Josh Coalson * - * dithering routine derived from (other GPLed source): - * mad - MPEG audio decoder - * Copyright (C) 2000-2001 Robert Leslie - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 @@ -20,5 +16,97 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include +#include + #include "canonical_tag.h" #include "FLAC/assert.h" + +static void local__safe_free(void *object) +{ + if(0 != object) + free(object); +} + +static void local__copy_field(char **dest, const char *src, unsigned n) +{ + if(n > 0) { + const char *p = src + n; + while(p > src && *(--p) == ' ') + ; + n = p - src + 1; + if(0 != (*dest = malloc(n+1))) { + memcpy(*dest, src, n); + (*dest)[n] = '\0'; + } + } + else + *dest = 0; +} + +FLAC_Plugin__CanonicalTag *FLAC_plugin__canonical_tag_new() +{ + FLAC_Plugin__CanonicalTag *object = (FLAC_Plugin__CanonicalTag*)malloc(sizeof(FLAC_Plugin__CanonicalTag)); + if(0 != object) + FLAC_plugin__canonical_tag_init(object); + return object; +} + +void FLAC_plugin__canonical_tag_delete(FLAC_Plugin__CanonicalTag *object) +{ + FLAC__ASSERT(0 != object); + FLAC_plugin__canonical_tag_clear(object); + free(object); +} + +void FLAC_plugin__canonical_tag_init(FLAC_Plugin__CanonicalTag *object) +{ + FLAC__ASSERT(0 != object); + object->title = 0; + object->artist = 0; + object->performer = 0; + object->album = 0; + object->year_recorded = 0; + object->year_performed = 0; + object->track_number = 0; + object->tracks_in_album = 0; + object->genre = 0; + object->comment = 0; +} + +void FLAC_plugin__canonical_tag_clear(FLAC_Plugin__CanonicalTag *object) +{ + FLAC__ASSERT(0 != object); + local__safe_free(object->title); + local__safe_free(object->artist); + local__safe_free(object->performer); + local__safe_free(object->album); + local__safe_free(object->year_recorded); + local__safe_free(object->year_performed); + local__safe_free(object->track_number); + local__safe_free(object->tracks_in_album); + local__safe_free(object->genre); + local__safe_free(object->comment); + FLAC_plugin__canonical_tag_init(object); +} + +void FLAC_plugin__canonical_tag_convert_from_id3v1(FLAC_Plugin__CanonicalTag *object, const FLAC_Plugin__Id3v1_Tag *id3v1_tag) +{ + local__copy_field(&object->title, id3v1_tag->title, 30); + local__copy_field(&object->artist, id3v1_tag->artist, 30); + local__copy_field(&object->album, id3v1_tag->album, 30); + local__copy_field(&object->year_performed, id3v1_tag->year, 4); + + /* Check for v1.1 tags. */ + if (id3v1_tag->comment.v1_1.zero == 0) { + if(0 != (object->track_number = malloc(4))) + sprintf(object->track_number, "%u", (unsigned)id3v1_tag->comment.v1_1.track); + local__copy_field(&object->comment, id3v1_tag->comment.v1_1.comment, 28); + } + else { + object->track_number = strdup("0"); + local__copy_field(&object->comment, id3v1_tag->comment.v1_0.comment, 30); + } + + object->genre = strdup(FLAC_plugin__id3v1_tag_get_genre_as_string(id3v1_tag->genre)); +} diff --git a/src/plugin_common/canonical_tag.h b/src/plugin_common/canonical_tag.h index 2701b54..4d6c871 100644 --- a/src/plugin_common/canonical_tag.h +++ b/src/plugin_common/canonical_tag.h @@ -1,10 +1,6 @@ /* plugin_common - Routines common to several plugins * Copyright (C) 2002 Josh Coalson * - * dithering routine derived from (other GPLed source): - * mad - MPEG audio decoder - * Copyright (C) 2000-2001 Robert Leslie - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 @@ -23,4 +19,26 @@ #ifndef FLAC__PLUGIN_COMMON__CANONICAL_TAG_H #define FLAC__PLUGIN_COMMON__CANONICAL_TAG_H +#include "id3v1.h" + +typedef struct { + char *title; + char *artist; + char *performer; + char *album; + char *year_recorded; + char *year_performed; + char *track_number; + char *tracks_in_album; + char *genre; + char *comment; +} FLAC_Plugin__CanonicalTag; + +FLAC_Plugin__CanonicalTag *FLAC_plugin__canonical_tag_new(); +void FLAC_plugin__canonical_tag_delete(FLAC_Plugin__CanonicalTag *); +void FLAC_plugin__canonical_tag_init(FLAC_Plugin__CanonicalTag *); +void FLAC_plugin__canonical_tag_clear(FLAC_Plugin__CanonicalTag *); + +void FLAC_plugin__canonical_tag_convert_from_id3v1(FLAC_Plugin__CanonicalTag *, const FLAC_Plugin__Id3v1_Tag *); + #endif diff --git a/src/plugin_common/dither.c b/src/plugin_common/dither.c index 5571b8a..4a54e2d 100644 --- a/src/plugin_common/dither.c +++ b/src/plugin_common/dither.c @@ -29,10 +29,6 @@ #define max(a,b) ((a)>(b)?(a):(b)) -#define FLAC__DO_DITHER - -#define MAX_SUPPORTED_CHANNELS 2 - #if defined _MSC_VER || defined __MINGW32__ #define FLAC__INLINE __inline #else @@ -103,16 +99,16 @@ static FLAC__INLINE FLAC__int32 linear_dither(unsigned source_bps, unsigned targ return output >> scalebits; } -unsigned FLAC__plugin_common__pack_pcm(FLAC__byte *data, FLAC__int32 *input, unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps) +unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, FLAC__int32 *input, unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps) { - static dither_state dither[MAX_SUPPORTED_CHANNELS]; + static dither_state dither[FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS]; FLAC__byte * const start = data; FLAC__int32 sample; unsigned samples = wide_samples * channels; const unsigned bytes_per_sample = target_bps / 8; - FLAC__ASSERT(MAX_SUPPORTED_CHANNELS == 2); - FLAC__ASSERT(channels > 0 && channels <= MAX_SUPPORTED_CHANNELS); + FLAC__ASSERT(FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS == 2); + FLAC__ASSERT(channels > 0 && channels <= FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS); FLAC__ASSERT(source_bps < 32); FLAC__ASSERT(target_bps <= 24); FLAC__ASSERT(target_bps <= source_bps); diff --git a/src/plugin_common/dither.h b/src/plugin_common/dither.h index b57e93a..0e5a932 100644 --- a/src/plugin_common/dither.h +++ b/src/plugin_common/dither.h @@ -1,10 +1,6 @@ /* plugin_common - Routines common to several plugins * Copyright (C) 2002 Josh Coalson * - * dithering routine derived from (other GPLed source): - * mad - MPEG audio decoder - * Copyright (C) 2000-2001 Robert Leslie - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 @@ -25,6 +21,8 @@ #include "FLAC/ordinals.h" -unsigned FLAC__plugin_common__pack_pcm(FLAC__byte *data, FLAC__int32 *input, unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps); +#define FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS 2 + +unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, FLAC__int32 *input, unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps); #endif