Skip to content

Instantly share code, notes, and snippets.

@inequation
Created October 24, 2011 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inequation/1309415 to your computer and use it in GitHub Desktop.
Save inequation/1309415 to your computer and use it in GitHub Desktop.
SMiW DSP
#include "WAVframework.h"//#include "Talkthrough.h"
#include <math.h>
int sample = 0;
float t = 0.f;
int buffer[5000];
#define TARGET_FREQ 30.f
float sajnus(float x)
{
return 0.5 + 0.5 * sinf(x * 2.f * 3.14159f);
}
float wonsz(float x)
{ if (x < 0.25)
return x * 4.f;
if (x < 0.375)
return 1.f - 4.f * (x - 0.25);
if (x < 0.5)
return 4.f * (x - 0.25);
if (x < 0.75)
return 1.f - 4.f * (x - 0.5);
if (x < 0.875)
return 4.f * (x - 0.75);
return 1.f - 4.f * (x - 0.75);
}
// przerabia x w
float okres(float x) {
float dummy;
return modff(x * TARGET_FREQ, &dummy);
}
float obwiednia(float x) {
if (x < 0.75)
return 0.0185 * (expf(4.f * x / 0.75) - 1.f);
if (x < 0.8125 || (x >= 0.875 && x < 0.9375))
return 1.f;
return 0.f;
}
//--------------------------------------------------------------------------//
// Function: Process_Data() //
// //
// Description: This function is called from inside the SPORT0 ISR every //
// time a complete audio frame has been received. The new //
// input samples can be found in the variables iChannel0LeftIn,//
// iChannel0RightIn, iChannel1LeftIn and iChannel1RightIn //
// respectively. The processed data should be stored in //
// iChannel0LeftOut, iChannel0RightOut, iChannel1LeftOut, //
// iChannel1RightOut, iChannel2LeftOut and iChannel2RightOut //
// respectively. //
//--------------------------------------------------------------------------//
void Process_Data(void)
{
int val;
// t zlicza czas w sekundach
t += 1.f / 48000.f;
//val = 0x6FFFFFFF * sajnus(okres(t)) * obwiednia(t);
val = 0x6FFFFFFF * wonsz(okres(t)) * obwiednia(t);
iChannel0LeftOut = val;
iChannel0RightOut = val;
iChannel1LeftOut = val;
iChannel1RightOut = val;
if (sample < sizeof(buffer) / sizeof(buffer[0]))
buffer[sample] = val;
++sample;
}
#include <stdio.h>
#include "WAVframework.h"
// tutaj zadeklarować zmienne wg tego co powinien mieć nasz procesor
int iChannel0LeftOut;
int iChannel0RightOut;
int iChannel1LeftOut;
int iChannel1RightOut;
int main(int argc, char *argv[])
{
int i;
FILE *f = fopen("wave.out", "wb");
// "przerób" 48000 próbek
for (i = 0; i < 48000; ++i)
{
Process_Data();
// jeśli trzeba, tu wybierz kanał z którego będziemy kopiować
fwrite(&iChannel0LeftOut, 1, sizeof(iChannel0LeftOut), f);
}
fclose(f);
return 0;
}
#ifndef WAVFRAMEWORK_H
#define WAVFRAMEWORK_H
#include <stdlib.h>
// tutaj zadeklarować zmienne wg tego co powinien mieć nasz procesor
extern int iChannel0LeftOut;
extern int iChannel0RightOut;
extern int iChannel1LeftOut;
extern int iChannel1RightOut;
void Process_Data(void);
#endif // WAVEFRAMEWORK_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment