Update of /cvsroot/audacity/lib-src/twolame/simplefrontend
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv26676/simplefrontend

Added Files:
        Makefile.am Makefile.in audio_wave.c audio_wave.h 
        simplefrontend.c 
Log Message:
Add twolame MP2 import library to lib-src

--- NEW FILE: Makefile.in ---
# Makefile.in generated by automake 1.7.9 from Makefile.am.
# @configure_input@

# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..

am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
SNDFILE_CFLAGS = @SNDFILE_CFLAGS@
SNDFILE_LIBS = @SNDFILE_LIBS@
STRIP = @STRIP@
TWOLAME_BIN = @TWOLAME_BIN@
TWOLAME_SO_VERSION = @TWOLAME_SO_VERSION@
VERSION = @VERSION@
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_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
ac_pt_PKG_CONFIG = @ac_pt_PKG_CONFIG@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@

AM_CFLAGS = -I../libtwolame/

# This is just sample code - don't install it
noinst_PROGRAMS = stwolame

stwolame_SOURCES = \
        simplefrontend.c \
        audio_wave.h \
        audio_wave.c


stwolame_LDADD = $(top_srcdir)/libtwolame/libtwolame.la
subdir = simplefrontend
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/build/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/build/config.h
CONFIG_CLEAN_FILES =
noinst_PROGRAMS = stwolame$(EXEEXT)
PROGRAMS = $(noinst_PROGRAMS)

am_stwolame_OBJECTS = simplefrontend.$(OBJEXT) audio_wave.$(OBJEXT)
stwolame_OBJECTS = $(am_stwolame_OBJECTS)
stwolame_DEPENDENCIES = $(top_srcdir)/libtwolame/libtwolame.la
stwolame_LDFLAGS =

DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)/build
depcomp = $(SHELL) $(top_srcdir)/build/depcomp
am__depfiles_maybe = depfiles
@[EMAIL PROTECTED] = ./$(DEPDIR)/audio_wave.Po \
@AMDEP_TRUE@    ./$(DEPDIR)/simplefrontend.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
        $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
DIST_SOURCES = $(stwolame_SOURCES)
DIST_COMMON = $(srcdir)/Makefile.in Makefile.am
SOURCES = $(stwolame_SOURCES)

all: all-am

.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in:  Makefile.am  $(top_srcdir)/configure.ac $(ACLOCAL_M4)
        cd $(top_srcdir) && \
          $(AUTOMAKE) --gnu  simplefrontend/Makefile
Makefile:  $(srcdir)/Makefile.in  $(top_builddir)/config.status
        cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ 
$(am__depfiles_maybe)

clean-noinstPROGRAMS:
        @list='$(noinst_PROGRAMS)'; for p in $$list; do \
          f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
          echo " rm -f $$p $$f"; \
          rm -f $$p $$f ; \
        done
stwolame$(EXEEXT): $(stwolame_OBJECTS) $(stwolame_DEPENDENCIES) 
        @rm -f stwolame$(EXEEXT)
        $(LINK) $(stwolame_LDFLAGS) $(stwolame_OBJECTS) $(stwolame_LDADD) 
$(LIBS)

mostlyclean-compile:
        -rm -f *.$(OBJEXT) core *.core

distclean-compile:
        -rm -f *.tab.c

@AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@
@AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@

.c.o:
@am__fastdepCC_TRUE@    if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@      -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
@am__fastdepCC_TRUE@    then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@    else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@    fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@       source='$<' object='$@' libtool=no 
@AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@       depfile='$(DEPDIR)/$*.Po' 
tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@   $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<

.c.obj:
@am__fastdepCC_TRUE@    if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@      -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; 
else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
@am__fastdepCC_TRUE@    then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@    else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@    fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@       source='$<' object='$@' libtool=no 
@AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@       depfile='$(DEPDIR)/$*.Po' 
tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@   $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; 
else $(CYGPATH_W) '$(srcdir)/$<'; fi`

.c.lo:
@am__fastdepCC_TRUE@    if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@      -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
@am__fastdepCC_TRUE@    then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; \
@am__fastdepCC_TRUE@    else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@    fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@       source='$<' object='$@' libtool=yes 
@AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@       depfile='$(DEPDIR)/$*.Plo' 
tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@       $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@   $(LTCOMPILE) -c -o $@ `test -f '$<' || echo 
'$(srcdir)/'`$<

mostlyclean-libtool:
        -rm -f *.lo

clean-libtool:
        -rm -rf .libs _libs

distclean-libtool:
        -rm -f libtool
uninstall-info-am:

ETAGS = etags
ETAGSFLAGS =

CTAGS = ctags
CTAGSFLAGS =

tags: TAGS

ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
        list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
        unique=`for i in $$list; do \
            if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
          done | \
          $(AWK) '    { files[$$0] = 1; } \
               END { for (i in files) print i; }'`; \
        mkid -fID $$unique

TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
                $(TAGS_FILES) $(LISP)
        tags=; \
        here=`pwd`; \
        list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
        unique=`for i in $$list; do \
            if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
          done | \
          $(AWK) '    { files[$$0] = 1; } \
               END { for (i in files) print i; }'`; \
        test -z "$(ETAGS_ARGS)$$tags$$unique" \
          || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
             $$tags $$unique

ctags: CTAGS
CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
                $(TAGS_FILES) $(LISP)
        tags=; \
        here=`pwd`; \
        list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
        unique=`for i in $$list; do \
            if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
          done | \
          $(AWK) '    { files[$$0] = 1; } \
               END { for (i in files) print i; }'`; \
        test -z "$(CTAGS_ARGS)$$tags$$unique" \
          || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
             $$tags $$unique

GTAGS:
        here=`$(am__cd) $(top_builddir) && pwd` \
          && cd $(top_srcdir) \
          && gtags -i $(GTAGS_ARGS) $$here

distclean-tags:
        -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)

top_distdir = ..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)

distdir: $(DISTFILES)
        @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
        topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
        list='$(DISTFILES)'; for file in $$list; do \
          case $$file in \
            $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
            $(top_srcdir)/*) file=`echo "$$file" | sed 
"s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
          esac; \
          if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
          dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
          if test "$$dir" != "$$file" && test "$$dir" != "."; then \
            dir="/$$dir"; \
            $(mkinstalldirs) "$(distdir)$$dir"; \
          else \
            dir=''; \
          fi; \
          if test -d $$d/$$file; then \
            if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
              cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
            fi; \
            cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
          else \
            test -f $(distdir)/$$file \
            || cp -p $$d/$$file $(distdir)/$$file \
            || exit 1; \
          fi; \
        done
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS)

installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am

install-am: all-am
        @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am

installcheck: installcheck-am
install-strip:
        $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
          install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
          `test -z '$(STRIP)' || \
            echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:

clean-generic:

distclean-generic:
        -rm -f $(CONFIG_CLEAN_FILES)

maintainer-clean-generic:
        @echo "This command is intended for maintainers to use"
        @echo "it deletes files that may require special tools to rebuild."
clean: clean-am

clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
        mostlyclean-am

distclean: distclean-am
        -rm -rf ./$(DEPDIR)
        -rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
        distclean-libtool distclean-tags

dvi: dvi-am

dvi-am:

info: info-am

info-am:

install-data-am:

install-exec-am:

install-info: install-info-am

install-man:

installcheck-am:

maintainer-clean: maintainer-clean-am
        -rm -rf ./$(DEPDIR)
        -rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic

mostlyclean: mostlyclean-am

mostlyclean-am: mostlyclean-compile mostlyclean-generic \
        mostlyclean-libtool

pdf: pdf-am

pdf-am:

ps: ps-am

ps-am:

uninstall-am: uninstall-info-am

.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
        clean-libtool clean-noinstPROGRAMS ctags distclean \
        distclean-compile distclean-generic distclean-libtool \
        distclean-tags distdir dvi dvi-am info info-am install \
        install-am install-data install-data-am install-exec \
        install-exec-am install-info install-info-am install-man \
        install-strip installcheck installcheck-am installdirs \
        maintainer-clean maintainer-clean-generic mostlyclean \
        mostlyclean-compile mostlyclean-generic mostlyclean-libtool pdf \
        pdf-am ps ps-am tags uninstall uninstall-am uninstall-info-am

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

--- NEW FILE: audio_wave.c ---
/*
 *  TwoLAME: an optimized MPEG Audio Layer Two encoder
 *
 *  Copyright (C) 2001-2004 Michael Cheng
 *  Copyright (C) 2004-2005 The TwoLAME Project
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *  
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "audio_wave.h"


/*****************************************************************************
*
*  Routines to determine byte order (of this machine) and swap bytes
*
*****************************************************************************/


enum byte_order { order_unknown, order_bigEndian, order_littleEndian };

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;
}

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];
  }
}




/*****************************************************************************
*
*  Read in specified number of samples
*
*****************************************************************************/

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




/*****************************************************************************
*
*  parse the wave header.
*  returns NULL if not open failed
*  returns a wave_info_t * if wave header successfully parsed.
*  needs to fill in : samplerate + channels
*  
*  POST: wave_info->soundfile is set to be at the start of the
*        PCM audio data 
*
*****************************************************************************/

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, "r"))==NULL) {
    fprintf(stdout,"WAV: cannot open input file: %s\n", inPath);
    return(NULL);
  }


  /**************************** WAVE *********************************/
  /*   Nick Burch <[EMAIL PROTECTED]> */
  /*********************************/
  /* 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;
    }

    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;
    }
    /* 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;
        wave_info->num_samples = -1; // UNKNOWN. But we really should be able 
to work 
                                 // it out. FIX THIS. MFC May03.
     
    // 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);
}




--- NEW FILE: audio_wave.h ---
/*
 *  TwoLAME: an optimized MPEG Audio Layer Two encoder
 *
 *  Copyright (C) 2001-2004 Michael Cheng
 *  Copyright (C) 2004-2005 The TwoLAME Project
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *  
 */


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

--- NEW FILE: Makefile.am ---

AM_CFLAGS = -I../libtwolame/

# This is just sample code - don't install it
noinst_PROGRAMS = stwolame

stwolame_SOURCES = \
        simplefrontend.c \
        audio_wave.h \
        audio_wave.c

stwolame_LDADD = $(top_srcdir)/libtwolame/libtwolame.la


--- NEW FILE: simplefrontend.c ---
/*
 *  TwoLAME: an optimized MPEG Audio Layer Two encoder
 *
 *  Copyright (C) 2001-2004 Michael Cheng
 *  Copyright (C) 2004-2005 The TwoLAME Project
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *  
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <twolame.h>

#include "audio_wave.h"


#define MP2BUFSIZE              (16384)
#define AUDIOBUFSIZE    (9216)



void usage (void) {                            
        fprintf(stdout,"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();
        

        /* Allocate some space for the PCM audio data */
        if ( (pcmaudio=(short *)calloc(AUDIOBUFSIZE, sizeof(short)))==NULL) {
                fprintf(stdout,"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(stdout,"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());


        /* Open the wave file */
        if ( (wave_info = wave_init(inputfilename)) == NULL ) {
                fprintf(stdout,"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_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 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);
    }

        /* Open the output file for the encoded MP2 data */
        if ((outfile = fopen(outputfilename, "w"))==0) {
                fprintf(stdout,"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/1152);
                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);


        twolame_close( &encodeOptions );
        free(pcmaudio);
        
        fprintf(stdout,"\nFinished nicely.\n");
        
        
        return(0);
}



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to