mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-08 21:05:34 +08:00
refactor: Rename BlackSound to swift::sound
This commit is contained in:
30
src/sound/sampleprovider/sawtoothgenerator.cpp
Normal file
30
src/sound/sampleprovider/sawtoothgenerator.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
#include "sawtoothgenerator.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace swift::sound::sample_provider
|
||||
{
|
||||
CSawToothGenerator::CSawToothGenerator(double frequency, QObject *parent) : ISampleProvider(parent),
|
||||
m_frequency(frequency)
|
||||
{
|
||||
this->setObjectName("CSawToothGenerator");
|
||||
}
|
||||
|
||||
int CSawToothGenerator::readSamples(QVector<float> &samples, qint64 count)
|
||||
{
|
||||
samples.clear();
|
||||
samples.fill(0, static_cast<int>(count));
|
||||
|
||||
for (int sampleCount = 0; sampleCount < count; sampleCount++)
|
||||
{
|
||||
double multiple = 2 * m_frequency / m_sampleRate;
|
||||
double sampleSaw = std::fmod((m_nSample * multiple), 2) - 1;
|
||||
double sampleValue = m_gain * sampleSaw;
|
||||
samples[sampleCount] = static_cast<float>(sampleValue);
|
||||
m_nSample++;
|
||||
}
|
||||
return static_cast<int>(count);
|
||||
}
|
||||
} // ns
|
||||
Reference in New Issue
Block a user