~ubuntu-branches/ubuntu/utopic/jconvolver/utopic-proposed

« back to all changes in this revision

Viewing changes to source/jconvolver.cc

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-01-17 17:43:09 UTC
  • Revision ID: james.westby@ubuntu.com-20100117174309-hc5fbqk31xwi1aok
Tags: upstream-0.8.4
ImportĀ upstreamĀ versionĀ 0.8.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  -----------------------------------------------------------------------------
 
2
//
 
3
//  Copyright (C) 2006-2009 Fons Adriaensen <fons@kokkinizita.net>
 
4
//  
 
5
//  This program is free software; you can redistribute it and/or modify
 
6
//  it under the terms of the GNU General Public License as published by
 
7
//  the Free Software Foundation; either version 2 of the License, or
 
8
//  (at your option) any later version.
 
9
//
 
10
//  This program is distributed in the hope that it will be useful,
 
11
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
//  GNU General Public License for more details.
 
14
//
 
15
//  You should have received a copy of the GNU General Public License
 
16
//  along with this program; if not, write to the Free Software
 
17
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
//
 
19
//  -----------------------------------------------------------------------------
 
20
 
 
21
 
 
22
#include <unistd.h>
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <ctype.h>
 
26
#include <string.h>
 
27
#include <sys/mman.h>
 
28
#include <signal.h>
 
29
#include "jclient.h"
 
30
#include "config.h"
 
31
 
 
32
 
 
33
static const char   *options = "hL:MN:v";
 
34
static const char   *N_val = "jconvolver";
 
35
static unsigned int  L_val = 0;
 
36
static bool          M_opt = false;
 
37
static bool          v_opt = false;
 
38
static bool          stop  = false;
 
39
 
 
40
 
 
41
Jclient       *jclient = 0;
 
42
Convproc      *conv = 0;
 
43
unsigned int   rate = 0;
 
44
unsigned int   frag = 0;
 
45
unsigned int   part = 0;
 
46
unsigned int   ninp = 0;
 
47
unsigned int   nout = 0;
 
48
unsigned int   size = 0;
 
49
 
 
50
 
 
51
static void help (void)
 
52
{
 
53
    fprintf (stderr, "\nJconvolver %s\n", VERSION);
 
54
    fprintf (stderr, "(C) 2006-2009 Fons Adriaensen  <fons@kokkinizita.net>\n\n");
 
55
    fprintf (stderr, "Usage: jconvolver <options> <config file> {<connect file>}\n");
 
56
    fprintf (stderr, "Options:\n");
 
57
    fprintf (stderr, "  -h                 Display this text\n");
 
58
    fprintf (stderr, "  -v                 Print partition list to stdout [off]\n");
 
59
    fprintf (stderr, "  -L <nframes>       Try to compensate <nframes> latency\n");
 
60
    fprintf (stderr, "  -M                 Use the FFTW_MEASURE option [off]\n");   
 
61
    fprintf (stderr, "  -N <name>          Name to use as JACK client [jconvolver]\n");   
 
62
    exit (1);
 
63
}
 
64
 
 
65
 
 
66
static void procoptions (int ac, char *av [], const char *where)
 
67
{
 
68
    int k;
 
69
    
 
70
    optind = 1;
 
71
    opterr = 0;
 
72
    while ((k = getopt (ac, av, (char *) options)) != -1)
 
73
    {
 
74
        if (optarg && (*optarg == '-'))
 
75
        {
 
76
            fprintf (stderr, "\n%s\n", where);
 
77
            fprintf (stderr, "  Missing argument for '-%c' option.\n", k); 
 
78
            fprintf (stderr, "  Use '-h' to see all options.\n");
 
79
            exit (1);
 
80
        }
 
81
        switch (k)
 
82
        {
 
83
        case 'h' : help (); exit (0);
 
84
        case 'v' : v_opt = true; break;
 
85
        case 'L' : L_val = atoi (optarg); break;
 
86
        case 'M' : M_opt = true; break;
 
87
        case 'N' : N_val = optarg; break; 
 
88
        case '?':
 
89
            fprintf (stderr, "\n%s\n", where);
 
90
            if (optopt != ':' && strchr (options, optopt))
 
91
            {
 
92
                fprintf (stderr, "  Missing argument for '-%c' option.\n", optopt); 
 
93
            }
 
94
            else if (isprint (optopt))
 
95
            {
 
96
                fprintf (stderr, "  Unknown option '-%c'.\n", optopt);
 
97
            }
 
98
            else
 
99
            {
 
100
                fprintf (stderr, "  Unknown option character '0x%02x'.\n", optopt & 255);
 
101
            }
 
102
            fprintf (stderr, "  Use '-h' to see all options.\n");
 
103
            exit (1);
 
104
        default:
 
105
            abort ();
 
106
        }
 
107
    }
 
108
}
 
109
 
 
110
 
 
111
static void sigint_handler (int)
 
112
{
 
113
    stop = true;
 
114
}
 
115
 
 
116
 
 
117
int main (int ac, char *av [])
 
118
{
 
119
    int flags;
 
120
     
 
121
    if (mlockall (MCL_CURRENT | MCL_FUTURE))
 
122
    {
 
123
        fprintf (stderr, "Warning: ");
 
124
        perror ("mlockall:");
 
125
    }
 
126
 
 
127
    procoptions (ac, av, "On command line:");
 
128
    if (ac <= optind) help ();
 
129
 
 
130
    conv = new Convproc;
 
131
    jclient = new Jclient (N_val, conv);
 
132
    rate = jclient->rate ();
 
133
    frag = jclient->frag ();
 
134
 
 
135
    if (M_opt) conv->set_fftwopt (FFTW_MEASURE);
 
136
    if (config (av [optind], L_val))
 
137
    {
 
138
        delete jclient;
 
139
        return 1;
 
140
    }
 
141
    if (v_opt) conv->print ();
 
142
 
 
143
    makeports ();
 
144
    jclient->start ();
 
145
 
 
146
    signal (SIGINT, sigint_handler); 
 
147
    while (! stop)
 
148
    {    
 
149
        usleep (100000);
 
150
        flags = jclient->flags ();
 
151
 
 
152
        if (flags & Jclient::FL_EXIT)
 
153
        {
 
154
            puts ("JACK ERROR");
 
155
            stop = true;
 
156
        }
 
157
        if (flags & Convproc::FL_LOAD)
 
158
        {
 
159
            puts ("CPU OVERLOAD");
 
160
            stop = true;
 
161
        }
 
162
        if (flags & Convproc::FL_LATE)
 
163
        {
 
164
            printf ("Processing can't keep up (%04x)\n", flags & Convproc::FL_LATE);
 
165
        }
 
166
    }
 
167
 
 
168
    jclient->stop ();
 
169
    while (conv->state () != Convproc::ST_STOP) usleep (100000);
 
170
    delete jclient;
 
171
    delete conv;
 
172
 
 
173
    return 0;
 
174
}
 
175