hexagon5un / AVR-Programming

Code examples for the book "Make: AVR Programming"
http://littlehacks.org/AVR-Programming
MIT License
744 stars 340 forks source link

In organ.c, the variable "wavelength" should called "period" or "timePeriod" #18

Closed aaron-scher closed 8 years ago

aaron-scher commented 8 years ago

In the file organ.c in Chapter05_Serial-IO, there is a variable called wavelength that is the reciprocal of frequency. However, in every day usage, "wavelength" refers to the the distance between successive crests of a wave (wavelength = v/f, where v is the velocity and f is the frequency), and therefore wavelength is not equal to the reciprocal of frequency. On the other hand, the "period" of a wave is equal to the reciprocal of the frequency: T = 1/f.

Therefore, to increase code readability, in organ.c, the variable "wavelength" should called "period" or "timePeriod".

rithma commented 8 years ago

As a sound engineer by trade, I agree that 'wavelength' was a bit confusing at first. At the same time, however, a term like 'period' might seem discouraging to the music production kids.
How about "frequency"? Its a comfortable word, and I believe correct by definition?

/Etienne

aaron-scher commented 8 years ago

Hi rithma, I appreciate your input on this manner. My issue with using "frequency" is that this variable we are talking about is not frequency, it is the inverse of frequency 1/f. That is why I suggested using "period", since the period T = 1/f in engineering.

rithma commented 8 years ago

I see. Since the c function determines the duration of each cycle, 'period' would be a good name.

I need to stop thinking in Layman's terms, now that I'm learning code....

hexagon5un commented 8 years ago

aararonsky, you're totally right. (And since I wrote the code a few years ago, I have no idea why I chose wavelength over period -- it's not like I don't know the difference...)

If it's confusing for someone, it's worth changing. I'll do that right away.

hexagon5un commented 8 years ago

... and done! Thanks again.