Beatmup
Beatmup::Audio::HarmonicSource Class Reference

A Source producing a sinusoidal signal, mainly for test purposes. More...

#include <source.h>

Inheritance diagram for Beatmup::Audio::HarmonicSource:
Beatmup::Audio::Source

Public Member Functions

 HarmonicSource ()
 
void setFrequency (float hz)
 
float getFrequency () const
 
void setPhase (float radians)
 
float getPhase () const
 
void setAmplitude (float amp)
 
float getAmplitude () const
 
void prepare (const dtime sampleRate, const AudioSampleFormat sampleFormat, const unsigned char numChannels, const dtime maxBufferLen)
 Prepares a source to render audio data. More...
 
void render (TaskThread &thread, sample8 *buffer, const dtime bufferLength)
 Renders audio data to the target output buffer given by the user. More...
 
void setClock (dtime time)
 Called by the source user when an abrupt time change occurs (e.g., due to seeking) More...
 
- Public Member Functions inherited from Beatmup::Audio::Source
virtual ~Source ()
 
virtual ThreadIndex getMaxThreads ()
 Returns the maximum number of working threads for rendering from this source. More...
 

Private Attributes

AudioSampleFormat sampleFormat
 
dtime sampleRate
 
dtime time
 
float amplitude
 
float frequency
 
float phase
 
unsigned char numChannels
 

Detailed Description

A Source producing a sinusoidal signal, mainly for test purposes.

Definition at line 86 of file source.h.

Constructor & Destructor Documentation

◆ HarmonicSource()

Beatmup::Audio::HarmonicSource::HarmonicSource ( )
inline

Definition at line 93 of file source.h.

Member Function Documentation

◆ setFrequency()

void Beatmup::Audio::HarmonicSource::setFrequency ( float  hz)
inline

Definition at line 95 of file source.h.

95 { frequency = hz; }

◆ getFrequency()

float Beatmup::Audio::HarmonicSource::getFrequency ( ) const
inline

Definition at line 96 of file source.h.

96 { return frequency; }

◆ setPhase()

void Beatmup::Audio::HarmonicSource::setPhase ( float  radians)
inline

Definition at line 98 of file source.h.

98 { phase = radians; }

◆ getPhase()

float Beatmup::Audio::HarmonicSource::getPhase ( ) const
inline

Definition at line 99 of file source.h.

99 { return phase; }

◆ setAmplitude()

void Beatmup::Audio::HarmonicSource::setAmplitude ( float  amp)
inline

Definition at line 101 of file source.h.

101 { this->amplitude = amp; }
JNIEnv jlong jfloat amp

◆ getAmplitude()

float Beatmup::Audio::HarmonicSource::getAmplitude ( ) const
inline

Definition at line 102 of file source.h.

102 { return amplitude; }

◆ prepare()

void HarmonicSource::prepare ( const dtime  sampleRate,
const AudioSampleFormat  sampleFormat,
const unsigned char  numChannels,
const dtime  maxBufferLen 
)
virtual

Prepares a source to render audio data.

Called by the user before any rendering to communicate the configuration of the upcoming rendering process.

Parameters
sampleRateThe output sample rate in Hz
sampleFormatThe output sample format
numChannelsNumber of channels in the output
maxBufferLenMaximum expected length of target audio buffers on rendering phase, in samples per one channel

Implements Beatmup::Audio::Source.

Definition at line 57 of file source.cpp.

62 {
63  this->sampleFormat = sampleFormat;
64  this->sampleRate = sampleRate;
65  this->numChannels = numChannels;
66 }
AudioSampleFormat sampleFormat
Definition: source.h:88
unsigned char numChannels
Definition: source.h:91

◆ render()

void HarmonicSource::render ( TaskThread thread,
sample8 buffer,
const dtime  bufferLength 
)
virtual

Renders audio data to the target output buffer given by the user.

Called after at least one call to prepare(). The sampling parameters must match the ones communicated on the preparation phase. The requested buffer length does not exceed the one set before. The time is given by the clock set before, and with every call it advances by {bufferLength} samples.

Parameters
threadthe task thread issuing this rendering call
buffera pointer to the beginning of a channelwise-multiplexed output buffer
bufferLengththe requested buffer length, in samples per single channel

Implements Beatmup::Audio::Source.

Definition at line 69 of file source.cpp.

69  {
70  BEATMUP_DEBUG_I("FILLING BUFFER OF %d SAMPLES at time %d", bufferLength, time);
71  switch (sampleFormat) {
72  case Int8:
73  fillSin<sample8>(buffer, time, bufferLength, amplitude, frequency, phase, sampleRate, numChannels, 127);
74  break;
75 
76  case Int16:
77  fillSin<sample16>(buffer, time, bufferLength, amplitude, frequency, phase, sampleRate, numChannels, 0x7FFF);
78  break;
79 
80  case Int32:
81  fillSin<sample32>(buffer, time, bufferLength, amplitude, frequency, phase, sampleRate, numChannels, 0x7FFFFFFF);
82  break;
83 
84  case Float32:
85  fillSin<sample32f>(buffer, time, bufferLength, amplitude, frequency, phase, sampleRate, numChannels, 1);
86  break;
87 
88  default:
89  Insanity::insanity("Unsupported sample format");
90  }
91  time += bufferLength;
92 }
static void insanity(const char *message)
Definition: exception.h:136
#define BEATMUP_DEBUG_I(...)
Definition: debug.h:33
@ 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

◆ setClock()

void HarmonicSource::setClock ( dtime  time)
virtual

Called by the source user when an abrupt time change occurs (e.g., due to seeking)

Reimplemented from Beatmup::Audio::Source.

Definition at line 95 of file source.cpp.

95  {
96  this->time = time;
97 }

Member Data Documentation

◆ sampleFormat

AudioSampleFormat Beatmup::Audio::HarmonicSource::sampleFormat
private

Definition at line 88 of file source.h.

◆ sampleRate

dtime Beatmup::Audio::HarmonicSource::sampleRate
private

Definition at line 89 of file source.h.

◆ time

dtime Beatmup::Audio::HarmonicSource::time
private

Definition at line 89 of file source.h.

◆ amplitude

float Beatmup::Audio::HarmonicSource::amplitude
private

Definition at line 90 of file source.h.

◆ frequency

float Beatmup::Audio::HarmonicSource::frequency
private

Definition at line 90 of file source.h.

◆ phase

float Beatmup::Audio::HarmonicSource::phase
private

Definition at line 90 of file source.h.

◆ numChannels

unsigned char Beatmup::Audio::HarmonicSource::numChannels
private

Definition at line 91 of file source.h.


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