Most of the time a ground loop is the cause of this problem. This problem is common especially if your stereos speakers are amplified, and can be fixed my making sure that your stereo unit and/or amplifier have a good ground connection. This can be done by either finding a more direct ground connection to the cars frame, sanding the area around your ground connection to remove any rust or paint that could be adding grounding resistance, or even running a ground wire from your stereo or amp directly to your battery.
In fact, it is most likely that you are constantly experiencing the whining sound. With the engine idling if you put your ear up to the speaker you will probably hear the sound, it just doesn't become noticeable until higher revs.