123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
-
- #include <avr/io.h>
- #include <stdint.h>
- #include <util/delay.h>
-
- #include "eq.h"
- #include "adc.h"
-
- #define Trs 72
- #define Ts 19
- #define To 36
-
- uint8_t result[7] = {128, 128, 128, 128, 128, 128, 128};
-
- #define RESETPORT PORTC
- #define STROBEPORT PORTC
- #define RESET PC3
- #define STROBE PC2
-
- #define RESETON RESETPORT |= (1 << RESET)
- #define RESETOFF RESETPORT &= ~(1 << RESET)
- #define STROBEON STROBEPORT |= (1 << STROBE)
- #define STROBEOFF STROBEPORT &= ~(1 << STROBE)
-
- void equalizerInit(void);
- uint8_t *equalizerGet(void);
- void calcMultiplicator(uint8_t *d);
- void heightenTreble(uint8_t *d);
- void filterNoise(uint8_t *data);
- uint8_t getOffset(void);
-
- void equalizerInit(void) {
- RESETON;
- STROBEOFF;
- }
-
- uint8_t *equalizerGet(void) {
- uint8_t i;
-
- RESETOFF;
- _delay_us(Trs);
-
- for (i = 0; i < 7; i++) {
- STROBEON;
- _delay_us(Ts);
- STROBEOFF;
- _delay_us(To);
-
- adcStartConversion(0);
- result[i] = adcGetByte();
- }
-
- RESETON;
- asm volatile ("nop");
- asm volatile ("nop");
-
- filterNoise(result);
- heightenTreble(result);
- calcMultiplicator(result);
- filterNoise(result);
-
- return result;
- }
-
- void calcMultiplicator(uint8_t *d) {
- uint8_t i;
- uint16_t multiplicator = ((uint16_t)getOffset() + 100) / 10;
-
- for (i = 0; i < 7; i++) {
- d[i] = (d[i] * multiplicator) / 10;
- }
- }
-
- void heightenTreble(uint8_t *d) {
- d[6] = d[5] * 10 / 15;
- }
-
- void filterNoise(uint8_t *data) {
- uint8_t i;
- for (i = 0; i < 7; i++) {
- if (data[i] < 60) {
- data[i] = data[i] * 10 / 15;
- }
- }
- }
-
- uint8_t getOffset(void) {
- adcStartConversion(0x01);
- return adcGetByte();
- }
|