| 28 | } |
| 29 | |
| 30 | void EqualPowerPanner::pan(ContextRenderLock & r, |
| 31 | double azimuth, double elevation, |
| 32 | const AudioBus& inputBus, AudioBus& outputBus, |
| 33 | int busOffset, |
| 34 | int framesToProcess) |
| 35 | { |
| 36 | m_smoothingConstant = AudioUtilities::discreteTimeConstantForSampleRate(SmoothingTimeConstant, r.context()->sampleRate()); |
| 37 | |
| 38 | bool isInputSafe = (inputBus.numberOfChannels() == Channels::Mono || |
| 39 | inputBus.numberOfChannels() == Channels::Stereo) && |
| 40 | (framesToProcess + busOffset) <= inputBus.length(); |
| 41 | ASSERT(isInputSafe); |
| 42 | if (!isInputSafe) |
| 43 | return; |
| 44 | |
| 45 | unsigned numberOfInputChannels = inputBus.numberOfChannels(); |
| 46 | |
| 47 | bool isOutputSafe = outputBus.numberOfChannels() == Channels::Stereo && |
| 48 | (framesToProcess + busOffset) <= outputBus.length(); |
| 49 | ASSERT(isOutputSafe); |
| 50 | if (!isOutputSafe) |
| 51 | return; |
| 52 | |
| 53 | const float * sourceL = inputBus.channelByType(Channel::Left)->data(); |
| 54 | const float * sourceR = numberOfInputChannels > 1 ? |
| 55 | inputBus.channelByType(Channel::Right)->data() : sourceL; |
| 56 | float * destinationL = outputBus.channelByType(Channel::Left)->mutableData(); |
| 57 | float * destinationR = outputBus.channelByType(Channel::Right)->mutableData(); |
| 58 | |
| 59 | if (!sourceL || !sourceR || !destinationL || !destinationR) |
| 60 | return; |
| 61 | |
| 62 | sourceL += busOffset; |
| 63 | sourceR += busOffset; |
| 64 | destinationL += busOffset; |
| 65 | destinationR += busOffset; |
| 66 | |
| 67 | // Clamp azimuth to allowed range of -180 -> +180. |
| 68 | azimuth = max(-180.0, azimuth); |
| 69 | azimuth = min(180.0, azimuth); |
| 70 | |
| 71 | // Alias the azimuth ranges behind us to in front of us: |
| 72 | // -90 -> -180 to -90 -> 0 and 90 -> 180 to 90 -> 0 |
| 73 | if (azimuth < -90) |
| 74 | azimuth = -180 - azimuth; |
| 75 | else if (azimuth > 90) |
| 76 | azimuth = 180 - azimuth; |
| 77 | |
| 78 | double desiredPanPosition; |
| 79 | double desiredGainL; |
| 80 | double desiredGainR; |
| 81 | |
| 82 | if (numberOfInputChannels == 1) |
| 83 | { // For mono source case. |
| 84 | // Pan smoothly from left to right with azimuth going from -90 -> +90 degrees. |
| 85 | desiredPanPosition = (azimuth + 90) / 180; |
| 86 | } |
| 87 | else |
nothing calls this directly
no test coverage detected