# Throttle block form wav files

**URL:** <https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242>\
**Category:** GNU Radio\
**Created:** [September 3, 2015, 4:24pm UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242 "2015-09-03T16:24:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [September 3, 2015, 4:24pm UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/1 "2015-09-03T16:24:53Z")

</div>

Hi,

I’m using a flow graph with no GUI to demodulate a signal. I have a  
selector block that allows me to select the source of the signal between  
the audio card and a wav file. I can change the source using an xmlrpc  
server/client.

If I don’t use a throttle block with the wav file, the flow graph takes  
all  
the CPU and the server/client is very slow.  
If I put a throttle, I get audio underruns when using the audio card.  
Same  
problem for a constant source.

Can anyone please recommend a better way to do this?

Cheers,  
Murray

---

<div class="post-metadata">

**Author:** ![Murray\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Murray\_T](https://www.ruby-forum.com/u/Murray_T)\
**Post date:** [September 3, 2015, 4:55pm UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/2 "2015-09-03T16:55:15Z")

</div>

On Sep 3, 2015, at 7:22, Murray T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m using a flow graph with no GUI to demodulate a signal. I have a selector  
> block that allows me to select the source of the signal between the audio card and  
> a wav file. I can change the source using an xmlrpc server/client.
> 
> If I don’t use a throttle block with the wav file, the flow graph takes all the  
> CPU and the server/client is very slow.  
> If I put a throttle, I get audio underruns when using the audio card. Same  
> problem for a constant source.

You can’t get audio underruns from an audio _source_, so I assume you  
have an audio _sink_ that you didn’t mention in your description that  
you’re using in both modes for the output of the demodulator.

It sounds like you have the audio _sink_ set not to block. In its  
properties, enable the OK to Block checkbox. Do not use a throttle.

This will allow the audio sink to limit the data rate from the wav  
source (by backpressure). When an audio source is being used, if the  
source and sink are from the same sound card and have the same sample  
rate requested then they should be happy too.

–  
Kevin R. [http://switchb.org/kpreid/](http://switchb.org/kpreid/)

---

<div class="post-metadata">

**Author:** ![Murray\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Murray\_T](https://www.ruby-forum.com/u/Murray_T)\
**Post date:** [September 3, 2015, 4:57pm UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/3 "2015-09-03T16:57:00Z")

</div>

You can’t have a throttle block inline with an audio source. Did you try  
putting the throttle between the file source and the selector?

(I haven’t actually tried this)

- Jeff

---

<div class="post-metadata">

**Author:** ![Murray\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Murray\_T](https://www.ruby-forum.com/u/Murray_T)\
**Post date:** [September 4, 2015, 11:07am UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/4 "2015-09-04T11:07:04Z")

</div>

On 3 September 2015 at 16:43, Kevin R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Sorry, it was a mistake. For the list, just clarify that  
I have an audio sink using the same audio card @ 96 KHz with the  
settings  
set to OK to block YES.

> Here are some better solutions, from simplest to best:  
> else that acts like it.)  
> (the demodulator and sink) into a GRC block which is used by the Python  
> program. Either way works.
> 
> Thanks, I’ll try these solutions tomorrow. I assume that they also apply  
> to add a constant block into a selector block.

---

<div class="post-metadata">

**Author:** ![Murray\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Murray\_T](https://www.ruby-forum.com/u/Murray_T)\
**Post date:** [September 3, 2015, 4:59pm UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/5 "2015-09-03T16:59:56Z")

</div>

Dear Murray T.,

Which value did you set as a throttle.  
Typically 48 kHz or something… But I asked this just in case.

Or this thread might help (  
[https://lists.gnu.org/archive/html/discuss-gnuradio/2013-08/msg00517.html](https://lists.gnu.org/archive/html/discuss-gnuradio/2013-08/msg00517.html)  
)

Regards,  
Jeon.

2015-09-03 23:22 GMT+09:00 Murray T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Murray\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Murray\_T](https://www.ruby-forum.com/u/Murray_T)\
**Post date:** [September 7, 2015, 2:43pm UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/6 "2015-09-07T14:43:54Z")

</div>

On 3 September 2015 at 17:04, Murray T.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > usage in any other way.  
> > that its documentation lies. It does not leave its unused inputs
> > 
> > 1. Using some method to force the wav source and audio source to match  
> > sample rates. Specifically, you could use a “Multiply by Matrix” block to  
> > replace the function of the Selector entirely: give it a matrix value of  
> > either ((1, 0),) or ((0, 1),) to select just one input.

Can I make a multiply to matrix block have several inputs and one only  
output? If not, I was thinking on multiplying one of them by a constant  
block zero and then adding both outputs. Would this be a valid  
workaround?

---

<div class="post-metadata">

**Author:** ![Murray\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Murray\_T](https://www.ruby-forum.com/u/Murray_T)\
**Post date:** [September 7, 2015, 4:33pm UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/7 "2015-09-07T16:33:44Z")

</div>

On Sep 7, 2015, at 5:42, Murray T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > 1. Using some method to force the wav source and audio source to match sample  
> > rates. Specifically, you could use a Multiply by Matrix block to replace the  
> > function of the Selector entirely: give it a matrix value of either ((1, 0),) or  
> > ((0, 1),) to select just one input.
> 
> Can I make a multiply to matrix block have several inputs and one only output?  
> If not, I was thinking on multiplying one of them by a constant block zero and  
> then adding both outputs. Would this be a valid workaround?

The number of inputs and outputs are determined by the dimensions of the  
matrix value entered. If you put in ((0, 1,),) with the comma (actually,  
I just remembered you can write [[0, 1]] as well and you don’t have to  
worry about the extra comma (blame Python for that)) then it will have 2  
inputs and 1 output. And, for example, if you wrote [[0], [1]], then it  
would have 1 input and 2 outputs.

By the way, you can of course enter any numeric values to scale the  
inputs as you like, so for example you could use [[0, 0]] as a mute  
mode, or enter an arbitrary number as a gain control, if you wanted one.

(If you did have an extra output that you couldn’t get rid of, a null  
sink would be simplest there.)

–  
Kevin R. [http://switchb.org/kpreid/](http://switchb.org/kpreid/)

---

<div class="post-metadata">

**Author:** ![Murray\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Murray\_T](https://www.ruby-forum.com/u/Murray_T)\
**Post date:** [September 4, 2015, 11:10am UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/8 "2015-09-04T11:10:34Z")

</div>

On Sep 3, 2015, at 8:24, Murray T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Even selecting source and sink from the audio card, if I have a wav file playing  
> in another input of the selector without a throttle, the CPU goes to 100%. To  
> avoid it I put the wav file, then the throttle and the the selector. I’ve read  
> that is bad practice but I couldn’t reduce the CPU usage in any other way.

(Please make sure to CC the mailing list in your replies.)

Ah. I just looked at the implementation of the selector block, and found  
that its documentation lies. It does not leave its unused inputs  
disconnected (which is actually good, because that would cause errors in  
some cases), but connects them to null sinks (which consume all the  
input they’re given).

So, using a throttle is a workaround for this. (The cost is that since  
the throttle’s timing is based on the CPU clock, not the audio card  
clock, you’ll occasionally get either underrun or overrun.)

Here are some better solutions, from simplest to best:

1. Using some method to force the wav source and audio source to match  
sample rates. Specifically, you could use a Multiply by Matrix block to  
replace the function of the Selector entirely: give it a matrix value of  
either ((1, 0),) or ((0, 1),) to select just one input.

2. Modifying, or creating a replacement for, the selector block which  
does not connect to a null sink but rather to a block of some sort which  
never accepts any data and so stops that branch of the flowgraph. (I  
don’t think such a block actually exists, but it could, and there might  
be something else that acts like it.)

3. Actually remove from the flowgraph whichever of the wav source and  
audio source are not currently in use. This is the most general,  
efficient, and straightforward solution, but unfortunately it cannot be  
built within GNU Radio Companion – you must write some C++ or Python  
code. If you don’t want to stop using GRC entirely, you could isolate  
that part by putting the connection changing logic inside a hierarchical  
block; this would be similar to the selector block itself, but it would  
be a source, which has the wav and audio sources “built into” it.  
Alternatively, you could write your main()/top block as a Python program  
and put the _rest_ of your logic (the demodulator and sink) into a GRC  
block which is used by the Python program. Either way works.

–  
Kevin R. [http://switchb.org/kpreid/](http://switchb.org/kpreid/)

---

<div class="post-metadata">

**Author:** ![Murray\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Murray\_T](https://www.ruby-forum.com/u/Murray_T)\
**Post date:** [September 7, 2015, 5:38pm UTC](https://www.ruby-forum.com/t/throttle-block-form-wav-files/243242/9 "2015-09-07T17:38:34Z")

</div>

On 7 September 2015 at 15:32, Kevin R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> block zero and then adding both outputs. Would this be a valid workaround?  
> enter an arbitrary number as a gain control, if you wanted one.
> 
> (If you did have an extra output that you couldn’t get rid of, a null sink  
> would be simplest there.)
> 
> That’s great help Kevin. Explains and solves my issue. Thanks!
