Beatmup
Beatmup::Audio::SignalFragment Class Reference

A piece of sound. More...

#include <signal_fragment.h>

Inheritance diagram for Beatmup::Audio::SignalFragment:
Beatmup::Fragments::Fragment

Classes

class  DynamicsLookup
 Data structure allowing to plot efficiently audio signal graphs. More...
 
struct  Plot
 

Public Member Functions

 SignalFragment (AudioSampleFormat format, unsigned char channels, int samples)
 
virtual SignalFragmentclone () const
 
sample8getData ()
 
const AudioSampleFormat getAudioFormat () const
 
msize getSizeBytes () const
 
unsigned char getBlockSize () const
 
unsigned char getChannelCount () const
 
void zero ()
 
bool isDynamicsLookupAvailable () const
 
void updateDynamicsLookup ()
 
template<typename sample >
void measureDynamics (int time0, int time1, sample *min, sample *max, Signal::Meter::MeasuringMode mode)
 Measures dynamics from time0 to time1 in each channels separately. More...
 
- Public Member Functions inherited from Beatmup::Fragments::Fragment
const int getSampleCount () const
 
Fragmentedit ()
 Enables editing of the current frame. More...
 
Fragmentuse ()
 References the frame when it is used one more time. More...
 
void drop ()
 Dereferences the frame when it is not used any more. More...
 

Private Attributes

AudioSampleFormat format
 
unsigned char channelCount
 number of channels More...
 
unsigned char blockSize
 size in bytes of a channelwise-multiplexed sample (block containing 1 sample per channel) More...
 
AlignedMemory data
 
struct Beatmup::Audio::SignalFragment::Plot plot
 

Additional Inherited Members

- Protected Member Functions inherited from Beatmup::Fragments::Fragment
 Fragment ()
 
virtual ~Fragment ()
 
- Protected Attributes inherited from Beatmup::Fragments::Fragment
int sampleCount
 number of samples within this frame More...
 

Detailed Description

A piece of sound.

Audio signals in Beatmup can be fragmented. SignalFragment is a continuous piece of audio signal in memory. A lookup structure is implemented allowing to measure the signal dynamics efficiently.

FOR INTERNAL USE, should not be included anywhere except audio_signal.cpp

Definition at line 38 of file signal_fragment.h.

Constructor & Destructor Documentation

◆ SignalFragment()

SignalFragment::SignalFragment ( AudioSampleFormat  format,
unsigned char  channels,
int  samples 
)

Definition at line 240 of file signal_fragment.cpp.

240  :
242 {
244  sampleCount = samples;
246 }
Aligned memory buffer.
Definition: memory.h:27
unsigned char blockSize
size in bytes of a channelwise-multiplexed sample (block containing 1 sample per channel)
unsigned char channelCount
number of channels
int sampleCount
number of samples within this frame
Definition: fragment.h:39
const int AUDIO_SAMPLE_SIZE[]
JNIEnv jobject jint jint jint channels

Member Function Documentation

◆ clone()

SignalFragment * SignalFragment::clone ( ) const
virtual

Implements Beatmup::Fragments::Fragment.

Definition at line 249 of file signal_fragment.cpp.

249  {
251  memcpy(copy->data(), data(), getSizeBytes());
252  copy->plot.fineLevelStep = plot.fineLevelStep;
253  copy->plot.coarserLevelStep = plot.coarserLevelStep;
254  // do not copy the lookup; it will be recomputed when needed
255  copy->plot.lookup.disposeTree();
256  return copy;
257 }
SignalFragment(AudioSampleFormat format, unsigned char channels, int samples)
struct Beatmup::Audio::SignalFragment::Plot plot
const int getSampleCount() const
Definition: fragment.h:44
Beatmup::AbstractBitmap * copy

◆ getData()

sample8* Beatmup::Audio::SignalFragment::getData ( )
inline

Definition at line 113 of file signal_fragment.h.

113 { return data.ptr<sample8>(); }
datatype * ptr(int offset=0)
Definition: memory.h:46

◆ getAudioFormat()

const AudioSampleFormat Beatmup::Audio::SignalFragment::getAudioFormat ( ) const
inline

Definition at line 114 of file signal_fragment.h.

114 { return format; }

◆ getSizeBytes()

msize Beatmup::Audio::SignalFragment::getSizeBytes ( ) const
inline

Definition at line 115 of file signal_fragment.h.

115 { return getSampleCount() * blockSize; }

◆ getBlockSize()

unsigned char Beatmup::Audio::SignalFragment::getBlockSize ( ) const
inline

Definition at line 116 of file signal_fragment.h.

116 { return blockSize; }

◆ getChannelCount()

unsigned char Beatmup::Audio::SignalFragment::getChannelCount ( ) const
inline

Definition at line 117 of file signal_fragment.h.

117 { return channelCount; }

◆ zero()

void SignalFragment::zero ( )

Definition at line 260 of file signal_fragment.cpp.

260  {
261  memchr(data(), 0, getSizeBytes());
262 }

◆ isDynamicsLookupAvailable()

bool Beatmup::Audio::SignalFragment::isDynamicsLookupAvailable ( ) const
inline

Definition at line 121 of file signal_fragment.h.

◆ updateDynamicsLookup()

void SignalFragment::updateDynamicsLookup ( )

Definition at line 265 of file signal_fragment.cpp.

265  {
267  channelCount,
271  );
272 
273  switch (format) {
274  case Int8:
276  break;
277  case Int16:
279  break;
280  case Int32:
282  break;
283  case Float32:
285  break;
286  default:
287  Insanity::insanity("Unknown sample format");
288  }
289 }
void updateTree(const sample *data, int sampleCount)
Updates tree from raw sample data.
void configureTree(unsigned char channelCount, int levelCount, int fineStepSize, int coarserStepSize)
Sets up the tree structure.
static void insanity(const char *message)
Definition: exception.h:136
@ 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

◆ measureDynamics()

template<typename sample >
template void SignalFragment::measureDynamics ( int  time0,
int  time1,
sample *  min,
sample *  max,
Signal::Meter::MeasuringMode  mode 
)

Measures dynamics from time0 to time1 in each channels separately.

Parameters
time0Start time
time1Stop time
minChannelwise multiplexed minima
maxChannelwise multiplexed maxima
modeMeasurement mode

Definition at line 292 of file signal_fragment.cpp.

292  {
293  BEATMUP_ASSERT_DEBUG(time0 <= time1);
294  BEATMUP_ASSERT_DEBUG(AUDIO_SAMPLE_SIZE[format] == sizeof(sample));
295 
296  const bool useLookup =
299 
300  if (useLookup)
301  RuntimeError::check(plot.lookup.isReady(), "Dynamics lookup is not ready");
302 
303  const void* sampleData = nullptr;
304 
305  // precise measurement
306  if (
309  ) {
310  sampleData = data();
311  }
312 
313  // use lookup
314  if (useLookup)
315  plot.lookup.measure(time0, time1, min, max, (sample*)sampleData);
316 
317  // don't use lookup
318  else {
319  BEATMUP_ASSERT_DEBUG(sampleData);
320  for (int ch = 0; ch < channelCount; ch++, min++, max++)
322  (sample*)sampleData + time0*channelCount + ch,
323  (sample*)sampleData + time1*channelCount + ch,
324  channelCount,
325  *min, *max
326  );
327  }
328 }
void measure(dtime time0, dtime time1, sample *min, sample *max, const void *data) const
Measures dynamics from time0 to time1 in each channels separately.
@ approximateUsingLookup
Find an approximated range using a lookup tree.
@ preciseUsingLookupAndSamples
Use lookup and then precise the measurement using sample data.
@ preciseUsingSamples
Just run across all samples.
static void check(const bool condition, const std::string &message)
Definition: exception.h:64
#define BEATMUP_ASSERT_DEBUG(C)
Definition: exception.h:163
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:724
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:728
void measureMultiplexedChannelDynamics(const sample *startSample, const sample *stopSample, const unsigned char stride, sample &min, sample &max)
Measures dynamics from samples for a single channel in a multiplexed stream.
JNIEnv jlong jint mode

Member Data Documentation

◆ format

AudioSampleFormat Beatmup::Audio::SignalFragment::format
private

Definition at line 97 of file signal_fragment.h.

◆ channelCount

unsigned char Beatmup::Audio::SignalFragment::channelCount
private

number of channels

Definition at line 98 of file signal_fragment.h.

◆ blockSize

unsigned char Beatmup::Audio::SignalFragment::blockSize
private

size in bytes of a channelwise-multiplexed sample (block containing 1 sample per channel)

Definition at line 99 of file signal_fragment.h.

◆ data

AlignedMemory Beatmup::Audio::SignalFragment::data
private

Definition at line 100 of file signal_fragment.h.

◆ plot

struct Beatmup::Audio::SignalFragment::Plot Beatmup::Audio::SignalFragment::plot
private

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