How to filter and downsample before FFT? I would like to perform STFT on musical signal with defined sampling rate (44100Hz).
I would like to get FFT result for smaller range of frequencies than are maximally available 
(not 22050Hz but for 4000Hz) so the result will have better frequency resolution.
So I think I should downsample it, but how can you downsample to the frequency
that is not in integer relation to the input frequency (you cannot leave the kth sample)?
Do you do some kind of interpolation to get values of new samples? 
How does it affect the signal?

I also know I should filter out the frequencies higher than 8000Hz otherwise
the signal would get aliased. Is there some kind of filter revelant for usage in STFT?

All I know about filters is that to get better (more sharp) filter 
you need more coefficents and so it will take more time to calculate. 
I know there are IIR filters and FIR filters. 
I read IIR filters can be unstable but should I care about it if I use a ready implementation (and I assume it's done right)? 

Is it better to filter the whole signal (whole audio file)
at once? If I get the infite response from the IIR filter and I filter
the whole signal at once will the energy be most smudged at the end part of the signal?

I also read filters can pose some kind of delay on the frequencies and it differs for different frequencies. How do you analyse and compensate this phenomenon?

Edit: I found that you can get FIR with linear delay and that now they are used more often than IIR. But there's still a delay, what does it mean? That the frequency events (like musical notes) will occur later in sample number time? What will be this delay?

Edit2: When I want to downsample to sampling rate of 8000Hz I have to filter so there won't be any frequencies over 4000Hz. Is this practically possible, because I looked at different FIR filters characteristics and they just seem to greatly damp the stopband frequencies not to eliminate them? If I will have just a bit of the high frequencies in the signal, will the signal look ok when downsampled (aliasing won't be noticeable)?
The process of changing the sampling rate by an arbitrary fraction $\frac{n}{k}$ is called resampling.  It is basically just interpolating and decimating at the same time.

It sounds like you are trying to go from 44100 Hz to 4000 Hz.  If so, that requires a sampling rate change of $\frac{40}{441}$, since $44100 * \frac{40}{441} = 4000$.  As a practical matter you don't want to do really large sample rate changes (like decimating by 441) all at once because it is very difficult to implement filters that can do that.  We thus try to break it down a bit into smaller steps.

If you factor the interpolation rate, 40, we see that it is 2 * 2 * 2 * 5.  We can likewise factor the decimation rate to 3 * 3 * 7 * 7.  One simple way to do the resampling, then, would be to do it in four steps like so:

$44100 Hz * \frac{2}{3} * \frac{2}{3} * \frac{2}{7} * \frac{5}{7}$

If you are trying to minimize the computational load you could rearrange the order of the resampling to reduce the sample rate as quickly as possible.  That would make the later resampling steps less computationally intensive because they don't have to work on as many samples.

$44100 Hz * \frac{2}{7} * \frac{2}{3} * \frac{2}{3} * \frac{5}{7}$

You could also combine the two $\frac{2}{3}$ resamples because their product, $\frac{4}{9}$, does not have any large numbers.  That leaves us with the following-

$44100 Hz * \frac{2}{7} * \frac{4}{9} * \frac{5}{7}$