1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-10 16:43:33 +02:00

Update twolame to 0.3.13.

This commit is contained in:
lllucius
2013-10-24 04:32:13 +00:00
parent 99acb56af6
commit 3effa9693f
124 changed files with 44671 additions and 44430 deletions

View File

@@ -1,14 +1,13 @@
AM_CFLAGS = -I../libtwolame/
AM_CFLAGS = -I$(top_srcdir)/libtwolame/ $(WARNING_CFLAGS)
# This is just sample code - don't install it
noinst_PROGRAMS = @STWOLAME_BIN@
EXTRA_PROGRAMS = stwolame
noinst_PROGRAMS = stwolame
stwolame_SOURCES = \
simplefrontend.c \
audio_wave.h \
audio_wave.c
stwolame_LDADD = $(top_srcdir)/libtwolame/libtwolame.la
stwolame_LDADD = $(top_builddir)/libtwolame/libtwolame.la

View File

@@ -32,24 +32,27 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
EXTRA_PROGRAMS = stwolame$(EXEEXT)
noinst_PROGRAMS = stwolame$(EXEEXT)
subdir = simplefrontend
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/build/m4/libtool.m4 \
$(top_srcdir)/build/m4/pkg.m4 $(top_srcdir)/configure.ac
am__aclocal_m4_deps = $(top_srcdir)/build-scripts/libtool.m4 \
$(top_srcdir)/build-scripts/ltoptions.m4 \
$(top_srcdir)/build-scripts/ltsugar.m4 \
$(top_srcdir)/build-scripts/ltversion.m4 \
$(top_srcdir)/build-scripts/lt~obsolete.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/build/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/build/config.h
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/libtwolame/config.h
CONFIG_CLEAN_FILES =
PROGRAMS = $(noinst_PROGRAMS)
am_stwolame_OBJECTS = simplefrontend.$(OBJEXT) audio_wave.$(OBJEXT)
stwolame_OBJECTS = $(am_stwolame_OBJECTS)
stwolame_DEPENDENCIES = $(top_srcdir)/libtwolame/libtwolame.la
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/build
depcomp = $(SHELL) $(top_srcdir)/build/depcomp
stwolame_DEPENDENCIES = $(top_builddir)/libtwolame/libtwolame.la
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/libtwolame
depcomp = $(SHELL) $(top_srcdir)/build-scripts/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -77,46 +80,53 @@ CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
ECHO = @ECHO@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
FGREP = @FGREP@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_ASCIIDOC = @PATH_ASCIIDOC@
PATH_DOXYGEN = @PATH_DOXYGEN@
PATH_SEPARATOR = @PATH_SEPARATOR@
PATH_XMLTO = @PATH_XMLTO@
PKG_CONFIG = @PKG_CONFIG@
RANLIB = @RANLIB@
SED = @SED@
@@ -125,17 +135,17 @@ SHELL = @SHELL@
SNDFILE_CFLAGS = @SNDFILE_CFLAGS@
SNDFILE_LIBS = @SNDFILE_LIBS@
STRIP = @STRIP@
STWOLAME_BIN = @STWOLAME_BIN@
TWOLAME_BIN = @TWOLAME_BIN@
TWOLAME_SO_VERSION = @TWOLAME_SO_VERSION@
VERSION = @VERSION@
WARNING_CFLAGS = @WARNING_CFLAGS@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
@@ -177,24 +187,17 @@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AM_CFLAGS = -I../libtwolame/
# This is just sample code - don't install it
noinst_PROGRAMS = @STWOLAME_BIN@
AM_CFLAGS = -I$(top_srcdir)/libtwolame/ $(WARNING_CFLAGS)
stwolame_SOURCES = \
simplefrontend.c \
audio_wave.h \
audio_wave.c
stwolame_LDADD = $(top_srcdir)/libtwolame/libtwolame.la
stwolame_LDADD = $(top_builddir)/libtwolame/libtwolame.la
all: all-am
.SUFFIXES:

View File

@@ -18,7 +18,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: audio_wave.c,v 1.3 2008-02-01 19:44:37 richardash1981 Exp $
* $Id$
*
*/
@@ -36,38 +36,38 @@
enum byte_order { order_unknown, order_bigEndian, order_littleEndian };
static enum byte_order DetermineByteOrder (void)
static enum byte_order DetermineByteOrder(void)
{
char s[sizeof (long) + 1];
union {
long longval;
char charval[sizeof (long)];
} probe;
probe.longval = 0x41424344L; /* ABCD in ASCII */
strncpy (s, probe.charval, sizeof (long));
s[sizeof (long)] = '\0';
/* fprintf( stderr, "byte order is %s\n", s ); */
if (strcmp (s, "ABCD") == 0)
return order_bigEndian;
else if (strcmp (s, "DCBA") == 0)
return order_littleEndian;
else
return order_unknown;
char s[sizeof(long) + 1];
union {
long longval;
char charval[sizeof(long)];
} probe;
probe.longval = 0x41424344L; /* ABCD in ASCII */
strncpy(s, probe.charval, sizeof(long));
s[sizeof(long)] = '\0';
/* printf("byte order is %s\n", s ); */
if (strcmp(s, "ABCD") == 0)
return order_bigEndian;
else if (strcmp(s, "DCBA") == 0)
return order_littleEndian;
else
return order_unknown;
}
static void SwapBytesInWords (short *loc, int words)
static void SwapBytesInWords(short *loc, int words)
{
int i;
short thisval;
char *dst, *src;
src = (char *) &thisval;
for (i = 0; i < words; i++) {
thisval = *loc;
dst = (char *) loc++;
dst[0] = src[1];
dst[1] = src[0];
}
int i;
short thisval;
char *dst, *src;
src = (char *) &thisval;
for (i = 0; i < words; i++) {
thisval = *loc;
dst = (char *) loc++;
dst[0] = src[1];
dst[1] = src[0];
}
}
@@ -79,18 +79,18 @@ static void SwapBytesInWords (short *loc, int words)
*
*****************************************************************************/
int wave_get_samples (wave_info_t *wave_info, short int pcm[], int numSamples)
int wave_get_samples(wave_info_t * wave_info, short int pcm[], int numSamples)
{
int samples_read;
FILE *file = wave_info->soundfile;
samples_read = fread (pcm, sizeof(short int), numSamples, file);
if (wave_info->byteswap) {
SwapBytesInWords (pcm, samples_read);
}
return (samples_read/wave_info->channels);
int samples_read;
FILE *file = wave_info->soundfile;
samples_read = fread(pcm, sizeof(short int), numSamples, file);
if (wave_info->byteswap) {
SwapBytesInWords(pcm, samples_read);
}
return (samples_read / wave_info->channels);
}
@@ -108,142 +108,146 @@ int wave_get_samples (wave_info_t *wave_info, short int pcm[], int numSamples)
*
*****************************************************************************/
wave_info_t *wave_init (char *inPath)
wave_info_t *wave_init(char *inPath)
{
unsigned char wave_header_buffer[40]; //HH fixed
int wave_header_read = 0;
int wave_header_stereo = -1;
int wave_header_16bit = -1;
unsigned long samplerate;
enum byte_order NativeByteOrder = order_unknown;
wave_info_t *wave_info = NULL;
FILE *file;
if ( (file = fopen(inPath, "rb"))==NULL) {
fprintf(stdout,"WAV: cannot open input file: %s\n", inPath);
return(NULL);
}
/************** WAVE ************************/
/* Nick Burch <The_Leveller@newmail.net> */
/********************************************/
/* Wave File Headers: (Dec) */
/* 8-11 = "WAVE" */
/* 22 = Stereo / Mono */
/* 01 = mono, 02 = stereo */
/* 24 = Sampling Frequency */
/* 32 = Data Rate */
/* 01 = x1 (8bit Mono) */
/* 02 = x2 (8bit Stereo or */
/* 16bit Mono) */
/* 04 = x4 (16bit Stereo) */
/********************************************/
fseek (file, 0, SEEK_SET);
fread (wave_header_buffer, 1, 40, file);
if (wave_header_buffer[8] == 'W' && wave_header_buffer[9] == 'A'
&& wave_header_buffer[10] == 'V' && wave_header_buffer[11] == 'E') {
fprintf (stderr, "Parsing Wave File Header\n");
if (NativeByteOrder == order_unknown) {
NativeByteOrder = DetermineByteOrder ();
if (NativeByteOrder == order_unknown) {
fprintf (stderr, "byte order not determined\n");
fclose(file); return(NULL);
}
}
if (NativeByteOrder == order_littleEndian) {
samplerate = *(unsigned long *) (&wave_header_buffer[24]);
} else {
samplerate = wave_header_buffer[27] +
(wave_header_buffer[26] << 8) +
(wave_header_buffer[25] << 16) + (wave_header_buffer[24] << 24);
}
/* Wave File */
wave_header_read = 1;
switch (samplerate) {
case 44100:
case 48000:
case 32000:
case 24000:
case 22050:
case 16000:
fprintf (stderr, ">>> %ld Hz sampling freq selected\n", samplerate);
break;
default:
/* Unknown Unsupported Frequency */
fprintf (stderr, ">>> Unknown samp freq %ld Hz in Wave Header\n",
samplerate);
fprintf (stderr, ">>> Default 44.1 kHz samp freq selected\n");
samplerate = 44100;
break;
}
if ((long) wave_header_buffer[22] == 1) {
fprintf (stderr, ">>> Input Wave File is Mono\n");
wave_header_stereo = 0;
}
if ((long) wave_header_buffer[22] == 2) {
fprintf (stderr, ">>> Input Wave File is Stereo\n");
wave_header_stereo = 1;
}
if ((long) wave_header_buffer[32] == 1) {
fprintf (stderr, ">>> Input Wave File is 8 Bit\n");
wave_header_16bit = 0;
fprintf (stderr, "Input File must be 16 Bit! Please Re-sample");
fclose(file); return(NULL);
}
if ((long) wave_header_buffer[32] == 2) {
if (wave_header_stereo == 1) {
fprintf (stderr, ">>> Input Wave File is 8 Bit\n");
wave_header_16bit = 0;
fprintf (stderr, "Input File must be 16 Bit! Please Re-sample");
fclose(file); return(NULL);
} else {
/* fprintf(stderr, ">>> Input Wave File is 16 Bit\n" ); */
wave_header_16bit = 1;
}
}
if ((long) wave_header_buffer[32] == 4) {
/* fprintf(stderr, ">>> Input Wave File is 16 Bit\n" ); */
wave_header_16bit = 1;
}
unsigned char wave_header_buffer[40]; // HH fixed
int wave_header_read = 0;
int wave_header_stereo = -1;
int wave_header_16bit = -1;
unsigned long samplerate;
enum byte_order NativeByteOrder = order_unknown;
/* should probably use the wave header to determine size here FIXME MFC Feb 2003 */
if (fseek (file, 44, SEEK_SET) != 0) {
/* there's a way of calculating the size of the
wave header. i'll just jump 44 to start with */
fprintf (stderr, "Could not seek to PCM sound data in \"%s\".\n", inPath);
fclose(file); return(NULL);
}
// Successfully processed the wave header
wave_info = (wave_info_t *)calloc(1, sizeof(wave_info_t));
wave_info->soundfile = file;
if (wave_header_stereo == 1)
wave_info->channels = 2;
else wave_info->channels = 1;
wave_info->samplerate = samplerate;
// UNKNOWN. But we really should be able to work
// it out. FIX THIS. MFC May03.
wave_info->num_samples = -1;
// Enable byte swap for big endian machines
if (NativeByteOrder == order_bigEndian)
wave_info->byteswap = 1;
else wave_info->byteswap = 0;
return(wave_info);
}
// not a wave file
fclose(file); return(NULL);
wave_info_t *wave_info = NULL;
FILE *file;
if ((file = fopen(inPath, "rb")) == NULL) {
printf("WAV: cannot open input file: %s\n", inPath);
return (NULL);
}
/************** WAVE ************************/
/* Nick Burch <The_Leveller@newmail.net> */
/********************************************/
/* Wave File Headers: (Dec) */
/* 8-11 = "WAVE" */
/* 22 = Stereo / Mono */
/* 01 = mono, 02 = stereo */
/* 24 = Sampling Frequency */
/* 32 = Data Rate */
/* 01 = x1 (8bit Mono) */
/* 02 = x2 (8bit Stereo or */
/* 16bit Mono) */
/* 04 = x4 (16bit Stereo) */
/********************************************/
fseek(file, 0, SEEK_SET);
fread(wave_header_buffer, 1, 40, file);
if (wave_header_buffer[8] == 'W' && wave_header_buffer[9] == 'A'
&& wave_header_buffer[10] == 'V' && wave_header_buffer[11] == 'E') {
printf("Parsing Wave File Header\n");
if (NativeByteOrder == order_unknown) {
NativeByteOrder = DetermineByteOrder();
if (NativeByteOrder == order_unknown) {
printf("byte order not determined\n");
fclose(file);
return (NULL);
}
}
if (NativeByteOrder == order_littleEndian) {
samplerate = *(unsigned long *) (&wave_header_buffer[24]);
} else {
samplerate = wave_header_buffer[27] +
(wave_header_buffer[26] << 8) +
(wave_header_buffer[25] << 16) + (wave_header_buffer[24] << 24);
}
/* Wave File */
wave_header_read = 1;
switch (samplerate) {
case 44100:
case 48000:
case 32000:
case 24000:
case 22050:
case 16000:
printf(">>> %ld Hz sampling freq selected\n", samplerate);
break;
default:
/* Unknown Unsupported Frequency */
printf(">>> Unknown samp freq %ld Hz in Wave Header\n", samplerate);
printf(">>> Default 44.1 kHz samp freq selected\n");
samplerate = 44100;
break;
}
if ((long) wave_header_buffer[22] == 1) {
printf(">>> Input Wave File is Mono\n");
wave_header_stereo = 0;
}
if ((long) wave_header_buffer[22] == 2) {
printf(">>> Input Wave File is Stereo\n");
wave_header_stereo = 1;
}
if ((long) wave_header_buffer[32] == 1) {
printf(">>> Input Wave File is 8 Bit\n");
wave_header_16bit = 0;
printf("Input File must be 16 Bit! Please Re-sample");
fclose(file);
return (NULL);
}
if ((long) wave_header_buffer[32] == 2) {
if (wave_header_stereo == 1) {
printf(">>> Input Wave File is 8 Bit\n");
wave_header_16bit = 0;
printf("Input File must be 16 Bit! Please Re-sample");
fclose(file);
return (NULL);
} else {
/* printf(">>> Input Wave File is 16 Bit\n" ); */
wave_header_16bit = 1;
}
}
if ((long) wave_header_buffer[32] == 4) {
/* printf(">>> Input Wave File is 16 Bit\n" ); */
wave_header_16bit = 1;
}
/* should probably use the wave header to determine size here FIXME MFC Feb 2003 */
if (fseek(file, 44, SEEK_SET) != 0) {
/* there's a way of calculating the size of the wave header. i'll just jump 44 to start
with */
printf("Could not seek to PCM sound data in \"%s\".\n", inPath);
fclose(file);
return (NULL);
}
// Successfully processed the wave header
wave_info = (wave_info_t *) calloc(1, sizeof(wave_info_t));
wave_info->soundfile = file;
if (wave_header_stereo == 1)
wave_info->channels = 2;
else
wave_info->channels = 1;
wave_info->samplerate = samplerate;
// UNKNOWN. But we really should be able to work
// it out. FIX THIS. MFC May03.
wave_info->num_samples = -1;
// Enable byte swap for big endian machines
if (NativeByteOrder == order_bigEndian)
wave_info->byteswap = 1;
else
wave_info->byteswap = 0;
return (wave_info);
}
// not a wave file
fclose(file);
return (NULL);
}
/* vim:ts=4:sw=4:nowrap: */

View File

@@ -18,24 +18,22 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: audio_wave.h,v 1.3 2008-02-01 19:44:37 richardash1981 Exp $
* $Id$
*
*/
typedef struct wave_info_struct
{
FILE *soundfile;
short channels; // 1 - mono . 2 - stereo. d'uh.
unsigned long num_samples; // total number of samples/channel if available
short samplesize; // 8 bit or 16bit. could probably just auto scale. but i think
// we'll just ignore 8bit sound. MFC May03
int samplerate; // in Hz
int byteswap;
}
wave_info_t;
typedef struct wave_info_struct {
FILE *soundfile;
short channels; // 1 - mono . 2 - stereo. d'uh.
unsigned long num_samples; // total number of samples/channel if available
short samplesize; // 8 bit or 16bit. could probably just auto scale. but i think
// we'll just ignore 8bit sound. MFC May03
int samplerate; // in Hz
int byteswap;
} wave_info_t;
wave_info_t *wave_init(char *inPath);
int wave_get_samples(wave_info_t *wave_info, short int pcm[], int num_samples);
int wave_get_samples(wave_info_t * wave_info, short int pcm[], int num_samples);
// vim:ts=4:sw=4:nowrap:

View File

@@ -18,7 +18,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: simplefrontend.c,v 1.3 2008-02-01 19:44:37 richardash1981 Exp $
* $Id$
*
*/
@@ -35,115 +35,114 @@
void usage (void) {
fprintf(stdout,"stwolame <input wavefile> <output mp2 file>\n");
exit (1);
static void usage(void)
{
printf("stwolame <input wavefile> <output mp2 file>\n");
exit(1);
}
int main (int argc, char **argv) {
twolame_options *encodeOptions;
char *inputfilename = argv[1];
char *outputfilename = argv[2];
FILE *outfile;
short int *pcmaudio;
unsigned char *mp2buffer;
int num_samples=0;
int mp2fill_size=0;
int frames=0;
wave_info_t *wave_info = NULL;
if (argc != 3) usage();
int main(int argc, char **argv)
{
twolame_options *encodeOptions;
char *inputfilename = argv[1];
char *outputfilename = argv[2];
FILE *outfile;
short int *pcmaudio;
unsigned char *mp2buffer;
int num_samples = 0;
int mp2fill_size = 0;
int frames = 0;
wave_info_t *wave_info = NULL;
/* Allocate some space for the PCM audio data */
if ( (pcmaudio=(short *)calloc(AUDIOBUFSIZE, sizeof(short)))==NULL) {
fprintf(stdout,"pcmaudio alloc failed\n");
exit(99);
}
if (argc != 3)
usage();
/* Allocate some space for the encoded MP2 audio data */
if ( (mp2buffer=(unsigned char *)calloc(MP2BUFSIZE, sizeof(unsigned char)))==NULL) {
fprintf(stdout,"mp2buffer alloc failed\n");
exit(99);
}
/* Allocate some space for the PCM audio data */
if ((pcmaudio = (short *) calloc(AUDIOBUFSIZE, sizeof(short))) == NULL) {
fprintf(stderr, "pcmaudio alloc failed\n");
exit(99);
}
/* Allocate some space for the encoded MP2 audio data */
if ((mp2buffer = (unsigned char *) calloc(MP2BUFSIZE, sizeof(unsigned char))) == NULL) {
fprintf(stderr, "mp2buffer alloc failed\n");
exit(99);
}
/* grab a set of default encode options */
encodeOptions = twolame_init();
fprintf(stdout,"Using libtwolame version %s.\n", get_twolame_version());
/* grab a set of default encode options */
encodeOptions = twolame_init();
printf("Using libtwolame version %s.\n", get_twolame_version());
/* Open the wave file */
if ( (wave_info = wave_init(inputfilename)) == NULL ) {
fprintf(stdout,"Not a recognised WAV file.\n");
exit(99);
}
/* Open the wave file */
if ((wave_info = wave_init(inputfilename)) == NULL) {
fprintf(stderr, "Not a recognised WAV file.\n");
exit(99);
}
// Use sound file to over-ride preferences for
// mono/stereo and sampling-frequency
twolame_set_num_channels(encodeOptions, wave_info->channels);
if (wave_info->channels == 1) {
twolame_set_mode(encodeOptions, TWOLAME_MONO);
} else {
twolame_set_mode(encodeOptions, TWOLAME_STEREO);
}
// Use sound file to over-ride preferences for
// mono/stereo and sampling-frequency
twolame_set_num_channels(encodeOptions, wave_info->channels);
if (wave_info->channels == 1) {
twolame_set_mode(encodeOptions, TWOLAME_MONO);
} else {
twolame_set_mode(encodeOptions, TWOLAME_JOINT_STEREO);
}
/* Set the input and output sample rate to the same */
twolame_set_in_samplerate(encodeOptions, wave_info->samplerate);
twolame_set_out_samplerate(encodeOptions, wave_info->samplerate);
/* Set the input and output sample rate to the same */
twolame_set_in_samplerate(encodeOptions, wave_info->samplerate);
twolame_set_out_samplerate(encodeOptions, wave_info->samplerate);
/* Set the bitrate to 160 kbps */
twolame_set_bitrate(encodeOptions, 160);
/* initialise twolame with this set of options */
if (twolame_init_params( encodeOptions ) != 0) {
fprintf(stderr, "Error: configuring libtwolame encoder failed.\n");
exit(99);
}
/* Set the bitrate to 192 kbps */
twolame_set_bitrate(encodeOptions, 192);
/* Open the output file for the encoded MP2 data */
if ((outfile = fopen(outputfilename, "wb"))==0) {
fprintf(stdout,"error opening output file %s\n",outputfilename);
exit(99);
}
/* initialise twolame with this set of options */
if (twolame_init_params(encodeOptions) != 0) {
fprintf(stderr, "Error: configuring libtwolame encoder failed.\n");
exit(99);
}
// Read num_samples of audio data *per channel* from the input file
while ( (num_samples = wave_get_samples(wave_info, pcmaudio, AUDIOBUFSIZE)) != 0 ) {
// Encode the audio!
mp2fill_size = twolame_encode_buffer_interleaved(encodeOptions, pcmaudio, num_samples, mp2buffer, MP2BUFSIZE);
// Write the MPEG bitstream to the file
fwrite(mp2buffer, sizeof(unsigned char), mp2fill_size, outfile);
// Display the number of MPEG audio frames we have encoded
frames += (num_samples/TWOLAME_SAMPLES_PER_FRAME);
fprintf(stdout,"[%04i]\r", frames);
fflush(stdout);
}
/* flush any remaining audio. (don't send any new audio data)
There should only ever be a max of 1 frame on a flush.
There may be zero frames if the audio data was an exact
multiple of 1152 */
mp2fill_size = twolame_encode_flush(encodeOptions, mp2buffer, MP2BUFSIZE);
fwrite(mp2buffer, sizeof(unsigned char), mp2fill_size, outfile);
/* Open the output file for the encoded MP2 data */
if ((outfile = fopen(outputfilename, "wb")) == 0) {
fprintf(stderr, "error opening output file %s\n", outputfilename);
exit(99);
}
// Read num_samples of audio data *per channel* from the input file
while ((num_samples = wave_get_samples(wave_info, pcmaudio, AUDIOBUFSIZE)) != 0) {
// Encode the audio!
mp2fill_size =
twolame_encode_buffer_interleaved(encodeOptions, pcmaudio, num_samples, mp2buffer,
MP2BUFSIZE);
// Write the MPEG bitstream to the file
fwrite(mp2buffer, sizeof(unsigned char), mp2fill_size, outfile);
// Display the number of MPEG audio frames we have encoded
frames += (num_samples / TWOLAME_SAMPLES_PER_FRAME);
printf("[%04i]\r", frames);
fflush(stdout);
}
/* flush any remaining audio. (don't send any new audio data) There should only ever be a max
of 1 frame on a flush. There may be zero frames if the audio data was an exact multiple of
1152 */
mp2fill_size = twolame_encode_flush(encodeOptions, mp2buffer, MP2BUFSIZE);
fwrite(mp2buffer, sizeof(unsigned char), mp2fill_size, outfile);
twolame_close( &encodeOptions );
free(pcmaudio);
fprintf(stdout,"\nFinished nicely.\n");
return(0);
twolame_close(&encodeOptions);
free(pcmaudio);
printf("\nFinished nicely.\n");
return (0);
}
/* vim:ts=4:sw=4:nowrap: */