Skip to content

Commit 220d66c

Browse files
committed
Smoke test
1 parent 6f16c8e commit 220d66c

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

include/AudioPortAudio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class AudioPortAudio : public AudioDevice
8787
PaStream* m_paStream = nullptr;
8888
std::vector<SampleFrame> m_outBuf;
8989
std::size_t m_outBufPos = 0;
90+
double m_phase = 0.;
9091
};
9192
} // namespace lmms
9293

src/core/audio/AudioPortAudio.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,26 @@ int AudioPortAudio::processCallback(const void*, void* output, unsigned long fra
188188
const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void* userData)
189189
{
190190
const auto device = static_cast<AudioPortAudio*>(userData);
191-
192191
const auto outputBuffer = static_cast<float*>(output);
192+
193+
const float frequency = 440.0f;
194+
const float sampleRate = 44100.0f;
195+
const float amplitude = 0.2f;
196+
193197
for (auto frame = std::size_t{0}; frame < frameCount; ++frame)
194198
{
195-
if (device->m_outBufPos == 0 && device->getNextBuffer(device->m_outBuf.data()) == 0)
196-
{
197-
std::fill(outputBuffer + frame * device->channels(), outputBuffer + frameCount * device->channels(), 0.f);
198-
return paComplete;
199-
}
199+
float sample = amplitude * std::sin(device->m_phase);
200200

201-
if (device->channels() == 1)
202-
{
203-
outputBuffer[frame] = device->m_outBuf[device->m_outBufPos].average();
204-
}
201+
if (device->channels() == 1) { outputBuffer[frame] = sample; }
205202
else
206203
{
207-
outputBuffer[frame * device->channels()] = device->m_outBuf[device->m_outBufPos][0];
208-
outputBuffer[frame * device->channels() + 1] = device->m_outBuf[device->m_outBufPos][1];
204+
outputBuffer[frame * 2] = sample;
205+
outputBuffer[frame * 2 + 1] = sample;
209206
}
210207

211-
device->m_outBufPos = (device->m_outBufPos + 1) % device->m_outBuf.size();
208+
device->m_phase += (2.0f * M_PI * frequency) / sampleRate;
209+
210+
if (device->m_phase >= 2.0f * M_PI) { device->m_phase -= 2.0f * M_PI; }
212211
}
213212

214213
return paContinue;

0 commit comments

Comments
 (0)