[xiph-commits] r3334 - libfishsound/branches/1.0-stable-flac/src/libfishsound

conrad at svn.annodex.net conrad at svn.annodex.net
Fri Jan 11 04:37:24 PST 2008


Author: conrad
Date: 2008-01-11 04:37:24 -0800 (Fri, 11 Jan 2008)
New Revision: 3334

Modified:
   libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c
Log:
remove dead code in flac.c, cleanup


Modified: libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c
===================================================================
--- libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c	2008-01-11 12:28:56 UTC (rev 3333)
+++ libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c	2008-01-11 12:37:24 UTC (rev 3334)
@@ -94,7 +94,7 @@
   return 0;
 }
 
-#ifdef FS_DECODE
+#if FS_DECODE
 static FLAC__StreamDecoderReadStatus
 fs_flac_read_callback(const FLAC__StreamDecoder *decoder,
                       FLAC__byte buffer[], unsigned *bytes,
@@ -137,7 +137,6 @@
 #endif
   fsound->frameno += frame->header.blocksize*frame->header.channels;
   if (fsound->callback.decoded_float) {
-    /*float norm = 1.0 / (1 + (1 << (frame->header.bits_per_sample - 1)));*/
     float norm = 1.0 / ((1 << (frame->header.bits_per_sample - 1)));
 
     if (fsound->interleave) {
@@ -210,8 +209,99 @@
   fprintf(stderr, "FLAC ERROR: %s\n", FLAC__StreamDecoderErrorStatusString[status]);
 }
 #endif
+#if FS_DECODE
+static void*
+fs_flac_decode_header (FishSound * fsound, unsigned char *buf, long bytes)
+{
+  FishSoundFlacInfo *fi = fsound->codec_data;
+  if (buf[0] != 0x7f) return NULL;
+  if (strncmp((char *)buf+1, "FLAC", 4) != 0) return NULL;
+  fi->version.major = buf[5];
+  fi->version.minor = buf[6];
+#ifdef DEBUG
+  printf("fs_flac_decode_header : Flac Ogg Mapping Version: %d.%d\n",
+         fi->version.major, fi->version.minor);
+#endif
+  fi->header_packets = buf[7] << 8 | buf[8];
+#ifdef DEBUG
+  printf("fs_flac_decode_header: Number of Header packets: %d\n",
+         fi->header_packets);
+#endif
 
-#ifdef FS_ENCODE
+  if ((fi->fsd = FLAC__stream_decoder_new()) == NULL) {
+#ifdef DEBUG
+    printf ("fs_flac_decode_header: unable to create new stream_decoder\n");
+#endif
+    return NULL;
+  }
+
+  FLAC__stream_decoder_set_read_callback(fi->fsd, fs_flac_read_callback);
+  FLAC__stream_decoder_set_write_callback(fi->fsd, fs_flac_write_callback);
+  FLAC__stream_decoder_set_metadata_callback(fi->fsd, fs_flac_meta_callback);
+  FLAC__stream_decoder_set_error_callback(fi->fsd, fs_flac_error_callback);
+  FLAC__stream_decoder_set_client_data(fi->fsd, fsound);
+
+  if (FLAC__stream_decoder_init(fi->fsd) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
+    return NULL;
+
+  return fi->fsd;
+}
+
+static long
+fs_flac_decode (FishSound * fsound, unsigned char * buf, long bytes)
+{
+  FishSoundFlacInfo *fi = fsound->codec_data;
+#ifdef DEBUG
+  printf("fs_flac_decode: IN, fi->packetno = %d\n", fi->packetno);
+#endif
+  if (fi->packetno == 0) {
+    if (fs_flac_decode_header (fsound, buf, bytes) == NULL) {
+#ifdef DEBUG
+      printf("fs_flac_decode: Error reading header\n");
+#endif
+      return -1;
+    }
+    fi->buffer = fs_malloc(sizeof(unsigned char)*bytes);
+    memcpy(fi->buffer, buf+9, bytes-9);
+    fi->bufferlength = bytes-9;
+  }
+  else if (fi->packetno <= fi->header_packets){
+    unsigned char* tmp = fs_malloc(sizeof(unsigned char)*(fi->bufferlength+bytes));
+#ifdef DEBUG
+    printf("fs_flac_decode: handling header (fi->header_packets = %d)\n",
+           fi->header_packets);
+#endif
+
+#if 0
+    if (fi->packetno ==  1) fish_sound_comments_decode (fsound, buf, bytes);
+#endif
+
+    memcpy(tmp, fi->buffer, fi->bufferlength);
+    memcpy(tmp+fi->bufferlength, buf, bytes);
+    fi->bufferlength += bytes;
+    fs_free(fi->buffer);
+    fi->buffer = tmp;
+    if (fi->packetno == fi->header_packets) {
+      FLAC__stream_decoder_process_until_end_of_metadata(fi->fsd);
+      fs_free(fi->buffer);
+    }
+  } else {
+    fi->buffer = buf;
+    fi->bufferlength = bytes;
+    FLAC__stream_decoder_process_single(fi->fsd);
+  }
+  fi->packetno++;
+
+  return 0;
+}
+#else /* !FS_DECODE */
+
+#define fs_flac_decode NULL
+
+#endif
+
+
+#if FS_ENCODE
 static FLAC__StreamEncoderWriteStatus
 fs_flac_enc_write_callback(const FLAC__StreamEncoder *encoder,
                            const FLAC__byte buffer[], unsigned bytes,
@@ -302,11 +392,7 @@
     break;
   }
 }
-#endif
 
-
-
-#if FS_ENCODE
 static FishSound *
 fs_flac_enc_headers (FishSound * fsound)
 {
@@ -318,29 +404,13 @@
   FLAC__stream_encoder_set_write_callback(fi->fse, fs_flac_enc_write_callback);
   FLAC__stream_encoder_set_metadata_callback(fi->fse, fs_flac_enc_meta_callback);
   FLAC__stream_encoder_set_client_data(fi->fse, fsound);
-  /* FLAC__stream_encoder_set_total_samples_estimate(fi->fse, );*/
-  if (FLAC__stream_encoder_init(fi->fse) != FLAC__STREAM_ENCODER_OK) return NULL;
+  /* FLAC__stream_encoder_set_total_samples_estimate(fi->fse, ...);*/
+  if (FLAC__stream_encoder_init(fi->fse) != FLAC__STREAM_ENCODER_OK)
+    return NULL;
   return fsound;
 }
 
-#if 0
 static long
-fs_flac_encode_i_ilv (FishSound * fsound, int ** pcm, long frames)
-{
-  FishSoundFlacInfo *fi = fsound->codec_data;
-  int i, *p = (int *)pcm;
-#ifdef DEBUG
-  printf("fs_flac_encode_i_ilv: frames: %ld\n", frames);
-#endif
-  if (fi->packetno == 0)
-    fs_flac_enc_headers (fsound);
-  /* FLAC__stream_encoder_process_interleaved(fi->fse, pcm, frames); */
-  fi->packetno++;
-  return frames;
-}
-#endif
-
-static long
 fs_flac_encode_f_ilv (FishSound * fsound, float ** pcm, long frames)
 {
   FishSoundFlacInfo *fi = fsound->codec_data;
@@ -363,115 +433,14 @@
 
   return frames;
 }
-#endif
+#else /* ! FS_ENCODE */
 
-#if FS_DECODE
-static void*
-fs_flac_decode_header (FishSound * fsound, unsigned char *buf, long bytes)
-{
-  FishSoundFlacInfo *fi = fsound->codec_data;
-  if (buf[0] != 0x7f) return NULL;
-  if (strncmp((char *)buf+1, "FLAC", 4) != 0) return NULL;
-  fi->version.major = buf[5];
-  fi->version.minor = buf[6];
-#ifdef DEBUG
-  printf("fs_flac_decode_header : Flac Ogg Mapping Version: %d.%d\n",
-         fi->version.major, fi->version.minor);
-#endif
-  fi->header_packets = buf[7] << 8 | buf[8];
-#ifdef DEBUG
-  printf("fs_flac_decode_header: Number of Header packets: %d\n",
-         fi->header_packets);
-#endif
+#define fs_flac_encode_f NULL
+#define fs_flac_encode_f_ilv NULL
 
-  if ((fi->fsd = FLAC__stream_decoder_new()) == NULL) {
-#ifdef DEBUG
-    printf ("fs_flac_decode_header: unable to create new stream_decoder\n");
-#endif
-    return NULL;
-  }
+#endif /* ! FS_ENCODE */
 
-  FLAC__stream_decoder_set_read_callback(fi->fsd, fs_flac_read_callback);
-  FLAC__stream_decoder_set_write_callback(fi->fsd, fs_flac_write_callback);
-  FLAC__stream_decoder_set_metadata_callback(fi->fsd, fs_flac_meta_callback);
-  FLAC__stream_decoder_set_error_callback(fi->fsd, fs_flac_error_callback);
-  FLAC__stream_decoder_set_client_data(fi->fsd, fsound);
 
-  if (FLAC__stream_decoder_init(fi->fsd) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
-    return NULL;
-
-  return fi->fsd;
-}
-
-static long
-fs_flac_decode (FishSound * fsound, unsigned char * buf, long bytes)
-{
-  FishSoundFlacInfo *fi = fsound->codec_data;
-#ifdef DEBUG
-  printf("fs_flac_decode: IN, fi->packetno = %d\n", fi->packetno);
-#endif
-  if (fi->packetno == 0) {
-    if (fs_flac_decode_header (fsound, buf, bytes) == NULL) {
-#ifdef DEBUG
-      printf("fs_flac_decode: Error reading header\n");
-#endif
-      return -1;
-    }
-    fi->buffer = fs_malloc(sizeof(unsigned char)*bytes);
-    memcpy(fi->buffer, buf+9, bytes-9);
-    fi->bufferlength = bytes-9;
-  }
-  else if (fi->packetno <= fi->header_packets){
-    unsigned char* tmp = fs_malloc(sizeof(unsigned char)*(fi->bufferlength+bytes));
-#ifdef DEBUG
-  printf("fs_flac_decode: handling header (fi->header_packets = %d)\n",
-          fi->header_packets);
-#endif
-
-#if 0
-   if (fi->packetno ==  1) fish_sound_comments_decode (fsound, buf, bytes);
-#endif
-    memcpy(tmp, fi->buffer, fi->bufferlength);
-    memcpy(tmp+fi->bufferlength, buf, bytes);
-    fi->bufferlength += bytes;
-    fs_free(fi->buffer);
-    fi->buffer = tmp;
-    if (fi->packetno == fi->header_packets) {
-      FLAC__stream_decoder_process_until_end_of_metadata(fi->fsd);
-      fs_free(fi->buffer);
-    }
-#if 0
-  if (fi->packetno == 0) {
-    if (process_header(fi, buf, bytes) == NULL) printf("EROROROROR\n");
-    buf[13] |= 0x80;
-    fi->buffer = buf+9;
-    fi->bufferlength = bytes-9;
-    FLAC__stream_decoder_process_until_end_of_metadata(fi->fsd);
-#if 0
-  } else if (fi->packetno == 1) {
-    fish_sound_comments_decode (fsound, buf, bytes);
-#endif
-  } else if (fi->packetno <= fi->header_packets) {
-    buf[0] |= 0x80;
-    fi->buffer = buf;
-    fi->bufferlength = bytes;
-    FLAC__stream_decoder_process_until_end_of_metadata(fi->fsd);
-#endif
-  } else {
-    fi->buffer = buf;
-    fi->bufferlength = bytes;
-    FLAC__stream_decoder_process_single(fi->fsd);
-  }
-  fi->packetno++;
-
-  return 0;
-}
-#else /* !FS_DECODE */
-
-#define fs_flac_decode NULL
-
-#endif
-
 static FishSound *
 fs_flac_delete (FishSound * fsound)
 {
@@ -546,14 +515,6 @@
 
   fsound->codec_data = fi;
 
-#if FS_ENCODE
-  /*
-  if (fsound->mode == FISH_SOUND_ENCODE) {
-    fs_flac_enc_init (fsound);
-  }
-  */
-#endif /* FS_ENCODE */
-
   return fsound;
 }
 



More information about the commits mailing list