| 1 |
/* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 |
/* SPDX-FileCopyrightText: OpenMPT Project Developers and Contributors */ |
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include "openmpt/all/BuildSettings.hpp" |
| 8 |
|
| 9 |
#include "mpt/audio/span.hpp" |
| 10 |
#include "mpt/base/macros.hpp" |
| 11 |
#include "openmpt/soundbase/SampleConvert.hpp" |
| 12 |
|
| 13 |
#include <algorithm> |
| 14 |
|
| 15 |
#include <cassert> |
| 16 |
#include <cstddef> |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
OPENMPT_NAMESPACE_BEGIN |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
template <typename TBufOut, typename TBufIn> |
| 25 |
void CopyAudio(TBufOut buf_out, TBufIn buf_in) |
| 26 |
{ |
| 27 |
assert(buf_in.size_frames() == buf_out.size_frames()); |
| 28 |
assert(buf_in.size_channels() == buf_out.size_channels()); |
| 29 |
std::size_t countFrames = std::min(buf_in.size_frames(), buf_out.size_frames()); |
| 30 |
std::size_t channels = std::min(buf_in.size_channels(), buf_out.size_channels()); |
| 31 |
for(std::size_t frame = 0; frame < countFrames; ++frame) |
| 32 |
{ |
| 33 |
for(std::size_t channel = 0; channel < channels; ++channel) |
| 34 |
{ |
| 35 |
buf_out(channel, frame) = SC::sample_cast<typename TBufOut::sample_type>(buf_in(channel, frame)); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
template <typename TBufOut, typename TBufIn> |
| 42 |
void CopyAudio(TBufOut buf_out, TBufIn buf_in, std::size_t countFrames) |
| 43 |
{ |
| 44 |
assert(countFrames <= buf_in.size_frames()); |
| 45 |
assert(countFrames <= buf_out.size_frames()); |
| 46 |
assert(buf_in.size_channels() == buf_out.size_channels()); |
| 47 |
std::size_t channels = std::min(buf_in.size_channels(), buf_out.size_channels()); |
| 48 |
for(std::size_t frame = 0; frame < countFrames; ++frame) |
| 49 |
{ |
| 50 |
for(std::size_t channel = 0; channel < channels; ++channel) |
| 51 |
{ |
| 52 |
buf_out(channel, frame) = SC::sample_cast<typename TBufOut::sample_type>(buf_in(channel, frame)); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
template <typename TBufOut, typename TBufIn> |
| 59 |
void CopyAudioChannels(TBufOut buf_out, TBufIn buf_in, std::size_t channels, std::size_t countFrames) |
| 60 |
{ |
| 61 |
assert(countFrames <= buf_in.size_frames()); |
| 62 |
assert(countFrames <= buf_out.size_frames()); |
| 63 |
assert(channels <= buf_in.size_channels()); |
| 64 |
assert(channels <= buf_out.size_channels()); |
| 65 |
for(std::size_t frame = 0; frame < countFrames; ++frame) |
| 66 |
{ |
| 67 |
for(std::size_t channel = 0; channel < channels; ++channel) |
| 68 |
{ |
| 69 |
buf_out(channel, frame) = SC::sample_cast<typename TBufOut::sample_type>(buf_in(channel, frame)); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
// Copy numChannels interleaved sample streams. |
| 76 |
template <typename Tin, typename Tout> |
| 77 |
void CopyAudioChannelsInterleaved(Tout *MPT_RESTRICT outBuf, const Tin *MPT_RESTRICT inBuf, std::size_t numChannels, std::size_t countFrames) |
| 78 |
{ |
| 79 |
CopyAudio(mpt::audio_span_interleaved<Tout>(outBuf, numChannels, countFrames), mpt::audio_span_interleaved<const Tin>(inBuf, numChannels, countFrames)); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
OPENMPT_NAMESPACE_END |