Skip to content

Instantly share code, notes, and snippets.

@suzukiplan
Created May 13, 2015 01:39
Show Gist options
  • Save suzukiplan/2ca084a578a2d0eba28b to your computer and use it in GitHub Desktop.
Save suzukiplan/2ca084a578a2d0eba28b to your computer and use it in GitHub Desktop.
double精度の波形出力(sin, square, pulse)
/* description: 波形情報をメモリではなく全て演算ベースにする新音源用のメモ */
/* とりあえず、サイン波、矩形波、ノコギリ波のみ */
/* ノイズ発生装置は後回し */
#include <math.h>
#define PI 3.1415926535897932
#define PI2 6.2831853071795864
double calcwav_sin(double r)
{
return sin(r);
}
double calcwav_square(double r)
{
r=fmod(r,PI2);
if(r<0.0) r+=PI2;
if(r<PI) return 1.0;
return -1.0;
}
double calcwav_pulse(double r)
{
r=fmod(r,PI2);
if(r<0.0) r+=PI2;
r/=PI;
r-=1.0;
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment