Beatmup
source.cpp File Reference
#include "source.h"
#include "../exception.h"
#include "../debug.h"
#include <cmath>
#include <algorithm>

Go to the source code of this file.

Functions

template<typename sample >
void fillSin (sample8 *buffer, dtime time, dtime length, float volume, float frequency, float phase, dtime sampleRate, unsigned char numChannels, int scale)
 

Function Documentation

◆ fillSin()

template<typename sample >
void fillSin ( sample8 buffer,
dtime  time,
dtime  length,
float  volume,
float  frequency,
float  phase,
dtime  sampleRate,
unsigned char  numChannels,
int  scale 
)
inline

Definition at line 34 of file source.cpp.

44 {
45  dtime stop = time + length;
46  sample* s = (sample*)buffer;
47  float f = 2 * pi * frequency / sampleRate;
48  sample v;
49  for (dtime t = time; t < stop; ++t) {
50  v.x = scale * std::min(std::max(-1.0f, volume * std::sin(t * f + phase)), 1.0f);
51  for (unsigned char c = 0; c < numChannels; c++)
52  (s++)->x = v.x;
53  }
54 }
const float pi
Definition: basic_types.h:29
int dtime
discrete time
Definition: basic_types.h:37
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
JNIEnv jlong jint jint jint jint jfloat scale
jlong jlong jint time
JNIEnv jlong jfloat jfloat s
JNIEnv jlong jfloat jfloat jfloat v