[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5648 - gnuradio/branches/features/ofdm/receiver/gnura
From: |
trondeau |
Subject: |
[Commit-gnuradio] r5648 - gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general |
Date: |
Sun, 3 Jun 2007 19:22:33 -0600 (MDT) |
Author: trondeau
Date: 2007-06-03 19:22:33 -0600 (Sun, 03 Jun 2007)
New Revision: 5648
Modified:
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general/gr_stream_mux.cc
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general/gr_stream_mux.h
Log:
fixed stream muxer for corner cases and simplified
Modified:
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general/gr_stream_mux.cc
===================================================================
---
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general/gr_stream_mux.cc
2007-06-04 00:49:58 UTC (rev 5647)
+++
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general/gr_stream_mux.cc
2007-06-04 01:22:33 UTC (rev 5648)
@@ -44,6 +44,10 @@
d_residual(0),
d_lengths(lengths)
{
+ if(d_lengths[d_stream] == 0) {
+ increment_stream();
+ }
+ d_residual = d_lengths[d_stream];
}
gr_stream_mux::~gr_stream_mux(void)
@@ -55,9 +59,17 @@
{
unsigned ninputs = ninput_items_required.size ();
for (unsigned i = 0; i < ninputs; i++)
- ninput_items_required[i] = 0;
+ ninput_items_required[i] = (d_lengths[i] == 0 ? 0 : 1);
}
+void gr_stream_mux::increment_stream()
+{
+ do {
+ d_stream = (d_stream+1) % d_lengths.size();
+ } while(d_lengths[d_stream] == 0);
+
+ d_residual = d_lengths[d_stream];
+}
int
gr_stream_mux::general_work(int noutput_items,
@@ -65,128 +77,46 @@
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
-
char *out = (char *) output_items[0];
const char *in;
+ int out_index = 0;
+ std::vector<int> input_index(d_lengths.size(), 0);
- int acc = 0;
- int N=0;
- int M=0;
- std::vector<int> consume_vector(d_lengths.size(), 0);
+ if(VERBOSE) {
+ printf("mux: nouput_items: %d d_stream: %d\n", noutput_items,
d_stream);
+ for(size_t i = 0; i < d_lengths.size(); i++)
+ printf("\tninput_items[%d]: %d\n", i, ninput_items[i]);
+ }
- #if VERBOSE
- printf("mux: nouput_items: %d d_stream: %d\n", noutput_items, d_stream);
- for(int i = 0; i < d_lengths.size(); i++)
- printf("\tninput_items[%d]: %d\n", i, ninput_items[i]);
- #endif
+ while (1) {
+ int r = std::min(noutput_items - out_index,
+ std::min(d_residual,
+ ninput_items[d_stream] -
input_index[d_stream]));
+ if(VERBOSE) {
+ printf("mux: r=%d\n", r);
+ printf("\tnoutput_items - out_index: %d\n",
+ noutput_items - out_index);
+ printf("\td_residual: %d\n",
+ d_residual);
+ printf("\tninput_items[d_stream] - input_index[d_stream]: %d\n",
+ ninput_items[d_stream] - input_index[d_stream]);
+ }
- in = (const char *) input_items[d_stream];
+ if(r <= 0) {
+ return out_index;
+ }
- if(d_residual) {
- #if VERBOSE
- printf("Cleaning up residual bytes (%d) from stream %d\n", d_residual,
d_stream);
- #endif
+ in = (const char *) input_items[d_stream] +
input_index[d_stream]*d_itemsize;
- // get the number of items available in input stream up to the
- // num items required
- N=std::min(d_residual, ninput_items[d_stream]);
-
- // get the number of items we can put into the output buffer
- M=std::min(N, noutput_items);
+ memcpy(&out[out_index*d_itemsize], in, r*d_itemsize);
+ out_index += r;
+ input_index[d_stream] += r;
+ d_residual -= r;
- // copy the items to the output buff
- memcpy(out, in, M*d_itemsize);
-
- // increment the output accumulator
- acc += M;
-
- // keep track of items consumed
- consume_vector[d_stream]=M;
+ consume(d_stream, r);
- // keep track if there are residual items left from the input stream
- d_residual -= M;
-
- #if VERBOSE
- printf("Stream: %d (%x) Wrote: %d bytes Output has: %d bytes
residual: %d bytes\n",
- d_stream, in, M, acc, d_residual);
- #endif
-
- // if no residual items, we're done with this input stream for
- // this round
- if (!d_residual) {
- if(d_stream == d_lengths.size() - 1) {
- d_stream=0; // wrap stream pointer
- }
- else {
- d_stream++; // or increment the stream pointer
- }
- #if VERBOSE
- printf("Going to next stream: %d\n", d_stream);
- #endif
- in = ((const char *) (input_items[d_stream])) +
d_itemsize*consume_vector[d_stream];
+ if(d_residual == 0) {
+ increment_stream();
}
}
-
- if(!d_residual) {
- while (acc<noutput_items){
- // get the number of items available in input stream up to the
- // num items required
- N=std::min(d_lengths[d_stream], ninput_items[d_stream]);
-
- // get the number of items we can put into the output buffer
- M=std::min(N, noutput_items-acc);
-
- // copy the items to the output buff
- memcpy(out+acc*d_itemsize,in,M*d_itemsize);
-
- // increment the output accumulator
- acc += M;
-
- // keep track of items consumed
- consume_vector[d_stream]+=M;
-
- // keep track if there are residual items left from the input stream
- d_residual=d_lengths[d_stream] - M;
-
- #if VERBOSE
- printf("Stream: %d (%x) Wrote: %d bytes Output has: %d bytes
residual: %d bytes\n",
- d_stream, in, M, acc, d_residual);
- #endif
-
- // if no residual items, we're done with this input stream for
- // this round
- if (!d_residual) {
- if(d_stream == d_lengths.size() - 1) {
- d_stream=0; // wrap stream pointer
- }
- else {
- d_stream++; // or increment the stream pointer
- }
- #if VERBOSE
- printf("Going to next stream: %d\n", d_stream);
- #endif
-
- // get next stream pointer
- in = ((const char *) (input_items[d_stream])) +
d_itemsize*consume_vector[d_stream];
- }
- else{
- break;
- }
- }
- }
-
- for (unsigned int j=0;j<d_lengths.size();j++){
- consume(j,consume_vector[j]);
-
- #if VERBOSE
- printf("consuming: %d on stream: %d\n", consume_vector[j], j);
- #endif
- }
-
- #if VERBOSE
- printf("mux: returning: %d\n\n", acc);
- #endif
-
- return acc;
-
}
Modified:
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general/gr_stream_mux.h
===================================================================
---
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general/gr_stream_mux.h
2007-06-04 00:49:58 UTC (rev 5647)
+++
gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general/gr_stream_mux.h
2007-06-04 01:22:33 UTC (rev 5648)
@@ -65,14 +65,15 @@
protected:
gr_stream_mux (size_t itemsize, const std::vector<int> &lengths);
+
private:
- size_t d_itemsize;
- unsigned int d_stream;
- int d_residual;
- int d_times;
- int d_unconsume;
- //gr_vector_int d_unconsume;
- gr_vector_int d_lengths;
+ size_t d_itemsize;
+ unsigned int d_stream; // index of currently selected stream
+ int d_residual; // number if items left to put into current stream
+ gr_vector_int d_lengths; // number if items to pack per stream
+
+ void increment_stream();
+
public:
~gr_stream_mux(void);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5648 - gnuradio/branches/features/ofdm/receiver/gnuradio-core/src/lib/general,
trondeau <=