diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/aiorecord.cc | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/src/aiorecord.cc b/src/aiorecord.cc index ff6eb74..458a700 100644 --- a/src/aiorecord.cc +++ b/src/aiorecord.cc @@ -72,6 +72,27 @@ void ctrl_c(int) running = false; } +void vu(const char *pcm, size_t size) +{ + static double avg = 0; + short *p = (short*)pcm; + size_t sz = size / sizeof(short); + short max = 0; + for(int i = 0; i < (int)sz; i++) { + if(abs(p[i]) > max) max = abs(p[i]); + } + char bar[33]; + char spc[33]; + avg = avg * 0.95 + (double)max * 0.05; + size_t pos = (int)avg / 1000; + memset(bar, '#', sizeof(bar)); + memset(spc, ' ', sizeof(spc)); + bar[pos] = '\0'; + spc[sizeof(spc) - pos] = '\0'; + printf("\rVU [% 6d]: |%s>%s|", (int)avg, bar, spc); + fflush(stdout); +} + int main(int argc, char *argv[]) { // This program acts as both a recorder and a player depending on which name @@ -177,33 +198,15 @@ int main(int argc, char *argv[]) return 1; } - double avg = 0; while(running) { char pcm[1024]; size_t size = src->readSamples(pcm, sizeof(pcm)); size_t w = fwrite(pcm, size, 1, fp); (void)w; - if(verbose) { - short *p = (short*)pcm; - size_t sz = size / sizeof(short); - short max = 0; - for(int i = 0; i < (int)sz; i++) { - if(abs(p[i]) > max) max = abs(p[i]); - } - char bar[33]; - char spc[33]; - avg = avg * 0.99 + (double)max * 0.01; - size_t pos = (int)avg / 1000; - memset(bar, '#', sizeof(bar)); - memset(spc, ' ', sizeof(spc)); - bar[pos] = '\0'; - spc[sizeof(spc) - pos] = '\0'; - printf("\rVU [% 6d]: %s%s", (int)avg, bar, spc); - fflush(stdout); - } + if(verbose) vu(pcm, size); } fclose(fp); - printf("done\n"); + printf("\ndone\n"); } break; @@ -220,6 +223,16 @@ int main(int argc, char *argv[]) perror(""); return 1; } + + while(running) { + char pcm[1024]; + size_t size = fread(pcm, size, 1, fp); + sink->writeSamples(pcm, size); + if(verbose) vu(pcm, size); + } + fclose(fp); + + printf("\ndone\n"); } break; |