[cvs-annodex] commit (libfishsound): trunk/src/libfishsound/convert.h trunk/src/libfishsound/speex.c

conrad nobody at lists.annodex.net
Fri Jul 16 13:56:51 EST 2004


Update of /annodex/libfishsound (new revision 128)

Modified files:
   trunk/src/libfishsound/convert.h
   trunk/src/libfishsound/speex.c

Log Message:
always decode using _int for speex 1.1, even to float or double.
This bypasses speex's own int->float conversion, so that we can
both convert and normalize to (-1.0,+1.0) at the same time.


Modified: trunk/src/libfishsound/convert.h
===================================================================
--- trunk/src/libfishsound/convert.h	2004-07-16 02:34:49 UTC (rev 127)
+++ trunk/src/libfishsound/convert.h	2004-07-16 03:56:50 UTC (rev 128)
@@ -66,6 +66,38 @@
 }
 
 static inline void
+_fs_deinterleave_s_f (short ** src, float * dest[], long frames, int channels,
+		      float mult)
+{
+  int i, j;
+  short * s = (short *)src;
+  float * d;
+
+  for (i = 0; i < frames; i++) {
+    for (j = 0; j < channels; j++) {
+      d = dest[j];
+      d[i] = ((float) s[i*channels + j]) * mult;
+    }
+  }
+}
+
+static inline void
+_fs_deinterleave_s_d (short ** src, double * dest[], long frames, int channels,
+		      double mult)
+{
+  int i, j;
+  short * s = (short *)src;
+  double * d;
+
+  for (i = 0; i < frames; i++) {
+    for (j = 0; j < channels; j++) {
+      d = dest[j];
+      d[i] = ((double) s[i*channels + j]) * mult;
+    }
+  }
+}
+
+static inline void
 _fs_deinterleave_f_s (float ** src, short * dest[],
 		      long frames, int channels, float mult)
 {
@@ -154,6 +186,26 @@
 }
 
 static inline void
+_fs_convert_s_f (short * src, float * dest, long samples, float mult)
+{
+  int i;
+
+  for (i = 0; i < samples; i++) {
+    dest[i] = ((float)src[i]) * mult;
+  }
+}
+
+static inline void
+_fs_convert_s_d (short * src, double * dest, long samples, double mult)
+{
+  int i;
+
+  for (i = 0; i < samples; i++) {
+    dest[i] = ((double)src[i]) * mult;
+  }
+}
+
+static inline void
 _fs_convert_f_s (float * src, short * dest, long samples)
 {
   int i;

Modified: trunk/src/libfishsound/speex.c
===================================================================
--- trunk/src/libfishsound/speex.c	2004-07-16 02:34:49 UTC (rev 127)
+++ trunk/src/libfishsound/speex.c	2004-07-16 03:56:50 UTC (rev 128)
@@ -296,6 +296,42 @@
   }
 }
 
+#if FS_FLOAT
+static inline void
+fs_speex_float_dispatch (FishSound * fsound)
+{
+  FishSoundSpeexInfo * fss = (FishSoundSpeexInfo *)fsound->codec_data;
+  FishSoundDecoded_FloatIlv df;
+  FishSoundDecoded_Float dfi;
+
+  if (fsound->interleave) {
+    dfi = (FishSoundDecoded_FloatIlv)fsound->callback.decoded_float_ilv;
+    dfi (fsound, (float **)fss->ipcm_out.f, fss->frame_size,
+	 fsound->user_data);
+  } else {
+    df = (FishSoundDecoded_Float)fsound->callback.decoded_float;
+    df (fsound, fss->pcm.f, fss->frame_size, fsound->user_data);
+  }
+}
+
+static inline void
+fs_speex_double_dispatch (FishSound * fsound)
+{
+  FishSoundSpeexInfo * fss = (FishSoundSpeexInfo *)fsound->codec_data;
+  FishSoundDecoded_DoubleIlv dd;
+  FishSoundDecoded_Double ddi;
+
+  if (fsound->interleave) {
+    ddi = (FishSoundDecoded_DoubleIlv)fsound->callback.decoded_double_ilv;
+    ddi (fsound, (double **)fss->ipcm_out.f, fss->frame_size,
+	 fsound->user_data);
+  } else {
+    dd = (FishSoundDecoded_Double)fsound->callback.decoded_double;
+    dd (fsound, fss->pcm.d, fss->frame_size, fsound->user_data);
+  }
+}
+#endif
+
 #if HAVE_SPEEX_1_1
 static long
 fs_speex_decode_short (FishSound * fsound)
@@ -321,6 +357,18 @@
 		       fss->frame_size * fsound->info.channels);
       fs_speex_int_dispatch (fsound);
       break;
+#if FS_FLOAT
+    case FISH_SOUND_PCM_FLOAT:
+      _fs_convert_s_f (fss->ipcm.s, fss->ipcm_out.f,
+		       fss->frame_size * fsound->info.channels, (1/32767.0));
+      fs_speex_float_dispatch (fsound);
+      break;
+    case FISH_SOUND_PCM_DOUBLE:
+      _fs_convert_s_d (fss->ipcm.s, fss->ipcm_out.d,
+		       fss->frame_size * fsound->info.channels, (1/32767.0));
+      fs_speex_double_dispatch (fsound);
+      break;
+#endif
     default:
       /* notreached */
       break;
@@ -355,6 +403,18 @@
 			    fss->frame_size, 2);
       fs_speex_int_dispatch (fsound);
       break;
+#if FS_FLOAT
+    case FISH_SOUND_PCM_FLOAT:
+      _fs_deinterleave_s_f ((short **)fss->ipcm.s, fss->pcm.f,
+			    fss->frame_size, 2, (1/32767.0));
+      fs_speex_float_dispatch (fsound);
+      break;
+    case FISH_SOUND_PCM_DOUBLE:
+      _fs_deinterleave_s_d ((short **)fss->ipcm.s, fss->pcm.d,
+			    fss->frame_size, 2, (1/32767.0));
+      fs_speex_double_dispatch (fsound);
+      break;
+#endif
     default:
       /* notreached */
       break;
@@ -365,41 +425,7 @@
 }
 #endif /* HAVE_SPEEX_1_1 */
 
-#if FS_FLOAT
-static inline void
-fs_speex_float_dispatch (FishSound * fsound)
-{
-  FishSoundSpeexInfo * fss = (FishSoundSpeexInfo *)fsound->codec_data;
-  FishSoundDecoded_FloatIlv df;
-  FishSoundDecoded_Float dfi;
-
-  if (fsound->interleave) {
-    dfi = (FishSoundDecoded_FloatIlv)fsound->callback.decoded_float_ilv;
-    dfi (fsound, (float **)fss->ipcm_out.f, fss->frame_size,
-	 fsound->user_data);
-  } else {
-    df = (FishSoundDecoded_Float)fsound->callback.decoded_float;
-    df (fsound, fss->pcm.f, fss->frame_size, fsound->user_data);
-  }
-}
-
-static inline void
-fs_speex_double_dispatch (FishSound * fsound)
-{
-  FishSoundSpeexInfo * fss = (FishSoundSpeexInfo *)fsound->codec_data;
-  FishSoundDecoded_DoubleIlv dd;
-  FishSoundDecoded_Double ddi;
-
-  if (fsound->interleave) {
-    ddi = (FishSoundDecoded_DoubleIlv)fsound->callback.decoded_double_ilv;
-    ddi (fsound, (double **)fss->ipcm_out.f, fss->frame_size,
-	 fsound->user_data);
-  } else {
-    dd = (FishSoundDecoded_Double)fsound->callback.decoded_double;
-    dd (fsound, fss->pcm.d, fss->frame_size, fsound->user_data);
-  }
-}
-
+#if (FS_FLOAT && !HAVE_SPEEX_1_1)
 static long
 fs_speex_decode_float (FishSound * fsound)
 {
@@ -497,8 +523,7 @@
   size_t pcm_size, pcm_out_size = 0, ilv_len;
   short * tmp;
 
-  if (HAVE_SPEEX_1_1 && (pcm_type == FISH_SOUND_PCM_SHORT ||
-			 pcm_type == FISH_SOUND_PCM_INT)) {
+  if (HAVE_SPEEX_1_1) {
     pcm_size = sizeof (short);
   } else {
     pcm_size = sizeof (float);
@@ -536,7 +561,7 @@
 
       /* set a shortcut pointer */
       fss->ipcm_out.s = fss->ipcm.s;
-    } else if (pcm_type == FISH_SOUND_PCM_FLOAT) {
+    } else if (!HAVE_SPEEX_1_1 && pcm_type == FISH_SOUND_PCM_FLOAT) {
       /* if ipcm_out was previously malloc'd, free it */
       if (fss->ipcm_out.s) fs_free (fss->ipcm_out.s);
 
@@ -631,22 +656,17 @@
     speex_bits_read_from (&fss->bits, (char *)buf, (int)bytes);
 
 #if HAVE_SPEEX_1_1
-    if (fsound->pcm_type == FISH_SOUND_PCM_SHORT ||
-	fsound->pcm_type == FISH_SOUND_PCM_INT) {
-      if (fsound->info.channels == 2 && !fsound->interleave) {
-	fs_speex_decode_short_dlv (fsound);
-      } else {
-	fs_speex_decode_short (fsound);
-      }
-    } else /* fall through to float decode */
-#endif
-
-#if FS_FLOAT      
-      if (fsound->info.channels == 2 && !fsound->interleave) {
-	fs_speex_decode_float_dlv (fsound);
-      } else {
-	fs_speex_decode_float (fsound);
-      }
+    if (fsound->info.channels == 2 && !fsound->interleave) {
+      fs_speex_decode_short_dlv (fsound);
+    } else {
+      fs_speex_decode_short (fsound);
+    }
+#elif FS_FLOAT      
+    if (fsound->info.channels == 2 && !fsound->interleave) {
+      fs_speex_decode_float_dlv (fsound);
+    } else {
+      fs_speex_decode_float (fsound);
+    }
 #else
     return FISH_SOUND_ERR_DISABLED; /* notreached */
 #endif


-- 
conrad



More information about the cvs-annodex mailing list