commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 02/07: gr-audio: implemented blocking in wi


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/07: gr-audio: implemented blocking in windows audio sink
Date: Thu, 13 Oct 2016 21:54:18 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 4edbf58d2462f1102216a3a027cdfacb46c7108b
Author: gnieboer <address@hidden>
Date:   Wed Oct 12 19:27:56 2016 -0400

    gr-audio: implemented blocking in windows audio sink
---
 gr-audio/lib/windows/windows_sink.cc | 22 ++++++++++++++++------
 gr-audio/lib/windows/windows_sink.h  | 14 ++++++++------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/gr-audio/lib/windows/windows_sink.cc 
b/gr-audio/lib/windows/windows_sink.cc
index 4ec798b..52456db 100644
--- a/gr-audio/lib/windows/windows_sink.cc
+++ b/gr-audio/lib/windows/windows_sink.cc
@@ -46,10 +46,10 @@ namespace gr {
     sink::sptr
     windows_sink_fcn(int sampling_rate,
         const std::string &device_name,
-        bool)
+        bool ok_to_block)
     {
       return sink::sptr
-        (new windows_sink(sampling_rate, device_name));
+        (new windows_sink(sampling_rate, device_name, ok_to_block));
     }
 
     static const double CHUNK_TIME = 
prefs::singleton()->get_double("audio_windows", "period_time", 0.1); // 100 ms 
(below 3ms distortion will likely occur regardless of number of buffers, will 
likely be a higher limit on slower machines)
@@ -63,13 +63,13 @@ namespace gr {
       return (default_device == "default" ? "WAVE_MAPPER" : default_device);
     }
 
-    windows_sink::windows_sink(int sampling_freq, const std::string 
device_name)
+    windows_sink::windows_sink(int sampling_freq, const std::string 
device_name, bool ok_to_block)
       : sync_block("audio_windows_sink",
                       io_signature::make(1, 2, sizeof(float)),
                       io_signature::make(0, 0, 0)),
         d_sampling_freq(sampling_freq),
         d_device_name(device_name.empty() ? default_device_name() : 
device_name),
-        d_fd(-1), d_buffers(0), d_chunk_size(0)
+        d_fd(-1), d_buffers(0), d_chunk_size(0), d_ok_to_block(ok_to_block)
     {
       /* Initialize the WAVEFORMATEX for 16-bit, 44KHz, stereo */
       wave_format.wFormatTag = WAVE_FORMAT_PCM;
@@ -154,10 +154,20 @@ namespace gr {
           }
         }
         if (!chosen_header) {
-          WaitForSingleObject(d_wave_write_event, 100);
-          printf("aO");
+          if (!d_ok_to_block)
+          {
+            // drop the input data, print warning, and return control.
+            printf("aO");
+            return noutput_items;
+          }
+          else {
+            WaitForSingleObject(d_wave_write_event, 100);
+          }
         }
         if (c++ > 10) {
+          // After waiting for 1 second, then something else is seriously 
wrong so let's 
+          // just fail and give some debugging information about the status
+          // of the buffers.
           for (int i = 0; i < nPeriods; i++) {
             printf("%d: %d\n", i, d_buffers[i]->dwFlags);
           }
diff --git a/gr-audio/lib/windows/windows_sink.h 
b/gr-audio/lib/windows/windows_sink.h
index 2bfdbd3..de905c6 100644
--- a/gr-audio/lib/windows/windows_sink.h
+++ b/gr-audio/lib/windows/windows_sink.h
@@ -49,22 +49,24 @@ namespace gr {
       int         d_fd;
       LPWAVEHDR  *d_buffers;
       DWORD       d_chunk_size;
-         DWORD       d_buffer_size;
+      DWORD          d_buffer_size;
+      bool        d_ok_to_block;
       HWAVEOUT    d_h_waveout;
       HANDLE      d_wave_write_event;
-         WAVEFORMATEX wave_format;
+      WAVEFORMATEX wave_format;
 
     protected:
       int string_to_int(const std::string & s);
       int open_waveout_device(void);
       int write_waveout(LPWAVEHDR lp_wave_hdr);
-         MMRESULT is_format_supported(LPWAVEFORMATEX pwfx, UINT uDeviceID);
-         bool is_number(const std::string& s);
-         UINT find_device(std::string szDeviceName);
+      MMRESULT is_format_supported(LPWAVEFORMATEX pwfx, UINT uDeviceID);
+      bool is_number(const std::string& s);
+      UINT find_device(std::string szDeviceName);
 
     public:
       windows_sink(int sampling_freq,
-                   const std::string device_name = "");
+                   const std::string device_name,
+                   bool ok_to_block);
       ~windows_sink();
 
       int work(int noutput_items,



reply via email to

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