I am trying to create a script capable of infinitely processing an incoming stream which is piped to it, and continuous producing an output stream which can be piped to something else something as follows:
<infinitely produce data stream> | myscript | <use modified stream>
In my case, I have a program which will continously generate a headerless wav sinusoid which will be piped into my script which will mix it with other sinusoids, and pass it out to a program which will play it as it streams in.
I have tried using
#!/bin/bash
while read data; do
#echo "data = $data"
./merge <($data) <(./sine 1000)
done
But this just leaves crazy symbols all over my terminal. It looks like for everyline of stdin it receives, it calls merge again and again.
My merge program is written in C and is written such that it is opening a file passed as an argument.
It works fine when I run in in the terminal as
./merge <(./sine 1000) <(./sine 2000) | ./audio_sink
This has two instances of sine running, generating 1kHz and 2kHz sine wave respectively, and merge reads the two input streams, mixes them, and produces an output to sdtout which can then be piped to audio_sink and I can hear it is working.
In this script I'm writing I need to be able to pipe the input directing into the first argument as above.
How can you write a bash script which allows you to use data continuously piped into it, manipulate it, and have the data piped back out?