Skip to content

Commit f16d781

Browse files
committed
patch to compile with blitz 0.10; add some missing mfiles; tick to 1.2.0; fix bug in znote_extract
1 parent 3183a10 commit f16d781

File tree

13 files changed

+424
-203
lines changed

13 files changed

+424
-203
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.sconsign.dblite
2+
.DS_Store
3+
*.bin
4+
*.wav
5+
*.[oa]
6+
/znote_extract
7+
/znote_label

README.org

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,67 @@
55
66
#+LANGUAGE: en
77

8-
Znote consists of a suite of libraries and programs for
9-
spectrotemporal decomposition of acoustic signals. Many bioacoustic
10-
signals, such as birdsong, consist of a set of spectrotemporally
11-
disjoint "objects". These objects may overlap in time with each
12-
other, as when a bird is vocalizing with both sides of its syrinx
13-
simultaneously; or overlap with sounds from other animals or the
14-
environment, as in field recordings. It is often possible to separate
15-
these objects from each other in the spectrotemporal domain, but it
16-
then becomes necessary to reconstruct the sound pressure waveforms
17-
giving rise to the isolated spectrotemporal components.
18-
19-
The first stage is to identify the components of the vocalization.
20-
znote_label provides one method of doing this, by finding all the
21-
connected components in a signal. Briefly, the spectrogram of the
22-
signal is computed, and all the points which are above this
23-
spectrogram are grouped into contiguous features. The output is an
24-
array with the same dimensions of the spectrogram, in which each
25-
time-frequency point is given an integer code indicating which
26-
component it belongs to.
27-
28-
The second stage is to invert the spectrographic transform for each of
29-
the identified components. This is done by znote_extract, which takes
30-
as input the original signal and the array indicating which points in
31-
the spectrogram belong to which features. It is not necessary to use
32-
znote_label to generate this array, and the feature-file can be
33-
manipulated after it is generated to group or split components. A
34-
MATLAB GUI for simple feature manipulation is provided.
8+
Znote consists of a suite of libraries and programs for spectrotemporal
9+
decomposition of acoustic signals. Many bioacoustic signals, such as birdsong,
10+
consist of a set of spectrotemporally disjoint "objects". These objects may
11+
overlap in time with each other, as when a bird is vocalizing with both sides of
12+
its syrinx simultaneously; or overlap with sounds from other animals or the
13+
environment, as in field recordings. It is often possible to separate these
14+
objects from each other in the spectrotemporal domain, but it then becomes
15+
necessary to reconstruct the sound pressure waveforms giving rise to the
16+
isolated spectrotemporal components.
17+
18+
The first stage is to identify the components of the vocalization. znote_label
19+
provides one method of doing this, by finding all the connected components in a
20+
signal. Briefly, the spectrogram of the signal is computed, and all the points
21+
which are above this spectrogram are grouped into contiguous features. The
22+
output is an array with the same dimensions of the spectrogram, in which each
23+
time-frequency point is given an integer code indicating which component it
24+
belongs to.
25+
26+
The second stage is to invert the spectrographic transform for each of the
27+
identified components. This is done by znote_extract, which takes as input the
28+
original signal and the array indicating which points in the spectrogram belong
29+
to which features. It is not necessary to use znote_label to generate this
30+
array, and the feature-file can be manipulated after it is generated to group or
31+
split components. A MATLAB GUI for simple feature manipulation is provided.
3532

3633
For more information on the algorithm, see:
3734

38-
Meliza CD, Chi Z, Margoliash D, "Representations of Conspecific
39-
Song by Starling Secondary Forebrain Auditory Neurons: Towards a
40-
Hierarchical Framework". J Neurophysiology, doi:10.1152/jn.00464.2009
35+
Meliza CD, Chi Z, Margoliash D, "Representations of Conspecific Song by Starling
36+
Secondary Forebrain Auditory Neurons: Towards a Hierarchical Framework". J
37+
Neurophysiology, doi:10.1152/jn.00464.2009
4138

42-
* License and warranty
39+
** License and warranty
4340

44-
Use of the code is free for non-commercial purposes under the
45-
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United
46-
States License (http://creativecommons.org/licenses/by-nc-sa/3.0/us/).
41+
Use of the code is free for non-commercial purposes under the Creative Commons
42+
Attribution-Noncommercial-Share Alike 3.0 United States License
43+
(http://creativecommons.org/licenses/by-nc-sa/3.0/us/).
4744

48-
C Daniel Meliza, Zhiyi Chi, and Daniel Margoliash (or the above paper)
49-
will be acknowledged as the source of the algorithms in any
50-
publications reporting its use or the use of any modified version of
51-
the program.
45+
C Daniel Meliza, Zhiyi Chi, and Daniel Margoliash (or the above paper) will be
46+
acknowledged as the source of the algorithms in any publications reporting its
47+
use or the use of any modified version of the program.
5248

53-
THE PROGRAMS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF MERCANTABILITY
54-
OR FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER WARRANTY, EXPRESS OR
55-
IMPLIED. IN NO EVENT SHALL THE UNIVERSITY OF CHICAGO, THE UNIVERSITY
56-
OF CONNECTICUT, OR DRS. MELIZA, CHI OR MARGOLIASH BE LIABLE FOR ANY
57-
DIRECT OR CONSEQUENTIAL DAMAGES RESULTING FROM USE OF THE PROGRAMS.
58-
THE USER BEARS THE ENTIRE RISK FOR USE OF THE PROGRAMS.
49+
THE PROGRAMS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF MERCANTABILITY OR FITNESS
50+
FOR A PARTICULAR PURPOSE OR ANY OTHER WARRANTY, EXPRESS OR IMPLIED. IN NO EVENT
51+
SHALL THE UNIVERSITY OF CHICAGO, THE UNIVERSITY OF CONNECTICUT, OR DRS. MELIZA,
52+
CHI OR MARGOLIASH BE LIABLE FOR ANY DIRECT OR CONSEQUENTIAL DAMAGES RESULTING
53+
FROM USE OF THE PROGRAMS. THE USER BEARS THE ENTIRE RISK FOR USE OF THE
54+
PROGRAMS.
5955

6056
To contact the authors, please consult the official repository for
6157
znote at http://www.github.org/dmeliza/znote
6258

63-
* Compilation and Installation
59+
** Compilation and Installation
6460

65-
znote depends on the Blitz C++ array library for data manipulation,
66-
the FFTW library for computing FFT transforms, and the libsndfile
67-
library for reading acoustic signal data. It also requires the LAPACK
68-
fucntions dsterf and dgtsv to generate the discrete prolate spherical
69-
sequences used by znote_label.
61+
*** Dependencies
7062

71-
The build process is controlled by scons, an improved version of make.
72-
Some editing of this file may be necessary to get it to build on your
73-
system.
63+
- a modern C++ compiler
64+
- scons >= 1.3
65+
- libsndfile >= 1.0.17 (http://www.mega-nerd.com/libsndfile)
66+
- blitz >= 0.9 (http://blitz.sourceforge.net/)
67+
- fftw >= 3.3 (http://www.fftw.org)
68+
- LAPACK (specifically functions dsterf and dgtsv)
7469

7570
*** Mac OS X
7671

@@ -124,13 +119,13 @@ overhead of setting up multiple threads is rarely worth it. To enable
124119
multiple threads in znote, edit SConstruct and set threads to some
125120
number less than or equal to the number of cores in your system.
126121

127-
* Usage
122+
** Usage
128123

129-
** znote_label
124+
*** znote_label
130125

131-
znote_label [--nfft <i>] [--fftshift <i>] [--ntapers <i>] [--nw <f>]
132-
[--thresh <f>] [--df <f>] [--dt <f>]
133-
[--min-size <f>] <input>
126+
: znote_label [--nfft <i>] [--fftshift <i>] [--ntapers <i>] [--nw <f>]
127+
: [--thresh <f>] [--df <f>] [--dt <f>]
128+
: [--min-size <f>] <input>
134129

135130
nfft: controls the size of the FFT analysis window. Default 512,
136131
which is appropriate most signals sampled at around 44 kHz. Larger
@@ -190,11 +185,11 @@ spectrogram, so this is not recommended for novice users.
190185
The program outputs a .bin file indicating which points in the
191186
spectrogram belong to which features.
192187

193-
** znote_extract
188+
*** znote_extract
194189

195-
znote_extract [--fbdw <f>] [--tbdw <f>]
196-
[--feat <i>] [--pad] [--del] [--recon]
197-
<signal> <labels>
190+
: znote_extract [--fbdw <f>] [--tbdw <f>]
191+
: [--feat <i>] [--pad] [--del] [--recon]
192+
: <signal> <labels>
198193

199194
znote_extract uses the labels defined in <labels> to generate masks,
200195
which it uses to extract the associated time series in <signal>. The
@@ -239,14 +234,14 @@ For component deletions, the output files are named as signal_fdel_000.wav, etc
239234

240235
The reconstruction has the name signal_recon.wav
241236

242-
** ZEdit
237+
*** ZEdit
243238

244239
Zedit is a simple MATLAB interface for editing .bin files. It allows
245240
merging and splitting of components while visualizing the spectrogram
246241
of the corresponding signal. To edit components for a signal, run
247242
zedit in MATLAB as follows:
248243

249-
>> zedit <wavefile>
244+
: >> zedit <wavefile>
250245

251246
zedit runs znote_label to generate spectrograms and calculate
252247
connected components. If the executable is not in your path, you may
@@ -256,7 +251,7 @@ contour indicating where the threshold lies.
256251

257252
The parameters of the spectrographic transform can be changed in the
258253
FFT/MTM panel. The threshold value can be edited manually or by
259-
clicking on the colorbar to the right of the spectrogram.
254+
clicking on the colorbar to the right of the spectrogram.
260255

261256
In the LabelSet panel, to calculate components, click the Label
262257
button. Note: this will overwrite the file <wavefile>_labels.bin. To
@@ -274,3 +269,12 @@ Save the edited labelset by clicking Save in the LabelSet panel.
274269
Choose a name for the output file; this can be used with znote_extract
275270
to generate the signals associated with the components.
276271

272+
** Version History
273+
274+
*** 1.1.0
275+
276+
First public release.
277+
278+
*** 1.2.0
279+
280+
Updated to compile with blitz 0.10. Should still compile with 0.9

SConstruct

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import os
22

3-
threads = 1
43
if hasattr(os,'uname'):
54
system = os.uname()[0]
65
else:
76
system = 'Windows'
87

8+
debug = ARGUMENTS.get('debug',1)
9+
threads = int(ARGUMENTS.get('thread',1))
10+
911
common_src = ['components.cc']
10-
lib_path = ['/lib','/usr/lib','/usr/lib64','/usr/local/lib','/usr/local/lib64']
1112

12-
env = Environment(LIBPATH = lib_path,
13-
CCFLAGS = ['-O2','-Wall'],
13+
env = Environment(CCFLAGS = ['-Wall'],
1414
LIBS=['m','blitz','sndfile','fftw3'])
1515
if threads > 1:
1616
env.Append(CCFLAGS = '-DTHREADS=%d' % threads,
@@ -30,5 +30,11 @@ elif system=='Windows':
3030
LIBPATH = ['./blitz-0.9/lib','./libsndfile/lib','./fftw/lib','./lapack/'],
3131
LIBS=['m','blitz','sndfile','fftw3','lapack','blas','g2c'])
3232

33+
if int(debug):
34+
env.Append(CCFLAGS=['-g2', '-DDEBUG=1'])
35+
else:
36+
env.Append(CCFLAGS=['-O2'])
37+
38+
3339
env.Program('znote_label',['znote_label.cc','mtm.cc','dpss.c'] + common_src)
3440
env.Program('znote_extract',['znote_extract.cc','spect.cc'] + common_src)

common.hh

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* @file common.hh
55
* @author Daniel Meliza <[email protected]>
66
* @date Mon Mar 1 13:33:47 2010
7-
*
7+
*
88
* @brief Define common types and functions for znote
9-
*
9+
*
1010
* Copyright C Daniel Meliza, Z Chi 2010. Licensed for use under Creative
1111
* Commons Attribution-Noncommercial-Share Alike 3.0 United States
1212
* License (http://creativecommons.org/licenses/by-nc-sa/3.0/us/).
@@ -21,6 +21,14 @@
2121
#define M_PI 3.14159265358979323846264338327
2222
#endif
2323

24+
// try to determine whether this is blitz 0.9. probably very fragile
25+
#define BZ_MAJOR_VERSION 0
26+
#ifndef BZ_ET_FORWARD_H
27+
#define BZ_MINOR_VERSION 9
28+
#else
29+
#define BZ_MINOR_VERSION 10
30+
#endif
31+
2432

2533
typedef blitz::Array<double,2> dmatrix;
2634
typedef blitz::Array<double,1> dvector;
@@ -35,46 +43,46 @@ typedef std::vector<coord> coord_vector;
3543
typedef std::vector<coord_list> clist_vector;
3644
typedef std::vector<coord_vector> cvec_vector;
3745

38-
/**
46+
/**
3947
* Determine if coordinates are in range for an array.
40-
*
48+
*
4149
* @param A Array to check
4250
* @param I Indices to check
43-
*
51+
*
4452
* @return true if A.lbound(i) <= I(i) <= A.ubound(i) for i in [0,N_rank)
4553
*/
4654
template <typename T, int N_rank> inline
47-
bool inrange(const blitz::Array<T,N_rank> &A, const blitz::TinyVector<int,N_rank> &I)
55+
bool inrange(const blitz::Array<T,N_rank> &A, const blitz::TinyVector<int,N_rank> &I)
4856
{
4957
for (int i = 0; i < N_rank; i++)
5058
if ((I(i) < A.lbound(i)) || (I(i) > A.ubound(i))) return false;
5159
return true;
5260
}
5361

54-
/**
62+
/**
5563
* Construct an evenly spaced vector across a range.
56-
*
64+
*
5765
* @param output Output vector. Resized and overwritten.
5866
* @param start Start point
5967
* @param stop Stop point (exclusive)
6068
* @param step Step size
6169
*/
6270
template <typename T> inline
63-
void arange(blitz::Array<T,1> &output, int start, int stop, int step=1)
71+
void arange(blitz::Array<T,1> &output, int start, int stop, int step=1)
6472
{
6573
blitz::firstIndex i;
6674
int n = (stop - start) / step;
6775
output.resize(n);
6876
output = start + i*step;
6977
}
7078

71-
/**
79+
/**
7280
* Split a file name into root and extension.
73-
*
81+
*
7482
* @param in input string
7583
* @param froot file name root
7684
* @param ext file name extension
77-
*
85+
*
7886
* @return split point
7987
*/
8088
inline
@@ -86,6 +94,6 @@ size_t splitext(const std::string &in, std::string &froot, std::string &ext) {
8694
ext.assign(in.substr(fidx));
8795
return fidx;
8896
}
89-
97+
9098

9199
#endif

0 commit comments

Comments
 (0)