shithub: aacenc

Download patch

ref: 0baf5465ee9510e5555d5c11b7d6993b68247132
parent: 20994d2e42b18f770054fcfa6f2ea0301b4c99de
author: knik <knik>
date: Sat Jun 21 04:58:27 EDT 2003

improved raw input support with bigendian byteorder

--- a/frontend/input.c
+++ b/frontend/input.c
@@ -16,7 +16,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: input.c,v 1.5 2003/03/26 17:20:05 knik Exp $
+ * $Id: input.c,v 1.6 2003/06/21 08:58:27 knik Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -77,7 +77,8 @@
 }
 WAVEFORMATEX;
 
-pcmfile_t *wav_open_read(const char *name)
+pcmfile_t *wav_open_read(const char *name,
+			 int rawchans, int rawbits, int rawrate)
 {
   int i;
   int skip;
@@ -91,6 +92,7 @@
   char *datal = "data";
   int fmtsize;
   pcmfile_t *sndf;
+  int dostdin = 0;
 
   if (!strcmp(name, "-"))
   {
@@ -98,6 +100,7 @@
     setmode(fileno(stdin), O_BINARY);
 #endif
     wave_f = stdin;
+    dostdin = 1;
   }
   else if (!(wave_f = fopen(name, "rb")))
   {
@@ -105,6 +108,8 @@
     return NULL;
   }
 
+  if (rawchans < 1) // header input
+  {
   if (fread(&riff, 1, sizeof(riff), wave_f) != sizeof(riff))
     return NULL;
   if (memcmp(&(riff.label), riffl, 4))
@@ -140,14 +145,35 @@
   }
   if (UINT16(wave.wFormatTag) != WAVE_FORMAT_PCM)
     return NULL;
+  }
 
   sndf = malloc(sizeof(*sndf));
   sndf->f = wave_f;
+  if (rawchans > 0) // raw input
+  {
+    sndf->bigendian = 1;
+    sndf->channels = rawchans;
+    sndf->samplebits = rawbits;
+    sndf->samplerate = rawrate;
+    if (dostdin)
+      sndf->samples = 0;
+    else
+    {
+      fseek(sndf->f, 0 , SEEK_END);
+      sndf->samples = ftell(sndf->f) /
+	(((sndf->samplebits > 8) ? 2 : 1) * sndf->channels);
+      rewind(sndf->f);
+    }
+  }
+  else
+  {
+    sndf->bigendian = 0;
   sndf->channels = UINT16(wave.nChannels);
   sndf->samplebits = UINT16(wave.wBitsPerSample);
   sndf->samplerate = UINT32(wave.nSamplesPerSec);
   sndf->samples = riffsub.len /
     (((UINT16(wave.wBitsPerSample) > 8) ? 2 : 1) * sndf->channels);
+  }
   return sndf;
 }
 
@@ -158,9 +184,17 @@
 
   if (sndf->samplebits > 8) {
     size = fread(buf, 2, num, sndf->f);
-    for (i = 0; i < size; i++) {
-      /* change endianess for big endian (ppc, sparc) machines */
-      buf[i] = UINT16(buf[i]);
+    // fix endianness
+#ifdef WORDS_BIGENDIAN
+    if (!sndf->bigendian)
+#else
+    if (sndf->bigendian)
+#endif
+      // swap bytes
+      for (i = 0; i < size; i++)
+      {
+	int s = buf[i];
+	buf[i] = ((s & 0xff) << 8) | ((s & 0xff00) >> 8);
     }
     return size;
   }
--- a/frontend/input.h
+++ b/frontend/input.h
@@ -16,7 +16,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: input.h,v 1.1 2002/11/23 17:39:14 knik Exp $
+ * $Id: input.h,v 1.2 2003/06/21 08:58:27 knik Exp $
  */
 
 #ifndef _INPUT_H
@@ -37,9 +37,11 @@
   int samplebits;
   int samplerate;
   int samples;
+  int bigendian;
 } pcmfile_t;
 
-pcmfile_t *wav_open_read(const char *path);
+pcmfile_t *wav_open_read(const char *path,
+			 int rawchans, int rawbits, int rawrate);
 size_t wav_read_short(pcmfile_t *file, short *ptr, size_t size);
 int wav_close(pcmfile_t *file);