File: jconvolver.cc

package info (click to toggle)
jconvolver 0.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 2,796 kB
  • ctags: 213
  • sloc: cpp: 1,552; makefile: 42
file content (215 lines) | stat: -rw-r--r-- 5,928 bytes parent folder | download | duplicates (2)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//  -----------------------------------------------------------------------------
//
//  Copyright (C) 2006-2014 Fons Adriaensen <fons@linuxaudio.org>
//  
//  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., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//  -----------------------------------------------------------------------------


#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <sys/mman.h>
#include <signal.h>
#include "jclient.h"
#include "config.h"


#if ZITA_CONVOLVER_MAJOR_VERSION < 3
#error "This program requires zita-convolver version 3 or higher."
#endif


static const char   *clopt = "hvL:MVN:s:";
static const char   *N_val = "jconvolver";
static const char   *s_val = 0;
static unsigned int  L_val = 0;
static bool          M_opt = false;
static bool          V_opt = false;
static bool          v_opt = false;
static bool          stop  = false;


Convproc      *convproc = 0;
unsigned int   latency = 0;
unsigned int   options = 0;
unsigned int   fsamp = 0;
unsigned int   fragm = 0;
unsigned int   ninp = 0;
unsigned int   nout = 0;
unsigned int   size = 0;
Jclient       *jclient = 0;


static void help (void)
{
    fprintf (stderr, "\nJconvolver %s\n", VERSION);
    fprintf (stderr, "(C) 2006-2014 Fons Adriaensen  <fons@linuxaudio.org>\n\n");
    fprintf (stderr, "Usage: jconvolver <options> <config file> {<connect file>}\n");
    fprintf (stderr, "Options:\n");
    fprintf (stderr, "  -h                 Display this text\n");
    fprintf (stderr, "  -v                 Print partition list to stdout [off]\n");
    fprintf (stderr, "  -L <nframes>       Try to compensate <nframes> latency\n");
    fprintf (stderr, "  -M                 Use the FFTW_MEASURE option [off]\n");   
    fprintf (stderr, "  -V                 Use vector mode processing [off]\n");   
    fprintf (stderr, "  -N <name>          Name to use as JACK client [jconvolver]\n");   
    fprintf (stderr, "  -s <server>        Jack server name\n");
    exit (1);
}


static void procoptions (int ac, char *av [], const char *where)
{
    int k;
    
    optind = 1;
    opterr = 0;
    while ((k = getopt (ac, av, (char *) clopt)) != -1)
    {
        if (optarg && (*optarg == '-'))
        {
            fprintf (stderr, "\n%s\n", where);
	    fprintf (stderr, "  Missing argument for '-%c' option.\n", k); 
            fprintf (stderr, "  Use '-h' to see all options.\n");
            exit (1);
        }
	switch (k)
	{
        case 'h' : help (); exit (0);
        case 'v' : v_opt = true; break;
        case 'L' : L_val = atoi (optarg); break;
        case 'M' : M_opt = true; break;
        case 'V' : V_opt = true; break;
        case 'N' : N_val = optarg; break; 
        case 's' : s_val = optarg; break; 
        case '?':
            fprintf (stderr, "\n%s\n", where);
            if (optopt != ':' && strchr (clopt, optopt))
	    {
                fprintf (stderr, "  Missing argument for '-%c' option.\n", optopt); 
	    }
            else if (isprint (optopt))
	    {
                fprintf (stderr, "  Unknown option '-%c'.\n", optopt);
	    }
            else
	    {
                fprintf (stderr, "  Unknown option character '0x%02x'.\n", optopt & 255);
	    }
            fprintf (stderr, "  Use '-h' to see all options.\n");
            exit (1);
        default:
            abort ();
 	}
    }
}


static void sigint_handler (int)
{
    stop = true;
}


int main (int ac, char *av [])
{
    unsigned int k;
     
    if (zita_convolver_major_version () != ZITA_CONVOLVER_MAJOR_VERSION)
    {
	fprintf (stderr, "Zita-convolver does not match compile-time version.\n");
	return 1;
    }

    if (mlockall (MCL_CURRENT | MCL_FUTURE))
    {
        fprintf (stderr, "Warning: ");
        perror ("mlockall:");
    }

    procoptions (ac, av, "On command line:");
    if (ac <= optind) help ();

    convproc = new Convproc;
    jclient = new Jclient (N_val, s_val, convproc);
    fsamp = jclient->fsamp ();
    fragm = jclient->fragm ();

    if ((fragm < Convproc::MINQUANT) || (fragm > Convproc::MAXQUANT))
    {
	fprintf (stderr, "Jack period must be in the range %d...%d\n",
                 Convproc::MINQUANT, Convproc::MAXQUANT);
	delete jclient;
	delete convproc;
	return 1;
    }
    if (fragm & (fragm - 1))
    {
	fprintf (stderr, "Jack period must be a power of 2\n");
	delete jclient;
	delete convproc;
	return 1;
    }

    if (M_opt) options |= Convproc::OPT_FFTW_MEASURE;
    if (V_opt) options |= Convproc::OPT_VECTOR_MODE;
    latency = L_val;
    if (config (av [optind]))
    {
	delete jclient;
	delete convproc;
        return 1;
    }
    if (v_opt) convproc->print ();

    makeports ();
    jclient->start ();
    signal (SIGINT, sigint_handler); 
    while (! stop)
    {    
	usleep (100000);
	k = jclient->flags ();

	if (k & Jclient::FL_EXIT)
	{
	    puts ("Zombified by Jack, exiting.");
	    stop = true;
	}
	if (k & Jclient::FL_BUFF)
	{
	    puts ("Jack buffer size change, exiting.");
	    stop = true;
	}
	if (k & Convproc::FL_LOAD)
	{
	    puts ("CPU overload, exiting.");
	    stop = true;
	}
	if (k & Convproc::FL_LATE)
	{
	    printf ("Computation threads are late (%04x).\n", k & Convproc::FL_LATE);
	}
    }

    jclient->stop ();
    delete jclient;
    delete convproc;

    return 0;
}