It does not. It's linear in other cases too. Square wave can be approximated by pushing sinusoidal function to some transformation $g(f)$, like : $$y(t)=\tanh\left(k\sin\left(\omega t\right)\right) \tag 1$$ Triangle wave similarly can be achieved by filtering sinusoidal by: $$ y(t) = \arcsin(\sin(\omega t)) \tag 2 $$ Nor hiperbolic tangent, neither $\sin^{-1}$ are periodic functions, only $\sin()$ is, so in both cases $E= \hbar \omega$ linear relationship also holds as long as custom wave can be represented by sinusoidal function $g(f)$ transformations. In addition I believe that almost all "convoluted" signals can be decomposed into series of sinusoidal functions by Fourier transform. Also sometimes (usually ?), the REAL signal used in telecommunications and other areas, does not have well-defined "single frequency". Lets look at this type of signal : [![enter image description here][1]][1] It can be shown that it's addition of two sinusoidal waves, by using trigonometric identity we see that $$ \sin (\omega_1 t) + \sin (\omega_2 t) = 2 \sin \left( \frac{\omega_1+\omega_2}{2} t \right) \cos \left( \frac{\omega_1-\omega_2}{2}t \right) \tag 3$$ where in the right side of equation there's _beat_ and _modulation_ frequencies. Hence we can define separate beat and modulation quanta energies : $$ E= \hbar \frac{\omega_1 \pm \omega_2}{2} = \frac {E_1}{2} \pm \frac{E_2}{2} \tag 4$$ So it is seen that beat and modulation frequencies are linear combination of some base sinusoidal frequencies $\omega_1,\omega_2$ for whom linear combination of energies can also be stated. Overall conclusion is that Planck linear relation is very universal and fits to all signals, because they can be decomposed into summation of sinusoidal components or simply transforming sinusoidal functions. [1]: https://i.sstatic.net/RSI1P.png