changeset 14335:8380694ba14f

af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
author alex
date Mon, 03 Jan 2005 18:59:16 +0000
parents 8ba01beafb7e
children 06d0050dd761
files libaf/af.c libaf/af_format.c libaf/af_format.h libaf/control.h
diffstat 4 files changed, 67 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/libaf/af.c	Mon Jan 03 18:26:48 2005 +0000
+++ b/libaf/af.c	Mon Jan 03 18:59:16 2005 +0000
@@ -270,8 +270,8 @@
 	  if(NULL == (new = af_prepend(s,af,"format")))
 	    return AF_ERROR;
 	  // Set output bits per sample
-	  if(AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_BPS,&in.bps)) || 
-	     AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_FMT,&in.format)))
+	  in.format |= af_bits2fmt(in.bps*8);
+	  if(AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_FMT,&in.format)))
 	    return rv;
 	  // Initialize format filter
 	  if(!new->prev) 
@@ -444,8 +444,8 @@
       else
 	af = s->last;
       // Init the new filter
-      if(!af ||(AF_OK != af->control(af,AF_CONTROL_FORMAT_BPS,&(s->output.bps))) 
-	 || (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT,&(s->output.format))))
+      s->output.format |= af_bits2fmt(s->output.bps*8);
+      if(!af || (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT,&(s->output.format))))
 	return -1;
       if(AF_OK != af_reinit(s,af))
 	return -1;
--- a/libaf/af_format.c	Mon Jan 03 18:26:48 2005 +0000
+++ b/libaf/af_format.c	Mon Jan 03 18:59:16 2005 +0000
@@ -110,6 +110,11 @@
     return -1;
 }
 
+inline int af_bits2fmt(int bits)
+{
+    return (bits/8 - 1) << 3;
+}
+
 /* Convert format to str input str is a buffer for the 
    converted string, size is the size of the buffer */
 char* af_fmt2str(int format, char* str, int size)
@@ -194,6 +199,53 @@
     return "??";
 }
 
+int af_str2fmt_short(char* str)
+{
+    int i;
+    static struct {
+	const char *name;
+	const int format;
+    } table[] = {
+	{ "mulaw", AF_FORMAT_MU_LAW },
+	{ "alaw", AF_FORMAT_A_LAW },
+	{ "mpeg2", AF_FORMAT_MPEG2 },
+	{ "ac3", AF_FORMAT_AC3 },
+	{ "imaadpcm", AF_FORMAT_IMA_ADPCM },
+
+	{ "u8", AF_FORMAT_U8 },
+	{ "s8", AF_FORMAT_S8 },
+	{ "u16le", AF_FORMAT_U16_LE },
+	{ "u16be", AF_FORMAT_U16_BE },
+	{ "u16ne", AF_FORMAT_U16_NE },
+	{ "s16le", AF_FORMAT_S16_LE },
+	{ "s16be", AF_FORMAT_S16_BE },
+	{ "s16ne", AF_FORMAT_S16_NE },
+	{ "u24le", AF_FORMAT_U24_LE },
+	{ "u24be", AF_FORMAT_U24_BE },
+	{ "u24ne", AF_FORMAT_U24_NE },
+	{ "s24le", AF_FORMAT_S24_LE },
+	{ "s24be", AF_FORMAT_S24_BE },
+	{ "s24ne", AF_FORMAT_S24_NE },
+	{ "u32le", AF_FORMAT_U32_LE },
+	{ "u32be", AF_FORMAT_U32_BE },
+	{ "u32ne", AF_FORMAT_U32_NE },
+	{ "s32le", AF_FORMAT_S32_LE },
+	{ "s32be", AF_FORMAT_S32_BE },
+	{ "s32ne", AF_FORMAT_S32_NE },
+	{ "floatle", AF_FORMAT_FLOAT_LE },
+	{ "floatbe", AF_FORMAT_FLOAT_BE },
+	{ "floatne", AF_FORMAT_FLOAT_NE },
+	
+	{ NULL, 0 }
+    };
+    
+    for (i = 0; table[i].name; i++)
+	if (!strcasecmp(str, table[i].name))
+	    return table[i].format;
+
+    return -1;
+}
+
 // Helper functions to check sanity for input arguments
 
 // Sanity check for bytes per sample
@@ -212,6 +264,7 @@
 {
   char buf[256];
   switch(format & AF_FORMAT_SPECIAL_MASK){
+  case(AF_FORMAT_IMA_ADPCM): 
   case(AF_FORMAT_MPEG2): 
   case(AF_FORMAT_AC3):
     af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n",
@@ -279,52 +332,22 @@
     return AF_OK;
   }
   case AF_CONTROL_COMMAND_LINE:{
-    int bps = 2;
-    int format = AF_FORMAT_NE;
-    char str[256];
-    str[0] = '\0';
-    sscanf((char*)arg,"%i:%s",&bps,str);
-    // Convert string to format
-    format = af_str2fmt(str);
-    
-    // Automatic correction of errors
-    switch(format & AF_FORMAT_SPECIAL_MASK){
-    case(AF_FORMAT_A_LAW):
-    case(AF_FORMAT_MU_LAW): 
-      bps=1; break;
-    case(AF_FORMAT_AC3):
-      bps=4; break; // I think
-    }
-    if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
-      bps=4;
-
-    // set appropriate AF_FORMAT_BITS
-    format |= (bps-1)<<3; // hack
-    
-    if((AF_OK != af->control(af,AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET,&bps)) ||
-       (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)))
+    int format = af_str2fmt_short(arg);
+    if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format))
       return AF_ERROR;
     return AF_OK;
   }
-  case AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET:
-    // Reinit must be called after this function has been called
-    
-    // Check for errors in configuraton
-    if(AF_OK != check_bps(*(int*)arg))
-      return AF_ERROR;
-
-    af->data->bps = *(int*)arg;
-    return AF_OK;
-  case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:
-    // Reinit must be called after this function has been called
-
+  case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{
     // Check for errors in configuraton
     if(AF_OK != check_format(*(int*)arg))
       return AF_ERROR;
 
     af->data->format = *(int*)arg;
+    af->data->bps = af_fmt2bits(af->data->format)/8;
+
     return AF_OK;
   }
+  }
   return AF_UNKNOWN;
 }
 
--- a/libaf/af_format.h	Mon Jan 03 18:26:48 2005 +0000
+++ b/libaf/af_format.h	Mon Jan 03 18:59:16 2005 +0000
@@ -81,7 +81,9 @@
 #endif
 
 extern int af_str2fmt(char *str);
+extern int af_str2fmt_short(char *str);
 extern int af_fmt2bits(int format);
+extern int af_bits2fmt(int bits);
 extern char* af_fmt2str(int format, char* str, int size);
 extern char* af_fmt2str_short(int format);
 
--- a/libaf/control.h	Mon Jan 03 18:26:48 2005 +0000
+++ b/libaf/control.h	Mon Jan 03 18:59:16 2005 +0000
@@ -113,13 +113,9 @@
 // Set resampling accuracy
 #define AF_CONTROL_RESAMPLE_ACCURACY	0x00000300 | AF_CONTROL_FILTER_SPECIFIC
 
-// Format 
+// Format
 
-// Set output format bits per sample
-#define AF_CONTROL_FORMAT_BPS		0x00000400 | AF_CONTROL_FILTER_SPECIFIC
-
-// Set output format sample format
-#define AF_CONTROL_FORMAT_FMT		0x00000500 | AF_CONTROL_FILTER_SPECIFIC
+#define AF_CONTROL_FORMAT_FMT		0x00000400 | AF_CONTROL_FILTER_SPECIFIC
 
 // Channels