changeset 2:ff028323c114

rename metro.c to lsonify.c
author paulo@localhost
date Thu, 21 May 2009 00:00:49 -0700
parents 46d4c88917a2
children 3dd48f06493e
files Makefile lsonify.c metro.c
diffstat 3 files changed, 282 insertions(+), 282 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Sun May 17 02:32:01 2009 -0700
     1.2 +++ b/Makefile	Thu May 21 00:00:49 2009 -0700
     1.3 @@ -6,7 +6,7 @@
     1.4  
     1.5  CC = gcc
     1.6  
     1.7 -SRC = metro.c
     1.8 +SRC = lsonify.c
     1.9  OBJ = ${SRC:.c=.o}
    1.10  
    1.11  TARGET := lsonify
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/lsonify.c	Thu May 21 00:00:49 2009 -0700
     2.3 @@ -0,0 +1,281 @@
     2.4 +/*
     2.5 +    Copyright (C) 2002 Anthony Van Groningen
     2.6 +    
     2.7 +    This program is free software; you can redistribute it and/or modify
     2.8 +    it under the terms of the GNU General Public License as published by
     2.9 +    the Free Software Foundation; either version 2 of the License, or
    2.10 +    (at your option) any later version.
    2.11 +
    2.12 +    This program is distributed in the hope that it will be useful,
    2.13 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 +    GNU General Public License for more details.
    2.16 +
    2.17 +    You should have received a copy of the GNU General Public License
    2.18 +    along with this program; if not, write to the Free Software
    2.19 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    2.20 +*/
    2.21 +
    2.22 +// 20090516 PBA: started modifying metro.c for lsonify 
    2.23 +
    2.24 +#include <stdlib.h>
    2.25 +#include <stdio.h>
    2.26 +#include <errno.h>
    2.27 +#include <unistd.h>
    2.28 +#include <math.h>
    2.29 +#include <getopt.h>
    2.30 +#include <string.h>
    2.31 +
    2.32 +#include <jack/jack.h>
    2.33 +#include <jack/transport.h>
    2.34 +
    2.35 +typedef jack_default_audio_sample_t sample_t;
    2.36 +
    2.37 +const double PI = 3.14;
    2.38 +
    2.39 +jack_client_t *client;
    2.40 +jack_port_t *output_port;
    2.41 +unsigned long sr;
    2.42 +int freq = 880;
    2.43 +int bpm;
    2.44 +jack_nframes_t tone_length, wave_length;
    2.45 +sample_t *wave;
    2.46 +long offset = 0;
    2.47 +int transport_aware = 0;
    2.48 +jack_transport_state_t transport_state;
    2.49 +
    2.50 +void
    2.51 +usage ()
    2.52 +
    2.53 +{
    2.54 +	fprintf (stderr, "\n"
    2.55 +"usage: lsonify \n"
    2.56 +"              [ --frequency OR -f frequency (in Hz) ]\n"
    2.57 +"              [ --amplitude OR -A maximum amplitude (between 0 and 1) ]\n"
    2.58 +"              [ --duration OR -D duration (in ms) ]\n"
    2.59 +"              [ --attack OR -a attack (in percent of duration) ]\n"
    2.60 +"              [ --decay OR -d decay (in percent of duration) ]\n"
    2.61 +"              [ --name OR -n jack name for metronome client ]\n"
    2.62 +"              [ --transport OR -t transport aware ]\n"
    2.63 +"              [ --nophysical OR -p to prevent auto-connect to all physical ports]\n"
    2.64 +"              --bpm OR -b beats per minute\n"
    2.65 +);
    2.66 +}
    2.67 +
    2.68 +void
    2.69 +process_silence (jack_nframes_t nframes) 
    2.70 +{
    2.71 +	sample_t *buffer = (sample_t *) jack_port_get_buffer (output_port, nframes);
    2.72 +	memset (buffer, 0, sizeof (jack_default_audio_sample_t) * nframes);
    2.73 +}
    2.74 +
    2.75 +void
    2.76 +process_audio (jack_nframes_t nframes) 
    2.77 +{
    2.78 +
    2.79 +	sample_t *buffer = (sample_t *) jack_port_get_buffer (output_port, nframes);
    2.80 +	jack_nframes_t frames_left = nframes;
    2.81 +		
    2.82 +	while (wave_length - offset < frames_left) {
    2.83 +		memcpy (buffer + (nframes - frames_left), wave + offset, sizeof (sample_t) * (wave_length - offset));
    2.84 +		frames_left -= wave_length - offset;
    2.85 +		offset = 0;
    2.86 +	}
    2.87 +	if (frames_left > 0) {
    2.88 +		memcpy (buffer + (nframes - frames_left), wave + offset, sizeof (sample_t) * frames_left);
    2.89 +		offset += frames_left;
    2.90 +	}
    2.91 +}
    2.92 +
    2.93 +int
    2.94 +process (jack_nframes_t nframes, void *arg)
    2.95 +{
    2.96 +	if (transport_aware) {
    2.97 +		jack_position_t pos;
    2.98 +
    2.99 +		if (jack_transport_query (client, &pos)
   2.100 +		    != JackTransportRolling) {
   2.101 +
   2.102 +			process_silence (nframes);
   2.103 +			return 0;
   2.104 +		}
   2.105 +		offset = pos.frame % wave_length;
   2.106 +	}
   2.107 +	process_audio (nframes);
   2.108 +	return 0;
   2.109 +}
   2.110 +
   2.111 +int
   2.112 +sample_rate_change () {
   2.113 +	printf("Sample rate has changed! Exiting...\n");
   2.114 +	exit(-1);
   2.115 +}
   2.116 +
   2.117 +int
   2.118 +main (int argc, char *argv[])
   2.119 +{
   2.120 +	
   2.121 +	sample_t scale;
   2.122 +	int i, attack_length, decay_length;
   2.123 +	double *amp;
   2.124 +	double max_amp = 0.5;
   2.125 +	int opt;
   2.126 +	int got_bpm = 0;
   2.127 +	int attack_percent = 1, decay_percent = 10, dur_arg = 100;
   2.128 +	char *client_name = 0;
   2.129 +	char *port_string = "out";
   2.130 +	int verbose = 0;
   2.131 +	int connect_physical_ports = 1;
   2.132 +	jack_status_t status;
   2.133 +
   2.134 +	const char *options = "f:A:D:a:d:b:n:tphv";
   2.135 +	struct option long_options[] =
   2.136 +	{
   2.137 +		{"frequency", 1, 0, 'f'},
   2.138 +		{"amplitude", 1, 0, 'A'},
   2.139 +		{"duration", 1, 0, 'D'},
   2.140 +		{"attack", 1, 0, 'a'},
   2.141 +		{"decay", 1, 0, 'd'},
   2.142 +		{"bpm", 1, 0, 'b'},
   2.143 +		{"name", 1, 0, 'n'},
   2.144 +		{"transport", 0, 0, 't'},
   2.145 +		{"nophysical", 0, 0, 'p'},
   2.146 +		{"help", 0, 0, 'h'},
   2.147 +		{"verbose", 0, 0, 'v'},
   2.148 +		{0, 0, 0, 0}
   2.149 +	};
   2.150 +	
   2.151 +	while ((opt = getopt_long (argc, argv, options, long_options, NULL)) != EOF) {
   2.152 +		switch (opt) {
   2.153 +		case 'f':
   2.154 +			if ((freq = atoi (optarg)) <= 0) {
   2.155 +				fprintf (stderr, "invalid frequency\n");
   2.156 +				return -1;
   2.157 +			}
   2.158 +			break;
   2.159 +		case 'A':
   2.160 +			if (((max_amp = atof (optarg)) <= 0)|| (max_amp > 1)) {
   2.161 +				fprintf (stderr, "invalid amplitude\n");
   2.162 +				return -1;
   2.163 +			}
   2.164 +			break;
   2.165 +		case 'D':
   2.166 +			dur_arg = atoi (optarg);
   2.167 +			fprintf (stderr, "durarg = %u\n", dur_arg);
   2.168 +			break;
   2.169 +		case 'a':
   2.170 +			if (((attack_percent = atoi (optarg)) < 0) || (attack_percent > 100)) {
   2.171 +				fprintf (stderr, "invalid attack percent\n");
   2.172 +				return -1;
   2.173 +			}
   2.174 +			break;
   2.175 +		case 'd':
   2.176 +			if (((decay_percent = atoi (optarg)) < 0) || (decay_percent > 100)) {
   2.177 +				fprintf (stderr, "invalid decay percent\n");
   2.178 +				return -1;
   2.179 +			}
   2.180 +			break;
   2.181 +		case 'b':
   2.182 +			got_bpm = 1;
   2.183 +			if ((bpm = atoi (optarg)) < 0) {
   2.184 +				fprintf (stderr, "invalid bpm\n");
   2.185 +				return -1;
   2.186 +			}
   2.187 +			break;
   2.188 +		case 'n':
   2.189 +			client_name = (char *) malloc (strlen (optarg) * sizeof (char));
   2.190 +			strcpy (client_name, optarg);
   2.191 +			break;
   2.192 +		case 'v':
   2.193 +			verbose = 1;
   2.194 +			break;
   2.195 +		case 't':
   2.196 +			transport_aware = 1;
   2.197 +			break;
   2.198 +		case 'p':
   2.199 +			connect_physical_ports = 0;
   2.200 +			break;
   2.201 +		default:
   2.202 +			fprintf (stderr, "unknown option %c\n", opt); 
   2.203 +		case 'h':
   2.204 +			usage ();
   2.205 +			return -1;
   2.206 +		}
   2.207 +	}
   2.208 +	if (!got_bpm) {
   2.209 +		fprintf (stderr, "bpm not specified\n");
   2.210 +		usage ();
   2.211 +		return -1;
   2.212 +	}
   2.213 +
   2.214 +	/* Initial Jack setup, get sample rate */
   2.215 +	if (!client_name) {
   2.216 +		pid_t pid = getpid();
   2.217 +		client_name = (char *) malloc (32 * sizeof (char));
   2.218 +		snprintf (client_name, 32, "metro_%d", pid);
   2.219 +	}
   2.220 +	if ((client = jack_client_open (client_name, JackNoStartServer, &status)) == 0) {
   2.221 +		fprintf (stderr, "jack server not running?\n");
   2.222 +		return 1;
   2.223 +	}
   2.224 +	jack_set_process_callback (client, process, 0);
   2.225 +	output_port = jack_port_register (client, port_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
   2.226 +
   2.227 +	sr = jack_get_sample_rate (client);
   2.228 +
   2.229 +	/* setup wave table parameters */
   2.230 +	wave_length = 60 * sr / bpm;
   2.231 +	tone_length = sr * dur_arg / 1000;
   2.232 +	attack_length = tone_length * attack_percent / 100;
   2.233 +	decay_length = tone_length * decay_percent / 100;
   2.234 +	scale = 2 * PI * freq / sr;
   2.235 +
   2.236 +	if (tone_length >= wave_length) {
   2.237 +		fprintf (stderr, "invalid duration (tone length = %" PRIu32
   2.238 +			 ", wave length = %" PRIu32 "\n", tone_length,
   2.239 +			 wave_length);
   2.240 +		return -1;
   2.241 +	}
   2.242 +	if (attack_length + decay_length > (int)tone_length) {
   2.243 +		fprintf (stderr, "invalid attack/decay\n");
   2.244 +		return -1;
   2.245 +	}
   2.246 +
   2.247 +	/* Build the wave table */
   2.248 +	wave = (sample_t *) malloc (wave_length * sizeof(sample_t));
   2.249 +	amp = (double *) malloc (tone_length * sizeof(double));
   2.250 +
   2.251 +	for (i = 0; i < attack_length; i++) {
   2.252 +		amp[i] = max_amp * i / ((double) attack_length);
   2.253 +	}
   2.254 +	for (i = attack_length; i < (int)tone_length - decay_length; i++) {
   2.255 +		amp[i] = max_amp;
   2.256 +	}
   2.257 +	for (i = (int)tone_length - decay_length; i < (int)tone_length; i++) {
   2.258 +		amp[i] = - max_amp * (i - (double) tone_length) / ((double) decay_length);
   2.259 +	}
   2.260 +	for (i = 0; i < (int)tone_length; i++) {
   2.261 +		wave[i] = amp[i] * sin (scale * i);
   2.262 +	}
   2.263 +	for (i = tone_length; i < (int)wave_length; i++) {
   2.264 +		wave[i] = 0;
   2.265 +	}
   2.266 +
   2.267 +	if (jack_activate (client)) {
   2.268 +		fprintf (stderr, "cannot activate client");
   2.269 +		return 1;
   2.270 +	}
   2.271 +
   2.272 +	/* connect to physical ports */
   2.273 +	if (connect_physical_ports) {
   2.274 +		const char **ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
   2.275 +		const char **c;
   2.276 +		for (c = ports; c && *c; c++)
   2.277 +			jack_connect (client, jack_port_name(output_port), *c);
   2.278 +	}
   2.279 +
   2.280 +	while (1) {
   2.281 +		sleep(1);
   2.282 +	};
   2.283 +	
   2.284 +}
     3.1 --- a/metro.c	Sun May 17 02:32:01 2009 -0700
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,281 +0,0 @@
     3.4 -/*
     3.5 -    Copyright (C) 2002 Anthony Van Groningen
     3.6 -    
     3.7 -    This program is free software; you can redistribute it and/or modify
     3.8 -    it under the terms of the GNU General Public License as published by
     3.9 -    the Free Software Foundation; either version 2 of the License, or
    3.10 -    (at your option) any later version.
    3.11 -
    3.12 -    This program is distributed in the hope that it will be useful,
    3.13 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 -    GNU General Public License for more details.
    3.16 -
    3.17 -    You should have received a copy of the GNU General Public License
    3.18 -    along with this program; if not, write to the Free Software
    3.19 -    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    3.20 -*/
    3.21 -
    3.22 -// 20090516 PBA: started modifying metro.c for lsonify 
    3.23 -
    3.24 -#include <stdlib.h>
    3.25 -#include <stdio.h>
    3.26 -#include <errno.h>
    3.27 -#include <unistd.h>
    3.28 -#include <math.h>
    3.29 -#include <getopt.h>
    3.30 -#include <string.h>
    3.31 -
    3.32 -#include <jack/jack.h>
    3.33 -#include <jack/transport.h>
    3.34 -
    3.35 -typedef jack_default_audio_sample_t sample_t;
    3.36 -
    3.37 -const double PI = 3.14;
    3.38 -
    3.39 -jack_client_t *client;
    3.40 -jack_port_t *output_port;
    3.41 -unsigned long sr;
    3.42 -int freq = 880;
    3.43 -int bpm;
    3.44 -jack_nframes_t tone_length, wave_length;
    3.45 -sample_t *wave;
    3.46 -long offset = 0;
    3.47 -int transport_aware = 0;
    3.48 -jack_transport_state_t transport_state;
    3.49 -
    3.50 -void
    3.51 -usage ()
    3.52 -
    3.53 -{
    3.54 -	fprintf (stderr, "\n"
    3.55 -"usage: lsonify \n"
    3.56 -"              [ --frequency OR -f frequency (in Hz) ]\n"
    3.57 -"              [ --amplitude OR -A maximum amplitude (between 0 and 1) ]\n"
    3.58 -"              [ --duration OR -D duration (in ms) ]\n"
    3.59 -"              [ --attack OR -a attack (in percent of duration) ]\n"
    3.60 -"              [ --decay OR -d decay (in percent of duration) ]\n"
    3.61 -"              [ --name OR -n jack name for metronome client ]\n"
    3.62 -"              [ --transport OR -t transport aware ]\n"
    3.63 -"              [ --nophysical OR -p to prevent auto-connect to all physical ports]\n"
    3.64 -"              --bpm OR -b beats per minute\n"
    3.65 -);
    3.66 -}
    3.67 -
    3.68 -void
    3.69 -process_silence (jack_nframes_t nframes) 
    3.70 -{
    3.71 -	sample_t *buffer = (sample_t *) jack_port_get_buffer (output_port, nframes);
    3.72 -	memset (buffer, 0, sizeof (jack_default_audio_sample_t) * nframes);
    3.73 -}
    3.74 -
    3.75 -void
    3.76 -process_audio (jack_nframes_t nframes) 
    3.77 -{
    3.78 -
    3.79 -	sample_t *buffer = (sample_t *) jack_port_get_buffer (output_port, nframes);
    3.80 -	jack_nframes_t frames_left = nframes;
    3.81 -		
    3.82 -	while (wave_length - offset < frames_left) {
    3.83 -		memcpy (buffer + (nframes - frames_left), wave + offset, sizeof (sample_t) * (wave_length - offset));
    3.84 -		frames_left -= wave_length - offset;
    3.85 -		offset = 0;
    3.86 -	}
    3.87 -	if (frames_left > 0) {
    3.88 -		memcpy (buffer + (nframes - frames_left), wave + offset, sizeof (sample_t) * frames_left);
    3.89 -		offset += frames_left;
    3.90 -	}
    3.91 -}
    3.92 -
    3.93 -int
    3.94 -process (jack_nframes_t nframes, void *arg)
    3.95 -{
    3.96 -	if (transport_aware) {
    3.97 -		jack_position_t pos;
    3.98 -
    3.99 -		if (jack_transport_query (client, &pos)
   3.100 -		    != JackTransportRolling) {
   3.101 -
   3.102 -			process_silence (nframes);
   3.103 -			return 0;
   3.104 -		}
   3.105 -		offset = pos.frame % wave_length;
   3.106 -	}
   3.107 -	process_audio (nframes);
   3.108 -	return 0;
   3.109 -}
   3.110 -
   3.111 -int
   3.112 -sample_rate_change () {
   3.113 -	printf("Sample rate has changed! Exiting...\n");
   3.114 -	exit(-1);
   3.115 -}
   3.116 -
   3.117 -int
   3.118 -main (int argc, char *argv[])
   3.119 -{
   3.120 -	
   3.121 -	sample_t scale;
   3.122 -	int i, attack_length, decay_length;
   3.123 -	double *amp;
   3.124 -	double max_amp = 0.5;
   3.125 -	int opt;
   3.126 -	int got_bpm = 0;
   3.127 -	int attack_percent = 1, decay_percent = 10, dur_arg = 100;
   3.128 -	char *client_name = 0;
   3.129 -	char *port_string = "out";
   3.130 -	int verbose = 0;
   3.131 -	int connect_physical_ports = 1;
   3.132 -	jack_status_t status;
   3.133 -
   3.134 -	const char *options = "f:A:D:a:d:b:n:tphv";
   3.135 -	struct option long_options[] =
   3.136 -	{
   3.137 -		{"frequency", 1, 0, 'f'},
   3.138 -		{"amplitude", 1, 0, 'A'},
   3.139 -		{"duration", 1, 0, 'D'},
   3.140 -		{"attack", 1, 0, 'a'},
   3.141 -		{"decay", 1, 0, 'd'},
   3.142 -		{"bpm", 1, 0, 'b'},
   3.143 -		{"name", 1, 0, 'n'},
   3.144 -		{"transport", 0, 0, 't'},
   3.145 -		{"nophysical", 0, 0, 'p'},
   3.146 -		{"help", 0, 0, 'h'},
   3.147 -		{"verbose", 0, 0, 'v'},
   3.148 -		{0, 0, 0, 0}
   3.149 -	};
   3.150 -	
   3.151 -	while ((opt = getopt_long (argc, argv, options, long_options, NULL)) != EOF) {
   3.152 -		switch (opt) {
   3.153 -		case 'f':
   3.154 -			if ((freq = atoi (optarg)) <= 0) {
   3.155 -				fprintf (stderr, "invalid frequency\n");
   3.156 -				return -1;
   3.157 -			}
   3.158 -			break;
   3.159 -		case 'A':
   3.160 -			if (((max_amp = atof (optarg)) <= 0)|| (max_amp > 1)) {
   3.161 -				fprintf (stderr, "invalid amplitude\n");
   3.162 -				return -1;
   3.163 -			}
   3.164 -			break;
   3.165 -		case 'D':
   3.166 -			dur_arg = atoi (optarg);
   3.167 -			fprintf (stderr, "durarg = %u\n", dur_arg);
   3.168 -			break;
   3.169 -		case 'a':
   3.170 -			if (((attack_percent = atoi (optarg)) < 0) || (attack_percent > 100)) {
   3.171 -				fprintf (stderr, "invalid attack percent\n");
   3.172 -				return -1;
   3.173 -			}
   3.174 -			break;
   3.175 -		case 'd':
   3.176 -			if (((decay_percent = atoi (optarg)) < 0) || (decay_percent > 100)) {
   3.177 -				fprintf (stderr, "invalid decay percent\n");
   3.178 -				return -1;
   3.179 -			}
   3.180 -			break;
   3.181 -		case 'b':
   3.182 -			got_bpm = 1;
   3.183 -			if ((bpm = atoi (optarg)) < 0) {
   3.184 -				fprintf (stderr, "invalid bpm\n");
   3.185 -				return -1;
   3.186 -			}
   3.187 -			break;
   3.188 -		case 'n':
   3.189 -			client_name = (char *) malloc (strlen (optarg) * sizeof (char));
   3.190 -			strcpy (client_name, optarg);
   3.191 -			break;
   3.192 -		case 'v':
   3.193 -			verbose = 1;
   3.194 -			break;
   3.195 -		case 't':
   3.196 -			transport_aware = 1;
   3.197 -			break;
   3.198 -		case 'p':
   3.199 -			connect_physical_ports = 0;
   3.200 -			break;
   3.201 -		default:
   3.202 -			fprintf (stderr, "unknown option %c\n", opt); 
   3.203 -		case 'h':
   3.204 -			usage ();
   3.205 -			return -1;
   3.206 -		}
   3.207 -	}
   3.208 -	if (!got_bpm) {
   3.209 -		fprintf (stderr, "bpm not specified\n");
   3.210 -		usage ();
   3.211 -		return -1;
   3.212 -	}
   3.213 -
   3.214 -	/* Initial Jack setup, get sample rate */
   3.215 -	if (!client_name) {
   3.216 -		pid_t pid = getpid();
   3.217 -		client_name = (char *) malloc (32 * sizeof (char));
   3.218 -		snprintf (client_name, 32, "metro_%d", pid);
   3.219 -	}
   3.220 -	if ((client = jack_client_open (client_name, JackNoStartServer, &status)) == 0) {
   3.221 -		fprintf (stderr, "jack server not running?\n");
   3.222 -		return 1;
   3.223 -	}
   3.224 -	jack_set_process_callback (client, process, 0);
   3.225 -	output_port = jack_port_register (client, port_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
   3.226 -
   3.227 -	sr = jack_get_sample_rate (client);
   3.228 -
   3.229 -	/* setup wave table parameters */
   3.230 -	wave_length = 60 * sr / bpm;
   3.231 -	tone_length = sr * dur_arg / 1000;
   3.232 -	attack_length = tone_length * attack_percent / 100;
   3.233 -	decay_length = tone_length * decay_percent / 100;
   3.234 -	scale = 2 * PI * freq / sr;
   3.235 -
   3.236 -	if (tone_length >= wave_length) {
   3.237 -		fprintf (stderr, "invalid duration (tone length = %" PRIu32
   3.238 -			 ", wave length = %" PRIu32 "\n", tone_length,
   3.239 -			 wave_length);
   3.240 -		return -1;
   3.241 -	}
   3.242 -	if (attack_length + decay_length > (int)tone_length) {
   3.243 -		fprintf (stderr, "invalid attack/decay\n");
   3.244 -		return -1;
   3.245 -	}
   3.246 -
   3.247 -	/* Build the wave table */
   3.248 -	wave = (sample_t *) malloc (wave_length * sizeof(sample_t));
   3.249 -	amp = (double *) malloc (tone_length * sizeof(double));
   3.250 -
   3.251 -	for (i = 0; i < attack_length; i++) {
   3.252 -		amp[i] = max_amp * i / ((double) attack_length);
   3.253 -	}
   3.254 -	for (i = attack_length; i < (int)tone_length - decay_length; i++) {
   3.255 -		amp[i] = max_amp;
   3.256 -	}
   3.257 -	for (i = (int)tone_length - decay_length; i < (int)tone_length; i++) {
   3.258 -		amp[i] = - max_amp * (i - (double) tone_length) / ((double) decay_length);
   3.259 -	}
   3.260 -	for (i = 0; i < (int)tone_length; i++) {
   3.261 -		wave[i] = amp[i] * sin (scale * i);
   3.262 -	}
   3.263 -	for (i = tone_length; i < (int)wave_length; i++) {
   3.264 -		wave[i] = 0;
   3.265 -	}
   3.266 -
   3.267 -	if (jack_activate (client)) {
   3.268 -		fprintf (stderr, "cannot activate client");
   3.269 -		return 1;
   3.270 -	}
   3.271 -
   3.272 -	/* connect to physical ports */
   3.273 -	if (connect_physical_ports) {
   3.274 -		const char **ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
   3.275 -		const char **c;
   3.276 -		for (c = ports; c && *c; c++)
   3.277 -			jack_connect (client, jack_port_name(output_port), *c);
   3.278 -	}
   3.279 -
   3.280 -	while (1) {
   3.281 -		sleep(1);
   3.282 -	};
   3.283 -	
   3.284 -}