23 #include "../utils/input_stream.h"
24 #include "../exception.h"
28 using namespace Audio;
39 defaultFragmentSize(
floorf_fast(defaultFragmentLenSec * sampleRate)),
40 sampleRate(sampleRate),
50 Sequence::insert(signal,
time);
75 stream(&header,
sizeof(header));
104 Writer pointer(*signal, 0);
105 while (pointer.hasData() && !stream.
eof()) {
110 pointer.jump(length);
127 file.write((
char*)&header,
sizeof(header));
131 while (pointer.hasData() && !file.eof()) {
136 file.write((
const char*)data, length *
channelCount * sampleSize);
138 pointer.jump(length);
160 if (pointer.isNull()) {
166 return pointer.length;
173 if (pointer.isNull()) {
179 return pointer.length;
184 Meter me(signal, 0, MeasuringMode::approximateUsingLookup);
185 for (
int skip = 0; skip < skipOnStart; skip++)
187 while (me.hasData()) {
191 for (
int skip = 0; skip < numSteps; skip++)
216 DynamicsLookupPreparation(
Signal& signal) : signal(signal) {}
219 DynamicsLookupPreparation
task(signal);
229 const dtime startTime = getTime();
231 sample *pMin =
min, *pMax =
max;
234 for (
int bin = 1; bin <= resolution; bin++) {
237 t1 = startTime + (
long long)len * bin / resolution;
240 dtime fragStart = t0 - getTime() + pointer.offset;
244 pMin[ch].x = sample::MAX_VALUE;
245 pMax[ch].x = sample::MIN_VALUE;
249 while (getTime() + pointer.length <
t1) {
250 ((
SignalFragment*)pointer.fragment)->measureDynamics(fragStart, pointer.offset + pointer.length, pMin, pMax,
mode);
252 fragStart = pointer.offset;
254 ((
SignalFragment*)pointer.fragment)->measureDynamics(fragStart, pointer.offset +
t1 - getTime(), pMin, pMax,
mode);
258 if (pMax[ch] < pMin[ch])
259 pMin[ch].x = pMax[ch].x = 0;
284 measureInFragments(len, resolution, tmin, tmax);
285 convertSamples<sample8, sample16>(tmin,
min, resolution);
286 convertSamples<sample8, sample16>(tmax,
max, resolution);
293 measureInFragments(len, resolution, tmin, tmax);
294 convertSamples<sample32, sample16>(tmin,
min, resolution);
295 convertSamples<sample32, sample16>(tmax,
max, resolution);
302 measureInFragments(len, resolution, tmin, tmax);
303 convertSamples<sample32f, sample16>(tmin,
min, resolution);
304 convertSamples<sample32f, sample16>(tmax,
max, resolution);
323 static const out_t _0{ 0 };
324 const int numc = (int)
std::min(inCh, outCh);
325 while (length > 0 && ptr.hasData()) {
331 const in_t* input = (
const in_t*)data;
332 for (
int t = 0; t < chunk; ++t, input += inCh, output += outCh) {
334 for (; c < numc; ++c)
335 output[c] = input[c];
336 for (; c < outCh; ++c)
345 memset(output, 0, length * outCh);
357 const unsigned char numChannels,
358 const dtime maxBufferLen
360 this->numChannels = numChannels;
361 this->sampleFormat = sampleFormat;
373 const dtime bufferLength
376 Processing::pipeline<Kernels::RenderAudio>(signal->getSampleFormat(), sampleFormat,
nullptr, buffer, ptr, bufferLength, signal->
getChannelCount(), numChannels);
377 time += bufferLength;
383 "Incompatible format: %s @ %d channels vs <-> %s @ %d channels",
Task: an operation that can be executed by multiple threads in parallel.
@ CPU_ONLY
this task does not use GPU
void measureInFragments(dtime len, int resolution, sample *min, sample *max)
Measures signal dynamics in a given period of time.
static void prepareSignal(Signal &signal, bool runTask=true)
Precomputes the dynamics lookup all over the signal, where needed.
void measure(dtime len, int resolution, sample min[], sample max[])
Measures signal dynamics in a given period of time.
Meter(Signal &signal, dtime time, MeasuringMode mode=MeasuringMode::approximateUsingLookup)
Constructs a new meter.
MeasuringMode
Specifies how to compute signal dynamics (minima and maxima in a given period of time)
static void prepare(Signal &signal, int skipOnStart=0, int numSteps=1)
Implements a Sequence::Pointer for audio signals.
unsigned char getChannelCount() const
virtual void releaseBuffer()
Pointer(Signal &signal, dtime time, bool writing)
Provides reading access to the signal.
Reader(Signal &signal, dtime time)
dtime acquireBuffer(const void *&data)
void prepare(const dtime sampleRate, const AudioSampleFormat sampleFormat, const unsigned char numChannels, const dtime maxBufferLen)
Prepares a source to render audio data.
void render(TaskThread &thread, sample8 *buffer, const dtime bufferLength)
Renders audio data to the target output buffer given by the user.
void setClock(dtime time)
Called by the source user when an abrupt time change occurs (e.g., due to seeking)
Provides writing access to the signal.
Writer(Signal &signal, dtime time)
dtime acquireBuffer(void *&data)
void insert(const Signal &signal, dtime time)
Inserts a Signal into the current signal at a specific time moment.
Context & getContext() const
unsigned char getChannelCount() const
AudioSampleFormat format
sample format
AudioSampleFormat getSampleFormat() const
Signal(Context &context, AudioSampleFormat format, int sampleRate, unsigned char channels, float defaultFragmentLenSec=DEFAULT_FRAGMENT_LENGTH_SEC)
Creates an empty signal.
unsigned char channelCount
number of channels
void reserve(dtime length)
Prolongates the sequence if necessary, to ensure given length.
static Signal * loadWAV(Context &ctx, const char *fileName)
int sampleRate
sampling frequency
void saveWAV(const char *filename)
Stores the signal to a PCM-encoded WAV file.
virtual Signal * createEmpty() const
Initializes an empty sequence, used to bootstrap copying operations.
const dtime defaultFragmentSize
Communicates an error related to a WAV file content.
static void check(Header &header)
Basic class: task and memory management, any kind of static data.
float performTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Performs a given task.
Base class for all exceptions.
const dtime getDuration() const
Returns sequence duration in number of samples.
void concatenate(Fragment &fragment, dtime offset, dtime length)
Adds a new fragment at the end of the sequence.
static void insanity(const char *message)
virtual ThreadIndex numThreads() const =0
ThreadIndex currentThread() const
static void process(const in_t *whatever, out_t *output, Signal::Reader &ptr, dtime length, const int inCh, const int outCh)
Renders a continuous audio signal from Signal::Reader.
#define BEATMUP_ASSERT_DEBUG(C)
const char *const AUDIO_FORMAT_NAME[]
const int AUDIO_SAMPLE_SIZE[]
unsigned char ThreadIndex
number of threads / thread index
static const ThreadIndex MAX_THREAD_INDEX
maximum possible thread index value
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
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
JNIEnv jobject jint jint jint channels
JNIEnv jobject jint jint jint jfloat fragment
JNIEnv jobject jint format
Beatmup::CustomPipeline::TaskHolder * newbie
JNIEnv jlong jstring filename
Beatmup::NNets::InferenceTask * task