mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-16 16:37:20 +00:00
Initial audio interface classes
This commit is contained in:
56
include/boo/audiodev/AudioMatrix.hpp
Normal file
56
include/boo/audiodev/AudioMatrix.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef BOO_AUDIOMATRIX_HPP
|
||||
#define BOO_AUDIOMATRIX_HPP
|
||||
|
||||
#include "IAudioVoice.hpp"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class AudioMatrixMono
|
||||
{
|
||||
AudioChannelSet m_setOut;
|
||||
float m_coefs[8];
|
||||
std::vector<int16_t> m_interleaveBuf;
|
||||
public:
|
||||
AudioMatrixMono(AudioChannelSet setOut)
|
||||
: m_setOut(setOut) {setDefaultMatrixCoefficients();}
|
||||
|
||||
AudioChannelSet setOut() const {return m_setOut;}
|
||||
void setDefaultMatrixCoefficients();
|
||||
void setMatrixCoefficients(const float coefs[8])
|
||||
{
|
||||
for (int i=0 ; i<8 ; ++i)
|
||||
m_coefs[i] = coefs[i];
|
||||
}
|
||||
|
||||
void bufferMonoSampleData(IAudioVoice& voice, const int16_t* data, size_t samples);
|
||||
};
|
||||
|
||||
class AudioMatrixStereo
|
||||
{
|
||||
AudioChannelSet m_setOut;
|
||||
float m_coefs[8][2];
|
||||
std::vector<int16_t> m_interleaveBuf;
|
||||
public:
|
||||
AudioMatrixStereo(AudioChannelSet setOut)
|
||||
: m_setOut(setOut) {setDefaultMatrixCoefficients();}
|
||||
|
||||
AudioChannelSet setOut() const {return m_setOut;}
|
||||
void setDefaultMatrixCoefficients();
|
||||
void setMatrixCoefficients(const float coefs[8][2])
|
||||
{
|
||||
for (int i=0 ; i<8 ; ++i)
|
||||
{
|
||||
m_coefs[i][0] = coefs[i][0];
|
||||
m_coefs[i][1] = coefs[i][1];
|
||||
}
|
||||
}
|
||||
|
||||
void bufferStereoSampleData(IAudioVoice& voice, const int16_t* data, size_t frames);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BOO_AUDIOMATRIX_HPP
|
||||
64
include/boo/audiodev/IAudioVoice.hpp
Normal file
64
include/boo/audiodev/IAudioVoice.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef BOO_IAUDIOVOICE_HPP
|
||||
#define BOO_IAUDIOVOICE_HPP
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
enum class AudioChannelSet
|
||||
{
|
||||
Stereo,
|
||||
Quad,
|
||||
Surround51,
|
||||
Surround71
|
||||
};
|
||||
|
||||
enum class AudioChannel
|
||||
{
|
||||
FrontLeft,
|
||||
FrontRight,
|
||||
RearLeft,
|
||||
RearRight,
|
||||
FrontCenter,
|
||||
LFE,
|
||||
SideLeft,
|
||||
SideRight
|
||||
};
|
||||
|
||||
struct ChannelMap
|
||||
{
|
||||
unsigned m_channelCount = 0;
|
||||
AudioChannel m_channels[8] = {};
|
||||
};
|
||||
|
||||
static inline unsigned ChannelCount(AudioChannelSet layout)
|
||||
{
|
||||
switch (layout)
|
||||
{
|
||||
case AudioChannelSet::Stereo:
|
||||
return 2;
|
||||
case AudioChannelSet::Quad:
|
||||
return 4;
|
||||
case AudioChannelSet::Surround51:
|
||||
return 6;
|
||||
case AudioChannelSet::Surround71:
|
||||
return 8;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct IAudioVoice
|
||||
{
|
||||
/** Get voice's actual channel-map based on client request and HW capabilities */
|
||||
virtual const ChannelMap& channelMap() const=0;
|
||||
|
||||
/** Called by client in response to IAudioVoiceCallback::needsNextBuffer()
|
||||
* Supplying channel-interleaved sample data */
|
||||
virtual void bufferSampleData(const int16_t* data, size_t frames)=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BOO_IAUDIOVOICE_HPP
|
||||
29
include/boo/audiodev/IAudioVoiceAllocator.hpp
Normal file
29
include/boo/audiodev/IAudioVoiceAllocator.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef BOO_IAUDIOVOICEALLOCATOR_HPP
|
||||
#define BOO_IAUDIOVOICEALLOCATOR_HPP
|
||||
|
||||
#include "IAudioVoice.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
struct IAudioVoiceCallback
|
||||
{
|
||||
/** Boo calls this on behalf of the audio platform to request more audio
|
||||
* frames from the client */
|
||||
virtual void needsNextBuffer(IAudioVoice* voice, size_t frames)=0;
|
||||
};
|
||||
|
||||
struct IAudioVoiceAllocator
|
||||
{
|
||||
/** Client calls this to request allocation of new mixer-voice.
|
||||
* Returns empty unique_ptr if necessary resources aren't available.
|
||||
* ChannelLayout automatically reduces to maximum-supported layout by HW. */
|
||||
virtual std::unique_ptr<IAudioVoice> allocateNewVoice(AudioChannelSet layoutOut,
|
||||
unsigned sampleRate,
|
||||
IAudioVoiceCallback* cb)=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BOO_IAUDIOVOICEALLOCATOR_HPP
|
||||
Reference in New Issue
Block a user