mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-18 01:15:26 +00:00
Overhauled audio system, now with internal mixing and sample-rate-conversion
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
#ifndef BOO_AUDIOMATRIX_HPP
|
||||
#define BOO_AUDIOMATRIX_HPP
|
||||
|
||||
#include "IAudioVoice.hpp"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class AudioMatrixMono
|
||||
{
|
||||
AudioChannelSet m_setOut = AudioChannelSet::Stereo;
|
||||
float m_coefs[8];
|
||||
std::vector<int16_t> m_interleaveBuf;
|
||||
public:
|
||||
AudioMatrixMono() {setDefaultMatrixCoefficients();}
|
||||
|
||||
AudioChannelSet audioChannelSet() const {return m_setOut;}
|
||||
void setAudioChannelSet(AudioChannelSet set) {m_setOut = set;}
|
||||
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 = AudioChannelSet::Stereo;
|
||||
float m_coefs[8][2];
|
||||
std::vector<int16_t> m_interleaveBuf;
|
||||
public:
|
||||
AudioMatrixStereo() {setDefaultMatrixCoefficients();}
|
||||
|
||||
AudioChannelSet audioChannelSet() const {return m_setOut;}
|
||||
void setAudioChannelSet(AudioChannelSet set) {m_setOut = set;}
|
||||
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
|
||||
@@ -56,18 +56,33 @@ struct IAudioVoice
|
||||
{
|
||||
virtual ~IAudioVoice() = default;
|
||||
|
||||
/** Get voice's actual channel-map based on client request and HW capabilities */
|
||||
virtual const ChannelMap& channelMap() const=0;
|
||||
/** Reset channel-gains to voice defaults */
|
||||
virtual void setDefaultMatrixCoefficients()=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;
|
||||
/** Set channel-gains for mono audio source (AudioChannel enum for array index) */
|
||||
virtual void setMonoMatrixCoefficients(const float coefs[8])=0;
|
||||
|
||||
/** Set channel-gains for stereo audio source (AudioChannel enum for array index) */
|
||||
virtual void setStereoMatrixCoefficients(const float coefs[8][2])=0;
|
||||
|
||||
/** Called by client to dynamically adjust the pitch of voices with dynamic pitch enabled */
|
||||
virtual void setPitchRatio(double ratio)=0;
|
||||
|
||||
/** Instructs platform to begin consuming sample data; invoking callback as needed */
|
||||
virtual void start()=0;
|
||||
|
||||
/** Instructs platform to stop consuming sample data */
|
||||
virtual void stop()=0;
|
||||
|
||||
/** Invalidates this voice by removing it from the AudioVoiceEngine */
|
||||
virtual void unbindVoice()=0;
|
||||
};
|
||||
|
||||
struct IAudioVoiceCallback
|
||||
{
|
||||
/** boo calls this on behalf of the audio platform to request more audio
|
||||
* frames from the client */
|
||||
virtual size_t supplyAudio(IAudioVoice& voice, size_t frames, int16_t* data)=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#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
|
||||
{
|
||||
virtual ~IAudioVoiceAllocator() = default;
|
||||
|
||||
/** 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.
|
||||
*
|
||||
* Client must be prepared to supply audio frames via the callback when this is called;
|
||||
* the backing audio-buffers are primed with initial data for low-latency playback start */
|
||||
virtual std::unique_ptr<IAudioVoice> allocateNewVoice(AudioChannelSet layoutOut,
|
||||
unsigned sampleRate,
|
||||
IAudioVoiceCallback* cb)=0;
|
||||
|
||||
/** Client may use this to determine current speaker-setup */
|
||||
virtual AudioChannelSet getAvailableSet()=0;
|
||||
|
||||
/** Ensure all voices' platform buffers are filled as much as possible */
|
||||
virtual void pumpVoices()=0;
|
||||
};
|
||||
|
||||
/** Obtain host platform's voice allocator */
|
||||
std::unique_ptr<IAudioVoiceAllocator> NewAudioVoiceAllocator();
|
||||
|
||||
}
|
||||
|
||||
#endif // BOO_IAUDIOVOICEALLOCATOR_HPP
|
||||
43
include/boo/audiodev/IAudioVoiceEngine.hpp
Normal file
43
include/boo/audiodev/IAudioVoiceEngine.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef BOO_IAUDIOVOICEENGINE_HPP
|
||||
#define BOO_IAUDIOVOICEENGINE_HPP
|
||||
|
||||
#include "IAudioVoice.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
/** Mixing and sample-rate-conversion system. Allocates voices and mixes them
|
||||
* before sending the final samples to an OS-supplied audio-queue */
|
||||
struct IAudioVoiceEngine
|
||||
{
|
||||
virtual ~IAudioVoiceEngine() = default;
|
||||
|
||||
/** 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.
|
||||
*
|
||||
* Client must be prepared to supply audio frames via the callback when this is called;
|
||||
* the backing audio-buffers are primed with initial data for low-latency playback start */
|
||||
virtual std::unique_ptr<IAudioVoice> allocateNewMonoVoice(double sampleRate,
|
||||
IAudioVoiceCallback* cb,
|
||||
bool dynamicPitch=false)=0;
|
||||
|
||||
/** Same as allocateNewMonoVoice, but source audio is stereo-interleaved */
|
||||
virtual std::unique_ptr<IAudioVoice> allocateNewStereoVoice(double sampleRate,
|
||||
IAudioVoiceCallback* cb,
|
||||
bool dynamicPitch=false)=0;
|
||||
|
||||
/** Client may use this to determine current speaker-setup */
|
||||
virtual AudioChannelSet getAvailableSet()=0;
|
||||
|
||||
/** Ensure backing platform buffer is filled as much as possible with mixed samples */
|
||||
virtual void pumpAndMixVoices()=0;
|
||||
};
|
||||
|
||||
/** Construct host platform's voice engine */
|
||||
std::unique_ptr<IAudioVoiceEngine> NewAudioVoiceEngine();
|
||||
|
||||
}
|
||||
|
||||
#endif // BOO_IAUDIOVOICEENGINE_HPP
|
||||
Reference in New Issue
Block a user