Beatmup
SLESPlayback::SLESBackend Class Reference

Public Member Functions

 SLESBackend ()
 
 ~SLESBackend ()
 
void initialize (Audio::AbstractPlayback::Mode mode, Audio::BasicRealtimePlayback &playback)
 
void start ()
 
void stop ()
 
void pushBuffer (sample8 *buffa)
 

Private Attributes

SLEngineItf engine
 
SLObjectItf engineObj
 
SLObjectItf outputMixObj
 
SLObjectItf playerObj
 
SLPlayItf playbackObj
 
SLAndroidSimpleBufferQueueItf bufferQueueObj
 
msize bufferSize
 

Detailed Description

Definition at line 47 of file sles_playback.cpp.

Constructor & Destructor Documentation

◆ SLESBackend()

SLESPlayback::SLESBackend::SLESBackend ( )
inline

Definition at line 60 of file sles_playback.cpp.

60  :
61  engine(nullptr), engineObj(nullptr), outputMixObj(nullptr)
62  {}

◆ ~SLESBackend()

SLESPlayback::SLESBackend::~SLESBackend ( )
inline

Definition at line 64 of file sles_playback.cpp.

64  {
65  //todo stop and destroy playback
66  }

Member Function Documentation

◆ initialize()

void SLESPlayback::SLESBackend::initialize ( Audio::AbstractPlayback::Mode  mode,
Audio::BasicRealtimePlayback playback 
)
inline

Definition at line 69 of file sles_playback.cpp.

69  {
70  SLresult result;
71 
72  // init engine if not yet
73  if (!engineObj) {
74  result = slCreateEngine(&engineObj, 0, NULL, 0, NULL, NULL);
75  assert(result, "Engine creation failed");
76 
77  result = (*engineObj)->Realize(engineObj, SL_BOOLEAN_FALSE);
78  assert(result, "Engine realization failed");
79  }
80 
81  if (!engine) {
82  result = (*engineObj)->GetInterface(engineObj, SL_IID_ENGINE, &engine);
83  assert(result, "Engine interface access failed");
84  }
85 
86  // create output mix
87  if (!outputMixObj) {
88  result = (*engine)->CreateOutputMix(engine, &outputMixObj, 0, NULL, NULL);
89  assert(result, "Output mix creation failed");
90  }
91 
92  // realize the output mix
93  result = (*outputMixObj)->Realize(outputMixObj, SL_BOOLEAN_FALSE);
94  assert(result, "Output mix realization failed");
95 
96  // configure buffers queue
97  SLDataLocator_AndroidSimpleBufferQueue bufferQueueConfig =
98  {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, mode.numBuffers};
99 
100  // configure format
101  SLDataFormat_PCM formatConfig = {
102  SL_DATAFORMAT_PCM,
103  mode.numChannels,
104  (SLuint32) mode.sampleRate * 1000, //in "milliHertz"
105  (SLuint32) AUDIO_SAMPLE_SIZE[mode.sampleFormat] *8,
106  (SLuint32) AUDIO_SAMPLE_SIZE[mode.sampleFormat] *8,
107  0,
108  SL_BYTEORDER_LITTLEENDIAN
109  };
110  SLDataSource audioSrc = {&bufferQueueConfig, &formatConfig};
111 
112  // configure audio sink
113  SLDataLocator_OutputMix outputMixLocator = {SL_DATALOCATOR_OUTPUTMIX, outputMixObj};
114  SLDataSink audioSnk = {&outputMixLocator, NULL};
115 
116  // create audio player
117  const SLInterfaceID ids[1] = {SL_IID_BUFFERQUEUE};
118  const SLboolean req[1] = {SL_BOOLEAN_TRUE};
119  result = (*engine)->CreateAudioPlayer(engine, &playerObj, &audioSrc, &audioSnk, 1, ids, req);
120  assert(result, "SLES playback initialization failed: buffered player creation", mode);
121 
122  // realize audio player
123  result = (*playerObj)->Realize(playerObj, SL_BOOLEAN_FALSE);
124  assert(result, "SLES playback initialization failed: buffered player realization", mode);
125 
126  // get playback control
127  result = (*playerObj)->GetInterface(playerObj, SL_IID_PLAY, &playbackObj);
128  assert(result, "SLES playback initialization failed: playback access", mode);
129 
130  // get buffer queue
131  result = (*playerObj)->GetInterface(playerObj, SL_IID_BUFFERQUEUE, &bufferQueueObj);
132  assert(result, "SLES playback initialization failed: buffered queue ccess", mode);
133 
134  // register callback
135  result = (*bufferQueueObj)->RegisterCallback(bufferQueueObj, &playerCallback, &playback);
136  assert(result, "SLES playback initialization failed: callback registration", mode);
137 
138  // store buffer size
139  bufferSize = (msize) (mode.bufferLength * mode.numChannels * AUDIO_SAMPLE_SIZE[mode.sampleFormat]);
140  }
SLAndroidSimpleBufferQueueItf bufferQueueObj
uint32_t msize
memory size
Definition: basic_types.h:30
const int AUDIO_SAMPLE_SIZE[]
void assert(SLresult code, const char *message)
void playerCallback(SLAndroidSimpleBufferQueueItf queue, void *data)
Beatmup::IntPoint result
JNIEnv jlong jint mode

◆ start()

void SLESPlayback::SLESBackend::start ( )
inline

Definition at line 143 of file sles_playback.cpp.

143  {
144  // start playing
145  SLresult result = (*playbackObj)->SetPlayState(playbackObj, SL_PLAYSTATE_PLAYING);
146  assert(result, "SLES playback error when starting");
147  }

◆ stop()

void SLESPlayback::SLESBackend::stop ( )
inline

Definition at line 150 of file sles_playback.cpp.

150  {
151  // start playing
152  SLresult result = (*playbackObj)->SetPlayState(playbackObj, SL_PLAYSTATE_STOPPED);
153  assert(result, "SLES playback error when stopping");
154  }

◆ pushBuffer()

void SLESPlayback::SLESBackend::pushBuffer ( sample8 buffa)
inline

Definition at line 157 of file sles_playback.cpp.

157  {
158  (*bufferQueueObj)->Enqueue(bufferQueueObj, buffa, bufferSize);
159  }

Member Data Documentation

◆ engine

SLEngineItf SLESPlayback::SLESBackend::engine
private

Definition at line 49 of file sles_playback.cpp.

◆ engineObj

SLObjectItf SLESPlayback::SLESBackend::engineObj
private

Definition at line 51 of file sles_playback.cpp.

◆ outputMixObj

SLObjectItf SLESPlayback::SLESBackend::outputMixObj
private

Definition at line 52 of file sles_playback.cpp.

◆ playerObj

SLObjectItf SLESPlayback::SLESBackend::playerObj
private

Definition at line 53 of file sles_playback.cpp.

◆ playbackObj

SLPlayItf SLESPlayback::SLESBackend::playbackObj
private

Definition at line 55 of file sles_playback.cpp.

◆ bufferQueueObj

SLAndroidSimpleBufferQueueItf SLESPlayback::SLESBackend::bufferQueueObj
private

Definition at line 56 of file sles_playback.cpp.

◆ bufferSize

msize SLESPlayback::SLESBackend::bufferSize
private

Definition at line 58 of file sles_playback.cpp.


The documentation for this class was generated from the following file: