/* * xen performance counters */ #include #include #include #include #include /* used for different purposes in perfc.h and here */ #undef PERFCOUNTER #undef PERFCOUNTER_CPU #undef PERFCOUNTER_ARRAY #define PERFCOUNTER( var, name ) "[0]"name"\0", #define PERFCOUNTER_CPU( var, name ) "C"name"\0", #define PERFCOUNTER_ARRAY( var, name, size ) "["#size"]"name"\0", char* perfc_name[] = { #include }; struct perfcounter_t perfcounters; void __perfc_print (unsigned long counter[], int offset) { int loop; int total_size = 0; int element_size = 0; int cpus = 0; int num = 0; for (loop = 0; loop < sizeof(perfc_name) / sizeof(char *); loop++) { if (perfc_name[loop][0] == 'C') { element_size = NR_CPUS; cpus = 1; } else { num = sscanf (perfc_name[loop], "[%d]", &element_size); } total_size += element_size == 0 ? 1 : element_size; if (total_size > offset) break; } if (loop == sizeof(perfc_name) / sizeof(char *)) { printf ("error: couldn't find variable\n"); return; } if (element_size == 0) { /* single counter */ printf ("%10lu 0x%08lx %s\n", counter[0], counter[0], perfc_name[loop] + 2 + num); } else if (cpus) { /* counter per CPU */ for (loop = 0; loop < smp_num_cpus; loop++) { printf ("%10lu 0x%08lx cpu[%02d] %s\n", counter[loop], counter[loop], loop, perfc_name[loop]); } } else { /* show entire array */ for (loop = 0; loop < element_size; loop++) { printf ("%10lu 0x%08lx %s:%d\n", counter[loop], counter[loop], perfc_name[loop] + 2 + num, loop); } } return; } void perfc_printall (u_char key, void *dev_id, struct pt_regs *regs) { int loop, idx; int element_size; int cpus=0; int num = 0; s_time_t now = NOW(); unsigned long *counters = (unsigned long *)&perfcounters; printf ("xen performance counters: now=0x%08X%08X\n", (u32)(now>>32), (u32)now); for (loop = 0; loop < sizeof(perfc_name) / sizeof(char *); loop++) { if (perfc_name[loop][0] == 'C') { element_size = NR_CPUS; cpus = 1; } else { num = sscanf (perfc_name[loop], "[%d]", &element_size); } for (idx = 0; idx < (element_size ? element_size : 1); idx++) { if (cpus) { if (idx < smp_num_cpus) printf ("%10ld 0x%08lx cpu[%02d] %s\n", *counters, *counters, idx, perfc_name[loop] + 1); } else if (element_size) { printf ("%10ld 0x%08lx %s:%d\n", *counters, *counters, perfc_name[loop] + num + 2, idx); } else { printf ("%10ld 0x%08lx %s\n", *counters, *counters, perfc_name[loop] + num + 2); } counters++; } } //perfc_reset( key, dev_id, regs ); return; } void perfc_reset (u_char key, void *dev_id, struct pt_regs *regs) { s_time_t now = NOW(); printk ("xen performance counters reset: now=0x%08X%08X\n", (u32)(now>>32), (u32)now); memset (&perfcounters, 0, sizeof(perfcounters)); } ef='#n7'>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
#include "audio.h"
#include "process_clicky.h"

#ifdef AUDIO_CLICKY

#ifdef AUDIO_CLICKY_ON
bool clicky_enable = true;
#else // AUDIO_CLICKY_ON
bool clicky_enable = false;
#endif // AUDIO_CLICKY_ON
#ifndef AUDIO_CLICKY_FREQ_DEFAULT
#define AUDIO_CLICKY_FREQ_DEFAULT 440.0f
#endif // !AUDIO_CLICKY_FREQ_DEFAULT
#ifndef AUDIO_CLICKY_FREQ_MIN
#define AUDIO_CLICKY_FREQ_MIN 65.0f
#endif // !AUDIO_CLICKY_FREQ_MIN
#ifndef AUDIO_CLICKY_FREQ_MAX
#define AUDIO_CLICKY_FREQ_MAX 1500.0f
#endif // !AUDIO_CLICKY_FREQ_MAX
#ifndef AUDIO_CLICKY_FREQ_FACTOR
#define AUDIO_CLICKY_FREQ_FACTOR 1.18921f
#endif // !AUDIO_CLICKY_FREQ_FACTOR
#ifndef AUDIO_CLICKY_FREQ_RANDOMNESS
#define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f
#endif // !AUDIO_CLICKY_FREQ_RANDOMNESS

float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
float clicky_song[][2]  = {{AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations

#ifndef NO_MUSIC_MODE
extern bool music_activated;
extern bool midi_activated;
#endif // !NO_MUSIC_MODE

void clicky_play(void) {
#ifndef NO_MUSIC_MODE
  if (music_activated || midi_activated) return;
#endif // !NO_MUSIC_MODE
  clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
  clicky_song[1][0] = clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
  PLAY_SONG(clicky_song);
}

bool process_clicky(uint16_t keycode, keyrecord_t *record) {
    if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_enable = !clicky_enable; }

    if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; }

    if (keycode == CLICKY_UP && record->event.pressed) {
      float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
      if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
        clicky_freq = new_freq;
      }
    }
    if (keycode == CLICKY_DOWN && record->event.pressed) {
      float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
      if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
        clicky_freq = new_freq;
      }
    }


    if ( clicky_enable ) {
      if (record->event.pressed) {
        clicky_play();;
      }
    }
    return true;
}

#endif //AUDIO_CLICKY