diff --git a/build/linux/platform_specific_code/juce_linux_Audio.cpp b/build/linux/platform_specific_code/juce_linux_Audio.cpp index 68991865c1..3bc69fa3fd 100644 --- a/build/linux/platform_specific_code/juce_linux_Audio.cpp +++ b/build/linux/platform_specific_code/juce_linux_Audio.cpp @@ -814,8 +814,7 @@ public: internal->setCallback (callback); if (callback != 0) - callback->audioDeviceAboutToStart (internal->sampleRate, - internal->bufferSize); + callback->audioDeviceAboutToStart (this); isStarted = (callback != 0); } diff --git a/build/macosx/platform_specific_code/juce_mac_CoreAudio.cpp b/build/macosx/platform_specific_code/juce_mac_CoreAudio.cpp index 8524fe544c..22e1190198 100644 --- a/build/macosx/platform_specific_code/juce_mac_CoreAudio.cpp +++ b/build/macosx/platform_specific_code/juce_mac_CoreAudio.cpp @@ -1001,8 +1001,7 @@ public: if (internal != 0 && ! isStarted) { if (callback != 0) - callback->audioDeviceAboutToStart (getCurrentSampleRate(), - getCurrentBufferSizeSamples()); + callback->audioDeviceAboutToStart (this); isStarted = true; internal->start (callback); diff --git a/build/win32/platform_specific_code/juce_win32_ASIO.cpp b/build/win32/platform_specific_code/juce_win32_ASIO.cpp index 891aaef72a..39d4e5ebce 100644 --- a/build/win32/platform_specific_code/juce_win32_ASIO.cpp +++ b/build/win32/platform_specific_code/juce_win32_ASIO.cpp @@ -763,7 +763,7 @@ public: { if (callback != 0) { - callback->audioDeviceAboutToStart (currentSampleRate, currentBlockSizeSamples); + callback->audioDeviceAboutToStart (this); const ScopedLock sl (callbackLock); currentCallback = callback; diff --git a/build/win32/platform_specific_code/juce_win32_DirectSound.cpp b/build/win32/platform_specific_code/juce_win32_DirectSound.cpp index ea235c9ebc..b12015104d 100644 --- a/build/win32/platform_specific_code/juce_win32_DirectSound.cpp +++ b/build/win32/platform_specific_code/juce_win32_DirectSound.cpp @@ -1162,7 +1162,7 @@ public: return; } - call->audioDeviceAboutToStart (sampleRate, bufferSizeSamples); + call->audioDeviceAboutToStart (this); const ScopedLock sl (startStopLock); callback = call; diff --git a/src/juce_appframework/audio/devices/juce_AudioDeviceManager.cpp b/src/juce_appframework/audio/devices/juce_AudioDeviceManager.cpp index bfb92e50bb..e0fdf6d565 100644 --- a/src/juce_appframework/audio/devices/juce_AudioDeviceManager.cpp +++ b/src/juce_appframework/audio/devices/juce_AudioDeviceManager.cpp @@ -414,8 +414,7 @@ void AudioDeviceManager::setAudioCallback (AudioIODeviceCallback* newCallback) lastCallback->audioDeviceStopped(); if (newCallback != 0) - newCallback->audioDeviceAboutToStart (currentAudioDevice->getCurrentSampleRate(), - currentAudioDevice->getCurrentBufferSizeSamples()); + newCallback->audioDeviceAboutToStart (currentAudioDevice); } currentCallback = newCallback; @@ -446,10 +445,13 @@ void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelDat } } -void AudioDeviceManager::audioDeviceAboutToStartInt (double sampleRate, int blockSize) +void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device) { cpuUsageMs = 0; + const double sampleRate = device->getCurrentSampleRate(); + const int blockSize = device->getCurrentBufferSizeSamples(); + if (sampleRate > 0.0 && blockSize > 0) { const double msPerBlock = 1000.0 * blockSize / sampleRate; @@ -457,7 +459,7 @@ void AudioDeviceManager::audioDeviceAboutToStartInt (double sampleRate, int bloc } if (currentCallback != 0) - currentCallback->audioDeviceAboutToStart (sampleRate, blockSize); + currentCallback->audioDeviceAboutToStart (device); sendChangeMessage (this); } @@ -603,9 +605,9 @@ void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** i owner->audioDeviceIOCallbackInt (inputChannelData, totalNumInputChannels, outputChannelData, totalNumOutputChannels, numSamples); } -void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (double sampleRate, int blockSize) +void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device) { - owner->audioDeviceAboutToStartInt (sampleRate, blockSize); + owner->audioDeviceAboutToStartInt (device); } void AudioDeviceManager::CallbackHandler::audioDeviceStopped() diff --git a/src/juce_appframework/audio/devices/juce_AudioDeviceManager.h b/src/juce_appframework/audio/devices/juce_AudioDeviceManager.h index c8f702c9f9..0655083503 100644 --- a/src/juce_appframework/audio/devices/juce_AudioDeviceManager.h +++ b/src/juce_appframework/audio/devices/juce_AudioDeviceManager.h @@ -369,7 +369,7 @@ private: int totalNumOutputChannels, int numSamples); - void audioDeviceAboutToStart (double sampleRate, int blockSize); + void audioDeviceAboutToStart (AudioIODevice*); void audioDeviceStopped(); @@ -385,7 +385,7 @@ private: float** outputChannelData, int totalNumOutputChannels, int numSamples); - void audioDeviceAboutToStartInt (double sampleRate, int blockSize); + void audioDeviceAboutToStartInt (AudioIODevice* const device); void audioDeviceStoppedInt(); void handleIncomingMidiMessageInt (MidiInput* source, const MidiMessage& message); diff --git a/src/juce_appframework/audio/devices/juce_AudioIODevice.h b/src/juce_appframework/audio/devices/juce_AudioIODevice.h index 5f418c1e0a..76fd51139a 100644 --- a/src/juce_appframework/audio/devices/juce_AudioIODevice.h +++ b/src/juce_appframework/audio/devices/juce_AudioIODevice.h @@ -35,6 +35,7 @@ #include "../../../juce_core/text/juce_StringArray.h" #include "../../../juce_core/containers/juce_BitArray.h" #include "../../../juce_core/containers/juce_OwnedArray.h" +class AudioIODevice; //============================================================================== @@ -103,13 +104,15 @@ public: callback has just been added to an audio device, or after the device has been restarted because of a sample-rate or block-size change. - @param sampleRate the sample rate it's going to use - @param numSamplesPerBlock the intended block size - this isn't a guaranteed - figure; see the notes about numSamples in the - audioDeviceIOCallback() method. + You can use this opportunity to find out the sample rate and block size + that the device is going to use by calling the AudioIODevice::getCurrentSampleRate() + and AudioIODevice::getCurrentBufferSizeSamples() on the supplied pointer. + + @param device the audio IO device that will be used to drive the callback. + Note that if you're going to store this this pointer, it is + only valid until the next time that audioDeviceStopped is called. */ - virtual void audioDeviceAboutToStart (double sampleRate, - int numSamplesPerBlock) = 0; + virtual void audioDeviceAboutToStart (AudioIODevice* device) = 0; /** Called to indicate that the device has stopped. */ diff --git a/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp b/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp index 7bfd53093b..8bc05d8420 100644 --- a/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp +++ b/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp @@ -316,7 +316,7 @@ void AudioSampleBuffer::addFrom (const int destChannel, int numSamples, const float gain) throw() { - jassert (&source != this); + jassert (&source != this || sourceChannel != destChannel); jassert (((unsigned int) destChannel) < (unsigned int) numChannels); jassert (destStartSample >= 0 && destStartSample + numSamples <= size); jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels); @@ -409,7 +409,7 @@ void AudioSampleBuffer::copyFrom (const int destChannel, const int sourceStartSample, int numSamples) throw() { - jassert (&source != this); + jassert (&source != this || sourceChannel != destChannel); jassert (((unsigned int) destChannel) < (unsigned int) numChannels); jassert (destStartSample >= 0 && destStartSample + numSamples <= size); jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels); diff --git a/src/juce_appframework/audio/midi/juce_MidiBuffer.cpp b/src/juce_appframework/audio/midi/juce_MidiBuffer.cpp index f93fdfbf74..fad79b3314 100644 --- a/src/juce_appframework/audio/midi/juce_MidiBuffer.cpp +++ b/src/juce_appframework/audio/midi/juce_MidiBuffer.cpp @@ -53,9 +53,14 @@ MidiBuffer::MidiBuffer (const MidiBuffer& other) throw() const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() { - bytesUsed = other.bytesUsed; - ensureAllocatedSize (bytesUsed); - memcpy (elements, other.elements, bytesUsed); + if (this != &other) + { + bytesUsed = other.bytesUsed; + ensureAllocatedSize (bytesUsed); + + if (bytesUsed > 0) + memcpy (elements, other.elements, bytesUsed); + } return *this; }