Skip to content

Instantly share code, notes, and snippets.

@znxkznxk1030
Last active August 11, 2017 07:13
Show Gist options
  • Save znxkznxk1030/05b87a16e6991b8944069a1778525ca6 to your computer and use it in GitHub Desktop.
Save znxkznxk1030/05b87a16e6991b8944069a1778525ca6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#pragma warning(disable : 4996)
#define LOW_B0 0.0605
#define LOW_B1 0.1210
#define LOW_B2 0.0605
#define LOW_A0 1.0000
#define LOW_A1 -1.1939
#define LOW_A2 0.4359
int main() {
float x[3] = { 0 , 0, 0 }, y[3] = { 0, 0, 0 };
FILE *fi, *fo;
if ((fi = fopen("input_sound.snd", "rb")) == NULL)
{
printf("error");
return -1;
}
fopen_s(&fo, "output_sound1.snd", "w");
if (fo == NULL)
{
printf("output error");
return -1;
}
fseek(fi, 0, SEEK_END);
int fsize = ftell(fi) / 16 ;
printf("%d\n", ftell(fi));
fseek(fi, 0, SEEK_SET);
printf("%d\n", fsize);
for (int i = 0; i < fsize; i++)
{
x[2] = x[1];
x[1] = x[0];
y[2] = y[1];
y[1] = y[0];
__int16 inbuf;
fread(&inbuf, sizeof(__int16), 1, fi);
x[0] = inbuf;
y[0] = LOW_B0 * x[0] + LOW_B1 * x[1] +LOW_B2 * x[2]
- LOW_A1 * y[1] - LOW_A2 * y[2];
__int16 outbuf = (__int16)x[0];
printf("%d %d\n",inbuf, x[0]);
fwrite(&outbuf, sizeof(__int16), 1, fo);
}
fclose(fi);
fclose(fo);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment