Amuse
BooBackend.hpp
1 #ifndef __AMUSE_BOO_BACKEND_HPP__
2 #define __AMUSE_BOO_BACKEND_HPP__
3 
4 #include <boo/audiodev/IAudioVoiceEngine.hpp>
5 #include <boo/audiodev/IAudioSubmix.hpp>
6 #include "IBackendVoice.hpp"
7 #include "IBackendSubmix.hpp"
8 #include "IBackendVoiceAllocator.hpp"
9 
10 namespace amuse
11 {
12 
15 {
16  friend class BooBackendVoiceAllocator;
17  Voice& m_clientVox;
18  struct VoiceCallback : boo::IAudioVoiceCallback
19  {
20  BooBackendVoice& m_parent;
21  size_t supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t* data);
22  VoiceCallback(BooBackendVoice& parent) : m_parent(parent) {}
23  } m_cb;
24  std::unique_ptr<boo::IAudioVoice> m_booVoice;
25 public:
26  BooBackendVoice(boo::IAudioVoiceEngine& engine, Voice& clientVox,
27  double sampleRate, bool dynamicPitch);
28  BooBackendVoice(boo::IAudioSubmix& submix, Voice& clientVox,
29  double sampleRate, bool dynamicPitch);
30  void resetSampleRate(double sampleRate);
31  void setMatrixCoefficients(const float coefs[8]);
32  void setPitchRatio(double ratio, bool slew);
33  void start();
34  void stop();
35 };
36 
39 {
40  friend class BooBackendVoiceAllocator;
41  Submix& m_clientSmx;
42  struct SubmixCallback : boo::IAudioSubmixCallback
43  {
44  BooBackendSubmix& m_parent;
45  bool canApplyEffect() const;
46  void applyEffect(int16_t* audio, size_t frameCount,
47  const boo::ChannelMap& chanMap, double sampleRate) const;
48  void applyEffect(int32_t* audio, size_t frameCount,
49  const boo::ChannelMap& chanMap, double sampleRate) const;
50  void applyEffect(float* audio, size_t frameCount,
51  const boo::ChannelMap& chanMap, double sampleRate) const;
52  SubmixCallback(BooBackendSubmix& parent) : m_parent(parent) {}
53  } m_cb;
54  std::unique_ptr<boo::IAudioSubmix> m_booSubmix;
55 public:
56  BooBackendSubmix(boo::IAudioVoiceEngine& engine, Submix& clientSmx);
57  BooBackendSubmix(boo::IAudioSubmix& parent, Submix& clientSmx);
58  void setChannelGains(const float gains[8]);
59  std::unique_ptr<IBackendVoice> allocateVoice(Voice& clientVox, double sampleRate, bool dynamicPitch);
60  double getSampleRate() const;
61  SubmixFormat getSampleFormat() const;
62 };
63 
66 {
67  boo::IAudioVoiceEngine& m_booEngine;
68 public:
69  BooBackendVoiceAllocator(boo::IAudioVoiceEngine& booEngine);
70  std::unique_ptr<IBackendVoice> allocateVoice(Voice& clientVox, double sampleRate, bool dynamicPitch);
71  std::unique_ptr<IBackendSubmix> allocateSubmix(Submix& clientSmx);
72  AudioChannelSet getAvailableSet();
73  void pumpAndMixVoices();
74 };
75 
76 }
77 
78 #endif // __AMUSE_BOO_BACKEND_HPP__
void resetSampleRate(double sampleRate)
void setMatrixCoefficients(const float coefs[8])
void setPitchRatio(double ratio, bool slew)