| 2019 | } |
| 2020 | |
| 2021 | void ModularSynth::AudioOut(float* const* output, int bufferSize, int nChannels) |
| 2022 | { |
| 2023 | PROFILER(audioOut_total); |
| 2024 | |
| 2025 | sAudioThreadId = std::this_thread::get_id(); |
| 2026 | |
| 2027 | static bool sFirst = true; |
| 2028 | if (sFirst) |
| 2029 | { |
| 2030 | FloatVectorOperations::disableDenormalisedNumberSupport(); |
| 2031 | sFirst = false; |
| 2032 | } |
| 2033 | |
| 2034 | if (mAudioPaused) |
| 2035 | { |
| 2036 | for (int ch = 0; ch < nChannels; ++ch) |
| 2037 | { |
| 2038 | for (int i = 0; i < bufferSize; ++i) |
| 2039 | output[ch][i] = 0; |
| 2040 | } |
| 2041 | return; |
| 2042 | } |
| 2043 | |
| 2044 | ScopedMutex mutex(&mAudioThreadMutex, "audioOut()"); |
| 2045 | |
| 2046 | /////////// AUDIO PROCESSING STARTS HERE ///////////// |
| 2047 | mNoteOutputQueue->Process(); |
| 2048 | |
| 2049 | int oversampling = UserPrefs.oversampling.Get(); |
| 2050 | |
| 2051 | assert(bufferSize * oversampling == mIOBufferSize); |
| 2052 | assert(nChannels == (int)mOutputBuffers.size()); |
| 2053 | assert(mIOBufferSize == gBufferSize); //need to be the same for now |
| 2054 | //if we want these different, need to fix outBuffer here, and also fix audioIn() |
| 2055 | //by now, many assumptions will have to be fixed to support mIOBufferSize and gBufferSize diverging |
| 2056 | for (int ioOffset = 0; ioOffset < mIOBufferSize; ioOffset += gBufferSize) |
| 2057 | { |
| 2058 | for (size_t i = 0; i < mOutputBuffers.size(); ++i) |
| 2059 | Clear(mOutputBuffers[i], mIOBufferSize); |
| 2060 | |
| 2061 | double elapsed = gInvSampleRateMs * mIOBufferSize; |
| 2062 | gTime += elapsed; |
| 2063 | TheTransport->Advance(elapsed); |
| 2064 | |
| 2065 | //process all audio |
| 2066 | for (int i = 0; i < mSources.size(); ++i) |
| 2067 | mSources[i]->Process(gTime); |
| 2068 | |
| 2069 | if (gTime - mLastClapboardTime < 100) |
| 2070 | { |
| 2071 | for (int ch = 0; ch < nChannels; ++ch) |
| 2072 | { |
| 2073 | for (int i = 0; i < bufferSize; ++i) |
| 2074 | { |
| 2075 | float sample = sin(GetPhaseInc(440) * i) * (1 - ((gTime - mLastClapboardTime) / 100)); |
| 2076 | output[ch][i] = sample; |
| 2077 | } |
| 2078 | } |
no test coverage detected