| 172 | } |
| 173 | |
| 174 | float Scale::PitchToFreq(float pitch) |
| 175 | { |
| 176 | if (mIntonation == kIntonation_SclFile) |
| 177 | { |
| 178 | auto ip = (int)pitch + 128; |
| 179 | if (ip < 0 || ip > 256) |
| 180 | return 440; |
| 181 | |
| 182 | // Interpolate in log space |
| 183 | auto lt = mTuningTable[ip]; |
| 184 | auto nt = mTuningTable[ip + ((ip != 255) ? 1 : 0)]; |
| 185 | auto fp = (pitch + 128) - ip; |
| 186 | auto interplt = (1 - fp) * lt + fp * nt; |
| 187 | |
| 188 | // Then pow2 it and multiply by freq0 |
| 189 | return Pow2(interplt) * Tunings::MIDI_0_FREQ; |
| 190 | } |
| 191 | |
| 192 | if (mIntonation == kIntonation_Oddsound) |
| 193 | { |
| 194 | if (mOddsoundMTSClient && MTS_HasMaster(mOddsoundMTSClient)) |
| 195 | { |
| 196 | if (pitch < 0 || pitch > 127) |
| 197 | return Pow2((pitch - mReferencePitch) / mPitchesPerOctave) * mReferenceFreq; // Improve this obviously |
| 198 | else |
| 199 | return MTS_NoteToFrequency(mOddsoundMTSClient, (int)pitch, 0); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | return Pow2((pitch - mReferencePitch) / mPitchesPerOctave) * mReferenceFreq; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | switch (mIntonation) |
| 208 | { |
| 209 | case kIntonation_Equal: |
| 210 | return Pow2((pitch - mReferencePitch) / mPitchesPerOctave) * mReferenceFreq; |
| 211 | /*case kIntonation_Rational: |
| 212 | { |
| 213 | int referencePitch = ScaleRoot(); |
| 214 | do |
| 215 | { |
| 216 | referencePitch += mPitchesPerOctave; |
| 217 | }while (referencePitch < mReferencePitch && abs(referencePitch - mReferencePitch) > mPitchesPerOctave); |
| 218 | float referenceFreq = Pow2((referencePitch-mReferencePitch)/mPitchesPerOctave)*mReferenceFreq; |
| 219 | |
| 220 | int intPitch = (int)pitch; |
| 221 | float remainder = pitch - intPitch; |
| 222 | float ratio1 = RationalizeNumber(Pow2(float(intPitch-referencePitch)/mPitchesPerOctave)); |
| 223 | float ratio2 = RationalizeNumber(Pow2(float((intPitch+1)-referencePitch)/mPitchesPerOctave)); |
| 224 | return ofLerp(ratio1,ratio2,remainder)*referenceFreq; |
| 225 | }*/ |
| 226 | case kIntonation_Pythagorean: |
| 227 | case kIntonation_Just: |
| 228 | case kIntonation_Rational: |
| 229 | case kIntonation_Meantone: |
| 230 | { |
| 231 | int referencePitch = ScaleRoot(); |
no test coverage detected