-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathefx_cabsim.c
80 lines (69 loc) · 4.18 KB
/
efx_cabsim.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
#include "efx_cabsim.h" // FlexFX Cabsim
#include <math.h> // Floating point for filter coeff calculations in the background process.
#include <string.h> // Memory and string functions
const char* product_name_string = "FlexFX Cabsim"; // Your product name
const char* usb_audio_output_name = "FlexFX Audio Out"; // USB audio output endpoint name
const char* usb_audio_input_name = "FlexFX Audio In"; // USB audio input endpoint name
const char* usb_midi_output_name = "FlexFX MIDI Out"; // USB MIDI output endpoint name
const char* usb_midi_input_name = "FlexFX MIDI In"; // USB MIDI input endpoint name
const int audio_sample_rate = 48000; // Audio sampling frequency
const int usb_output_chan_count = 2; // 2 USB audio class 2.0 output channels
const int usb_input_chan_count = 2; // 2 USB audio class 2.0 input channels
const int i2s_channel_count = 2; // ADC/DAC channels per SDIN/SDOUT wire
//const char interface_string[] = "No interface is specified";
//const char controller_string[] = "No controller is available";
const int i2s_sync_word[8] = { 0xFFFFFFFF,0x00000000,0,0,0,0,0,0 }; // I2S WCLK values per slot
static void adc_read( double values[4] ) // I2C control for the Analog Devices AD7999 ADC.
{
byte ii, hi, lo, value;
i2c_start( 100000 ); // Set bit clock to 400 kHz and assert start condition.
i2c_write( 0x52+1 ); // Select I2C peripheral for Read.
for( ii = 0; ii < 4; ++ii ) {
hi = i2c_read(); i2c_ack(0); // Read low byte, assert ACK.
lo = i2c_read(); i2c_ack(ii==3); // Read high byte, assert ACK (NACK on last read).
value = (hi<<4) + (lo>>4); // Select correct value and store ADC sample.
values[hi>>4] = ((double)value)/256.0; // Convert from byte to double (0<=val<1.0).
}
i2c_stop();
}
void app_control( const int rcv_prop[6], int usb_prop[6], int dsp_prop[6] )
{
// Pass incoming properties on to CABSIM control ...
efx_cabsim__app_control( rcv_prop, usb_prop, dsp_prop );
// If outgoing USB or DSP properties are now use then come back later ...
if( usb_prop[0] != 0 || dsp_prop[0] != 0 ) return;
double volume = 0, tone = 0, preset = 0, pot_values[4];
adc_read( pot_values ); // Read pot values for volume, tone and preset
// Check to see if any of the pots have changed in a meaningful way ...
int updated[3] = {0,0,0};
updated[0] = (pot_values[3] < volume-FQ(0.01)) || (pot_values[3] > volume+FQ(0.01));
updated[1] = (pot_values[2] < tone-FQ(0.01)) || (pot_values[2] > tone+FQ(0.01));
static int focus = 0; double step = FQ(0.1111111), gap = QF(0.03);
for( int click = 0, ii = 0; ii < 9; ++ii ) {
click = preset >= (ii*step+gap) && preset <= (ii*(step+1)-gap);
if( !click && focus ) focus = 0;
if( !focus && click ) updated[2] = 1;
}
// Check to see of any pot changes result in a need to update control settings ...
if( updated[0] || updated[1] || updated[2] ) {
if( updated[0] ) volume = pot_values[3];
if( updated[1] ) tone = pot_values[2];
if( updated[2] ) preset = pot_values[1];
// Send property with updated controll settings to the DSP threads via cabsim control ...
dsp_prop[0] = 0x00008001;
dsp_prop[1] = volume; dsp_prop[2] = tone; dsp_prop[3] = preset;
efx_cabsim__app_control( rcv_prop, usb_prop, dsp_prop );
}
}
void app_mixer( const int usb_output[32], int usb_input[32],
const int i2s_output[32], int i2s_input[32],
const int dsp_output[32], int dsp_input[32], const int property[6] )
{
efx_cabsim__app_mixer( usb_output, usb_input, i2s_output, i2s_input,
dsp_output, dsp_input, property );
}
void app_thread1( int samples[32], const int property[6] ) {efx_cabsim__app_thread1(samples,property);}
void app_thread2( int samples[32], const int property[6] ) {efx_cabsim__app_thread2(samples,property);}
void app_thread3( int samples[32], const int property[6] ) {efx_cabsim__app_thread3(samples,property);}
void app_thread4( int samples[32], const int property[6] ) {efx_cabsim__app_thread4(samples,property);}
void app_thread5( int samples[32], const int property[6] ) {efx_cabsim__app_thread5(samples,property);}