Difference between jpg compression and mp3 compression
Actually, it's kind of the other way around. If you reuse the same JPEG encoder at the same quality level (without any smoothing steps as built-in prepcosessing) and a decoder which faithfully decompresses the images, I expect the image quality not to degrade from generation to generation. This is because quantization (the lossy part) is done the same way during the 2nd compression. You can imagine scalar quantization like this: given some value v and a quantizer step s, the quantized value is round(v/s)*s. Example:

v = 6.3
s = 2
q = round(v/s)*s = 6


So, the first "compression" includes an error of 0.3 in this case. But if you feed this into the encoder a 2nd time

v = 6
s = 2
q = round(v/s)*s = 6


it does not change anymore. It stays 6. If you change the quality level from one compression to the next, you also change the quantizer step s. This would add a new rounding error.

Keep in mind that this is just a simple example. JPEG Quantization may include a "dead zone quantizer" which changes the threshold a bit near 0. For example, you might want to round any value v to zero in case |v|&lt;0.7. Something like this might give you a slightly higher quality-per-bit ratio because zeros can be much more compactly represented. But this should not change what I described above.

With MP3 the "quantization steps" are computed dynamically and depend on the actual signal. This is what the "psychoacoustic model" is for. It analyzes the audio data and tells us how strongly we can quantize certain portions of the signal without us noticing a difference. But this quantization adds "quantization noise" which could make the psychoacoustic model compute other quanzitation steps during the 2nd compression even in the case where you told the encoder to use the same "quality level". In the case the 2nd compression uses different quantization steps, you'll introduce new rounding errors.

Actually, something like this has been done before. Some artist did such an experiment where he compressed some audio file over and over again (like 1000 times) and the result had little to do with the original. Unfortunately, I don't remember any names or references.

There are other issues which make lossy audio compression more complicated. For example, a decoder might add or remove some leading samples (encoder+decoder delay mismatch) which would make the encoder work on different blocks for the 2nd pass. This would also add new rounding errors. But if I remember correctly, such a "block position mismatch" was shown to be beneficial w.r.t. generation loss by some experiments done by the Hydrogenaudio crowd a couple of years ago. So, while there was still a generation loss, the loss was less annoying than with matching block positions.