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){
- signed int amplituda = 0;
- signed int x = 0;
- int i;
- int minus = 0;
- const long a_1 = 12868; //3.14159 w dziesiętnym;
- const long a_2 = 21167; //5.16771 w dziesiętnym;
- const long a_3 = 10445; //2.55016 w dziesiętnym;
- const long a_4 = 2455; //0.59926 w dziesiętnym;
- int dwa = 0;
- int trzy = 0;
- int piec = 0;
- int siedem = 0;
- long y = 0;
- tablica_sin[0] = 0;
- for(i = 1; i < dl_tablicy; i++){
- amplituda = amplituda + step;
- if(amplituda < 0){
- minus = 1;
- }
- x = amplituda < 0 ? -amplituda : amplituda;
- if(x > 0.5){
- x = 32767 - x;
- }
- dwa = _smpy(x, x);
- trzy = _smpy(dwa, x);
- piec = _smpy(dwa, trzy);
- siedem = _smpy(dwa, piec);
- y = a_1*x - a_2*trzy + a_3*piec - a_4*siedem;
- tablica_sin[i] = (int)((y + (1<<11)) >> 12);
- if(minus == 1){
- tablica_sin[i] = -tablica_sin[i];
- }
- }
- }
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment