Thread: [Flake-enc-svnlog] SF.net SVN: flake-enc:[234]
Status: Beta
Brought to you by:
jbr79
From: <jb...@us...> - 2009-01-01 04:11:52
|
Revision: 234 http://flake-enc.svn.sourceforge.net/flake-enc/?rev=234&view=rev Author: jbr79 Date: 2009-01-01 04:11:47 +0000 (Thu, 01 Jan 2009) Log Message: ----------- add support for all valid FLAC bit depths (8 to 32) Modified Paths: -------------- flake/flake.c libflake/encode.c libflake/optimize.c Modified: flake/flake.c =================================================================== --- flake/flake.c 2009-01-01 03:44:51 UTC (rev 233) +++ flake/flake.c 2009-01-01 04:11:47 UTC (rev 234) @@ -374,7 +374,7 @@ // set parameters from input audio s.channels = wf.channels; s.sample_rate = wf.sample_rate; - s.bits_per_sample = 16; + s.bits_per_sample = wf.bit_width; // TODO: FLAC supports values up to 36-bits for number of samples, but libflake only uses a 32-bit value s.samples = MIN(wf.samples, UINT32_MAX); @@ -441,9 +441,6 @@ fprintf(stderr, "input file: \"%s\"\n", files->infile); fprintf(stderr, "output file: \"%s\"\n", files->outfile); pcmfile_print(&wf, stderr); - if(wf.bit_width != 16) { - fprintf(stderr, "WARNING! converting to 16-bit (not lossless)\n"); - } if(wf.samples > 0) { int64_t tms; int th, tm, ts; Modified: libflake/encode.c =================================================================== --- libflake/encode.c 2009-01-01 03:44:51 UTC (rev 233) +++ libflake/encode.c 2009-01-01 04:11:47 UTC (rev 234) @@ -424,10 +424,12 @@ break; } } - if(i == 8) return -1; - // FIXME: For now, only 16-bit encoding is supported - if(ctx->bps != 16) return -1; + if(i == 8) { + ctx->bps = s->bits_per_sample; + ctx->bps_code = 0; + } + ctx->sample_count = s->samples; ctx->params = s->params; Modified: libflake/optimize.c =================================================================== --- libflake/optimize.c 2009-01-01 03:44:51 UTC (rev 233) +++ libflake/optimize.c 2009-01-01 04:11:47 UTC (rev 234) @@ -45,22 +45,22 @@ switch(order) { case 1: for(i=1; i<n; i++) { - res[i] = smp[i] - (smp[i-1]); + res[i] = (int32_t)(smp[i] - smp[i-1]); } return; case 2: for(i=2; i<n; i++) { - res[i] = smp[i] - (smp[i-1] << 1) + smp[i-2]; + res[i] = (int32_t)(smp[i] - 2LL*smp[i-1] + smp[i-2]); } return; case 3: for(i=3; i<n; i++) { - res[i] = smp[i] - 3*smp[i-1] + 3*smp[i-2] - smp[i-3]; + res[i] = (int32_t)(smp[i] - 3LL*smp[i-1] + 3LL*smp[i-2] - smp[i-3]); } return; case 4: for(i=4; i<n; i++) { - res[i] = smp[i] - (smp[i-1] << 2) + 6*smp[i-2] - (smp[i-3] << 2) + smp[i-4]; + res[i] = (int32_t)(smp[i] - 4LL*smp[i-1] + 6LL*smp[i-2] - 4LL*smp[i-3] + smp[i-4]); } return; default: return; @@ -72,7 +72,7 @@ int32_t *coefs, int shift) { int i; - int32_t pred; + int64_t pred; for(i=0; i<order; i++) { res[i] = smp[i]; @@ -82,42 +82,42 @@ // note that all cases fall through. // the result is in an unrolled loop for each order switch(order) { - case 32: pred += coefs[31] * smp[i-32]; - case 31: pred += coefs[30] * smp[i-31]; - case 30: pred += coefs[29] * smp[i-30]; - case 29: pred += coefs[28] * smp[i-29]; - case 28: pred += coefs[27] * smp[i-28]; - case 27: pred += coefs[26] * smp[i-27]; - case 26: pred += coefs[25] * smp[i-26]; - case 25: pred += coefs[24] * smp[i-25]; - case 24: pred += coefs[23] * smp[i-24]; - case 23: pred += coefs[22] * smp[i-23]; - case 22: pred += coefs[21] * smp[i-22]; - case 21: pred += coefs[20] * smp[i-21]; - case 20: pred += coefs[19] * smp[i-20]; - case 19: pred += coefs[18] * smp[i-19]; - case 18: pred += coefs[17] * smp[i-18]; - case 17: pred += coefs[16] * smp[i-17]; - case 16: pred += coefs[15] * smp[i-16]; - case 15: pred += coefs[14] * smp[i-15]; - case 14: pred += coefs[13] * smp[i-14]; - case 13: pred += coefs[12] * smp[i-13]; - case 12: pred += coefs[11] * smp[i-12]; - case 11: pred += coefs[10] * smp[i-11]; - case 10: pred += coefs[ 9] * smp[i-10]; - case 9: pred += coefs[ 8] * smp[i- 9]; - case 8: pred += coefs[ 7] * smp[i- 8]; - case 7: pred += coefs[ 6] * smp[i- 7]; - case 6: pred += coefs[ 5] * smp[i- 6]; - case 5: pred += coefs[ 4] * smp[i- 5]; - case 4: pred += coefs[ 3] * smp[i- 4]; - case 3: pred += coefs[ 2] * smp[i- 3]; - case 2: pred += coefs[ 1] * smp[i- 2]; - case 1: pred += coefs[ 0] * smp[i- 1]; + case 32: pred += (int64_t)coefs[31] * (int64_t)smp[i-32]; + case 31: pred += (int64_t)coefs[30] * (int64_t)smp[i-31]; + case 30: pred += (int64_t)coefs[29] * (int64_t)smp[i-30]; + case 29: pred += (int64_t)coefs[28] * (int64_t)smp[i-29]; + case 28: pred += (int64_t)coefs[27] * (int64_t)smp[i-28]; + case 27: pred += (int64_t)coefs[26] * (int64_t)smp[i-27]; + case 26: pred += (int64_t)coefs[25] * (int64_t)smp[i-26]; + case 25: pred += (int64_t)coefs[24] * (int64_t)smp[i-25]; + case 24: pred += (int64_t)coefs[23] * (int64_t)smp[i-24]; + case 23: pred += (int64_t)coefs[22] * (int64_t)smp[i-23]; + case 22: pred += (int64_t)coefs[21] * (int64_t)smp[i-22]; + case 21: pred += (int64_t)coefs[20] * (int64_t)smp[i-21]; + case 20: pred += (int64_t)coefs[19] * (int64_t)smp[i-20]; + case 19: pred += (int64_t)coefs[18] * (int64_t)smp[i-19]; + case 18: pred += (int64_t)coefs[17] * (int64_t)smp[i-18]; + case 17: pred += (int64_t)coefs[16] * (int64_t)smp[i-17]; + case 16: pred += (int64_t)coefs[15] * (int64_t)smp[i-16]; + case 15: pred += (int64_t)coefs[14] * (int64_t)smp[i-15]; + case 14: pred += (int64_t)coefs[13] * (int64_t)smp[i-14]; + case 13: pred += (int64_t)coefs[12] * (int64_t)smp[i-13]; + case 12: pred += (int64_t)coefs[11] * (int64_t)smp[i-12]; + case 11: pred += (int64_t)coefs[10] * (int64_t)smp[i-11]; + case 10: pred += (int64_t)coefs[ 9] * (int64_t)smp[i-10]; + case 9: pred += (int64_t)coefs[ 8] * (int64_t)smp[i- 9]; + case 8: pred += (int64_t)coefs[ 7] * (int64_t)smp[i- 8]; + case 7: pred += (int64_t)coefs[ 6] * (int64_t)smp[i- 7]; + case 6: pred += (int64_t)coefs[ 5] * (int64_t)smp[i- 6]; + case 5: pred += (int64_t)coefs[ 4] * (int64_t)smp[i- 5]; + case 4: pred += (int64_t)coefs[ 3] * (int64_t)smp[i- 4]; + case 3: pred += (int64_t)coefs[ 2] * (int64_t)smp[i- 3]; + case 2: pred += (int64_t)coefs[ 1] * (int64_t)smp[i- 2]; + case 1: pred += (int64_t)coefs[ 0] * (int64_t)smp[i- 1]; case 0: default: break; } - res[i] = smp[i] - (pred >> shift); + res[i] = (int32_t)((int64_t)smp[i] - (pred >> shift)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-01-01 04:26:28
|
Revision: 236 http://flake-enc.svn.sourceforge.net/flake-enc/?rev=236&view=rev Author: jbr79 Date: 2009-01-01 04:26:24 +0000 (Thu, 01 Jan 2009) Log Message: ----------- update Changelog and TODO list Modified Paths: -------------- Changelog TODO Modified: Changelog =================================================================== --- Changelog 2009-01-01 04:11:58 UTC (rev 235) +++ Changelog 2009-01-01 04:26:24 UTC (rev 236) @@ -9,6 +9,8 @@ - Added SVN revision to the version string. Also added the version string to the commandline output - Added support for plain AIFF files +- API changed so that flake_encode_frame() takes 32-bit ints instead of 16-bit +- Added support for lossless encoding of all valid FLAC bit depths (4 to 32) version 0.11 : 5 August 2007 - Significant speed improvements Modified: TODO =================================================================== --- TODO 2009-01-01 04:11:58 UTC (rev 235) +++ TODO 2009-01-01 04:26:24 UTC (rev 236) @@ -17,5 +17,4 @@ ------------------ - Redesign the metadata API - Better warning and error messages -- 24-bit/32-bit lossless - RICE2 encoding for 24-bit This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-01-01 17:33:11
|
Revision: 243 http://flake-enc.svn.sourceforge.net/flake-enc/?rev=243&view=rev Author: jbr79 Date: 2009-01-01 17:33:07 +0000 (Thu, 01 Jan 2009) Log Message: ----------- silence some gcc warnings Modified Paths: -------------- flake/flake.c util/wavinfo.c Modified: flake/flake.c =================================================================== --- flake/flake.c 2009-01-01 17:07:55 UTC (rev 242) +++ flake/flake.c 2009-01-01 17:33:07 UTC (rev 243) @@ -420,7 +420,9 @@ fprintf(stderr, "Error initializing encoder.\n"); return 1; } - fwrite(s.header, 1, header_size, files->ofp); + if (fwrite(s.header, 1, header_size, files->ofp) != 1) { + fprintf(stderr, "\nError writing header to output\n"); + } // print encoding parameters if(first_file && !opts->quiet) { @@ -451,7 +453,7 @@ ts = ts % 60; th = tm / 60; tm = tm % 60; - fprintf(stderr, "samples: %llu (", wf.samples); + fprintf(stderr, "samples: %"PRIu64" (", wf.samples); if(th) fprintf(stderr, "%dh", th); fprintf(stderr, "%dm", tm); fprintf(stderr, "%d.%03ds)\n", ts, (int)tms); @@ -473,7 +475,9 @@ if(fs < 0) { fprintf(stderr, "\nError encoding frame\n"); } else if(fs > 0) { - fwrite(frame, 1, fs, files->ofp); + if(fwrite(frame, 1, fs, files->ofp) != 1) { + fprintf(stderr, "\nError writing frame to output\n"); + } samplecount = MAX(samplecount, samplecount+nr); if(!opts->quiet) { bytecount += fs; @@ -504,7 +508,9 @@ if(!flake_get_streaminfo(&s, &strminfo)) { uint8_t strminfo_data[34]; flake_write_streaminfo(&strminfo, strminfo_data); - fwrite(strminfo_data, 1, 34, files->ofp); + if (fwrite(strminfo_data, 1, 34, files->ofp) != 1) { + fprintf(stderr, "\nError writing header to output\n"); + } } } Modified: util/wavinfo.c =================================================================== --- util/wavinfo.c 2009-01-01 17:07:55 UTC (rev 242) +++ util/wavinfo.c 2009-01-01 17:33:07 UTC (rev 243) @@ -284,7 +284,7 @@ printf("File:\n"); printf(" Name: %s\n", wi->fname); if(wf->seekable) { - printf(" File Size: %lld\n", wf->file_size); + printf(" File Size: %"PRIu64"\n", wf->file_size); } else { printf(" File Size: unknown\n"); } @@ -300,8 +300,8 @@ printf(" Block Align: %d bytes\n", wf->block_align); printf(" Bit Width: %d\n", wf->bit_width); printf("Data:\n"); - printf(" Start: %lld\n", wf->data_start); - printf(" Data Size: %lld\n", wf->data_size); + printf(" Start: %"PRIu64"\n", wf->data_start); + printf(" Data Size: %"PRIu64"\n", wf->data_size); leftover = wf->file_size - wf->data_size - wf->data_start; if(leftover < 0) { if(!wf->seekable) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-06-06 03:41:44
|
Revision: 249 http://flake-enc.svn.sourceforge.net/flake-enc/?rev=249&view=rev Author: jbr79 Date: 2009-06-06 03:41:42 +0000 (Sat, 06 Jun 2009) Log Message: ----------- add support for using libsndfile instead of libpcm_io. since it has not been extensively tested, it is not enabled by default. to use it, configure with the CMake option -DUSE_LIBSNDFILE=yes Modified Paths: -------------- CMakeLists.txt Changelog flake/flake.c Added Paths: ----------- CMakeModules/Libsndfile.cmake Modified: CMakeLists.txt =================================================================== --- CMakeLists.txt 2009-05-20 02:35:40 UTC (rev 248) +++ CMakeLists.txt 2009-06-06 03:41:42 UTC (rev 249) @@ -4,6 +4,9 @@ # CMake files written by Prakash Punnoor CMAKE_MINIMUM_REQUIRED(VERSION 2.4) +IF(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +ENDIF(COMMAND cmake_policy) SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules") Project(Flake C) @@ -26,8 +29,10 @@ INCLUDE(${CMAKE_MODULE_PATH}/FlagsTests.cmake) INCLUDE(${CMAKE_MODULE_PATH}/CompilerVisibility.cmake) INCLUDE(${CMAKE_MODULE_PATH}/DetectCompiler.cmake) +INCLUDE(${CMAKE_MODULE_PATH}/Libsndfile.cmake) OPTION(SHARED "build shared Flake library" OFF) +OPTION(USE_LIBSNDFILE "use libsndfile library for audio input" OFF) INCLUDE_DIRECTORIES(${Flake_BINARY_DIR}/) INCLUDE_DIRECTORIES(${Flake_SOURCE_DIR}/) @@ -131,6 +136,11 @@ CHECK_INCLUDE_FILE_DEFINE(byteswap.h HAVE_BYTESWAP_H) CHECK_FUNCTION_DEFINE("#include <string.h>" "strnlen" "(\"help\", 6)" HAVE_STRNLEN) +# check for libsndfile +IF(USE_LIBSNDFILE) +CHECK_LIBSNDFILE_DEFINE(HAVE_LIBSNDFILE) +ENDIF(USE_LIBSNDFILE) + # output SVN version to config.h EXECUTE_PROCESS(COMMAND svn info --xml WORKING_DIRECTORY ${Flake_SOURCE_DIR} OUTPUT_VARIABLE SVN_INFO ERROR_QUIET) @@ -160,7 +170,9 @@ TARGET_LINK_LIBRARIES(flake_static ${LIBM} ${ADD_LIBS}) # building a separate static lib for the pcm audio decoder +IF(NOT USE_LIBSNDFILE) ADD_LIBRARY(pcm_io STATIC ${LIBPCM_IO_SRCS}) +ENDIF(NOT USE_LIBSNDFILE) ADD_EXECUTABLE(flake_exe ${FLAKE_SRCS}) SET_TARGET_PROPERTIES(flake_exe PROPERTIES OUTPUT_NAME flake) @@ -169,12 +181,22 @@ # When linking to static lib, dllimport mustn't be used SET_TARGET_PROPERTIES(flake_exe PROPERTIES COMPILE_FLAGS -DFLAKE_BUILD_LIBRARY) ENDIF(WIN32) +IF(USE_LIBSNDFILE) +TARGET_LINK_LIBRARIES(flake_exe flake_static) +ELSE(USE_LIBSNDFILE) TARGET_LINK_LIBRARIES(flake_exe pcm_io flake_static) +ENDIF(USE_LIBSNDFILE) +IF(NOT USE_LIBSNDFILE) ADD_EXECUTABLE(wavinfo util/wavinfo.c) TARGET_LINK_LIBRARIES(wavinfo pcm_io) +ENDIF(NOT USE_LIBSNDFILE) -INSTALL(TARGETS ${INSTALL_TARGETS} flake_exe wavinfo +SET(INSTALL_TARGETS ${INSTALL_TARGETS} flake_exe) +IF(NOT USE_LIBSNDFILE) +SET(INSTALL_TARGETS ${INSTALL_TARGETS} wavinfo) +ENDIF(NOT USE_LIBSNDFILE) +INSTALL(TARGETS ${INSTALL_TARGETS} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) Added: CMakeModules/Libsndfile.cmake =================================================================== --- CMakeModules/Libsndfile.cmake (rev 0) +++ CMakeModules/Libsndfile.cmake 2009-06-06 03:41:42 UTC (rev 249) @@ -0,0 +1,19 @@ +MACRO(CHECK_LIBSNDFILE_DEFINE VAR) +SET(CMAKE_REQUIRED_LIBRARIES "-lsndfile") +CHECK_C_SOURCE_COMPILES( +" +#include <sndfile.h> +int main(){ + char buffer[128]; + sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer)); +#ifndef SNDFILE_1 +#error \"Version 1.0.X required.\" +#endif +} +" ${VAR}) +IF(${VAR}) + ADD_DEFINE("${VAR} 1") + SET(ADD_LIBS "${ADD_LIBS}-lsndfile") +ENDIF(${VAR}) +SET(CMAKE_REQUIRED_LIBRARIES "") +ENDMACRO(CHECK_LIBSNDFILE_DEFINE) Modified: Changelog =================================================================== --- Changelog 2009-05-20 02:35:40 UTC (rev 248) +++ Changelog 2009-06-06 03:41:42 UTC (rev 249) @@ -12,6 +12,8 @@ - API changed so that flake_encode_frame() takes 32-bit ints instead of 16-bit - Added support for lossless encoding of all valid FLAC bit depths (4 to 32) - Added support for RICE2 entropy coding +- Added a compile-time option (USE_LIBSNDFILE) for using libsndfile instead of + libpcm_io for reading the input files version 0.11 : 5 August 2007 - Significant speed improvements Modified: flake/flake.c =================================================================== --- flake/flake.c 2009-05-20 02:35:40 UTC (rev 248) +++ flake/flake.c 2009-06-06 03:41:42 UTC (rev 249) @@ -17,6 +17,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* required for fileno() */ +#define _XOPEN_SOURCE + #include "common.h" #include <limits.h> @@ -27,8 +30,14 @@ #include <io.h> #endif +/* libsndfile */ +#if HAVE_LIBSNDFILE +#include <sndfile.h> +#else +#include "pcm_io.h" +#endif + #include "bswap.h" -#include "pcm_io.h" #include "flake.h" #ifndef PATH_MAX @@ -38,14 +47,14 @@ static void print_usage(FILE *out) { - fprintf(out, "usage: flake [options] <input.wav> [-o output.flac]\n" + fprintf(out, "usage: flake [options] <input> [-o output.flac]\n" "type 'flake -h' for more details.\n\n"); } static void print_help(FILE *out) { - fprintf(out, "usage: flake [options] <input.wav> [-o output.flac]\n" + fprintf(out, "usage: flake [options] <input> [-o output.flac]\n" "options:\n" " [-h] Print out list of commandline options\n" " [-q] Quiet mode: no console output\n" @@ -353,11 +362,134 @@ fprintf(stderr, "header padding: %d\n", s->params.padding_size); } +#if HAVE_LIBSNDFILE +typedef SNDFILE PcmContext; +typedef SF_INFO PcmInfo; + static int +pcm_init_sndfile(PcmContext **ctx, PcmInfo *info, FILE *ifp, FlakeContext *s) +{ + *ctx = sf_open_fd(fileno(ifp), SFM_READ, info, 0); + if (!*ctx) + return -1; + + // set parameters from input audio + s->channels = info->channels; + s->sample_rate = info->samplerate; + switch (info->format & SF_FORMAT_SUBMASK) { + case SF_FORMAT_PCM_S8: + case SF_FORMAT_PCM_U8: s->bits_per_sample = 8; break; + case SF_FORMAT_PCM_16: s->bits_per_sample = 16; break; + case SF_FORMAT_PCM_24: s->bits_per_sample = 24; break; + case SF_FORMAT_PCM_32: s->bits_per_sample = 32; break; + default: + fprintf(stderr, "sample format not supported.\n"); + sf_close(*ctx); + return -1; + } + s->samples = MIN(info->frames, UINT32_MAX); + return 0; +} + +#else +typedef PcmFile PcmContext; +typedef void PcmInfo; + +static int +pcm_init_pcmio(PcmContext *ctx, FILE *ifp, FlakeContext *s) +{ + if(pcmfile_init(ctx, ifp, PCM_SAMPLE_FMT_S32, PCM_FORMAT_UNKNOWN)) + return 1; + + // set parameters from input audio + s->channels = ctx->channels; + s->sample_rate = ctx->sample_rate; + s->bits_per_sample = ctx->bit_width; + s->samples = MIN(ctx->samples, UINT32_MAX); + return 0; +} + +#endif /* !HAVE_LIBSNDFILE */ + +static int +pcm_init(PcmContext **ctx, PcmInfo *info, FILE *ifp, FlakeContext *s) +{ +#if HAVE_LIBSNDFILE + return pcm_init_sndfile(ctx, info, ifp, s); +#else + return pcm_init_pcmio(*ctx, ifp, s); +#endif +} + +#if HAVE_LIBSNDFILE +static int +sndfile_read_samples(SNDFILE *sfctx, int32_t *wav, int bps, int channels, + int samples) +{ + int i, nr=0; + if (bps > 16) { + nr = sf_readf_int(sfctx, wav, samples); + if (nr && bps == 24) { + for (i = 0; i < nr * channels; i++) { + wav[i] >>= 8; + } + } + } else { + int16_t *wav16 = (int16_t *)wav; + nr = sf_readf_short(sfctx, wav16, samples); + for (i = (nr * channels) - 1; i >= 0; i--) { + wav[i] = wav16[i]; + } + } + return nr; +} + +static void +sndfile_print(SF_INFO *info, FILE *st) +{ + SF_FORMAT_INFO format_info; + const char *chan, *fmt, *order; + int bps=0; + + if(st == NULL || info == NULL) return; + + chan = "?-channel"; + fmt = "unknown"; + order = "?-endian"; + + switch (info->channels) { + case 1: chan = "mono"; break; + case 2: chan = "stereo"; break; + case 3: chan = "3-channel"; break; + case 4: chan = "4-channel"; break; + case 5: chan = "5-channel"; break; + case 6: chan = "6-channel"; break; + case 7: chan = "7-channel"; break; + case 8: chan = "8-channel"; break; + default: chan = "multi-channel"; break; + } + + format_info.format = info->format & SF_FORMAT_TYPEMASK; + sf_command(NULL, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info)); + fmt = format_info.name; + + switch (info->format & SF_FORMAT_SUBMASK) { + case SF_FORMAT_PCM_S8: + case SF_FORMAT_PCM_U8: bps = 8; break; + case SF_FORMAT_PCM_16: bps = 16; break; + case SF_FORMAT_PCM_24: bps = 24; break; + case SF_FORMAT_PCM_32: bps = 32; break; + } + + fprintf(st, "%s %d-bit %d Hz %s\n", fmt, bps, info->samplerate, chan); +} + +#endif + +static int encode_file(CommandOptions *opts, FilePair *files, int first_file) { FlakeContext s; - PcmFile wf; int header_size, subset; uint8_t *frame; int32_t *wav; @@ -365,19 +497,23 @@ int fs; uint32_t nr, samplecount, bytecount; float kb, sec, kbps, wav_bytes; + int block_align; + PcmContext *ctx=NULL; +#if HAVE_LIBSNDFILE + SF_INFO info1; + SF_INFO *info = &info1; +#else + PcmFile ctx1; + void *info = NULL; + ctx = &ctx1; +#endif - if(pcmfile_init(&wf, files->ifp, PCM_SAMPLE_FMT_S32, PCM_FORMAT_UNKNOWN)) { - fprintf(stderr, "invalid input file: %s\n", files->infile); + if (pcm_init(&ctx, info, files->ifp, &s)) { + fprintf(stderr, "\ninvalid input file: %s\n", files->infile); return 1; } + block_align = s.bits_per_sample * s.channels / 8; - // set parameters from input audio - s.channels = wf.channels; - s.sample_rate = wf.sample_rate; - s.bits_per_sample = wf.bit_width; - // TODO: FLAC supports values up to 36-bits for number of samples, but libflake only uses a 32-bit value - s.samples = MIN(wf.samples, UINT32_MAX); - // set parameters from commandline s.params.compression = opts->compr; if(flake_set_defaults(&s.params)) { @@ -442,18 +578,22 @@ fprintf(stderr, "\n"); fprintf(stderr, "input file: \"%s\"\n", files->infile); fprintf(stderr, "output file: \"%s\"\n", files->outfile); - pcmfile_print(&wf, stderr); - if(wf.samples > 0) { +#if HAVE_LIBSNDFILE + sndfile_print(info, stderr); +#else + pcmfile_print(ctx, stderr); +#endif + if(s.samples > 0) { int64_t tms; int th, tm, ts; - tms = (int64_t)(wf.samples * 1000.0 / wf.sample_rate); + tms = (int64_t)(s.samples * 1000.0 / s.sample_rate); ts = tms / 1000; tms = tms % 1000; tm = ts / 60; ts = ts % 60; th = tm / 60; tm = tm % 60; - fprintf(stderr, "samples: %"PRIu64" (", wf.samples); + fprintf(stderr, "samples: %"PRIu32" (", s.samples); if(th) fprintf(stderr, "%dh", th); fprintf(stderr, "%dm", tm); fprintf(stderr, "%d.%03ds)\n", ts, (int)tms); @@ -464,13 +604,25 @@ } frame = flake_get_buffer(&s); - wav = malloc(s.params.block_size * wf.channels * sizeof(int32_t)); + wav = malloc(s.params.block_size * s.channels * sizeof(int32_t)); samplecount = percent = 0; wav_bytes = 0; bytecount = header_size; - nr = pcmfile_read_samples(&wf, wav, s.params.block_size); +#if HAVE_LIBSNDFILE + nr = sndfile_read_samples(ctx, wav, s.bits_per_sample, s.channels, + s.params.block_size); +#else + nr = pcmfile_read_samples(ctx, wav, s.params.block_size); +#endif while(nr > 0) { + /*unsigned int z,ch; + for (z = 0; z < nr; z++) { + fprintf(stderr, "\n"); + for (ch = 0; ch < s.channels; ch++) { + fprintf(stderr, "%-5d", wav[z*s.channels+ch]); + } + }*/ fs = flake_encode_frame(&s, wav, nr); if(fs < 0) { fprintf(stderr, "\nError encoding frame\n"); @@ -488,7 +640,7 @@ if(s.samples > 0) { percent = ((samplecount * 100.5) / s.samples); } - wav_bytes = samplecount*wf.block_align; + wav_bytes = samplecount * block_align; if(!opts->quiet) { fprintf(stderr, "\rprogress: %3d%% | ratio: %1.3f | " "bitrate: %4.1f kbps ", @@ -496,7 +648,12 @@ } } } - nr = pcmfile_read_samples(&wf, wav, s.params.block_size); +#if HAVE_LIBSNDFILE + nr = sndfile_read_samples(ctx, wav, s.bits_per_sample, s.channels, + s.params.block_size); +#else + nr = pcmfile_read_samples(ctx, wav, s.params.block_size); +#endif } if(!opts->quiet) { fprintf(stderr, "| bytes: %d \n\n", bytecount); @@ -514,7 +671,11 @@ } } - pcmfile_close(&wf); +#if HAVE_LIBSNDFILE + sf_close(ctx); +#else + pcmfile_close(ctx); +#endif flake_encode_close(&s); free(wav); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |