# HG changeset patch # User mathieub # Date 1308339233 -3600 # Node ID cd5e0ac31ff7e27d116bbad9a2f09525edcda3de code, doc, and build (osx) of the Calcium Signal Analyser Vamp plugin (Release 1) diff -r 000000000000 -r cd5e0ac31ff7 COPYING --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/COPYING Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,280 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS diff -r 000000000000 -r cd5e0ac31ff7 CalciumSignalAnalyser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CalciumSignalAnalyser.cpp Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,607 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Calcium Signal Analyser Vamp Plugin + + Description: Detects and characterises the transients in noisy signals. + + Authors: Mathieu Barthet. + Based on the QM Vamp note onset detector plugin by Christian Landone, + Chris Duxbury, and Juan Pablo Bello. + + Version: 1 + + Centre for Digital Music, Queen Mary, University of London. + All rights reserved. + */ + +#include "CalciumSignalAnalyser.h" + +#include +#include + +using std::string; +using std::vector; +using std::cerr; +using std::endl; + +#define MAX_PEAKFREQ 10; //maximum peak frequency in Hz + +//#define VERBOSE //remove comment to have output messages for data display or debugging information + +CalciumSignalAnalyser::CalciumSignalAnalyser(float inputSampleRate) : +Vamp::Plugin(inputSampleRate), +m_inputSampleRate(inputSampleRate), +m_blockSize(0), +m_stepSize(0), +data(0), +time(0), +m_sensitivity(50), +m_delta(0.2), +processcounter(0) +{ +#ifdef VERBOSE + cout << "Sample rate: " << inputSampleRate << endl; +#endif +} + +CalciumSignalAnalyser::~CalciumSignalAnalyser() +{ +#ifdef VERBOSE + cout << "Destructor" << endl; +#endif + + if (!data.empty()){ +#ifdef VERBOSE + cout << "Data vector reset" << endl; +#endif + data.clear(); //clears the vector's elements + } + + if (!time.empty()){ +#ifdef VERBOSE + cout << "Time vector reset" << endl; +#endif + time.clear(); //clears the vector's elements + } +} + +string +CalciumSignalAnalyser::getIdentifier() const +{ + return "peakdetection"; +} + +string +CalciumSignalAnalyser::getName() const +{ + return "Calcium Signal Analyser"; +} + +string +CalciumSignalAnalyser::getDescription() const +{ + return "Automatic detection and characterisation of the signal's transients"; +} + +string +CalciumSignalAnalyser::getMaker() const +{ + return "Mathieu Barthet"; +} + +int +CalciumSignalAnalyser::getPluginVersion() const +{ + return 1; +} + +string +CalciumSignalAnalyser::getCopyright() const +{ + return "Plugin by Mathieu Barthet. Based on the note onset detector plugin by Christian Landone, Chris Duxbury and Juan Pablo Bello. Copyright (c) 2010 QMUL - All Rights Reserved"; +} + +CalciumSignalAnalyser::ParameterList +CalciumSignalAnalyser::getParameterDescriptors() const +{ + ParameterList list; + ParameterDescriptor desc; + + desc.identifier = "sensitivity"; + desc.name = "Peak-picking sensitivity"; + desc.description = "Sensitivity of the peak detection (criterion based on quadratic interpolation)"; + desc.minValue = 0; + desc.maxValue = 100; + desc.defaultValue = 50; + desc.isQuantized = true; + desc.quantizeStep = 1; + desc.unit = "%"; + list.push_back(desc); + + desc.identifier = "deltathreshold"; + desc.name = "Peak-picking offset threshold (delta)"; + desc.description = "Offset threshold aiming at improving the peak detection by discarding the noise"; + desc.minValue = 0; + desc.maxValue = 1; + desc.defaultValue = 0.2; + desc.isQuantized = true; + desc.quantizeStep = 0.05; + desc.unit = ""; + list.push_back(desc); + + return list; +} + +float +CalciumSignalAnalyser::getParameter(std::string name) const +{ + if (name == "sensitivity"){ + return m_sensitivity; + } + else if (name == "deltathreshold") { + return m_delta; + } + + return 0.0; +} + +void +CalciumSignalAnalyser::setParameter(std::string name, float value) +{ + if (name == "sensitivity") { + if (m_sensitivity == value) return; + m_sensitivity = value; + + } + else if (name == "deltathreshold") { + if (m_delta == value) return; + m_delta = value; + } +} + + +CalciumSignalAnalyser::ProgramList +CalciumSignalAnalyser::getPrograms() const +{ + ProgramList programs; + + return programs; +} + +std::string +CalciumSignalAnalyser::getCurrentProgram() const +{ + return ""; +} + +void +CalciumSignalAnalyser::selectProgram(std::string program) +{ +} + +bool +CalciumSignalAnalyser::initialise(size_t channels, size_t stepSize, size_t blockSize) +{ + +#ifdef VERBOSE + cout << "Initialise" << endl; +#endif + + m_blockSize = 1; + m_stepSize = 1; + +#ifdef VERBOSE + cout << m_blockSize << " " << m_stepSize << endl; +#endif + + if (channels < getMinChannelCount() || + channels > getMaxChannelCount()) { + std::cerr << "CalciumSignalAnalyser::initialise: Unsupported channel count: " + << channels << std::endl; + return false; + } + + if (stepSize != getPreferredStepSize()) { + + std::cerr << "ERROR: CalciumSignalAnalyser::initialise: the step size has to be 1." << std::endl; + return false; + } + + if (blockSize != getPreferredBlockSize()) { + + std::cerr << "ERROR: CalciumSignalAnalyser::initialise: the block size has to be 1." << std::endl; + return false; + } + + return true; +} + +void +CalciumSignalAnalyser::reset() +{ +#ifdef VERBOSE + cout << "Reset" << endl; +#endif + + if (!data.empty()){ +#ifdef VERBOSE + cout << "Data vector reset" << endl; +#endif + data.clear(); //clears the vector's elements + } + + if (!time.empty()){ +#ifdef VERBOSE + cout << "Time vector reset" << endl; +#endif + time.clear(); //clears the vector's elements + } +} + +size_t +CalciumSignalAnalyser::getPreferredStepSize() const +{ + return getPreferredBlockSize(); +} + +size_t +CalciumSignalAnalyser::getPreferredBlockSize() const +{ + return 1; +} + +size_t +CalciumSignalAnalyser::getMinChannelCount() const +{ + return 1; +} + +size_t +CalciumSignalAnalyser::getMaxChannelCount() const +{ + return 1; +} + + +CalciumSignalAnalyser::OutputList +CalciumSignalAnalyser::getOutputDescriptors() const +{ +#ifdef VERBOSE + cout << "get output desc" << endl; +#endif + + OutputList list; + + OutputDescriptor pt; + pt.identifier = "peaktimes"; + pt.name = "Peaks times"; + pt.description = "Time positions of the peaks (in seconds)"; + pt.unit = ""; + pt.hasFixedBinCount = true; + pt.binCount = 0; //0 for time only feature + pt.sampleType = OutputDescriptor::VariableSampleRate; + pt.hasDuration = false; + pt.hasKnownExtents = false; + pt.isQuantized = false; + pt.sampleRate = 0; //no sensible resolution, the time of the feature are given in the timestamp of the feature + list.push_back(pt); + + OutputDescriptor po; + po.identifier = "peakonsets"; + po.name = "Peaks onsets"; + po.description = "Time positions of the peak onsets (in seconds)"; + po.unit = ""; + po.hasFixedBinCount = true; + po.binCount = 0; //0 for time only feature + po.sampleType = OutputDescriptor::VariableSampleRate; + po.hasDuration = false; + po.hasKnownExtents = false; + po.isQuantized = false; + po.sampleRate = 0; //no sensible resolution, the time of the feature are given in the timestamp of the feature + list.push_back(po); + + OutputDescriptor sdf; + sdf.identifier = "smoothed_df"; + sdf.name = "Smoothed Detection Function"; + sdf.description = "Smoothed probability function used for peak-picking"; + sdf.unit = ""; + sdf.hasFixedBinCount = true; + sdf.binCount = 1; + sdf.hasKnownExtents = false; + sdf.isQuantized = false; + sdf.sampleType = OutputDescriptor::FixedSampleRate; + sdf.sampleRate = m_inputSampleRate; //the smoothed detection function has the same sample rate as the input signal + list.push_back(sdf); + + OutputDescriptor pf; + pf.identifier = "peak_frequency"; + pf.name = "Peak frequency"; + pf.description = "Frequency of the peaks (in Hz)"; + //pf.unit = "Hz"; //if unit is Hz then the feature is treated as a pitch which is not relevant in this case + pf.unit = ""; + pf.hasFixedBinCount = true; + pf.binCount = 1; //1 corresponds to time and value + pf.sampleType = OutputDescriptor::VariableSampleRate; + pf.sampleRate = 0; //no sensible resolution, the time of the feature is given in the timestamp of the feature + pf.hasKnownExtents = true; + pf.minValue = 0; + pf.maxValue = MAX_PEAKFREQ; + pf.isQuantized = false; + pf.hasDuration = true; //duration of the signal + list.push_back(pf); + + OutputDescriptor mipi; + mipi.identifier = "mean_interpeakinterval"; + mipi.name = "Mean Inter Peak Interval"; + mipi.description = "Mean of the time intervals between peaks (in seconds)"; + mipi.unit = "s"; + mipi.hasFixedBinCount = true; + mipi.binCount = 1; //1 corresponds to time and value + mipi.sampleType = OutputDescriptor::VariableSampleRate; + mipi.sampleRate = 0; //no sensible resolution, the time of the feature is given in the timestamp of the feature + mipi.hasKnownExtents = false; + mipi.isQuantized = false; + mipi.hasDuration = true; //duration of the signal + list.push_back(mipi); + + return list; +} + +CalciumSignalAnalyser::FeatureSet +CalciumSignalAnalyser::process(const float *const *inputBuffers, + Vamp::RealTime timestamp) +{ + FeatureSet fs; + + if (m_blockSize == 0 || m_stepSize == 0) { + cerr << "ERROR: CalciumSignalAnalyser::process: " + << "CalciumSignalAnalyser has not been initialised." + << endl; + return fs; + } + + data.push_back(inputBuffers[0][0]); //assumes that only one sample is read at a time + time.push_back(timestamp); + + processcounter ++; + + fs = FeatureSet(); //empty feature set + + return fs; +} + +CalciumSignalAnalyser::FeatureSet +CalciumSignalAnalyser::getRemainingFeatures() +{ + FeatureSet returnFeatures; + returnFeatures = FeatureSet(); + +#ifdef VERBOSE + cout << "Get remaining features" << endl << endl; +#endif + + /*************************************** + Peak times + ****************************************/ + + double aCoeffs[] = { 1.0000, -0.5949, 0.2348 }; + double bCoeffs[] = { 0.1600, 0.3200, 0.1600 }; + + //The signal is directly treated as a detection function for the peak picking stage + + PPickParams ppParams; + ppParams.length = data.size(); //length of the signal + +#ifdef VERBOSE + cout << "Length: " << ppParams.length << endl; +#endif + + // tau and cutoff appear to be unused in PeakPicking, but I've + // inserted some moderately plausible values rather than leave + // them unset. The QuadThresh values come from trial and error. + // The rest of these are copied from ttParams in the BeatTracker + // code: I don't claim to know whether they're good or not --cc + + ppParams.tau = m_stepSize / m_inputSampleRate; //not used for peak picking + + ppParams.alpha = 9; + ppParams.cutoff = m_inputSampleRate/4; //not used for peak picking + ppParams.LPOrd = 2; + ppParams.LPACoeffs = aCoeffs; + ppParams.LPBCoeffs = bCoeffs; + + //TO-DO: the duration of the median filtering window could be another adjustable parameter + //of the plugin since the optimal duration may vary according to signals. It should not be + //set up in samples but in seconds instead to maintain the same behavior for different signal + //sample frequencies. + + ppParams.WinT.post = 8; //works well with calcium data (15 samples at 3 Hz --> W = 5 s --> M = 2.5 s) + ppParams.WinT.pre = 7; + + ppParams.QuadThresh.a = (100 - m_sensitivity) / 1000.0; + ppParams.QuadThresh.b = 0; + ppParams.QuadThresh.c = (100 - m_sensitivity) / 1500.0; + ppParams.delta = m_delta; //delta threshold used as an offset when computing the smoothed detection function + + PeakPicking peakPicker(ppParams); + + double *ppSrc = new double[ppParams.length]; + if (ppSrc==NULL) { + cerr << "ERROR: CalciumSignalAnalyser::getRemainingFeatures:" + << "Unable to allocate memory (ppSrc)." + << endl; + return returnFeatures; + } + + for (unsigned int i = 0; i < ppParams.length; ++i) { + + ppSrc[i] = (double) data[i]; + } + + vector peaks; + vector peak_frame; + vector onsets_frame; + + peakPicker.process(ppSrc, ppParams.length, peaks); + + for (size_t i = 0; i < peaks.size(); ++i) { + + //peak times + size_t index = peaks[i]; + size_t peakframe = peaks[i] * m_stepSize; + peak_frame.push_back(peakframe); + + Feature featurepeaks; + featurepeaks.hasTimestamp = true; + featurepeaks.timestamp = Vamp::RealTime::frame2RealTime(peakframe, lrintf(m_inputSampleRate)); + + returnFeatures[0].push_back(featurepeaks); // peak times are output 0 + + //algorithm to detect the peak onsets + + double prevDiff = 0.0; + while (index > 1) { + double diff = ppSrc[index] - ppSrc[index-1]; + if (diff < prevDiff * 0.9) break; + prevDiff = diff; + --index; + } + + size_t onsetframe = index * m_stepSize; + onsets_frame.push_back(onsetframe); + + Feature featureonsets; + featureonsets.hasTimestamp = true; + featureonsets.timestamp = Vamp::RealTime::frame2RealTime(onsetframe, lrintf(m_inputSampleRate)); + +#ifdef VERBOSE + cout << featureonsets.timestamp << endl; +#endif + returnFeatures[1].push_back(featureonsets); // peak onsets are output 1 + } + + for (unsigned int i = 0; i < ppParams.length; ++i) { + + Feature feature; + feature.hasTimestamp = true; + size_t frame = i * m_stepSize; + + feature.timestamp = Vamp::RealTime::frame2RealTime(frame, lrintf(m_inputSampleRate)); + + feature.values.push_back(ppSrc[i]); + + returnFeatures[2].push_back(feature); // smoothed df is output 2 + } + + /*************************************** + Peak frequency + ****************************************/ + + double peakfreq, duration; + int npeaks; //total number of peaks + + //last element of the time vector is the duration of the signal - converts the RealTime to a float + duration = time.back()/Vamp::RealTime(1,0); //division by 1 s to obtain a double + + npeaks = peaks.size(); + peakfreq = npeaks/duration; + +#ifdef VERBOSE + cout << npeaks << endl; + cout << duration << endl; + cout << peakfreq << endl; +#endif + + Feature pf; + pf.hasTimestamp = true; + pf.timestamp = time[0]; + pf.hasDuration = true; + pf.duration = time.back()-time[0]; + +#ifdef VERBOSE + cout << "processcounter" << processcounter << endl; + + cout << "time.back " << time.back().toText() << endl; + cout << "time.size " << time.size() << endl; + cout << "data.size " << data.size() << endl; + cout << "time[0, 1 ...] " << time[0].toText() << " " << time[1].toText() << " " << time[2].toText() << " " << time[time.size()].toText() << endl; + + cout << "time[999] " << time[999].toText() << endl; + cout << "data[999] " << data[999] << endl; + cout << "time[1000] " << time[1000].toText() << endl; + cout << "data[1000] " << data[1000]<< endl; +#endif + + pf.values.push_back(peakfreq); + + char pflabel[256]; + sprintf(pflabel,"%f Hz",peakfreq); + pf.label = pflabel; + +#ifdef VERBOSE + cout << "label: " << pflabel << endl; +#endif + + returnFeatures[3].push_back(pf); //peak frequency is output 3 + + /*************************************** + Mean Inter Peak Interval + ****************************************/ + + double o1,o2; + + double sumipi_s = 0; + double meanipi_s; + + for (int j = 0; j < npeaks-1; ++j) { + o2 = Vamp::RealTime::frame2RealTime(peak_frame[j+1], lrintf(m_inputSampleRate))/Vamp::RealTime(1,0); + o1 = Vamp::RealTime::frame2RealTime(peak_frame[j], lrintf(m_inputSampleRate))/Vamp::RealTime(1,0); +#ifdef VERBOSE + cout << "o1: " << o1 << endl; + cout << "o2: " << o2 << endl; +#endif + sumipi_s = sumipi_s + o2 - o1; + } + + meanipi_s = sumipi_s/(npeaks-1); + +#ifdef VERBOSE + cout << "Sum IPI: " << sumipi_s << endl; + cout << "Mean IPI: " << meanipi_s << endl; +#endif + + Feature mipi; + mipi.hasTimestamp = true; + mipi.timestamp = time[0]; + mipi.hasDuration = true; + mipi.duration = time.back()-time[0]; + + mipi.values.push_back(meanipi_s); //mean inter peak interval in secs + + returnFeatures[4].push_back(mipi); //mean inter peak interval is output 4 + + //clear data + + delete [] ppSrc; + + if (!data.empty()){ +#ifdef VERBOSE + cout << "Data vector reset" << endl; +#endif + data.clear(); //clears the vector's elements + } + + if (!time.empty()){ +#ifdef VERBOSE + cout << "Time vector reset" << endl; +#endif + time.clear(); //clears the vector's elements + } + +#ifdef VERBOSE + cout << "End of get remaining features" << endl << endl; +#endif + return returnFeatures; +} + diff -r 000000000000 -r cd5e0ac31ff7 CalciumSignalAnalyser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CalciumSignalAnalyser.h Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,79 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Header file for the Calcium Signal Analyser Vamp Plugin + + Description: Detects and characterises the transients in noisy signals. + + Authors: Mathieu Barthet. + Based on the QM Vamp note onset detector plugin by Christian Landone, + Chris Duxbury, and Juan Pablo Bello. + + Version: 1 + + Centre for Digital Music, Queen Mary, University of London. + All rights reserved. + +*/ + +#ifndef _CALCIUM_SIGNAL_ANALSYER_PLUGIN_H_ +#define _CALCIUM_SIGNAL_ANALSYER_PLUGIN_H_ + +#include + +using std::vector; + +class CalciumSignalAnalyser : public Vamp::Plugin +{ +public: + CalciumSignalAnalyser(float inputSampleRate); + virtual ~CalciumSignalAnalyser(); + + bool initialise(size_t channels, size_t stepSize, size_t blockSize); + void reset(); + + InputDomain getInputDomain() const { return TimeDomain; } //input data are passed to the plugin in the time domain + + std::string getIdentifier() const; + std::string getName() const; + std::string getDescription() const; + std::string getMaker() const; + int getPluginVersion() const; + std::string getCopyright() const; + + ParameterList getParameterDescriptors() const; + float getParameter(std::string) const; + void setParameter(std::string, float); + + ProgramList getPrograms() const; + std::string getCurrentProgram() const; + void selectProgram(std::string program); + + size_t getPreferredStepSize() const; + size_t getPreferredBlockSize() const; + size_t getMinChannelCount() const; + size_t getMaxChannelCount() const; + + OutputList getOutputDescriptors() const; + + FeatureSet process(const float *const *inputBuffers, + Vamp::RealTime timestamp); + + FeatureSet getRemainingFeatures(); + +protected: + + float m_inputSampleRate; + size_t m_blockSize; + size_t m_stepSize; + + vector data; + vector time; + + float m_sensitivity; + float m_delta; + + int processcounter; +}; + +#endif diff -r 000000000000 -r cd5e0ac31ff7 CalciumSignalAnalyser.o Binary file CalciumSignalAnalyser.o has changed diff -r 000000000000 -r cd5e0ac31ff7 CalciumSignalAnalyser_plugins.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CalciumSignalAnalyser_plugins.cpp Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,44 @@ +/* +Calcium Signal Analyser Vamp Plugin + +Description: Detects and characterises the transients in noisy signals. + +Authors: Mathieu Barthet. +Based on the QM Vamp note onset detector plugin by Christian Landone, +Chris Duxbury, and Juan Pablo Bello. + +Version: 1 + +Centre for Digital Music, Queen Mary University of London. +All rights reserved. +*/ + +#include +#include + +#include "CalciumSignalAnalyser.h" + +// Declare one static adapter here for each plugin class in this library. + +static Vamp::PluginAdapter CalciumSignalAnalyserAdapter; + +// This is the entry-point for the library, and the only function that +// needs to be publicly exported. + +const VampPluginDescriptor * +vampGetPluginDescriptor(unsigned int version, unsigned int index) +{ + if (version < 1) return 0; + + // Return a different plugin adaptor's descriptor for each index, + // and return 0 for the first index after you run out of plugins. + // (That's how the host finds out how many plugins are in this + // library.) + + switch (index) { + case 0: return CalciumSignalAnalyserAdapter.getDescriptor(); + default: return 0; + } +} + + diff -r 000000000000 -r cd5e0ac31ff7 CalciumSignalAnalyser_plugins.o Binary file CalciumSignalAnalyser_plugins.o has changed diff -r 000000000000 -r cd5e0ac31ff7 INSTALL.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INSTALL.txt Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,48 @@ + +Requirements +============ + +The following additional libraries are required when building the Calcium Signal +Analyser Vamp plugin: + +REQUIRED Vamp Plugin SDK v2.x http://www.vamp-plugins.org/ +REQUIRED QM DSP Library https://code.soundsoftware.ac.uk/projects/qm-dsp + + +To install (by compiling from source) +===================================== + +First download and install the required libraries following the associated instructions +(they may require to install other dependencies). + +You can edit the Makefile of the Calcium Signal Analyser Vamp plugin depending your +operating system and various options. The directories of the required libraries can be +specified. By default, the required libraries are assumed to be installed at the same +directory tree level as the plugin. + +To build on a Unix-like system, run + +$ make + +Then install the plugin as follows depending on your operating system: + + Win 32 -> Copy vamp-calciumsignalanalyser.dll, vamp-calciumsignalanalyser.cat and + vamp-calciumsignalanalyser.n3 to C:\Program Files\Vamp Plugins\ + + Win 64 -> Copy vamp-calciumsignalanalyser.dll, vamp-calciumsignalanalyser.cat and + vamp-calciumsignalanalyser.n3 to C:\Program Files\Vamp Plugins (x86)\ + + OS/X -> Copy vamp-calciumsignalanalyser.dylib, vamp-calciumsignalanalyser.cat and + vamp-calciumsignalanalyser.n3 to $HOME/Library/Audio/Plug-Ins/Vamp/ + or /Library/Audio/Plug-Ins/Vamp/ + + Linux -> Copy vamp-calciumsignalanalyser.so, vamp-calciumsignalanalyser.cat and + vamp-calciumsignalanalyser.n3 to $HOME/vamp/ or /usr/local/lib/vamp/ + or /usr/lib/vamp/ + + + + + + + diff -r 000000000000 -r cd5e0ac31ff7 README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,70 @@ + +Calcium Signal Analyser Vamp plugin +=================================== + +The Calcium Signal Analyser is a Vamp plugin for the detection and +characterization of transients in noisy signals. It is adapted for +the analysis of calcium signals measured using confocal microscopy. + +The plugin is based on the QM Vamp note onset detector developed +by Christian Landone, Chris Duxbury, and Juan Pablo Bello. + +The Vamp architecture is a feature extraction system developed at +Queen Mary University of London (see more information at: +http://www.vamp-plugins.org/). + +This code is Copyright (c) 2006-2011 Mathieu Barthet, Queen Mary +University of London. + +About This Release +================== + +This is release 1. + +License +======= + +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. See the file +COPYING included with this distribution for more information. + +Compiling +========= + +If you are planning to compile the Calcium Signal Analyser Vamp plugin +from source code, please read the file INSTALL.txt. + +To Install +========== + +Installation depends on your operating system. + + Win 32 -> Copy vamp-calciumsignalanalyser.dll, vamp-calciumsignalanalyser.cat and + vamp-calciumsignalanalyser.n3 to C:\Program Files\Vamp Plugins\ + + Win 64 -> Copy vamp-calciumsignalanalyser.dll, vamp-calciumsignalanalyser.cat and + vamp-calciumsignalanalyser.n3 to C:\Program Files\Vamp Plugins (x86)\ + + OS/X -> Copy vamp-calciumsignalanalyser.dylib, vamp-calciumsignalanalyser.cat and + vamp-calciumsignalanalyser.n3 to $HOME/Library/Audio/Plug-Ins/Vamp/ + or /Library/Audio/Plug-Ins/Vamp/ + + Linux -> Copy vamp-calciumsignalanalyser.so, vamp-calciumsignalanalyser.cat and + vamp-calciumsignalanalyser.n3 to $HOME/vamp/ or /usr/local/lib/vamp/ + or /usr/lib/vamp/ + +Documentation +============= + +A documentation on the plugin can be found in the /doc directory of the distribution. + + +Credits and references +====================== + +This project was partly funded by the Queen Mary University of London +Bridging the Gaps scheme (EPSRC grant no EP/F033133/1). + + diff -r 000000000000 -r cd5e0ac31ff7 build/osx/vamp-calcium-signal-analyser.dylib Binary file build/osx/vamp-calcium-signal-analyser.dylib has changed diff -r 000000000000 -r cd5e0ac31ff7 doc/vamp-calcium-signal-analyser_doc.pdf Binary file doc/vamp-calcium-signal-analyser_doc.pdf has changed diff -r 000000000000 -r cd5e0ac31ff7 makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/makefile Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,90 @@ +# Makefile for the Calcium Signal Analyser Vamp plugin + +## Skeleton Makefile for Vamp plugin builds using command-line tools. +## +## Rename this to Makefile, and edit as appropriate. +## This Makefile WILL NOT WORK until you have edited it as described +## below -- the Makefile as supplied does nothing useful at all! +## +## Various sets of options are provided, commented out -- just uncomment +## (remove the '#' characters for) the set that most closely resembles +## your own situation, and adjust to taste. Then run "make". +## +## (For Windows builds using MS Visual Studio, start instead with the +## VampExamplePlugins project found in the build directory of the SDK.) + + +# Edit this to the base name of your plugin library +# +PLUGIN_LIBRARY_NAME = vamp-calcium-signal-analyser + +# Edit this to list one .o file for each .cpp file in your plugin project +# +PLUGIN_CODE_OBJECTS = CalciumSignalAnalyser.o CalciumSignalAnalyser_plugins.o + +# Edit this to the location of the Vamp plugin SDK, relative to your +# project directory +# + +VAMP_SDK_DIR = ../vamp-plugin-sdk + +# Directory of the qm-dsp files + +QM_DSP_DIR = ../qm-dsp + +## Uncomment these for an OS/X native build using command-line tools: + +CXXFLAGS = -I$(VAMP_SDK_DIR) -I$(QM_DSP_DIR) -Wall -fPIC +PLUGIN_EXT = .dylib +PLUGIN = $(PLUGIN_LIBRARY_NAME)$(PLUGIN_EXT) +LDFLAGS = -dynamiclib -install_name $(PLUGIN) $(VAMP_SDK_DIR)/libvamp-sdk.a $(QM_DSP_DIR)/libqm-dsp.a -exported_symbols_list vamp-plugin.list + +## Uncomment these for an OS/X universal binary using command-line tools: + +# CXXFLAGS = -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc -I$(VAMP_SDK_DIR) -I$(QM_DSP_DIR) -Wall -fPIC +# PLUGIN_EXT = .dylib +# PLUGIN = $(PLUGIN_LIBRARY_NAME)$(PLUGIN_EXT) +# LDFLAGS = -dynamiclib -install_name $(PLUGIN) $(VAMP_SDK_DIR)/libvamp-sdk.a $(QM_DSP_DIR)/libqm-dsp.a -exported_symbols_list vamp-plugin.list + + +## Uncomment these for Linux using the standard tools: + +# CXXFLAGS = -I$(VAMP_SDK_DIR) -I$(QM_DSP_DIR) -Wall -fPIC +# PLUGIN_EXT = .so +# PLUGIN = $(PLUGIN_LIBRARY_NAME)$(PLUGIN_EXT) +# LDFLAGS = -shared -Wl,-soname=$(PLUGIN) $(VAMP_SDK_DIR)/libvamp-sdk.a $(QM_DSP_DIR)/libqm-dsp.a -Wl,--version-script=vamp-plugin.map + + +## Uncomment these for a cross-compile from Linux to Windows using MinGW: + +# MINGW_DIR = ../mingw-cross-env/usr/bin + +# CXX = $(MINGW_DIR)/./i686-pc-mingw32-g++ +# CXXFLAGS = -I$(VAMP_SDK_DIR) -I$(QM_DSP_DIR) -Wall +# PLUGIN_EXT = .dll +# PLUGIN = $(PLUGIN_LIBRARY_NAME)$(PLUGIN_EXT) +# LDFLAGS = --static-libgcc -Wl,-soname=$(PLUGIN) -shared $(VAMP_SDK_DIR)/libvamp-sdk.a $(QM_DSP_DIR)/libqm-dsp.a + + +## Uncomment these for OpenSolaris using SunStudio compiler and GNU make: + +# CXX = CC +# CXXFLAGS = -G -I$(VAMP_SDK_DIR) -I$(QM_DSP_DIR) +w -KPIC +# PLUGIN_EXT = .so +# PLUGIN = $(PLUGIN_LIBRARY_NAME)$(PLUGIN_EXT) +# LDFLAGS = -G -h$(PLUGIN) $(VAMP_SDK_DIR)/libvamp-sdk.a $(QM_DSP_DIR)/libqm-dsp.a -Qoption ld -Mvamp-plugin.map + + + +## All of the above + +$(PLUGIN): $(PLUGIN_CODE_OBJECTS) + $(CXX) -o $@ $^ $(LDFLAGS) + +clean: + rm -f *.o + +# only relevant for OS/X + +copy: + sudo cp $(PLUGIN_LIBRARY_NAME).dylib /Library/Audio/Plug-Ins/Vamp diff -r 000000000000 -r cd5e0ac31ff7 vamp-calcium-signal-analyser.dylib Binary file vamp-calcium-signal-analyser.dylib has changed diff -r 000000000000 -r cd5e0ac31ff7 vamp-calcium-signal-analyser_peaktimes.n3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vamp-calcium-signal-analyser_peaktimes.n3 Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,24 @@ +@prefix xsd: . +@prefix vamp: . +@prefix : <#> . + +:transform_plugin a vamp:Plugin ; + vamp:identifier "peakdetection" . + +:transform_library a vamp:PluginLibrary ; + vamp:identifier "vamp-calcium-signal-analyser" ; + vamp:available_plugin :transform_plugin . + +:transform a vamp:Transform ; + vamp:plugin :transform_plugin ; + vamp:step_size "1"^^xsd:int ; + vamp:block_size "1"^^xsd:int ; + vamp:parameter_binding [ + vamp:parameter [ vamp:identifier "deltathreshold" ] ; + vamp:value "0.2"^^xsd:float ; + ] ; + vamp:parameter_binding [ + vamp:parameter [ vamp:identifier "sensitivity" ] ; + vamp:value "50"^^xsd:float ; + ] ; + vamp:output [ vamp:identifier "peaktimes" ] . diff -r 000000000000 -r cd5e0ac31ff7 vamp-plugin.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vamp-plugin.list Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,1 @@ +_vampGetPluginDescriptor diff -r 000000000000 -r cd5e0ac31ff7 vamp-plugin.map --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vamp-plugin.map Fri Jun 17 20:33:53 2011 +0100 @@ -0,0 +1,4 @@ +{ + global: vampGetPluginDescriptor; + local: *; +};