Beatmup
abstract_playback.cpp
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "../../debug.h"
20 #include "abstract_playback.h"
21 
22 using namespace Beatmup;
23 using namespace Audio;
24 
25 PlaybackException::PlaybackException(const char *message, int resultCode, const AbstractPlayback::Mode& mode):
26  Exception("%s\nResult code: %d\nSampling mode: %d\nSample format: %d\nChannels: %d\nBuffers: %d of %d samples\n",
27  message, resultCode, mode.sampleRate, mode.sampleFormat, mode.numChannels, mode.numBuffers, mode.bufferLength)
28 {}
29 
30 PlaybackException::PlaybackException(const char *message, int resultCode):
31  Exception("%s\nResult code: %d", message, resultCode)
32 {}
33 
34 
35 
37  dtime bufferLength, int numBuffers):
38  sampleRate(sampleRate),
39  sampleFormat(format),
40  numChannels((unsigned char) numChannels),
41  bufferLength(bufferLength),
42  numBuffers((unsigned char) numBuffers)
43 {
44  // check that all the mode parameters are in their valid ranges
45  if (numBuffers < 2)
46  Insanity::insanity("Bad playback mode: less that 2 buffers");
47  if (numChannels < 1)
48  Insanity::insanity("Bad playback mode: no channels");
49  if (bufferLength < 1)
50  Insanity::insanity("Bad playback mode: non-positive buffer length");
51  switch (format) {
52  case Int8:
53  case Int16:
54  case Int32:
55  case Float32:
56  break;
57  default:
58  Insanity::insanity("Bad playback mode: invalid sample format");
59  }
60  // we accept zero/negative sample rate which signifies "not set"
61 }
62 
64  dtime bufferLength):
65  Mode(sampleRate, format, numChannels, bufferLength, 2)
66 {}
67 
69 
70 
71 
73 
75  this->mode = mode;
76  clock = 0;
77 }
78 
79 
81  return source ? source->getMaxThreads() : 1;
82 }
83 
85  if (source) {
88  }
89 }
90 
93 }
ThreadIndex getMaxThreads() const
Gives the upper limint on the number of threads the task may be performed by.
void advanceTime()
Moves time pointer one buffer forward.
virtual void initialize(Mode mode)
Initializes the playback setting its main parameters.
void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu)
Instruction called before the task is executed.
PlaybackException(const char *message, int resultCode)
virtual void setClock(dtime time)
Called by the source user when an abrupt time change occurs (e.g., due to seeking)
Definition: source.cpp:29
virtual ThreadIndex getMaxThreads()
Returns the maximum number of working threads for rendering from this source.
Definition: source.h:63
virtual void prepare(const dtime sampleRate, const AudioSampleFormat sampleFormat, const unsigned char numChannels, const dtime maxBufferLen)=0
Prepares a source to render audio data.
Base class for all exceptions.
Definition: exception.h:37
Internal low-level GPU control API.
Definition: pipeline.h:33
static void insanity(const char *message)
Definition: exception.h:136
unsigned char ThreadIndex
number of threads / thread index
Definition: parallelism.h:68
int dtime
discrete time
Definition: basic_types.h:37
ProcessingTarget
Definition: basic_types.h:55
AudioSampleFormat
Format of audio samples.
@ Int8
signed integer, 8 bit per sample
@ Int32
signed integer, 32 bit per sample
@ Float32
floating point, 32 bit per sample
@ Int16
signed integer, 16 bit per sample
AudioSampleFormat sampleFormat
format of each sample
dtime sampleRate
samples per second / sample rate in Hz
unsigned char numBuffers
number of atomic buffers
unsigned char numChannels
number of channels
dtime bufferLength
length of each atomic buffer in samples
JNIEnv jobject jint format
JNIEnv jlong jint mode