1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Changed the result of MidiMessage::getMidiNoteInHertz to correctly map midi 69 to 440Hz

This commit is contained in:
jules 2012-10-23 12:43:09 +01:00
parent 896e55ae27
commit 70257e902f
4 changed files with 11 additions and 17 deletions

View file

@ -951,8 +951,7 @@ String MidiMessage::getMidiNoteName (int note, bool useSharps, bool includeOctav
const double MidiMessage::getMidiNoteInHertz (int noteNumber, const double frequencyOfA) noexcept const double MidiMessage::getMidiNoteInHertz (int noteNumber, const double frequencyOfA) noexcept
{ {
noteNumber -= 12 * 6 + 9; // now 0 = A return frequencyOfA * pow (2.0, (noteNumber - 69) / 12.0);
return frequencyOfA * pow (2.0, noteNumber / 12.0);
} }
String MidiMessage::getGMInstrumentName (const int n) String MidiMessage::getGMInstrumentName (const int n)

View file

@ -918,7 +918,7 @@ void AudioDeviceManager::playTestSound()
AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength); AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
float* samples = newSound->getSampleData (0); float* samples = newSound->getSampleData (0);
const double frequency = MidiMessage::getMidiNoteInHertz (80); const double frequency = 440.0;
const float amplitude = 0.5f; const float amplitude = 0.5f;
const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency); const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);

View file

@ -23,7 +23,7 @@
============================================================================== ==============================================================================
*/ */
//==============================================================================
SamplerSound::SamplerSound (const String& name_, SamplerSound::SamplerSound (const String& name_,
AudioFormatReader& source, AudioFormatReader& source,
const BigInteger& midiNotes_, const BigInteger& midiNotes_,
@ -61,7 +61,6 @@ SamplerSound::~SamplerSound()
{ {
} }
//==============================================================================
bool SamplerSound::appliesToNote (const int midiNoteNumber) bool SamplerSound::appliesToNote (const int midiNoteNumber)
{ {
return midiNotes [midiNoteNumber]; return midiNotes [midiNoteNumber];
@ -72,7 +71,6 @@ bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
return true; return true;
} }
//============================================================================== //==============================================================================
SamplerVoice::SamplerVoice() SamplerVoice::SamplerVoice()
: pitchRatio (0.0), : pitchRatio (0.0),
@ -103,10 +101,8 @@ void SamplerVoice::startNote (const int midiNoteNumber,
if (sound != nullptr) if (sound != nullptr)
{ {
const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber); pitchRatio = pow (2.0, (midiNoteNumber - sound->midiRootNote) / 12.0)
const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote); * sound->sourceSampleRate / getSampleRate();
pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
sourceSamplePosition = 0.0; sourceSamplePosition = 0.0;
lgain = velocity; lgain = velocity;
@ -127,13 +123,9 @@ void SamplerVoice::startNote (const int midiNoteNumber,
} }
if (sound->releaseSamples > 0) if (sound->releaseSamples > 0)
{
releaseDelta = (float) (-pitchRatio / sound->releaseSamples); releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
}
else else
{
releaseDelta = 0.0f; releaseDelta = 0.0f;
}
} }
} }
@ -162,9 +154,7 @@ void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
//============================================================================== //==============================================================================
void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples) void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
{ {
const SamplerSound* const playingSound = static_cast <SamplerSound*> (getCurrentlyPlayingSound().get()); if (const SamplerSound* const playingSound = static_cast <SamplerSound*> (getCurrentlyPlayingSound().get()))
if (playingSound != nullptr)
{ {
const float* const inL = playingSound->data->getSampleData (0, 0); const float* const inL = playingSound->data->getSampleData (0, 0);
const float* const inR = playingSound->data->getNumChannels() > 1 const float* const inR = playingSound->data->getNumChannels() > 1

View file

@ -63,6 +63,11 @@ public:
*/ */
PluginDescription* getType (int index) const noexcept { return types [index]; } PluginDescription* getType (int index) const noexcept { return types [index]; }
/** Type iteration. */
PluginDescription** begin() const noexcept { return types.begin(); }
/** Type iteration. */
PluginDescription** end() const noexcept { return types.end(); }
/** Looks for a type in the list which comes from this file. */ /** Looks for a type in the list which comes from this file. */
PluginDescription* getTypeForFile (const String& fileOrIdentifier) const; PluginDescription* getTypeForFile (const String& fileOrIdentifier) const;