The frequency is controlled by the source. For a wave that travels from one medium into another, the wave will either speed up or slow down due to the change in the characteristics of the medium that it is traveling in, and the wavelength of the wave will change, according to the equation $v=f\lambda$. This means that wave velocity changes, and wavelength changes, such that the frequency remains constant.
As a thought experiment, imagine that you are shaking a rope up and down at a frequency of your choice. The rope that you are shaking is tied to a thinner rope 3 meters from your hand, and due to this, the smaller rope transmits the wave at a higher velocity than the rope that you have in your hand. When the waves that you are creating get to the smaller rope, they speed up and the wavelength gets longer, but the smaller rope STILL has to move up and down at the frequency that you are shaking the rope in your hand.