-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_effect_pedal.c
154 lines (108 loc) · 4.39 KB
/
main_effect_pedal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* =====================================================================================
*
* Filename: main_effect_pedal.c
*
* Description: Main of the effect pedal operating system
*
* Version: 1.0
* Created: 05.02.2021 12:15:03
* Revision: none
* Compiler: TI C6000 Compiler (v7)
*
* Author: Jan Claußen (JC), [email protected]
* Organization: HAW Hamburg
*
* =====================================================================================
*/
#define LEFT 1
#define RIGHT 0
#include <stdio.h> //stdio library
#include <stdlib.h> //stdlib library
#include <math.h> //math library
#include <csl_mcbsp.h> // for MCBSP_read(...) and MCBSP_write(...)
#include <math.h>
/* Libraries for DSK board */
#include "c6713dskinit.h" //codec-DSK support file
#include "dsk6713.h"
#include "dsk6713_aic23.h"
/* Local libraries */
#include "main.h"
/* global variables for DSK board version */
extern MCBSP_Handle DSK6713_AIC23_DATAHANDLE;
static Uint32 CODECEventId;
Uint32 fs=DSK6713_AIC23_FREQ_48KHZ; //for sampling frequency
#define MIC 0x0015
#define LINE 0x0011
/* this union allows to store left and right channel 16 bit samples in a 32 bit int */
typedef union {
unsigned int both;
short channel[2];
} AIC23_DATA;
AIC23_DATA AIC23_data;
/* Global variables */
float IN = 0, OUT = 0;
float *sample = &IN;
short fb = 200; // Width of passband in Hz
float Wb = 200.0 * 2.0 / Fs; // Calculate normalized passband width
float MIX = 1.0;
Uint16 inputsource = MIC;
short effect = AUTOWAH;
interrupt
void intser_McBSP1()
{
/* Read date from line or mic input */
AIC23_data.both = MCBSP_read(DSK6713_AIC23_DATAHANDLE);
/* Convert new sample to float */
*sample = (float) AIC23_data.channel[LEFT] / 32768;
/* ------------------------ Effects are applied here ----------------------------- */
/* Apply Autowah sample-by-sample */
if(effect & AUTOWAH)
sample = autowah_sbs (sample, 200, 200, 2500, /*SENSE:*/ 4.0, /* GAIN:*/1.0, /*MIX*/ 0.99);
/* Apply Vibrato filter sample-by-sample */
if(effect & VIBRATO)
sample = unicomb(sample, 5.0, SINE, 0.0, 0.001, 0.0, 1.0, 0.0);
/* Apply Flanger filter sample-by-sample */
if(effect & FLANGER)
sample = unicomb(sample, 0.1, SINE, 0.000, 0.001, 0.7071, 0.7071, 0.7071);
/* Apply Chorus filter sample-by-sample */
if(effect & CHORUS)
sample = unicomb(sample, 0.15, HARMONICNOISE, 0.015, 0.015, 0.7071, 1.0, 0);
/* Apply Chorus filter sample-by-sample */
if(effect & WHITECHORUS)
sample = unicomb(sample, 0.10, SINE3, 0.005, 0.025, 0.7071, 1.0, -0.7071);
/* Apply doubling filter sample-by-sample */
if(effect & DOUBLING)
sample = unicomb(sample, 0, REDNOISE, 0.100, 0.100, 0.7071, 0.7071, 0.0);
/* ------------------------ Effects are done here ----------------------------- */
OUT = *sample;
/* Write filter output to AIC23 strucute, left and right channel */
AIC23_data.channel[LEFT] = (short) floor(OUT * 32768.0);
AIC23_data.channel[RIGHT] = (short) floor(OUT * 32768.0);;
/* Write data to line and headphone output */
MCBSP_write(DSK6713_AIC23_DATAHANDLE, AIC23_data.both);
return;
}
void main()
{
IRQ_globalDisable(); //disable interrupts
DSK6713_init(); //call BSL to init DSK-EMIF,PLL)
// handle(pointer) to codec
hAIC23_handle=DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hAIC23_handle, fs); //set sample rate
DSK6713_AIC23_rset(hAIC23_handle, 0x0004, inputsource);
//interface 32 bits toAIC23
MCBSP_config(DSK6713_AIC23_DATAHANDLE,&AIC23CfgData);
//start data channel
MCBSP_start(DSK6713_AIC23_DATAHANDLE, MCBSP_XMIT_START | MCBSP_RCV_START |
MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, 220);
CODECEventId= MCBSP_getXmtEventId(DSK6713_AIC23_DATAHANDLE);//McBSP1 Xmit
IRQ_map(CODECEventId, 5); //map McBSP1 Xmit to INT5
IRQ_reset(CODECEventId); //reset codec INT5
IRQ_globalEnable(); //globally enable interrupts
IRQ_nmiEnable(); //enable NMI interrupt
IRQ_enable(CODECEventId); //enable CODEC eventXmit INT5
IRQ_set(CODECEventId); //manually start the first interrupt
while(1){
}
}