commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r6147 - gnuradio/trunk/gr-audio-osx/src


From: michaelld
Subject: [Commit-gnuradio] r6147 - gnuradio/trunk/gr-audio-osx/src
Date: Fri, 17 Aug 2007 09:18:21 -0600 (MDT)

Author: michaelld
Date: 2007-08-17 09:18:20 -0600 (Fri, 17 Aug 2007)
New Revision: 6147

Modified:
   gnuradio/trunk/gr-audio-osx/src/audio_osx_sink.h
   gnuradio/trunk/gr-audio-osx/src/audio_osx_source.cc
   gnuradio/trunk/gr-audio-osx/src/audio_osx_source.h
Log:
Added and changed comments debugging commands.

Changed the 'do_block' argument from true to false as the default.

Corrected a bug in the source: if 'do_block' is false and there is no
data to return in "work()", now correctly releases the internal mutex
before returning (0).



Modified: gnuradio/trunk/gr-audio-osx/src/audio_osx_sink.h
===================================================================
--- gnuradio/trunk/gr-audio-osx/src/audio_osx_sink.h    2007-08-17 03:23:02 UTC 
(rev 6146)
+++ gnuradio/trunk/gr-audio-osx/src/audio_osx_sink.h    2007-08-17 15:18:20 UTC 
(rev 6147)
@@ -35,7 +35,7 @@
 audio_osx_sink_sptr
 audio_osx_make_sink (int sample_rate = 44100,
                     const std::string device_name = "2",
-                    bool do_block = true,
+                    bool do_block = false,
                     int channel_config = -1,
                     int max_sample_count = -1);
 

Modified: gnuradio/trunk/gr-audio-osx/src/audio_osx_source.cc
===================================================================
--- gnuradio/trunk/gr-audio-osx/src/audio_osx_source.cc 2007-08-17 03:23:02 UTC 
(rev 6146)
+++ gnuradio/trunk/gr-audio-osx/src/audio_osx_source.cc 2007-08-17 15:18:20 UTC 
(rev 6147)
@@ -114,7 +114,7 @@
   d_max_sample_count = max_sample_count;
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "source(): max # samples = %ld", d_max_sample_count);
+  fprintf (stderr, "source(): max # samples = %ld\n", d_max_sample_count);
 #endif
 
   OSStatus err = noErr;
@@ -630,11 +630,12 @@
 }
 
 int
-audio_osx_source::work (int noutput_items,
-                       gr_vector_const_void_star &input_items,
-                       gr_vector_void_star &output_items)
+audio_osx_source::work
+(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
 {
-// acquire control to do processing here only
+  // acquire control to do processing here only
   d_internal->wait ();
 
 #if _OSX_AU_DEBUG_
@@ -642,35 +643,44 @@
           d_queueSampleCount, noutput_items, output_items.size());
 #endif
 
-// ?: always block until there is something to output from the source
-//    or return anything that is available, even if it's less than desired?
+  // set the actual # of output items to the 'desired' amount then
+  // verify that data is available; if not enough data is available,
+  // either wait until it is (is "do_block" is true), return (0) is no
+  // data is available and "do_block" is false, or process the actual
+  // amount of available data.
 
   UInt32 actual_noutput_items = noutput_items;
 
   if (d_queueSampleCount < actual_noutput_items) {
     if (d_queueSampleCount == 0) {
-// no data; do_block decides what to do
+      // no data; do_block decides what to do
       if (d_do_block == true) {
        while (d_queueSampleCount == 0) {
-// release control so-as to allow data to be retrieved
+         // release control so-as to allow data to be retrieved
          d_internal->post ();
-// block until there is data to return
+         // block until there is data to return
          d_cond_data->wait ();
-// the condition's signal() was called; acquire control
-// to keep thread safe
+         // the condition's signal() was called; acquire control to
+         // keep thread safe
          d_internal->wait ();
        }
       } else {
-// not enough data & not blocking; return nothing
+       // no data & not blocking; return nothing
+       // release control so-as to allow data to be retrieved
+       d_internal->post ();
        return (0);
       }
     }
+    // use the actual amount of available data
     actual_noutput_items = d_queueSampleCount;
   }
 
+  // number of channels
   int l_counter = (int) output_items.size();
 
-// get the items from the circular buffers
+  // copy the items from the circular buffer(s) to 'work's output buffers
+  // verify that the number copied out is as expected.
+
   while (--l_counter >= 0) {
     UInt32 t_n_output_items = actual_noutput_items;
     d_buffers[l_counter]->dequeue ((float*) output_items[l_counter],
@@ -684,6 +694,9 @@
     }
   }
 
+  // subtract the actual number of items removed from the buffer(s)
+  // from the local accounting of the number of available samples
+
   d_queueSampleCount -= actual_noutput_items;
 
 #if _OSX_AU_DEBUG_
@@ -691,21 +704,28 @@
           d_queueSampleCount, actual_noutput_items);
 #endif
 
-// release control to allow for other processing parts to run
+  // release control to allow for other processing parts to run
+
   d_internal->post ();
 
+#if _OSX_AU_DEBUG_
+  fprintf (stderr, "work3: Returning.\n");
+#endif
+
   return (actual_noutput_items);
 }
 
 OSStatus
-audio_osx_source::ConverterCallback (AudioConverterRef inAudioConverter,
-                                    UInt32* ioNumberDataPackets,
-                                    AudioBufferList* ioData,
-                                    AudioStreamPacketDescription** ioASPD,
-                                    void* inUserData)
+audio_osx_source::ConverterCallback
+(AudioConverterRef inAudioConverter,
+ UInt32* ioNumberDataPackets,
+ AudioBufferList* ioData,
+ AudioStreamPacketDescription** ioASPD,
+ void* inUserData)
 {
-// take current device buffers and copy them to the tail of the input buffers
-// the lead buffer is already there in the first d_leadSizeFrames slots
+  // take current device buffers and copy them to the tail of the
+  // input buffers the lead buffer is already there in the first
+  // d_leadSizeFrames slots
 
   audio_osx_source* This = static_cast<audio_osx_source*>(inUserData);
   AudioBufferList* l_inputABL = This->d_InputBuffer;
@@ -726,6 +746,10 @@
     l_ioD_AB->mDataByteSize = totalInputBufferSizeBytes;
   }
 
+#if _OSX_AU_DEBUG_
+  fprintf (stderr, "cc2: Returning.\n");
+#endif
+
   return (noErr);
 }
 
@@ -841,7 +865,7 @@
     float* inBuffer = (float*) This->d_OutputBuffer->mBuffers[l_counter].mData;
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb2.5: enqueuing audio data.\n");
+  fprintf (stderr, "cb3: enqueuing audio data.\n");
 #endif
 
     int l_res = This->d_buffers[l_counter]->enqueue (inBuffer, 
ActualOutputFrames);
@@ -862,7 +886,7 @@
   }
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb3: #OI = %4ld, #Cnt = %4ld, mSC = %ld, \n",
+  fprintf (stderr, "cb4: #OI = %4ld, #Cnt = %4ld, mSC = %ld, \n",
           ActualOutputFrames, This->d_queueSampleCount,
           This->d_max_sample_count);
 #endif
@@ -871,14 +895,14 @@
   This->d_cond_data->signal ();
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb4: releasing internal mutex.\n");
+  fprintf (stderr, "cb5: releasing internal mutex.\n");
 #endif
 
 // release control to allow for other processing parts to run
   This->d_internal->post ();
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb5: returning.\n");
+  fprintf (stderr, "cb6: returning.\n");
 #endif
 
   return (err);

Modified: gnuradio/trunk/gr-audio-osx/src/audio_osx_source.h
===================================================================
--- gnuradio/trunk/gr-audio-osx/src/audio_osx_source.h  2007-08-17 03:23:02 UTC 
(rev 6146)
+++ gnuradio/trunk/gr-audio-osx/src/audio_osx_source.h  2007-08-17 15:18:20 UTC 
(rev 6147)
@@ -35,7 +35,7 @@
 audio_osx_source_sptr
 audio_osx_make_source (int sample_rate = 44100,
                       const std::string device_name = "",
-                      bool do_block = true,
+                      bool do_block = false,
                       int channel_config = -1,
                       int max_sample_count = -1);
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]