commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r3768 - gnuradio/branches/developers/jcorgan/cppwrap/g


From: jcorgan
Subject: [Commit-gnuradio] r3768 - gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native
Date: Tue, 10 Oct 2006 15:44:07 -0600 (MDT)

Author: jcorgan
Date: 2006-10-10 15:44:07 -0600 (Tue, 10 Oct 2006)
New Revision: 3768

Modified:
   
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native/gr_flow_graph.cc
   
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native/gr_flow_graph.h
Log:
Work in progress.

Implemented gr_flow_graph::allocate_buffer() and sub-functions.


Modified: 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native/gr_flow_graph.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native/gr_flow_graph.cc
      2006-10-10 20:06:34 UTC (rev 3767)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native/gr_flow_graph.cc
      2006-10-10 21:44:07 UTC (rev 3768)
@@ -22,6 +22,7 @@
 #include <gr_flow_graph.h>
 #include <gr_block_detail.h>
 #include <gr_io_signature.h>
+#include <gr_buffer.h>
 
 #include <utility>
 #include <algorithm>
@@ -152,16 +153,15 @@
        if (!(*block_iter)->check_topology(ninputs, noutputs))
            throw std::invalid_argument("gr_flow_graph::validate");
 
-       // Block is good, now do per block processing
-
-       // 'assign_details' functionality here
-       printf("Assigning detail with %i inputs and %i outputs\n", ninputs, 
noutputs);
-       (*block_iter)->set_detail(gr_make_block_detail(ninputs, noutputs));
-
-       // 'assign_buffers' functionality here
-       
-       // 'connect_inputs' functionality here
+       // Allocate block detail and output buffer and assign
+       gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs);
+       for(int i = 0; i < noutputs; i++)
+           detail->set_output(i, allocate_buffer(*block_iter, i));
+       (*block_iter)->set_detail(detail);
     }
+    
+    // connect_inputs() functionality will require separate loop as all the 
blocks 
+    // will need to have details and buffers set first
 }
 
 std::vector<int> gr_flow_graph::calc_used_ports(gr_block_sptr block, bool 
direction)
@@ -212,6 +212,44 @@
     }
 }
 
+gr_buffer_sptr gr_flow_graph::allocate_buffer(gr_block_sptr block, int port)
+{
+    // Start by allocating at least number of items in fixed block size
+    int item_size = block->output_signature()->sizeof_stream_item(port);
+    int nitems = s_fixed_buffer_size/item_size;
+    
+    // Make sure there are at least twice the output_multiple no. of items
+    if (nitems < 2*block->output_multiple())   // Note: this means 
output_multiple()
+       nitems = 2*block->output_multiple();    // can't be changed by block 
dynamically
+
+    // If any downstream blocks are decimators and/or have a large 
output_multiple,
+    // ensure we have a buffer at least twice their decimation 
factor*output_multiple
+    gr_block_vector_t blocks = calc_downstream_blocks(gr_endpoint_t(block, 
port));
+    gr_block_vector_iterator_t block_iter;
+    for(block_iter = blocks.begin(); block_iter != blocks.end(); block_iter++) 
{
+       int decimation = (int)(1.0/(*block_iter)->relative_rate());
+       int multiple   = (*block_iter)->output_multiple();
+       int history    = (*block_iter)->history();
+       nitems = std::max(nitems, 2*(decimation*multiple+history));
+    }
+
+    return gr_make_buffer(nitems, item_size);
+}
+
+gr_block_vector_t gr_flow_graph::calc_downstream_blocks(gr_endpoint_t src)
+{
+    gr_block_vector_t result;
+    gr_edge_vector_iterator_t edge_iter;
+    
+    for(edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++)
+       if (edge_iter->first == src)
+           result.push_back(edge_iter->second.first);
+        
+    sort(result.begin(), result.end());
+    unique(result.begin(), result.end());
+    return result;
+}
+
 void gr_flow_graph::start()
 {
     // TODO: check if already started

Modified: 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native/gr_flow_graph.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native/gr_flow_graph.h
       2006-10-10 20:06:34 UTC (rev 3767)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/native/gr_flow_graph.h
       2006-10-10 21:44:07 UTC (rev 3768)
@@ -36,6 +36,8 @@
 
 gr_flow_graph_sptr gr_make_flow_graph();
 
+#define GR_FIXED_BUFFER_SIZE 32000
+
 class gr_flow_graph
 {
 private:
@@ -47,12 +49,17 @@
     void check_dst_not_used(gr_endpoint_t dst);
     void check_type_match(gr_endpoint_t src, gr_endpoint_t dst);
     void disconnect_prim(gr_endpoint_t src, gr_endpoint_t dst);
+
     void create_block_list();
     void connect_blocks();
     std::vector<int> calc_used_ports(gr_block_sptr block, bool direction);
     void check_contiguity(gr_block_sptr block, gr_io_signature_sptr sig,
                          std::vector<int> &used_ports);
 
+    gr_buffer_sptr allocate_buffer(gr_block_sptr block, int port);
+    gr_block_vector_t calc_downstream_blocks(gr_endpoint_t src);
+        
+    static const int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE;
     gr_edge_vector_t  d_edges;
     gr_block_vector_t d_blocks;
                             





reply via email to

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