Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dsplib.h>
- #define NUM_SAMPLES 5000
- #define krok 137
- int pila[NUM_SAMPLES];
- int prostokatny[NUM_SAMPLES];
- int trojkatny[NUM_SAMPLES];
- int sinus[NUM_SAMPLES];
- int dsplib_sin[NUM_SAMPLES];
- int white_noise[NUM_SAMPLES];
- void saw(int* tablica, unsigned int dl_tablicy, unsigned int step){
- int amplituda = 0;
- int i;
- tablica[0] = 0;
- for(i = 1; i < dl_tablicy; i++){
- amplituda = amplituda + step;
- tablica[i] = amplituda;
- }
- }
- void rect(int* tablica_prost, unsigned int dl_tablicy, unsigned int step, int prog){
- int amplituda = 0;
- int i;
- for(i = 1; i < dl_tablicy; i++){
- if(amplituda < prog){
- tablica_prost[i] = 32767;
- }
- else{
- tablica_prost[i] = -32768;
- }
- amplituda = amplituda + step;
- }
- }
- void tri(int* tablica_tri, unsigned int dl_tablicy, unsigned int step){
- signed int amplituda = 0;
- signed int bezwzgledna = 0;
- int i;
- tablica_tri[0] = 0;
- for(i = 1; i < dl_tablicy; i++){
- amplituda = amplituda + step;
- bezwzgledna = amplituda < 0 ? -amplituda : amplituda;
- tablica_tri[i] = ((bezwzgledna<<1) - 32767);
- }
- }
- void sint(int* tablica_sin, unsigned int dl_tablicy, unsigned int step){
- int amplituda = 0;
- int i;
- const long a_1 = 3.14159; //102944
- const long a_2 = 10.33542; //338671
- const long a_3 = 61.20393; //2005531
- const long a_4 = 431.4746; //14138424
- tablica_sin[0] = 0;
- for(i = 1; i < dl_tablicy; i++){
- amplituda = amplituda + step;
- tablica_sin[i] = a_1*amplituda - a_2*pow(amplituda, 3) + a_3*pow(amplituda, 5) - a_4*pow(amplituda, 7);
- }
- }
- void main(void) {
- //saw(pila, NUM_SAMPLES, krok);
- //rect(prostokatny, NUM_SAMPLES, krok, 0);
- //tri(trojkatny, NUM_SAMPLES, krok);
- sint(sinus, NUM_SAMPLES, krok);
- //ushort oflag = sine (DATA *pila, DATA *dsplib_sin, 5000);
- //sine((DATA*)pila, (DATA*)dsplib_sin, NUM_SAMPLES);
- //rand16init();
- //rand16((DATA*)white_noise, NUM_SAMPLES);
- while (1); // do not exit
- }
Add Comment
Please, Sign In to add comment