Skip to content

Instantly share code, notes, and snippets.

@h2yk
Created October 28, 2020 07:19
Show Gist options
  • Save h2yk/b5624950a54a58ff09a218512db83e33 to your computer and use it in GitHub Desktop.
Save h2yk/b5624950a54a58ff09a218512db83e33 to your computer and use it in GitHub Desktop.
Sinwave array (*255)
#include <stdio.h>
#include <math.h>
#include <string.h>
void dump(int target[]){
printf("[360] {\n");
for (int i = 0; i < 360; i++)
{
printf("%d",target[i]);
if (i != 360)
{
printf(",\n");
}
}
printf ("}\n\n");
}
void main(int argc, char *argv[])
{
char *p;
int i;
if (argc != 2)
{
printf("Usage\n\n-u -> Show results as human-readable\n-a -> Show results as C array\n\n");
return;
} else if (strcmp(argv[1], "-a")&& strcmp(argv[1], "-u"))
{
printf("ERROR:invalid option:%s.exiting.\n",argv[1]);
return;
}
int trianglewave_HIGH[360];
int trianglewave_LOW[360];
int sinwave[360];
float pi = 3.14;
for (int angle = 0; angle < 360; angle++) {
double angle_rad = angle * pi / 180;
int sin_temp = sin(angle_rad) * 255.0;
trianglewave_HIGH[angle] = acos(cos(angle_rad)) / pi * 255;
trianglewave_LOW[angle] = acos(cos(angle_rad)) / pi * 255 - 255;
sinwave[angle] = (int)sin_temp;
if (!strcmp(argv[1], "-u"))
{
printf("\nsin_temp@angle:");
printf("%d",sin_temp);
printf("\nsinwave[angle]:");
printf("%d",sinwave[angle]);
printf("\ntrianglewave_HIGH[angle]:");
printf("%d",trianglewave_HIGH[angle]);
printf("\ntrianglewave_LOW[angle]:");
printf("%d",trianglewave_LOW[angle]);
printf("\n******************************\n");
}
}
if (!strcmp(argv[1], "-a"))
{
printf("int sinwave");
dump(sinwave);
printf("int trianglewave_HIGH");
dump(trianglewave_HIGH);
printf("int trianglewave_LOW");
dump(trianglewave_LOW);
printf("\n//EOF\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment