Some information: I am using a rpi2b with a cirrus logic audio card and have worked out the kernel changes to get the sound card going, I can output without problems, I can record from line in without problems (I am using pyAudio).
Now I only want to filter the signal and have found a lot of functions in the scipy library...
First thing to mention I can only use 2 channels (stereo) input the soundcard seems to doesnt allow 1 channel and I dont have a source to stream mono (iPhone, simple USB player everyone has only stereo)....
The filter line (specifications) is just an example I think it will be an other filter if it works :D
So before the code begins a little to explain. When using stereo input the samples appear to be interleaved so you get on the one channel a sample on the other... I thought this thread was helpful: Convert multi-channel PyAudio into NumPy array
Thats why I also tried to decode my stream into an array, filter and then code it again into a stream for output. If I neglect the interleaving fact I get weird noises thats why I think I should take care of it :)
Now comes the part where I fail: lFilter doesnt want to work! If I just use my unprocessed input_data it says the axis is out of range (I tried -1,0,1,2) dont know :/ and when using my reshaped etc. data I get:
return sigtools._linear_filter(b, a, x, axis, zi)
ValueError: object of too small depth for desired array
Can someone please explain why this is happening? :D Never used signals thats why I am unexperienced but I cant understand why the unprocessed data has axis problems and even though it wouldnt bother because I need the reshaped data like in the linked thread...
WIDTH = 2
CHANNELS = 2
RATE = 44100
p = pyaudio.PyAudio()
[b,a] = signal.iirfilter(2,[50,200],rs=60,btype='band',analog=True,ftype='cheby2')
full_data = np.array([])
def callback(in_data, frame_count, time_info, status):
global b,a,full_data
full_data = decode (in_data, 2)
audio_data = signal.lfilter(b,a, full_data)
print (audio_data)
stream_data = encode(audio_data)
return (stream_data, pyaudio.paContinue)
I skipped the stream open part and the decode and encode since the last ones are right now exactly the same as in the thread and the first one works thats why I just posted these parts. If needed I can also provide the others.
Any help is highly appreciated!
- Sanj3k
This is an example of what the data looks like, at first its a 1d np array and after the reshape etc ist 2d because of the stereo....
What does lFilter need? Since I have axis errors and with 2d its to small....
Edit: Btw here is the documentation from scipy library for the lfilter function and it says:
x : array_like
An N-dimensional input array.
http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lfilter.html