int QSoundManager::playWave(CWaveFile *waveFile, int iChannel, uint flags, CProximity &prox) { if (!waveFile || !waveFile->isLoaded()) return 0; prox._channelVolume = CLIP(prox._channelVolume, 0, 100); prox._balance = CLIP(prox._balance, -100, 100); int slotIndex = findFreeSlot(); if (slotIndex == -1) return -1; // Set the volume setChannelVolume(iChannel, prox._channelVolume, prox._channelMode); switch (prox._positioningMode) { case POSMODE_POLAR: qsWaveMixSetPolarPosition(iChannel, 8, QSPOLAR(prox._azimuth, prox._range, prox._elevation)); qsWaveMixEnableChannel(iChannel, QMIX_CHANNEL_ELEVATION, true); qsWaveMixSetDistanceMapping(iChannel, 8, QMIX_DISTANCES(5.0, 3.0, 1.0)); break; case POSMODE_VECTOR: qsWaveMixSetSourcePosition(iChannel, 8, QSVECTOR(prox._posX, prox._posY, prox._posZ)); qsWaveMixEnableChannel(iChannel, QMIX_CHANNEL_ELEVATION, true); qsWaveMixSetDistanceMapping(iChannel, 8, QMIX_DISTANCES(5.0, 3.0, 1.0)); break; default: qsWaveMixEnableChannel(iChannel, QMIX_CHANNEL_ELEVATION, true); qsWaveMixSetPolarPosition(iChannel, 8, QSPOLAR(0.0, 1.0, 0.0)); break; } if (prox._frequencyMultiplier || prox._frequencyAdjust != 1.875) { uint freq = (uint)(waveFile->getFrequency() * prox._frequencyMultiplier); qsWaveMixSetFrequency(iChannel, 8, freq); } _sounds.add(waveFile, iChannel, prox._endTalkerFn, prox._talker); QMIXPLAYPARAMS playParams; playParams.callback = soundFinished; playParams.dwUser = this; if (!qsWaveMixPlayEx(iChannel, flags, waveFile, prox._repeated ? -1 : 0, playParams)) { Slot &slot = _slots[slotIndex]; slot._handle = _handleCtr++; slot._channel = iChannel; slot._waveFile = waveFile; slot._positioningMode = prox._positioningMode; return slot._handle; } else { _sounds.flushChannel(waveFile, iChannel); if (prox._disposeAfterUse == DisposeAfterUse::YES) delete waveFile; return 0; } }
void QSoundManager::setVectorPosition(int handle, double x, double y, double z, uint panRate) { for (uint idx = 0; idx < _slots.size(); ++idx) { Slot &slot = _slots[idx]; if (slot._handle == handle) { qsWaveMixSetPanRate(slot._channel, QMIX_USEONCE, panRate); qsWaveMixSetSourcePosition(slot._channel, QMIX_USEONCE, QSVECTOR(x, y, z)); break; } } }