big rework

This commit is contained in:
Josh Coalson 2002-08-27 05:36:09 +00:00
parent 162b8a36ec
commit b5cc55f312
8 changed files with 139 additions and 29 deletions

View File

@ -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 \

View File

@ -7,7 +7,9 @@ INCLUDES = -I../../include
OBJS = \
canonical_tag.o \
dither.o
charset.o \
dither.o \
id3v1.o
include ../../build/lib.mk

View File

@ -10,7 +10,9 @@
C_FILES= \
canonical_tag.c \
dither.c
charset.c \
dither.c \
id3v1.c
OBJS= $(C_FILES:.c=.obj)

View File

@ -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

View File

@ -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 <stdlib.h>
#include <stdio.h>
#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));
}

View File

@ -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

View File

@ -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);

View File

@ -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