Fex

Check-in [2e02103397]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:ver 2.0
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v2.0 | trunk
Files: files | file ages | folders
SHA3-256: 2e02103397a57710267acdac06cc86a298e4f613c00564fbc4fed76ea4c632ec
User & Date: jesse@mccluresk9.com 2014-08-12 20:24:31
Context
2014-08-16
19:11
rpm packaging check-in: 0c22652f69 user: jesse@mccluresk9.com tags: trunk, master
2014-08-12
20:24
ver 2.0 Leaf check-in: 2e02103397 user: jesse@mccluresk9.com tags: v2.0, trunk
2014-07-15
17:32
clean up cursors check-in: 6fed09b0e9 user: jesse@mccluresk9.com tags: trunk
Changes

Changes to Makefile.

1
2
3
4
5
6
7
8
9
PROG     =  fex
VER      =  2.0rc
CC       ?= gcc
DEPS     =  x11 cairo freetype2 fftw3 sndfile
DEFS		=  -DPROGRAM_NAME=${PROG} -DPROGRAM_VER=${VER}
CFLAGS   += $(shell pkg-config --cflags ${DEPS}) ${DEFS}
LDLIBS   += $(shell pkg-config --libs ${DEPS}) -lm -lXpm
PREFIX   ?= /usr
MODULES  =  config fex fft spectro wave xlib

|







1
2
3
4
5
6
7
8
9
PROG     =  fex
VER      =  2.0
CC       ?= gcc
DEPS     =  x11 cairo freetype2 fftw3 sndfile
DEFS		=  -DPROGRAM_NAME=${PROG} -DPROGRAM_VER=${VER}
CFLAGS   += $(shell pkg-config --cflags ${DEPS}) ${DEFS}
LDLIBS   += $(shell pkg-config --libs ${DEPS}) -lm -lXpm
PREFIX   ?= /usr
MODULES  =  config fex fft spectro wave xlib

Changes to pkg/debian/DEBBUILD.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pkgname="fex"
pkgver="2"
pkgrel=1
pkgdesc='Frequency Excursion Calculator'
url='http://behaviorenterprises.com/software.html?package=fex'
license='GPL3'
arch="$(dpkg --print-architecture)"
depends=('desktop-file-utils' 'libasound2' 'libcairo2' 'libfftw3-3'
	'libxpm4' 'libsndfile1' 'python2.6')
makedepends=('build-essential' 'dpkg-dev' 'checkinstall' 'git'
	'libasound2-dev' 'libcairo2-dev' 'libfftw3-dev' 'libsndfile1-dev'
	'libx11-dev' 'libxpm-dev' 'texlive')
optdepends=('sox')
source=("git://github.com/TrilbyWhite/fex.git")
sha256sums=('SKIP')







|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pkgname="fex"
pkgver="2"
pkgrel=1
pkgdesc='Frequency Excursion Calculator'
url='http://behaviorenterprises.com/software.html?package=fex'
license='GPL3'
arch="$(dpkg --print-architecture)"
depends=('desktop-file-utils' 'libcairo2' 'libfftw3-3'
	'libxpm4' 'libsndfile1' 'python2.6')
makedepends=('build-essential' 'dpkg-dev' 'checkinstall' 'git'
	'libasound2-dev' 'libcairo2-dev' 'libfftw3-dev' 'libsndfile1-dev'
	'libx11-dev' 'libxpm-dev' 'texlive')
optdepends=('sox')
source=("git://github.com/TrilbyWhite/fex.git")
sha256sums=('SKIP')

Added pkg/fedora/fex.spec.











































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
summary: Frequency Excursion Calculator
name: fex
version: 1.0
release: 1
copyright: GPL3
group: Applications/Science
source: https://github.com/BehaviorEnterprises/fex.git
nosource: 0
url:
vendor: Behavior Enterprises
packager: Jesse McClure jesse [at] mccluresk9 [dot] com
requires: cairo, desktop-file-utils, fftw, libxpm, libsndfile, python2, git, texlive-core
prefix: /usr

%description
This spec file is a work in progress.  It is not yet complete, and
completely untested.  Do not use as-is.  Input from rpm-based distro
users would be appreciated.
TODO
check dependency names on rpm system
test whether git source for prep can even work
determine suitable version numbering (git tags perhaps)

%prep
rm -rf "${RPM_BUILD_DIR}/fex-${version}-${release}"
git clone https://github.com/BehaviorEnterprises/fex.git fex-${version}-${release}

%build
make

%install
make "DESTDIR=${RPM_BUILD_ROOT}" "PREFIX=${prefix}" install

%clean
rm -rf "${RPM_BUILD_ROOT}"

%post
update-desktop-database -q

%postun
update-desktop-database -q

%files
/usr/bin/fex
/usr/bin/fex-gtk
/usr/share/applications/
/usr/share/applications/fex.desktop
/usr/share/fex/
/usr/share/fex/config
/usr/share/man/man1/fex-help.1.gz
/usr/share/man/man1/fex.1.gz
/usr/share/pixmaps/fex.png

Changes to src/config.c.

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
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
...
116
117
118
119
120
121
122

123
124
125
126
127
128
129
...
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
#define C_TYPE_F	0x02
#define C_TYPE_LF	0x03
#define C_TYPE_S	0x04
#define C_TYPE_LN	0x05

#define STRING(s)		STRINGIFY(s)
#define STRINGIFY(s)	#s
#define LINE_LEN	256

static FT_Library library;
static FT_Face face, bface;
static WindowFunction custom;
static WindowFunction windows[] = {
	{ "hanning",         {0.5,       0.5,       0.0,       0.0}       },
	{ "hamming",         {0.54,      0.46,      0.0,       0.0}       },
................................................................................
		"  fex(1) and fex-help(1)\n"
		"\n" );
	exit(0);
}

const char *configure(int argc, const char **argv) {
	int i;

	const char *arg, *fname = NULL, *rcname = NULL;
	char help_cmd[256] = "xterm -e man man";
	conf.help_cmd = NULL;
	conf.long_out = False;
	conf.layers = True;

	for (i = 1; i < argc; i++) {
		arg = argv[i];
		if (strncmp(arg,"--h",3) == 0 || strncmp(arg,"-h",2) == 0)
			help();
		else if (strncmp(arg,"--v",3) == 0 || strncmp(arg,"-v",2) == 0)
			version();
		else if (strncmp(arg,"--l",3) == 0 || strncmp(arg,"-l",2) == 0)
................................................................................
			conf.long_out = True;
		else if (strncmp(arg,"-c",2) == 0 && (++i) < argc)
			rcname = argv[i];
		else
			fname = argv[i];
	}
	if (!fname) die("no audio file provided");

	FILE *rc = NULL;
	char *pwd = getenv("PWD");
	if (rcname) rc = fopen(rcname,"r");
	else if ( (!chdir(getenv("XDG_CONFIG_HOME")) && !chdir("fex")) ||
			(!chdir(getenv("HOME")) && !chdir(".config/fex")) )
		rc = fopen("config","r");
	if (!rc && !chdir(getenv("HOME"))) rc = fopen(".fexrc","r");
	chdir(pwd);
	if (!rc) rc = fopen("/usr/share/fex/config","r");
	if (!rc) die("unable to open configuration file");

	char line[LINE_LEN], prefix[32], option[32], fmt[LINE_LEN];
	char window[32], font_path1[LINE_LEN], font_path2[LINE_LEN];
	const char *fspec[] = { "", "%d ","%f ", "%lf ", "%s", "%[^\n]" };
	int j, mode;
	conf.thresh = 14.0;
	conf.spect_floor = 40.0;
	conf.hipass = 12.0;
................................................................................
		const char *name;
		int mode;
		int type[5];
		void *var[5];
	} cf[] = {
		#include "config.h"
	};

	while (fgets(line,LINE_LEN,rc)) {
		if (line[0] == '#' || line[0] == '\n') continue;
		sscanf(line,"%s %s",prefix,option);
		if (strncasecmp(prefix,"set",3) == 0) mode = CONF_SET;
		else if (strncasecmp(prefix,"col",3) == 0) mode = CONF_COL;
		else fprintf(stderr,"bad config entry: %s",line);
		sprintf(fmt,"%s %s ",prefix,option);
................................................................................
					cf[i].mode == mode ) {
				for (j = 0; j < 5; j++) strcat(fmt,fspec[cf[i].type[j]]);
				sscanf(line,fmt,cf[i].var[0],cf[i].var[1],cf[i].var[2],
						cf[i].var[3],cf[i].var[4]);
			}
		}
	}

	if (!conf.hop) conf.hop = conf.winlen / 4;
	conf.thresh *= -1;
	conf.spect_floor *= -1;
	if (strncasecmp(window,"custom",6) == 0)
		conf.win = (WindowFunction *) &custom;
	else if (strlen(window))
		for (i = 0; i < sizeof(windows)/sizeof(windows[0]); i++)
			if (!strncasecmp(window,windows[i].type,strlen(window)))
				conf.win = (WindowFunction *) &windows[i];

	if (FT_Init_FreeType(&library)) die("unable to init freetype");
	if ( FT_New_Face(library, font_path1, 0, &face) |
			FT_Set_Pixel_Sizes(face, 0, conf.font_size) )
		fprintf(stderr,"unable to load freetype font: %s\n",font_path1);
	if ( FT_New_Face(library, font_path2, 0, &bface) |
			FT_Set_Pixel_Sizes(bface, 0, conf.font_size) )
		fprintf(stderr,"unable to load freetype font: %s\n",font_path2);
	conf.font = cairo_ft_font_face_create_for_ft_face(face,0);
	conf.bfont = cairo_ft_font_face_create_for_ft_face(bface,0);

	char *help_arg = strtok(help_cmd," ");
	for (i = 0; help_arg; i++) {
		conf.help_cmd = realloc(conf.help_cmd, (i+2) * sizeof(char *));
		conf.help_cmd[i] = strdup(help_arg);
		conf.help_cmd[i+1] = NULL;
		help_arg = strtok(NULL," ");
	}

	return fname;
}

int deconfig() {

	int i;
	for (i = 0; conf.help_cmd[i]; i++) free(conf.help_cmd[i]);
	free(conf.help_cmd);
	cairo_font_face_destroy(conf.font);
	cairo_font_face_destroy(conf.bfont);
	FT_Done_Face(face);
	FT_Done_Face(bface);
}







|







 







>





>







 







>










>







 







>







 







>









>









|







>




>








30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
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
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
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
#define C_TYPE_F	0x02
#define C_TYPE_LF	0x03
#define C_TYPE_S	0x04
#define C_TYPE_LN	0x05

#define STRING(s)		STRINGIFY(s)
#define STRINGIFY(s)	#s
#define LINE_LEN		256

static FT_Library library;
static FT_Face face, bface;
static WindowFunction custom;
static WindowFunction windows[] = {
	{ "hanning",         {0.5,       0.5,       0.0,       0.0}       },
	{ "hamming",         {0.54,      0.46,      0.0,       0.0}       },
................................................................................
		"  fex(1) and fex-help(1)\n"
		"\n" );
	exit(0);
}

const char *configure(int argc, const char **argv) {
	int i;
	/* set defaults */
	const char *arg, *fname = NULL, *rcname = NULL;
	char help_cmd[256] = "xterm -e man man";
	conf.help_cmd = NULL;
	conf.long_out = False;
	conf.layers = True;
	/* process command line */
	for (i = 1; i < argc; i++) {
		arg = argv[i];
		if (strncmp(arg,"--h",3) == 0 || strncmp(arg,"-h",2) == 0)
			help();
		else if (strncmp(arg,"--v",3) == 0 || strncmp(arg,"-v",2) == 0)
			version();
		else if (strncmp(arg,"--l",3) == 0 || strncmp(arg,"-l",2) == 0)
................................................................................
			conf.long_out = True;
		else if (strncmp(arg,"-c",2) == 0 && (++i) < argc)
			rcname = argv[i];
		else
			fname = argv[i];
	}
	if (!fname) die("no audio file provided");
	/* find configuration file */
	FILE *rc = NULL;
	char *pwd = getenv("PWD");
	if (rcname) rc = fopen(rcname,"r");
	else if ( (!chdir(getenv("XDG_CONFIG_HOME")) && !chdir("fex")) ||
			(!chdir(getenv("HOME")) && !chdir(".config/fex")) )
		rc = fopen("config","r");
	if (!rc && !chdir(getenv("HOME"))) rc = fopen(".fexrc","r");
	chdir(pwd);
	if (!rc) rc = fopen("/usr/share/fex/config","r");
	if (!rc) die("unable to open configuration file");
	/* initialize conf structure and config reading variables */
	char line[LINE_LEN], prefix[32], option[32], fmt[LINE_LEN];
	char window[32], font_path1[LINE_LEN], font_path2[LINE_LEN];
	const char *fspec[] = { "", "%d ","%f ", "%lf ", "%s", "%[^\n]" };
	int j, mode;
	conf.thresh = 14.0;
	conf.spect_floor = 40.0;
	conf.hipass = 12.0;
................................................................................
		const char *name;
		int mode;
		int type[5];
		void *var[5];
	} cf[] = {
		#include "config.h"
	};
	/* read config file */
	while (fgets(line,LINE_LEN,rc)) {
		if (line[0] == '#' || line[0] == '\n') continue;
		sscanf(line,"%s %s",prefix,option);
		if (strncasecmp(prefix,"set",3) == 0) mode = CONF_SET;
		else if (strncasecmp(prefix,"col",3) == 0) mode = CONF_COL;
		else fprintf(stderr,"bad config entry: %s",line);
		sprintf(fmt,"%s %s ",prefix,option);
................................................................................
					cf[i].mode == mode ) {
				for (j = 0; j < 5; j++) strcat(fmt,fspec[cf[i].type[j]]);
				sscanf(line,fmt,cf[i].var[0],cf[i].var[1],cf[i].var[2],
						cf[i].var[3],cf[i].var[4]);
			}
		}
	}
	/* set hop, threshold, floor, and windowing function */
	if (!conf.hop) conf.hop = conf.winlen / 4;
	conf.thresh *= -1;
	conf.spect_floor *= -1;
	if (strncasecmp(window,"custom",6) == 0)
		conf.win = (WindowFunction *) &custom;
	else if (strlen(window))
		for (i = 0; i < sizeof(windows)/sizeof(windows[0]); i++)
			if (!strncasecmp(window,windows[i].type,strlen(window)))
				conf.win = (WindowFunction *) &windows[i];
	/* set fonts */
	if (FT_Init_FreeType(&library)) die("unable to init freetype");
	if ( FT_New_Face(library, font_path1, 0, &face) |
			FT_Set_Pixel_Sizes(face, 0, conf.font_size) )
		fprintf(stderr,"unable to load freetype font: %s\n",font_path1);
	if ( FT_New_Face(library, font_path2, 0, &bface) |
			FT_Set_Pixel_Sizes(bface, 0, conf.font_size) )
		fprintf(stderr,"unable to load freetype font: %s\n",font_path2);
	conf.font = cairo_ft_font_face_create_for_ft_face(face,0);
	conf.bfont = cairo_ft_font_face_create_for_ft_face(bface,0);
	/* prep 'help' function */
	char *help_arg = strtok(help_cmd," ");
	for (i = 0; help_arg; i++) {
		conf.help_cmd = realloc(conf.help_cmd, (i+2) * sizeof(char *));
		conf.help_cmd[i] = strdup(help_arg);
		conf.help_cmd[i+1] = NULL;
		help_arg = strtok(NULL," ");
	}
	/* return audio file name */
	return fname;
}

int deconfig() {
	/* clean up, free data */
	int i;
	for (i = 0; conf.help_cmd[i]; i++) free(conf.help_cmd[i]);
	free(conf.help_cmd);
	cairo_font_face_destroy(conf.font);
	cairo_font_face_destroy(conf.bfont);
	FT_Done_Face(face);
	FT_Done_Face(bface);
}

Changes to src/config.h.

59
60
61
62
63
64
65

	{ C_TYPE_LF, C_TYPE_LF, C_TYPE_LF, C_TYPE_LF, C_TYPE_LF },
	{ &conf.col[5].r, &conf.col[5].g, &conf.col[5].b, &conf.col[5].a,
			&conf.col[5].w } },
{ "crop", CONF_COL,
	{ C_TYPE_LF, C_TYPE_LF, C_TYPE_LF, C_TYPE_LF, C_TYPE_LF },
	{ &conf.col[6].r, &conf.col[6].g, &conf.col[6].b, &conf.col[6].a,
			&conf.col[6].w } },








>
59
60
61
62
63
64
65
66
	{ C_TYPE_LF, C_TYPE_LF, C_TYPE_LF, C_TYPE_LF, C_TYPE_LF },
	{ &conf.col[5].r, &conf.col[5].g, &conf.col[5].b, &conf.col[5].a,
			&conf.col[5].w } },
{ "crop", CONF_COL,
	{ C_TYPE_LF, C_TYPE_LF, C_TYPE_LF, C_TYPE_LF, C_TYPE_LF },
	{ &conf.col[6].r, &conf.col[6].g, &conf.col[6].b, &conf.col[6].a,
			&conf.col[6].w } },

Changes to src/fex.c.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	va_list arg;
	fprintf(stderr,"Fatal Error: ");
	va_start(arg, msg);
	vfprintf(stderr,msg,arg);
	va_end(arg);
	exit(1);
}



int main(int argc, const char **argv) {
	const char *fname = configure(argc,argv);
	Wave *wav = create_wave(fname);
	FFT *fft = create_fft(wav);
	create_spectro(fft, fname);
	free_wave(&wav);







<
<







26
27
28
29
30
31
32


33
34
35
36
37
38
39
	va_list arg;
	fprintf(stderr,"Fatal Error: ");
	va_start(arg, msg);
	vfprintf(stderr,msg,arg);
	va_end(arg);
	exit(1);
}



int main(int argc, const char **argv) {
	const char *fname = configure(argc,argv);
	Wave *wav = create_wave(fname);
	FFT *fft = create_fft(wav);
	create_spectro(fft, fname);
	free_wave(&wav);