/* Crystality Plugin - A plugin for remastering mp3 sound in realtime * * Copyright (C) 2001 Rafal Bosak * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include "crystality.h" int run_gui = 1; #define CONFIG_FILE_NAME "/.crystalityrc" int read_config(void) { FILE *f; char *fname, *home; char n[60]; int v; home = getenv("HOME"); if (home == NULL) return -1; fname = malloc(strlen(home) + strlen(CONFIG_FILE_NAME) + 2); strcpy(fname, home); strcpy(fname + strlen(home), CONFIG_FILE_NAME); // fprintf(stderr, "reading %s\n", fname); if ((f = fopen(fname, "rt")) == NULL) { free(fname); return -1; } free(fname); while (fscanf(f, "%40s %i", n, &v) == 2){ // fprintf(stderr, "<%s> %i\n",n, v); if (strcmp(n, "expander") == 0) bext_level = v; if (strcmp(n, "echo") == 0) echo_level = v; if (strcmp(n, "stereo") == 0) stereo_level = v; if (strcmp(n, "filter") == 0) filter_level = v; if (strcmp(n, "feedback") == 0) feedback_level = v; if (strcmp(n, "harmonics") == 0) harmonics_level = v; } return 1; } int write_config(void) { FILE *f; char *fname, *home; home = getenv("HOME"); if (home == NULL) return -1; fname = malloc(strlen(home) + strlen(CONFIG_FILE_NAME) + 2); strcpy(fname, home); strcpy(fname + strlen(home), CONFIG_FILE_NAME); // fprintf(stderr, "writing %s\n", fname); if ((f = fopen(fname, "wt")) == NULL) { free(fname); return -1; } free(fname); fprintf(f, "expander %i\n", bext_level); fprintf(f, "echo %i\n", echo_level); fprintf(f, "stereo %i\n", stereo_level); fprintf(f, "filter %i\n", filter_level); fprintf(f, "feedback %i\n", feedback_level); fprintf(f, "harmonics %i\n", harmonics_level); return 1; } void clean_exit(int status){ cleanup(); if (run_gui) gtk_main_quit(); exit(status); } void *process_sound_stdio() { #define BUF_SIZE 4096 char buf[BUF_SIZE]; int length; while ((length = fread(buf, 1, BUF_SIZE, stdin)) > 0){ length = process_sound((void*)buf, (int)length, 0, 44100, 2); if (fwrite(buf, 1, length, stdout) == 0){ perror("fwrite"); clean_exit(11); } } if (!feof(stdin)) { clean_exit(12); } clean_exit (0); } int main(int argc, char **argv) { pthread_t thread; if (argc > 1 && strcmp(argv[1], "-g") == 0) run_gui = 0; if (argc > 1 && strcmp(argv[1], "-h") == 0) { fprintf(stderr, "Crystality plugin v0.92, stdin/out\n"); fprintf(stderr, "Bandwidth Extender, Harmonic Booster and 3D Echo.\n"); fprintf(stderr, "By Rafal Bosak 2001.\n\n"); fprintf(stderr, "usage: %s [ -b | -h ]\n", argv[0]); fprintf(stderr, " -h this help\n"); fprintf(stderr, " -g run without GUI\n\n"); fprintf(stderr, "config file: ~/.crystalityrc is written automatically on exit\n"); exit(0); } if (run_gui) gtk_init (&argc, &argv); init(); if (run_gui) configure(); thread= (pthread_t)malloc(sizeof(pthread_t)); pthread_create(&thread, 0, (void*(*)(void*))process_sound_stdio, 0); signal(SIGINT, clean_exit); signal(SIGTERM, clean_exit); if (run_gui) gtk_main(); else { for (;;) sleep(3600); } return 0; }