File Resampler.h¶
File List > Amplitude > DSP > Resampler.h
Go to the documentation of this file
// Copyright (c) 2021-present Sparky Studios. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifndef _AM_DSP_RESAMPLER_H
#define _AM_DSP_RESAMPLER_H
#include <SparkyStudios/Audio/Amplitude/Core/Common.h>
#include <SparkyStudios/Audio/Amplitude/Sound/Sound.h>
namespace SparkyStudios::Audio::Amplitude
{
class Resampler;
class AM_API_PUBLIC ResamplerInstance
{
public:
ResamplerInstance() = default;
virtual ~ResamplerInstance() = default;
virtual void Initialize(AmUInt16 channelCount, AmUInt32 sampleRateIn, AmUInt32 sampleRateOut) = 0;
virtual bool Process(const AudioBuffer& input, AmUInt64& inputFrames, AudioBuffer& output, AmUInt64& outputFrames) = 0;
virtual void SetSampleRate(AmUInt32 sampleRateIn, AmUInt32 sampleRateOut) = 0;
[[nodiscard]] virtual AmUInt32 GetSampleRateIn() const = 0;
[[nodiscard]] virtual AmUInt32 GetSampleRateOut() const = 0;
[[nodiscard]] virtual AmUInt16 GetChannelCount() const = 0;
[[nodiscard]] virtual AmUInt64 GetRequiredInputFrames(AmUInt64 outputFrameCount) const = 0;
[[nodiscard]] virtual AmUInt64 GetExpectedOutputFrames(AmUInt64 inputFrameCount) const = 0;
[[nodiscard]] virtual AmUInt64 GetInputLatency() const = 0;
[[nodiscard]] virtual AmUInt64 GetOutputLatency() const = 0;
virtual void Reset() = 0;
virtual void Clear() = 0;
};
class AM_API_PUBLIC Resampler
{
public:
explicit Resampler(AmString name);
Resampler();
virtual ~Resampler();
virtual std::shared_ptr<ResamplerInstance> CreateInstance() = 0;
[[nodiscard]] const AmString& GetName() const;
static void Register(std::shared_ptr<Resampler> resampler);
static void Unregister(std::shared_ptr<const Resampler> resampler);
static std::shared_ptr<Resampler> Find(const AmString& name);
static std::shared_ptr<ResamplerInstance> Construct(const AmString& name);
static void LockRegistry();
static void UnlockRegistry();
static const std::map<AmString, std::shared_ptr<Resampler>>& GetRegistry();
protected:
AmString m_name;
};
} // namespace SparkyStudios::Audio::Amplitude
#endif // _AM_DSP_RESAMPLER_H