Fixed ioctl code and added coeff setting example code
[aic34-eq] / setcoeffs.c
1 #include <stdint.h>
2 #include <fcntl.h>
3 #include <alsa/asoundlib.h>
4 #include <alsa/hwdep.h>
5 #include <stdio.h>
6
7 struct iir_coeffs {
8     int16_t N0, N1, N2, D1, D2;
9     int16_t N3, N4, N5, D4, D5;
10 };
11
12 int main(){
13     struct iir_coeffs coeffs = {
14         .N0 = 32767, .N1 = 4265, .N2 = -10472, .D1 = -6269, .D2 = 0,
15         .N3 = 32027, .N4 = -31187, .N5 = 30352, .D4 = 31187, .D5 = -29613
16     };
17
18     snd_hwdep_t *hwdep;
19     int ret; int arg;
20     
21     ret = snd_hwdep_open(&hwdep, "hw:0,0", SND_HWDEP_OPEN_DUPLEX);
22     printf("open: %i\n", ret);
23     if(ret) return 1;
24     
25     ret = snd_hwdep_write(hwdep, (void*)&coeffs, sizeof(coeffs));
26     printf("write: %i\n", ret);
27
28     /* Set state to 2, which is 'Custom'. This writes coeffs to hardware
29      * and enables filter */
30     arg = 2;
31     ret = snd_hwdep_ioctl(hwdep, 1, &arg);
32     printf("ioctl: %i\n", ret);
33     return 0;
34 }