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

conrad at svn.annodex.net conrad at svn.annodex.net
Fri Jan 11 04:28:57 PST 2008


Author: conrad
Date: 2008-01-11 04:28:56 -0800 (Fri, 11 Jan 2008)
New Revision: 3333

Modified:
   libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c
Log:
miscellaneous FLAC fixes:
 * implement fs_flac_flush()
 * fix nr. (other) header packets field in encoded Ogg FLAC header
 * re-order flac.c functions to match ordering of vorbis.c, speex.c


Modified: libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c
===================================================================
--- libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c	2008-01-10 11:10:09 UTC (rev 3332)
+++ libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c	2008-01-11 12:28:56 UTC (rev 3333)
@@ -67,6 +67,33 @@
   void* pcm;
 } FishSoundFlacInfo;
 
+int
+fish_sound_flac_identify (unsigned char * buf, long bytes)
+{
+  if (bytes < 8) return FISH_SOUND_UNKNOWN;
+  if (buf[0] != 0x7f) return FISH_SOUND_UNKNOWN;
+  if (!strncmp ((char *)buf+1, "FLAC", 4)) {
+#ifdef DEBUG
+    printf("fish_sound_flac_identify: flac found\n");
+#endif
+    /* if only a short buffer was passed, do a weak identify */
+    if (bytes == 8) return FISH_SOUND_FLAC;
+
+    /* otherwise, look for the fLaC header preceding STREAMINFO */
+    if (!strncmp ((char *)buf+9, "fLaC", 4)) {
+      return FISH_SOUND_FLAC;
+    }
+  }
+
+  return FISH_SOUND_UNKNOWN;
+}
+
+static int
+fs_flac_command (FishSound * fsound, int command, void * data, int datasize)
+{
+  return 0;
+}
+
 #ifdef FS_DECODE
 static FLAC__StreamDecoderReadStatus
 fs_flac_read_callback(const FLAC__StreamDecoder *decoder,
@@ -89,6 +116,7 @@
 #endif
     return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
   }
+
   memcpy(buffer, fi->buffer, fi->bufferlength);
   *bytes = fi->bufferlength;
   fi->bufferlength = 0;
@@ -155,6 +183,11 @@
 #endif
   switch (metadata->type) {
   case FLAC__METADATA_TYPE_STREAMINFO:
+#ifdef DEBUG
+    printf("fs_flac_meta_callback: channels %d, samplerate %d\n",
+           metadata->data.stream_info.channels,
+           metadata->data.stream_info.sample_rate);
+#endif
     fsound->info.channels = metadata->data.stream_info.channels;
     fsound->info.samplerate = metadata->data.stream_info.sample_rate;
     break;
@@ -211,8 +244,8 @@
 	fi->buffer[4] = 0x43; /* 'C' */
 	fi->buffer[5] = 1;    /* Version major generated by this file */
 	fi->buffer[6] = 0;    /* Version minor generated by this file */
-	fi->buffer[7] = 0;    /* MSB(be): Nr. non-audio header packets */
-	fi->buffer[8] = 2;    /* LSB(be): Nr. non-audio header packets */
+	fi->buffer[7] = 0;    /* MSB(be): Nr. other non-audio header packets */
+	fi->buffer[8] = 1;    /* LSB(be): Nr. other non-audio header packets */
 	memcpy (fi->buffer+9, buffer, bytes); /* fLaC header ++ STREAMINFO */
         fi->bufferlength = bytes+9;
 	fi->header++;
@@ -248,13 +281,14 @@
   /* FishSound* fsound = (FishSound*)client_data; */
   /* FishSoundFlacInfo* fi = (FishSoundFlacInfo *)fsound->codec_data; */
 #ifdef DEBUG
-  printf("fs_flac_meta_callback: IN\n");
+  printf("fs_flac_enc_meta_callback: IN\n");
 #endif
   switch (metadata->type) {
   case FLAC__METADATA_TYPE_STREAMINFO:
 #ifdef DEBUG
-    printf("fs_flac_meta_callback: channels %d\n",
-           metadata->data.stream_info.channels);
+    printf("fs_flac_enc_meta_callback: channels %d, samplerate %d\n",
+           metadata->data.stream_info.channels,
+           metadata->data.stream_info.sample_rate);
 #endif
     /*
     fsound->info.channels = metadata->data.stream_info.channels;
@@ -270,33 +304,8 @@
 }
 #endif
 
-int
-fish_sound_flac_identify (unsigned char * buf, long bytes)
-{
-  if (bytes < 8) return FISH_SOUND_UNKNOWN;
-  if (buf[0] != 0x7f) return FISH_SOUND_UNKNOWN;
-  if (!strncmp ((char *)buf+1, "FLAC", 4)) {
-#ifdef DEBUG
-    printf("fish_sound_flac_identify: flac found\n");
-#endif
-    /* if only a short buffer was passed, do a weak identify */
-    if (bytes == 8) return FISH_SOUND_FLAC;
 
-    /* otherwise, look for the fLaC header preceding STREAMINFO */
-    if (!strncmp ((char *)buf+9, "fLaC", 4)) {
-      return FISH_SOUND_FLAC;
-    }
-  }
 
-  return FISH_SOUND_UNKNOWN;
-}
-
-static int
-fs_flac_command (FishSound * fsound, int command, void * data, int datasize)
-{
-  return 0;
-}
-
 #if FS_ENCODE
 static FishSound *
 fs_flac_enc_headers (FishSound * fsound)
@@ -340,7 +349,7 @@
   int i;
   long length = frames * fsound->info.channels;
 #ifdef DEBUG
-  printf("fs_flac_encode_f_ilv: IN\n");
+  printf("fs_flac_encode_f_ilv: IN, frames = %ld\n", frames);
 #endif
   fi->pcm = realloc(fi->pcm, sizeof(FLAC__int32)*fsound->info.channels*frames);
   buffer = (FLAC__int32*) fi->pcm;
@@ -414,6 +423,11 @@
   }
   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
@@ -500,6 +514,19 @@
 static long
 fs_flac_flush (FishSound * fsound)
 {
+  FishSoundFlacInfo * fi = (FishSoundFlacInfo *)fsound->codec_data;
+
+#ifdef DEBUG
+  printf("fs_flac_flush: IN (%s)\n",
+         fsound->mode == FISH_SOUND_DECODE ? "decode" : "encode");
+#endif
+
+  if (fsound->mode == FISH_SOUND_DECODE) {
+    FLAC__stream_decoder_finish(fi->fsd);
+  } else if (fsound->mode == FISH_SOUND_ENCODE) {
+    FLAC__stream_encoder_finish(fi->fse);
+  }
+
   return 0;
 }
 



More information about the commits mailing list