pushing r now reloads audio, as requested in issue #81

added terminate on or off to audio struct. r will terminate the audio thread and jump back to audio init.
master
karlstav 10 years ago
parent fdb065106f
commit be2947b064
  1. 87
      cava.c
  2. 8
      input/alsa.c
  3. 14
      input/fifo.c
  4. 6
      input/pulse.c

@ -85,6 +85,8 @@ int autobars = 1;
int stereo = -1; int stereo = -1;
int M = 2048; int M = 2048;
// general: cleanup // general: cleanup
void cleanup(void) void cleanup(void)
{ {
@ -491,7 +493,7 @@ int main(int argc, char **argv)
double inl[2 * (M / 2 + 1)]; double inl[2 * (M / 2 + 1)];
fftw_complex outl[M / 2 + 1][2]; fftw_complex outl[M / 2 + 1][2];
fftw_plan pl; fftw_plan pl;
int cont = 1; //int cont = 1;
int fall[200]; int fall[200];
float fpeak[200]; float fpeak[200];
float k[200]; float k[200];
@ -514,18 +516,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
printf("%c]0;%s%c", '\033', PACKAGE, '\007'); printf("%c]0;%s%c", '\033', PACKAGE, '\007');
configPath[0] = '\0'; configPath[0] = '\0';
audio.format = -1;
audio.rate = 0;
if (stereo) audio.channels = 2;
if (!stereo) audio.channels = 1;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
for (i = 0; i < M; i++) {
audio.audio_out_l[i] = 0;
audio.audio_out_r[i] = 0;
}
// general: handle Ctrl+C // general: handle Ctrl+C
struct sigaction action; struct sigaction action;
memset(&action, 0, sizeof(action)); memset(&action, 0, sizeof(action));
@ -556,12 +549,38 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
n = 0; n = 0;
} }
load_config(configPath); // Check if we're running in a Virtual console todo: replace virtual console with terminal emulator
inAVirtualConsole = 1;
if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), "/dev/console") == 0) inAVirtualConsole = 0;
if (!inAVirtualConsole) {
system("setfont cava.psf >/dev/null 2>&1");
system("echo yep > /tmp/testing123");
system("setterm -blank 0");
}
// general: main loop
while (1) {
// config: validate //config: load & validate
load_config(configPath);
validate_config(); validate_config();
//input: init
audio.format = -1;
audio.rate = 0;
audio.terminate = 0;
if (stereo) audio.channels = 2;
if (!stereo) audio.channels = 1;
for (i = 0; i < M; i++) {
audio.audio_out_l[i] = 0;
audio.audio_out_r[i] = 0;
}
#ifdef ALSA #ifdef ALSA
// input_alsa: wait for the input to be ready // input_alsa: wait for the input to be ready
if (im == 1) { if (im == 1) {
@ -630,18 +649,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
pr = fftw_plan_dft_r2c_1d(M, inr, *outr, FFTW_MEASURE); pr = fftw_plan_dft_r2c_1d(M, inr, *outr, FFTW_MEASURE);
} }
// Check if we're running in a Virtual console todo: replace virtual console with terminal emulator bool reloadConf = FALSE;
inAVirtualConsole = 1;
if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), "/dev/console") == 0) inAVirtualConsole = 0;
if (!inAVirtualConsole) { while (!reloadConf) {//jumbing back to this loop means that you resized the screen
system("setfont cava.psf >/dev/null 2>&1");
system("echo yep > /tmp/testing123");
system("setterm -blank 0");
}
while (1) {//jumbing back to this loop means that you resized the screen
for (i = 0; i < 200; i++) { for (i = 0; i < 200; i++) {
flast[i] = 0; flast[i] = 0;
flastd[i] = 0; flastd[i] = 0;
@ -737,9 +747,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
if (stereo) bars = bars * 2; if (stereo) bars = bars * 2;
cont = 1; bool resizeTerminal = FALSE;
// general: main loop
while (cont) { while (!resizeTerminal) {
// general: keyboard controls // general: keyboard controls
#ifdef NCURSES #ifdef NCURSES
@ -755,11 +765,11 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
break; break;
case 68: // key right case 68: // key right
bw++; bw++;
cont = 0; resizeTerminal = TRUE;
break; break;
case 67: // key left case 67: // key left
if (bw > 1) bw--; if (bw > 1) bw--;
cont = 0; resizeTerminal = TRUE;
break; break;
case 'm': case 'm':
if (mode == modes) { if (mode == modes) {
@ -769,19 +779,22 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
} }
break; break;
case 'r': //reload config case 'r': //reload config
load_config(configPath); //**telling audio thread to terminate**//
validate_config(); audio.terminate = 1;
cont = 0; pthread_join( p_thread, NULL);
reloadConf = TRUE;
resizeTerminal = TRUE;
break; break;
case 'c': //change forground color case 'c': //change forground color
if (col < 7) col++; if (col < 7) col++;
else col = 0; else col = 0;
cont = 0; resizeTerminal = TRUE;
break; break;
case 'b': //change backround color case 'b': //change backround color
if (bgcol < 7) bgcol++; if (bgcol < 7) bgcol++;
else bgcol = 0; else bgcol = 0;
cont = 0; resizeTerminal = TRUE;
break; break;
case 'q': case 'q':
@ -789,7 +802,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (cont == 0) break; //if (cont == 0) break;
#ifdef DEBUG #ifdef DEBUG
//clear(); //clear();
@ -936,7 +949,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
break; break;
} }
if (rc == -1) break; //terminal has been resized breaking to recalibrating values if (rc == -1) resizeTerminal = TRUE; //terminal has been resized breaking to recalibrating values
if (framerate <= 1) { if (framerate <= 1) {
req.tv_sec = 1 / (float)framerate; req.tv_sec = 1 / (float)framerate;
@ -952,5 +965,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
flastd[o] = f[o]; flastd[o] = f[o];
} }
} }
}//reloading config
req.tv_sec = 1; //waiting a second to free audio streams
req.tv_nsec = 0;
nanosleep (&req, NULL);
} }
} }

@ -120,8 +120,14 @@ void* input_alsa(void* data)
n++; n++;
} }
if (audio->terminate == 1) {
free(buffer);
snd_pcm_close(handle);
break;
}
} }
fprintf(stderr,"test\n"); return 0;
} }

@ -4,9 +4,10 @@ struct audio_data {
int audio_out_l[2048]; int audio_out_l[2048];
int format; int format;
unsigned int rate ; unsigned int rate ;
char *source; //alsa device or fifo path char *source; //alsa device, fifo path or pulse source
int im; //input mode alsa or fifo int im; //input mode alsa, fifo or pulse
int channels; int channels;
int terminate; // shared variable used to terminate audio thread
}; };
@ -77,6 +78,13 @@ templ) /
if (n == 2048 - 1)n = 0; if (n == 2048 - 1)n = 0;
} }
} }
if (audio->terminate == 1) {
close(fd);
break;
}
} }
close(fd);
return 0;
} }

@ -59,6 +59,12 @@ void* input_pulse(void* data)
n++; n++;
if (n == 2048 - 1)n = 0; if (n == 2048 - 1)n = 0;
} }
if (audio->terminate == 1) {
pa_simple_free(s);
break;
}
} }
return 0;
} }

Loading…
Cancel
Save