diff --git a/src/share/file_utils/Makefile.am b/src/share/file_utils/Makefile.am deleted file mode 100644 index d9258db0..00000000 --- a/src/share/file_utils/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -## Process this file with automake to produce Makefile.in - -AUTOMAKE_OPTIONS = foreign - -INCLUDES = -I$(top_srcdir)/include - -noinst_LIBRARIES = libfile_utils.a - -libfile_utils_a_SOURCES = file_utils.c - -EXTRA_DIST = \ - Makefile.lite \ - Makefile.vc \ - file_utils.dsp - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@" diff --git a/src/share/file_utils/Makefile.lite b/src/share/file_utils/Makefile.lite deleted file mode 100644 index f337baba..00000000 --- a/src/share/file_utils/Makefile.lite +++ /dev/null @@ -1,15 +0,0 @@ -# -# GNU makefile -# - -topdir = ../../.. - -LIB_NAME = libfile_utils -INCLUDES = -I$(topdir)/include - -OBJS = \ - file_utils.o - -include $(topdir)/build/lib.mk - -# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/src/share/file_utils/Makefile.vc b/src/share/file_utils/Makefile.vc deleted file mode 100644 index 86e62776..00000000 --- a/src/share/file_utils/Makefile.vc +++ /dev/null @@ -1,23 +0,0 @@ -!include - -!IFDEF DEBUG -.c.obj: - $(cc) /D "_LIB" -DFLAC__NO_DLL /GX $(cdebug) $(cflags) /I "..\..\..\include" -DSTRICT -YX /Od /D "_DEBUG" $< -!else -.c.obj: - $(cc) /D "_LIB" -DFLAC__NO_DLL /O2 $(crelease) $(cflags) /I "..\..\..\include" -DSTRICT -YX -DNODEBUG $< -!endif - -C_FILES= \ - file_utils.c \ - -OBJS= $(C_FILES:.c=.obj) - -all: file_utils.lib - -file_utils.lib: $(OBJS) - link.exe -lib /nodefaultlib -out:../../../obj/lib/$*.lib $(OBJS) - -clean: - -del *.obj *.pch - -del ..\..\..\obj\lib\file_utils.lib ..\..\..\obj\lib\file_utils.pdb diff --git a/src/share/file_utils/file_utils.c b/src/share/file_utils/file_utils.c deleted file mode 100644 index 54054e3a..00000000 --- a/src/share/file_utils/file_utils.c +++ /dev/null @@ -1,142 +0,0 @@ -/* file_utils - Convenience lib for manipulating file stats - * Copyright (C) 2002 Josh Coalson - * - * 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 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#if defined _MSC_VER || defined __MINGW32__ -#include /* for utime() */ -#include /* for chmod(), _setmode(), unlink() */ -#include /* for _O_BINARY */ -#else -#include /* some flavors of BSD (like OS X) require this to get time_t */ -#include /* for utime() */ -#endif -#ifdef __CYGWIN__ -#include /* for setmode(), O_BINARY */ -#include /* for _O_BINARY */ -#endif -#include /* for stat(), maybe chmod() */ -#if defined _WIN32 && !defined __CYGWIN__ -#else -#include /* for unlink() */ -#endif -#include -#include -#include /* for strrchr() */ -#include "share/file_utils.h" - - -FILE_UTILS_API void FLAC__file_utils_copy_metadata(const char *srcpath, const char *destpath) -{ - struct stat srcstat; - struct utimbuf srctime; - - if(0 == stat(srcpath, &srcstat)) { - srctime.actime = srcstat.st_atime; - srctime.modtime = srcstat.st_mtime; - (void)chmod(destpath, srcstat.st_mode); - (void)utime(destpath, &srctime); - } -} - -FILE_UTILS_API off_t FLAC__file_utils_get_filesize(const char *srcpath) -{ - struct stat srcstat; - - if(0 == stat(srcpath, &srcstat)) - return srcstat.st_size; - else - return -1; -} - -FILE_UTILS_API const char *FLAC__file_utils_get_basename(const char *srcpath) -{ - const char *p; - - p = strrchr(srcpath, '/'); - if(0 == p) { - p = strrchr(srcpath, '\\'); - if(0 == p) - return srcpath; - } - return ++p; -} - -FILE_UTILS_API FLAC__bool FLAC__file_utils_change_stats(const char *filename, FLAC__bool read_only) -{ - struct stat stats; - - if(0 == stat(filename, &stats)) { -#if !defined _MSC_VER && !defined __MINGW32__ - if(read_only) { - stats.st_mode &= ~S_IWUSR; - stats.st_mode &= ~S_IWGRP; - stats.st_mode &= ~S_IWOTH; - } - else { - stats.st_mode |= S_IWUSR; - } -#else - if(read_only) - stats.st_mode &= ~S_IWRITE; - else - stats.st_mode |= S_IWRITE; -#endif - if(0 != chmod(filename, stats.st_mode)) - return false; - } - else - return false; - - return true; -} - -FILE_UTILS_API FLAC__bool FLAC__file_utils_remove_file(const char *filename) -{ - return FLAC__file_utils_change_stats(filename, /*read_only=*/false) && 0 == unlink(filename); -} - -FILE_UTILS_API FILE *FLAC__file_utils_get_binary_stdin() -{ - /* if something breaks here it is probably due to the presence or - * absence of an underscore before the identifiers 'setmode', - * 'fileno', and/or 'O_BINARY'; check your system header files. - */ -#if defined _MSC_VER || defined __MINGW32__ - _setmode(_fileno(stdin), _O_BINARY); -#elif defined __CYGWIN__ - /* almost certainly not needed for any modern Cygwin, but let's be safe... */ - setmode(_fileno(stdin), _O_BINARY); -#endif - - return stdin; -} - -FILE_UTILS_API FILE *FLAC__file_utils_get_binary_stdout() -{ - /* if something breaks here it is probably due to the presence or - * absence of an underscore before the identifiers 'setmode', - * 'fileno', and/or 'O_BINARY'; check your system header files. - */ -#if defined _MSC_VER || defined __MINGW32__ - _setmode(_fileno(stdout), _O_BINARY); -#elif defined __CYGWIN__ - /* almost certainly not needed for any modern Cygwin, but let's be safe... */ - setmode(_fileno(stdout), _O_BINARY); -#endif - - return stdout; -} diff --git a/src/share/file_utils/file_utils.dsp b/src/share/file_utils/file_utils.dsp deleted file mode 100644 index fcfca0ea..00000000 --- a/src/share/file_utils/file_utils.dsp +++ /dev/null @@ -1,115 +0,0 @@ -# Microsoft Developer Studio Project File - Name="file_utils" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=file_utils - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "file_utils.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "file_utils.mak" CFG="file_utils - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "file_utils - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "file_utils - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "file_utils" -# PROP Scc_LocalPath "..\..\.." -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "file_utils - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\obj\lib" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I ".\include" /I "..\..\..\include" /D "NDEBUG" /D "REPLAYGAIN_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" /d "_USRDLL" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 -# ADD LINK32 /nologo /subsystem:windows /dll /machine:I386 /out:"..\..\..\obj\bin/file_utils.dll" - -!ELSEIF "$(CFG)" == "file_utils - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\obj\lib" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I ".\include" /I "..\..\..\include" /D "_DEBUG" /D "_CHATTER" /D "REPLAYGAIN_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" /d "_USRDLL" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 /nologo /subsystem:windows /dll /debug /machine:I386 /out:"..\..\..\obj\bin/file_utils.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "file_utils - Win32 Release" -# Name "file_utils - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp" -# Begin Source File - -SOURCE=.\file_utils.c -# End Source File -# End Group -# Begin Group "Private Header Files" - -# PROP Default_Filter "" -# End Group -# Begin Group "Protected Header Files" - -# PROP Default_Filter "" -# End Group -# Begin Group "Public Header Files" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\include\share\file_utils.h -# End Source File -# End Group -# End Target -# End Project diff --git a/src/share/replaygain/Makefile.am b/src/share/replaygain/Makefile.am deleted file mode 100644 index 2ba111ed..00000000 --- a/src/share/replaygain/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -## Process this file with automake to produce Makefile.in - -AUTOMAKE_OPTIONS = foreign - -INCLUDES = -I$(top_srcdir)/include - -noinst_LIBRARIES = libreplaygain.a - -libreplaygain_a_SOURCES = replaygain.c - -EXTRA_DIST = \ - Makefile.lite \ - Makefile.vc \ - replaygain.dsp - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@" diff --git a/src/share/replaygain/Makefile.lite b/src/share/replaygain/Makefile.lite deleted file mode 100644 index 61a3c282..00000000 --- a/src/share/replaygain/Makefile.lite +++ /dev/null @@ -1,15 +0,0 @@ -# -# GNU makefile -# - -topdir = ../../.. - -LIB_NAME = libreplaygain -INCLUDES = -I$(topdir)/include - -OBJS = \ - replaygain.o - -include $(topdir)/build/lib.mk - -# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/src/share/replaygain/Makefile.vc b/src/share/replaygain/Makefile.vc deleted file mode 100644 index 0e532e58..00000000 --- a/src/share/replaygain/Makefile.vc +++ /dev/null @@ -1,23 +0,0 @@ -!include - -!IFDEF DEBUG -.c.obj: - $(cc) /D "_LIB" -DFLAC__NO_DLL /GX $(cdebug) $(cflags) /I "..\..\..\include" -DSTRICT -YX /Od /D "_DEBUG" $< -!else -.c.obj: - $(cc) /D "_LIB" -DFLAC__NO_DLL /O2 $(crelease) $(cflags) /I "..\..\..\include" -DSTRICT -YX -DNODEBUG $< -!endif - -C_FILES= \ - replaygain.c \ - -OBJS= $(C_FILES:.c=.obj) - -all: replaygain.lib - -replaygain.lib: $(OBJS) - link.exe -lib /nodefaultlib -out:../../../obj/lib/$*.lib $(OBJS) - -clean: - -del *.obj *.pch - -del ..\..\..\obj\lib\replaygain.lib ..\..\..\obj\lib\replaygain.pdb diff --git a/src/share/replaygain/replaygain.c b/src/share/replaygain/replaygain.c deleted file mode 100644 index 775f7f49..00000000 --- a/src/share/replaygain/replaygain.c +++ /dev/null @@ -1,606 +0,0 @@ -/* replaygain - Convenience lib for calculating/storing ReplayGain in FLAC - * Copyright (C) 2002 Josh Coalson - * - * 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 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "share/file_utils.h" -#include "share/replaygain.h" -#include "share/gain_analysis.h" -#include "FLAC/assert.h" -#include "FLAC/file_decoder.h" -#include "FLAC/metadata.h" -#include -#include -#include -#include -#if defined _MSC_VER || defined __MINGW32__ -#include /* for chmod() */ -#endif -#include /* for stat(), maybe chmod() */ - -#ifdef local_min -#undef local_min -#endif -#define local_min(a,b) ((a)<(b)?(a):(b)) - -#ifdef local_max -#undef local_max -#endif -#define local_max(a,b) ((a)>(b)?(a):(b)) - -static const FLAC__byte *tag_title_gain_ = "REPLAYGAIN_TRACK_GAIN"; -static const FLAC__byte *tag_title_peak_ = "REPLAYGAIN_TRACK_PEAK"; -static const FLAC__byte *tag_album_gain_ = "REPLAYGAIN_ALBUM_GAIN"; -static const FLAC__byte *tag_album_peak_ = "REPLAYGAIN_ALBUM_PEAK"; -static const char *peak_format_ = "%s=%1.8f"; -static const char *gain_format_ = "%s=%+2.2f dB"; - -static double album_peak_, title_peak_; - -REPLAYGAIN_API const unsigned FLAC__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED = 148; -/* - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 10 + - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 12 + - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 10 + - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 12 -*/ - - -static FLAC__bool get_file_stats_(const char *filename, struct stat *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - return (0 == stat(filename, stats)); -} - -static void set_file_stats_(const char *filename, struct stat *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - - (void)chmod(filename, stats->st_mode); -} - -static FLAC__bool append_tag_(FLAC__StreamMetadata *block, const char *format, const FLAC__byte *name, float value) -{ - char buffer[256]; - FLAC__StreamMetadata_VorbisComment_Entry entry; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(0 != name); - FLAC__ASSERT(0 != value); - - buffer[sizeof(buffer)-1] = '\0'; - snprintf(buffer, sizeof(buffer)-1, format, name, value); - - entry.entry = buffer; - entry.length = strlen(buffer); - - return FLAC__metadata_object_vorbiscomment_insert_comment(block, block->data.vorbis_comment.num_comments, entry, /*copy=*/true); -} - -REPLAYGAIN_API FLAC__bool FLAC__replaygain_is_valid_sample_frequency(unsigned sample_frequency) -{ - static const unsigned valid_sample_rates[] = { - 8000, - 11025, - 12000, - 16000, - 22050, - 24000, - 32000, - 44100, - 48000 - }; - static const unsigned n_valid_sample_rates = sizeof(valid_sample_rates) / sizeof(valid_sample_rates[0]); - - unsigned i; - - for(i = 0; i < n_valid_sample_rates; i++) - if(sample_frequency == valid_sample_rates[i]) - return true; - return false; -} - -REPLAYGAIN_API FLAC__bool FLAC__replaygain_init(unsigned sample_frequency) -{ - title_peak_ = album_peak_ = 0.0; - return InitGainAnalysis((long)sample_frequency) == INIT_GAIN_ANALYSIS_OK; -} - -REPLAYGAIN_API FLAC__bool FLAC__replaygain_analyze(const FLAC__int32 * const input[], FLAC__bool is_stereo, unsigned bps, unsigned samples) -{ - /* using a small buffer improves data locality; we'd like it to fit easily in the dcache */ - static Float_t lbuffer[2048], rbuffer[2048]; - static const unsigned nbuffer = sizeof(lbuffer) / sizeof(lbuffer[0]); - FLAC__int32 block_peak = 0, s; - unsigned i, j; - - FLAC__ASSERT(bps >= 4 && bps <= FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE); - FLAC__ASSERT(FLAC__MIN_BITS_PER_SAMPLE == 4); - /* - * We use abs() on a FLAC__int32 which is undefined for the most negative value. - * If the reference codec ever handles 32bps we will have to write a special - * case here. - */ - FLAC__ASSERT(FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE < 32); - - if(bps == 16) { - if(is_stereo) { - j = 0; - while(samples > 0) { - const unsigned n = local_min(samples, nbuffer); - for(i = 0; i < n; i++, j++) { - s = input[0][j]; - lbuffer[i] = (Float_t)s; - s = abs(s); - block_peak = local_max(block_peak, s); - - s = input[1][j]; - rbuffer[i] = (Float_t)s; - s = abs(s); - block_peak = local_max(block_peak, s); - } - samples -= n; - if(AnalyzeSamples(lbuffer, rbuffer, n, 2) != GAIN_ANALYSIS_OK) - return false; - } - } - else { - j = 0; - while(samples > 0) { - const unsigned n = local_min(samples, nbuffer); - for(i = 0; i < n; i++, j++) { - s = input[0][j]; - lbuffer[i] = (Float_t)s; - s = abs(s); - block_peak = local_max(block_peak, s); - } - samples -= n; - if(AnalyzeSamples(lbuffer, 0, n, 1) != GAIN_ANALYSIS_OK) - return false; - } - } - } - else { /* bps must be < 32 according to above assertion */ - const double scale = ( - (bps > 16)? - (double)1. / (double)(1u << (bps - 16)) : - (double)(1u << (16 - bps)) - ); - - if(is_stereo) { - j = 0; - while(samples > 0) { - const unsigned n = local_min(samples, nbuffer); - for(i = 0; i < n; i++, j++) { - s = input[0][j]; - lbuffer[i] = (Float_t)(scale * (double)s); - s = abs(s); - block_peak = local_max(block_peak, s); - - s = input[1][j]; - rbuffer[i] = (Float_t)(scale * (double)s); - s = abs(s); - block_peak = local_max(block_peak, s); - } - samples -= n; - if(AnalyzeSamples(lbuffer, rbuffer, n, 2) != GAIN_ANALYSIS_OK) - return false; - } - } - else { - j = 0; - while(samples > 0) { - const unsigned n = local_min(samples, nbuffer); - for(i = 0; i < n; i++, j++) { - s = input[0][j]; - lbuffer[i] = (Float_t)(scale * (double)s); - s = abs(s); - block_peak = local_max(block_peak, s); - } - samples -= n; - if(AnalyzeSamples(lbuffer, 0, n, 1) != GAIN_ANALYSIS_OK) - return false; - } - } - } - - { - const double peak_scale = (double)(1u << (bps - 1)); - double peak = (double)block_peak / peak_scale; - if(peak > title_peak_) - title_peak_ = peak; - if(peak > album_peak_) - album_peak_ = peak; - } - - return true; -} - -REPLAYGAIN_API void FLAC__replaygain_get_album(float *gain, float *peak) -{ - *gain = (float)GetAlbumGain(); - *peak = (float)album_peak_; - album_peak_ = 0.0; -} - -REPLAYGAIN_API void FLAC__replaygain_get_title(float *gain, float *peak) -{ - *gain = (float)GetTitleGain(); - *peak = (float)title_peak_; - title_peak_ = 0.0; -} - - -typedef struct { - unsigned channels; - unsigned bits_per_sample; - unsigned sample_rate; - FLAC__bool error; -} DecoderInstance; - -static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - DecoderInstance *instance = (DecoderInstance*)client_data; - const unsigned bits_per_sample = frame->header.bits_per_sample; - const unsigned channels = frame->header.channels; - const unsigned sample_rate = frame->header.sample_rate; - const unsigned samples = frame->header.blocksize; - - (void)decoder; - - if( - !instance->error && - (channels == 2 || channels == 1) && - bits_per_sample == instance->bits_per_sample && - channels == instance->channels && - sample_rate == instance->sample_rate - ) { - instance->error = !FLAC__replaygain_analyze(buffer, channels==2, bits_per_sample, samples); - } - else { - instance->error = true; - } - - if(!instance->error) - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - else - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; -} - -static void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - DecoderInstance *instance = (DecoderInstance*)client_data; - - (void)decoder; - - if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { - instance->bits_per_sample = metadata->data.stream_info.bits_per_sample; - instance->channels = metadata->data.stream_info.channels; - instance->sample_rate = metadata->data.stream_info.sample_rate; - - if(instance->channels != 1 && instance->channels != 2) { - instance->error = true; - return; - } - - if(!FLAC__replaygain_is_valid_sample_frequency(instance->sample_rate)) { - instance->error = true; - return; - } - } -} - -static void error_callback_(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - DecoderInstance *instance = (DecoderInstance*)client_data; - - (void)decoder, (void)status; - - instance->error = true; -} - -REPLAYGAIN_API const char *FLAC__replaygain_analyze_file(const char *filename, float *title_gain, float *title_peak) -{ - DecoderInstance instance; - FLAC__FileDecoder *decoder = FLAC__file_decoder_new(); - - if(0 == decoder) - return "memory allocation error"; - - instance.error = false; - - /* It does these three by default but lets be explicit: */ - FLAC__file_decoder_set_md5_checking(decoder, false); - FLAC__file_decoder_set_metadata_ignore_all(decoder); - FLAC__file_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO); - - FLAC__file_decoder_set_filename(decoder, filename); - FLAC__file_decoder_set_write_callback(decoder, write_callback_); - FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback_); - FLAC__file_decoder_set_error_callback(decoder, error_callback_); - FLAC__file_decoder_set_client_data(decoder, &instance); - - if(FLAC__file_decoder_init(decoder) != FLAC__FILE_DECODER_OK) { - FLAC__file_decoder_delete(decoder); - return "initializing decoder"; - } - - if(!FLAC__file_decoder_process_until_end_of_file(decoder) || instance.error) { - FLAC__file_decoder_delete(decoder); - return "decoding file"; - } - - FLAC__file_decoder_delete(decoder); - - FLAC__replaygain_get_title(title_gain, title_peak); - - return 0; -} - -REPLAYGAIN_API const char *FLAC__replaygain_store_to_vorbiscomment(FLAC__StreamMetadata *block, float album_gain, float album_peak, float title_gain, float title_peak) -{ - const char *error; - - if(0 != (error = FLAC__replaygain_store_to_vorbiscomment_title(block, title_gain, title_peak))) - return error; - - if(0 != (error = FLAC__replaygain_store_to_vorbiscomment_album(block, album_gain, album_peak))) - return error; - - return 0; -} - -REPLAYGAIN_API const char *FLAC__replaygain_store_to_vorbiscomment_album(FLAC__StreamMetadata *block, float album_gain, float album_peak) -{ - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if( - FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, tag_album_gain_) < 0 || - FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, tag_album_peak_) < 0 - ) - return "memory allocation error"; - - if( - !append_tag_(block, peak_format_, tag_album_peak_, album_peak) || - !append_tag_(block, gain_format_, tag_album_gain_, album_gain) - ) - return "memory allocation error"; - - return 0; -} - -REPLAYGAIN_API const char *FLAC__replaygain_store_to_vorbiscomment_title(FLAC__StreamMetadata *block, float title_gain, float title_peak) -{ - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if( - FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, tag_title_gain_) < 0 || - FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, tag_title_peak_) < 0 - ) - return "memory allocation error"; - - if( - !append_tag_(block, peak_format_, tag_title_peak_, title_peak) || - !append_tag_(block, gain_format_, tag_title_gain_, title_gain) - ) - return "memory allocation error"; - - return 0; -} - -static const char *store_to_file_pre_(const char *filename, FLAC__Metadata_Chain **chain, FLAC__StreamMetadata **block) -{ - FLAC__Metadata_Iterator *iterator; - const char *error; - FLAC__bool found_vc_block = false; - - if(0 == (*chain = FLAC__metadata_chain_new())) - return "memory allocation error"; - - if(!FLAC__metadata_chain_read(*chain, filename)) { - error = FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(*chain)]; - FLAC__metadata_chain_delete(*chain); - return error; - } - - if(0 == (iterator = FLAC__metadata_iterator_new())) { - FLAC__metadata_chain_delete(*chain); - return "memory allocation error"; - } - - FLAC__metadata_iterator_init(iterator, *chain); - - do { - *block = FLAC__metadata_iterator_get_block(iterator); - if((*block)->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) - found_vc_block = true; - } while(!found_vc_block && FLAC__metadata_iterator_next(iterator)); - - if(!found_vc_block) { - /* create a new block */ - *block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); - if(0 == *block) { - FLAC__metadata_chain_delete(*chain); - FLAC__metadata_iterator_delete(iterator); - return "memory allocation error"; - } - while(FLAC__metadata_iterator_next(iterator)) - ; - if(!FLAC__metadata_iterator_insert_block_after(iterator, *block)) { - error = FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(*chain)]; - FLAC__metadata_chain_delete(*chain); - FLAC__metadata_iterator_delete(iterator); - return error; - } - /* iterator is left pointing to new block */ - FLAC__ASSERT(FLAC__metadata_iterator_get_block(iterator) == *block); - } - - FLAC__metadata_iterator_delete(iterator); - - FLAC__ASSERT(0 != *block); - FLAC__ASSERT((*block)->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - return 0; -} - -static const char *store_to_file_post_(const char *filename, FLAC__Metadata_Chain *chain, FLAC__bool preserve_modtime) -{ - struct stat stats; - const FLAC__bool have_stats = get_file_stats_(filename, &stats); - - (void)FLAC__file_utils_change_stats(filename, /*read_only=*/false); - - FLAC__metadata_chain_sort_padding(chain); - if(!FLAC__metadata_chain_write(chain, /*use_padding=*/true, preserve_modtime)) { - FLAC__metadata_chain_delete(chain); - return FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]; - } - - FLAC__metadata_chain_delete(chain); - - if(have_stats) - set_file_stats_(filename, &stats); - - return 0; -} - -REPLAYGAIN_API const char *FLAC__replaygain_store_to_file(const char *filename, float album_gain, float album_peak, float title_gain, float title_peak, FLAC__bool preserve_modtime) -{ - FLAC__Metadata_Chain *chain; - FLAC__StreamMetadata *block; - const char *error; - - if(0 != (error = store_to_file_pre_(filename, &chain, &block))) - return error; - - if(0 != (error = FLAC__replaygain_store_to_vorbiscomment(block, album_gain, album_peak, title_gain, title_peak))) { - FLAC__metadata_chain_delete(chain); - return error; - } - - if(0 != (error = store_to_file_post_(filename, chain, preserve_modtime))) - return error; - - return 0; -} - -REPLAYGAIN_API const char *FLAC__replaygain_store_to_file_album(const char *filename, float album_gain, float album_peak, FLAC__bool preserve_modtime) -{ - FLAC__Metadata_Chain *chain; - FLAC__StreamMetadata *block; - const char *error; - - if(0 != (error = store_to_file_pre_(filename, &chain, &block))) - return error; - - if(0 != (error = FLAC__replaygain_store_to_vorbiscomment_album(block, album_gain, album_peak))) { - FLAC__metadata_chain_delete(chain); - return error; - } - - if(0 != (error = store_to_file_post_(filename, chain, preserve_modtime))) - return error; - - return 0; -} - -REPLAYGAIN_API const char *FLAC__replaygain_store_to_file_title(const char *filename, float title_gain, float title_peak, FLAC__bool preserve_modtime) -{ - FLAC__Metadata_Chain *chain; - FLAC__StreamMetadata *block; - const char *error; - - if(0 != (error = store_to_file_pre_(filename, &chain, &block))) - return error; - - if(0 != (error = FLAC__replaygain_store_to_vorbiscomment_title(block, title_gain, title_peak))) { - FLAC__metadata_chain_delete(chain); - return error; - } - - if(0 != (error = store_to_file_post_(filename, chain, preserve_modtime))) - return error; - - return 0; -} - -static FLAC__bool parse_double_(const FLAC__StreamMetadata_VorbisComment_Entry *entry, double *val) -{ - char s[32], *end; - const char *p, *q; - double v; - - FLAC__ASSERT(0 != entry); - FLAC__ASSERT(0 != val); - -fprintf(stderr,"@@@@ tag=[");fwrite(entry->entry,1,entry->length,stderr);fprintf(stderr,"]\n"); - p = (const char *)entry->entry; - q = strchr(p, '='); - if(0 == q) - return false; - q++; - memset(s, 0, sizeof(s)-1); - strncpy(s, q, local_min(sizeof(s)-1, entry->length - (q-p))); -fprintf(stderr,"@@@@ s=[%s]\n",s); - - v = strtod(s, &end); - if(end == s) - return false; - - *val = v; -fprintf(stderr,"@@@@ v=[%0.12f]\n",v); - return true; -} - -REPLAYGAIN_API FLAC__bool FLAC__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadata *block, FLAC__bool album_mode, double *gain, double *peak) -{ - int gain_offset, peak_offset; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if(0 > (gain_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, album_mode? tag_album_gain_ : tag_title_gain_))) - return false; - if(0 > (peak_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, album_mode? tag_album_peak_ : tag_title_peak_))) - return false; - - if(!parse_double_(block->data.vorbis_comment.comments + gain_offset, gain)) - return false; - if(!parse_double_(block->data.vorbis_comment.comments + peak_offset, peak)) - return false; - - return true; -} - -REPLAYGAIN_API double FLAC__replaygain_compute_scale_factor(double peak, double gain, double preamp, FLAC__bool prevent_clipping) -{ - double scale; - FLAC__ASSERT(peak >= 0.0); - gain += preamp; - scale = (float) pow(10.0, gain * 0.05); - if(prevent_clipping && peak > 0.0) { - const double max_scale = (float)(1.0 / peak); - if(scale > max_scale) - scale = max_scale; - } - return scale; -} diff --git a/src/share/replaygain/replaygain.dsp b/src/share/replaygain/replaygain.dsp deleted file mode 100644 index cc84716e..00000000 --- a/src/share/replaygain/replaygain.dsp +++ /dev/null @@ -1,115 +0,0 @@ -# Microsoft Developer Studio Project File - Name="replaygain" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=replaygain - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "replaygain.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "replaygain.mak" CFG="replaygain - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "replaygain - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "replaygain - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "replaygain" -# PROP Scc_LocalPath "..\..\.." -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "replaygain - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\obj\lib" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I ".\include" /I "..\..\..\include" /D "NDEBUG" /D "REPLAYGAIN_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" /d "_USRDLL" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 -# ADD LINK32 /nologo /subsystem:windows /dll /machine:I386 /out:"..\..\..\obj\bin/replaygain.dll" - -!ELSEIF "$(CFG)" == "replaygain - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\obj\lib" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I ".\include" /I "..\..\..\include" /D "_DEBUG" /D "_CHATTER" /D "REPLAYGAIN_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" /d "_USRDLL" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 /nologo /subsystem:windows /dll /debug /machine:I386 /out:"..\..\..\obj\bin/replaygain.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "replaygain - Win32 Release" -# Name "replaygain - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp" -# Begin Source File - -SOURCE=.\replaygain.c -# End Source File -# End Group -# Begin Group "Private Header Files" - -# PROP Default_Filter "" -# End Group -# Begin Group "Protected Header Files" - -# PROP Default_Filter "" -# End Group -# Begin Group "Public Header Files" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\include\share\replaygain.h -# End Source File -# End Group -# End Target -# End Project