Approach for shorter durations
In general, you could solve this with a "patterned interleaver" block out of the box, where you connect the file source to one input, and a null source to the other, and then forward one chunk of audio-file-length input from the first input, and then one hour minus that length from the other (null) input.
[ 0 0 0 … 0 0 1 1 … … … … … … 1 ]
^ ^ ^ ^
\ / \ /
audio remainder of
length a full hour
It's just that here, the time periods become too long and hence, the interleaver pattern vector becomes infeasible to manage (it needs to be 1 hr of samples in size, which, at 44.1kHz sampling rate, is more than 605 MB of integers, to select which input to forward from).
Another problem is that you'd need to know how many samples are in your audio file to create that interleaver pattern.
Solution: Write your own Finite State Machine
So, the solution here is to write your own block that has two states:
- pass through the audio file input
- produce zeros (and not pass any input samples)
where you switch from state 1 to state 2 when you see that the full audio file has been passed through, and from state 2 to state 1 when you see that a full hour has passed.
That's really easy if you write an embedded python block!
Pseudocode for the work function that would be
import numpy as np
from gnuradio import gr
class yourblock(gr.basic_block):
def __init__(self, period=60, input_length=708000, rate=44100):
gr.basic_block.__init__(self,
name = "My block",
in_sig = [np.float32],
out_sig = [np.float32]
)
self._samples_per_cycle = int(period * rate)
self._zeros_left = self._samples_per_cycle - input_length
self._input_length = input_length
self._input_left = input_length
self._state = 0
def general_work(self, input_items, output_items):
in_ = input_items[0]
out_ = output_items[0]
if self._state == 0: # Passing through from input
to_copy = min(self._input_left, len(in_), len(out_))
out_[0:to_copy] = in_[0:to_copy]
self._input_left -= to_copy
if(self._input_left == 0):
self._state = 1
self._zeros_left = self._samples_per_cycle - self._input_length
self.consume_each(to_copy) # copied this much from input
return to_copy # wrote this much to output
if self._state == 1:
to_zero = min(self._zeros_left, len(in_), len(out_))
out_[0:to_zero] = 0.0
self._zeros_left -= to_zero
if(self._zeros_left == 0):
self._state = 0
self._input_left = self._input_length
self.consume_each(to_zero) # copied this much from input
return to_zero # wrote this much to output