[xiph-commits] r11323 - trunk/xiph-qt/CASpeex/src

arek at svn.xiph.org arek at svn.xiph.org
Sun Apr 30 15:09:39 PDT 2006


Author: arek
Date: 2006-04-30 15:09:34 -0700 (Sun, 30 Apr 2006)
New Revision: 11323

Modified:
   trunk/xiph-qt/CASpeex/src/CAOggSpeexDecoder.cpp
   trunk/xiph-qt/CASpeex/src/CASpeexDecoder.cpp
Log:
Fixed a packet-frame-counting bug. Added some small improvements (hopefully).

Modified: trunk/xiph-qt/CASpeex/src/CAOggSpeexDecoder.cpp
===================================================================
--- trunk/xiph-qt/CASpeex/src/CAOggSpeexDecoder.cpp	2006-04-30 15:19:38 UTC (rev 11322)
+++ trunk/xiph-qt/CASpeex/src/CAOggSpeexDecoder.cpp	2006-04-30 22:09:34 UTC (rev 11323)
@@ -102,13 +102,18 @@
 UInt32 CAOggSpeexDecoder::ProduceOutputPackets(void* outOutputData, UInt32& ioOutputDataByteSize, UInt32& ioNumberPackets,
                                                AudioStreamPacketDescription* outPacketDescription)
 {
+    dbg_printf(" >> [%08lx] CAOggSpeexDecoder :: ProduceOutputPackets(%ld [%ld])\n", (UInt32) this, ioNumberPackets, ioOutputDataByteSize);
+    UInt32 ret = kAudioCodecProduceOutputPacketSuccess;
+
     if (mFramesBufferedList.empty()) {
         ioOutputDataByteSize = 0;
         ioNumberPackets = 0;
-        return kAudioCodecProduceOutputPacketNeedsMoreInputData;
+        ret = kAudioCodecProduceOutputPacketNeedsMoreInputData;
+        dbg_printf("<!E [%08lx] CAOggSpeexDecoder :: ProduceOutputPackets(%ld [%ld]) = %ld [%ld]\n", (UInt32) this,
+                   ioNumberPackets, ioOutputDataByteSize, ret, FramesReady());
+        return ret;
     }
 
-    UInt32 ret = kAudioCodecProduceOutputPacketSuccess;
     UInt32 speex_packets = mFramesBufferedList.front();
     UInt32 ogg_packets = 0;
     UInt32 speex_returned_data = ioOutputDataByteSize;
@@ -150,6 +155,9 @@
             ioNumberPackets = ogg_packets;
         }
     }
+
+    dbg_printf("<.. [%08lx] CAOggSpeexDecoder :: ProduceOutputPackets(%ld [%ld]) = %ld [%ld]\n",
+               (UInt32) this, ioNumberPackets, ioOutputDataByteSize, ret, FramesReady());
     return ret;
 }
 
@@ -182,6 +190,7 @@
 
 void CAOggSpeexDecoder::InPacket(const void* inInputData, const AudioStreamPacketDescription* inPacketDescription)
 {
+    dbg_printf(" >> [%08lx] CAOggSpeexDecoder :: InPacket({%ld, %ld})\n", (UInt32) this, inPacketDescription->mDataByteSize, inPacketDescription->mVariableFramesInPacket);
     if (!mCompressionInitialized)
         CODEC_THROW(kAudioCodecUnspecifiedError);
 
@@ -197,6 +206,9 @@
     UInt32 page_packets = ogg_page_packets(&op);
     SInt32 packet_length_adjust = 0;
 
+    dbg_printf("  > [%08lx] CAOggSpeexDecoder :: InPacket(): no: %ld, fs: %ld, fpp: %ld, np: %ld\n",
+               (UInt32) this, ogg_page_pageno(&op), mSpeexHeader.frame_size, mSpeexHeader.frames_per_packet, page_packets);
+
     if (mSpeexHeader.frame_size != 0 && mSpeexHeader.frames_per_packet != 0) {
         if (mSpeexHeader.frame_size * mSpeexHeader.frames_per_packet * page_packets != inPacketDescription->mVariableFramesInPacket) {
             packet_length_adjust = mSpeexHeader.frame_size * mSpeexHeader.frames_per_packet * page_packets - inPacketDescription->mVariableFramesInPacket;
@@ -207,6 +219,8 @@
                 }
                 packet_length_adjust = -packet_length_adjust;
             }
+            dbg_printf("  > [%08lx] CAOggSpeexDecoder :: InPacket(): p_l_adjust: %ld\n",
+                       (UInt32) this, packet_length_adjust);
         }
     }
 
@@ -222,7 +236,7 @@
         packet_count++;
 
         speex_packet_desc.mDataByteSize = opk.bytes;
-        speex_packet_desc.mVariableFramesInPacket = mSpeexHeader.frame_size;
+        speex_packet_desc.mVariableFramesInPacket = mSpeexHeader.frame_size * mSpeexHeader.frames_per_packet;
         if (packet_count == 1 && packet_length_adjust > 0) {
             speex_packet_desc.mVariableFramesInPacket -= packet_length_adjust;
             packet_length_adjust = 0;
@@ -234,6 +248,8 @@
     }
 
     mFramesBufferedList.push_back(packet_count);
+
+    dbg_printf("<.. [%08lx] CAOggSpeexDecoder :: InPacket(): packet_count: %ld\n", (UInt32) this, packet_count);
 }
 
 

Modified: trunk/xiph-qt/CASpeex/src/CASpeexDecoder.cpp
===================================================================
--- trunk/xiph-qt/CASpeex/src/CASpeexDecoder.cpp	2006-04-30 15:19:38 UTC (rev 11322)
+++ trunk/xiph-qt/CASpeex/src/CASpeexDecoder.cpp	2006-04-30 22:09:34 UTC (rev 11323)
@@ -174,7 +174,17 @@
     case kAudioCodecPropertyPacketFrameSize:
         if(ioPropertyDataSize == sizeof(UInt32))
         {
-            *reinterpret_cast<UInt32*>(outPropertyData) = kSpeexFramesPerPacket;
+            UInt32 *outProp = reinterpret_cast<UInt32*>(outPropertyData);
+            if (!mCompressionInitialized)
+                *outProp = kSpeexFramesPerPacket;
+            else if (mSpeexHeader.frame_size != 0 * mSpeexHeader.frames_per_packet != 0)
+                *outProp = mSpeexHeader.frame_size * mSpeexHeader.frames_per_packet;
+            else
+                *outProp = 8192;
+            if (*outProp < 8192 && mInputFormat.mFormatID == kAudioFormatXiphOggFramedSpeex)
+                *outProp = 8192;
+            dbg_printf("  = [%08lx] CASpeexDecoder :: GetProperty('pakf'): %ld\n",
+                       (UInt32) this, *outProp);
         }
         else
         {
@@ -390,6 +400,9 @@
 
     //TODO: fix some of the header fields here
 
+    int enhzero = 0;
+    speex_decoder_ctl(mSpeexDecoderState, SPEEX_SET_ENH, &enhzero);
+
     if (mSpeexHeader.nb_channels == 2)
     {
         SpeexCallback callback;
@@ -489,6 +502,12 @@
 
     speex_bits_read_from(&mSpeexBits, reinterpret_cast<char*> (mBDCBuffer.GetData()), sfp.bytes);
 
+    if (sfp.frames > 0 && (sfp.frames - mSpeexHeader.frame_size * mSpeexHeader.frames_per_packet > 0)) {
+        UInt32 zeroBytes = mOutputFormat.FramesToBytes(sfp.frames - mSpeexHeader.frame_size * mSpeexHeader.frames_per_packet);
+        memset(mOutBuffer + mOutBufferUsedSize, 0, zeroBytes);
+        mOutBufferUsedSize += zeroBytes;
+    }
+
     for (SInt32 i = 0; i < mSpeexHeader.frames_per_packet; i++) {
         if (mOutputFormat.mFormatFlags & kAudioFormatFlagsNativeFloatPacked != 0)
             result = speex_decode(mSpeexDecoderState, &mSpeexBits, reinterpret_cast<float*> (mOutBuffer + mOutBufferUsedSize));



More information about the commits mailing list