pax_global_header00006660000000000000000000000064121532044030014504gustar00rootroot0000000000000052 comment=b7906112cf6db3b4e54568713eba1c46253bb8dd silan-0.3.2/000077500000000000000000000000001215320440300126145ustar00rootroot00000000000000silan-0.3.2/AUTHORS000066400000000000000000000000401215320440300136560ustar00rootroot00000000000000Robin Gareus silan-0.3.2/COPYING000066400000000000000000000432541215320440300136570ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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 How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. silan-0.3.2/ChangeLog000066400000000000000000000022561215320440300143730ustar00rootroot000000000000002013-06-03 (v0.3.2) Robin Gareus * add fast-scan mode (seek forward/backward) * regularly flush output -- make silan work with live-streams * code optimizations * add static-build scripts 2013-03-05 (v0.3.1) Robin Gareus * add total file duration to JSON output * ffmpeg backwards compatibilty for debian/squeeze and Ubuntu/Lucid 2013-01-10 (v0.3.0) Robin Gareus * add support for JSON output * separate format (-f) and unit (-u) options. * fix off-by-one error in holdoff compensation * always end with a "Sound off" * cleaned up and documented audio-decoder library * remove explicit flac support (libav and libsndfile can read it) * add GPLv2 and LGPLv2.1 boilerplates 2012-12-30 (v0.2.0) Robin Gareus * change default output format to seconds * add print --bounds only feature 2012-10-01 (v0.1.1) Robin Gareus * high-pass filter * holdoff delay * cleanup output, use stderr for all info, don't clutter data-out * audacity label-file-format output 2012-10-01 (v0.1.0) Robin Gareus * started project based on SampleCat's audio-decoder * basic silence detection * simple output silan-0.3.2/Makefile.am000066400000000000000000000003301215320440300146440ustar00rootroot00000000000000## Process this file with automake to produce Makefile.in SUBDIRS = audio_decoder src man_MANS = silan.1 EXTRA_DIST = silan.1 man: src/silan help2man -N -l -n "Soundfile Silence Analyzer" -o silan.1 ./src/silan silan-0.3.2/NEWS000066400000000000000000000000001215320440300133010ustar00rootroot00000000000000silan-0.3.2/README000066400000000000000000000011331215320440300134720ustar00rootroot00000000000000silan -- Audiofile Silence Analyzer =================================== Silan is a standalone application to analyze audio files for silence and print ranges of detected signals. It supports a variety of audio-formats and codecs by making use of libsndfile and ffmpeg/libav for reading audio-data. Signal threshold and hold-off time can be freely configured. The output can be formatted with samples or seconds as unit or printed as audacity label file. For more information please read the included manual page. Silan is licensed in terms of the GNU General Public License (version 2 or later). silan-0.3.2/TODO000066400000000000000000000002331215320440300133020ustar00rootroot00000000000000some ideas: * custom output format using % encoding * beat/onset detection (using aubio) * adaptive threshold, volume pre-scaling (replaygain, ebu128,..) silan-0.3.2/audio_decoder/000077500000000000000000000000001215320440300154025ustar00rootroot00000000000000silan-0.3.2/audio_decoder/Makefile.am000066400000000000000000000003341215320440300174360ustar00rootroot00000000000000AM_CFLAGS = \ -g -Wall -O2 \ -I$(top_srcdir) \ $(SNDFILE_CFLAGS) \ $(FFMPEG_CFLAGS) noinst_LIBRARIES = libad.a libad_a_SOURCES = \ ad_ffmpeg.c \ ad.h \ ad_plugin.c \ ad_plugin.h \ ad_soundfile.c \ ffcompat.h silan-0.3.2/audio_decoder/ad.h000066400000000000000000000076661215320440300161560ustar00rootroot00000000000000/** @brief audio-decoder - wrapper around libsndfile and libav* @file ad.h @author Robin Gareus Copyright (C) 2011-2013 Robin Gareus This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation; either version 2.1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __AD_H__ #define __AD_H__ #include #include struct adinfo { unsigned int sample_rate; unsigned int channels; int64_t length; //milliseconds int64_t frames; //total number of frames (eg a frame for 16bit stereo is 4 bytes). int bit_rate; int bit_depth; char * meta_data; }; /* global init function - register codecs */ void ad_init(); /* --- public API --- */ /** open an audio file * @param fn file-name * @param nfo pointer to a adinfo struct which will hold information about the file. * @return NULL on error, a pointer to an opaque soundfile-decoder object on success. */ void * ad_open (const char *fn, struct adinfo *nfo); /** close an audio file and release decoder structures * @param sf decoder handle * @return 0 on succees, -1 if sf was invalid or not open (return value can usually be ignored) */ int ad_close (void *sf); /** seel to a given position in the file * @param sf decoder handle * @param pos frame position to seek to in frames (1 frame = number-of-channel samples) from the start of the file. * @return the current position in frames (multi-channel samples) from the start of the file. On error this function returns -1. */ int64_t ad_seek (void *sf, int64_t pos); /** decode audio data chunk to raw interleaved channel floating point data * * @param sf decoder handle * @param out place to store data -- must be large enough to hold (sizeof(float) * len) bytes. * @param len number of samples (!) to read (should be a multiple of nfo->channels). * @return the number of read samples. */ ssize_t ad_read (void *sf, float* out, size_t len); /** re-read the file information and meta-data. * * this is not neccesary in general \ref ad_open includes an inplicit call * but meta-data may change in live-stream in which case en explicit call to * ad_into is needed to update the inforation * * @param fn file-name * @param nfo pointer to a adinfo struct which will hold information about the file. * @return 0 on succees, -1 if sf was invalid or not open */ int ad_info (void *sf, struct adinfo *nfo); /** zero initialize the information struct. * (does not free nfo->meta_data) * @param nfo pointer to a adinfo struct */ void ad_clear_nfo (struct adinfo *nfo); /** free possibly allocated meta-data text * @param nfo pointer to a adinfo struct */ void ad_free_nfo (struct adinfo *nfo); /* --- helper functions --- */ /** read file info * combines ad_open() and ad_close() */ int ad_finfo (const char *, struct adinfo *); /** * wrapper around \ref ad_read, downmixes all channels to mono */ ssize_t ad_read_mono_dbl (void *, struct adinfo *, double*, size_t); /** * calls dbg() to print file info to stderr. * * @param dbglvl * @param nfo */ void ad_dump_nfo (int dbglvl, struct adinfo *nfo); /** set audio-decoder debug level -- all info is printed to stderr. * * @param lvl debug-level threshold * -1: absolutley silent * 0: errors only * 1: errors + info * 2: + debug * 3: + low-level-debug info */ void ad_set_debuglevel(int lvl); #endif silan-0.3.2/audio_decoder/ad_ffmpeg.c000066400000000000000000000301451215320440300174610ustar00rootroot00000000000000/** Copyright (C) 2011-2013 Robin Gareus This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation; either version 2.1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config.h" #include #include #include #include #include #include "audio_decoder/ad_plugin.h" #ifdef HAVE_FFMPEG #include "ffcompat.h" #ifndef MIN #define MIN(a,b) ( ( (a) < (b) )? (a) : (b) ) #endif typedef struct { AVFormatContext* formatContext; AVCodecContext* codecContext; AVCodec* codec; AVPacket packet; int audioStream; int pkt_len; uint8_t* pkt_ptr; int16_t m_tmpBuffer[AVCODEC_MAX_AUDIO_FRAME_SIZE]; int16_t* m_tmpBufferStart; unsigned long m_tmpBufferLen; int64_t decoder_clock; int64_t output_clock; int64_t seek_frame; unsigned int samplerate; unsigned int channels; int64_t length; } ffmpeg_audio_decoder; static int ad_info_ffmpeg(void *sf, struct adinfo *nfo) { ffmpeg_audio_decoder *priv = (ffmpeg_audio_decoder*) sf; if (!priv) return -1; if (nfo) { nfo->sample_rate = priv->samplerate; nfo->channels = priv->channels; nfo->frames = priv->length; if (nfo->sample_rate==0) return -1; nfo->length = (nfo->frames * 1000) / nfo->sample_rate; nfo->bit_rate = priv->formatContext->bit_rate; nfo->bit_depth = 0; nfo->meta_data = NULL; #ifdef WITH_GTK // XXX replace g_* functions with POSIX equiv AVDictionaryEntry *tag = NULL; // Tags in container while ((tag = av_dict_get(priv->formatContext->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { dbg(2, "FTAG: %s=%s", tag->key, tag->value); char * tmp = g_strdup_printf("%s%s%s:%s", nfo->meta_data?nfo->meta_data:"",nfo->meta_data?"\n":"", tag->key, tag->value); if (nfo->meta_data) g_free(nfo->meta_data); nfo->meta_data = tmp; } // Tags in stream tag=NULL; AVStream *stream = priv->formatContext->streams[priv->audioStream]; while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { dbg(2, "STAG: %s=%s", tag->key, tag->value); char * tmp = g_strdup_printf("%s%s%s:%s", nfo->meta_data?nfo->meta_data:"",nfo->meta_data?"\n":"", tag->key, tag->value); if (nfo->meta_data) g_free(nfo->meta_data); nfo->meta_data = tmp; } #endif } return 0; } static void *ad_open_ffmpeg(const char *fn, struct adinfo *nfo) { ffmpeg_audio_decoder *priv = (ffmpeg_audio_decoder*) calloc(1, sizeof(ffmpeg_audio_decoder)); priv->m_tmpBufferStart=NULL; priv->m_tmpBufferLen=0; priv->decoder_clock=priv->output_clock=priv->seek_frame=0; priv->packet.size=0; priv->packet.data=NULL; if (avformat_open_input(&priv->formatContext, fn, NULL, NULL) <0) { dbg(0, "ffmpeg is unable to open file '%s'.", fn); free(priv); return(NULL); } if (avformat_find_stream_info(priv->formatContext, NULL) < 0) { avformat_close_input(&priv->formatContext); dbg(0, "av_find_stream_info failed" ); free(priv); return(NULL); } priv->audioStream = -1; unsigned int i; for (i=0; iformatContext->nb_streams; i++) { if (priv->formatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { priv->audioStream = i; break; } } if (priv->audioStream == -1) { dbg(0, "No Audio Stream found in file"); avformat_close_input(&priv->formatContext); free(priv); return(NULL); } priv->codecContext = priv->formatContext->streams[priv->audioStream]->codec; priv->codec = avcodec_find_decoder(priv->codecContext->codec_id); if (priv->codec == NULL) { avformat_close_input(&priv->formatContext); dbg(0, "Codec not supported by ffmpeg"); free(priv); return(NULL); } if (avcodec_open2(priv->codecContext, priv->codec, NULL) < 0) { dbg(0, "avcodec_open failed" ); free(priv); return(NULL); } dbg(2, "ffmpeg - audio tics: %i/%i [sec]",priv->formatContext->streams[priv->audioStream]->time_base.num,priv->formatContext->streams[priv->audioStream]->time_base.den); int64_t len = priv->formatContext->duration - priv->formatContext->start_time; priv->formatContext->flags|=AVFMT_FLAG_GENPTS; priv->formatContext->flags|=AVFMT_FLAG_IGNIDX; priv->samplerate = priv->codecContext->sample_rate; priv->channels = priv->codecContext->channels ; priv->length = (int64_t)( len * priv->samplerate / AV_TIME_BASE ); if (ad_info_ffmpeg((void*)priv, nfo)) { dbg(0, "invalid file info (sample-rate==0)"); free(priv); return(NULL); } dbg(1, "ffmpeg - %s", fn); if (nfo) dbg(1, "ffmpeg - sr:%i c:%i d:%"PRIi64" f:%"PRIi64, nfo->sample_rate, nfo->channels, nfo->length, nfo->frames); return (void*) priv; } static int ad_close_ffmpeg(void *sf) { ffmpeg_audio_decoder *priv = (ffmpeg_audio_decoder*) sf; if (!priv) return -1; avcodec_close(priv->codecContext); avformat_close_input(&priv->formatContext); free(priv); return 0; } static void int16_to_float(int16_t *in, float *out, int num_channels, int num_samples, int out_offset) { int i,ii; for (i=0;ichannels; size_t written = 0; ssize_t ret = 0; while (ret >= 0 && written < frames) { dbg(3,"loop: %i/%i (bl:%lu)",written, frames, priv->m_tmpBufferLen ); if (priv->seek_frame == 0 && priv->m_tmpBufferLen > 0 ) { int s = MIN(priv->m_tmpBufferLen / priv->channels, frames - written ); int16_to_float(priv->m_tmpBufferStart, d, priv->channels, s , written); written += s; priv->output_clock+=s; s = s * priv->channels; priv->m_tmpBufferStart += s; priv->m_tmpBufferLen -= s; ret = 0; } else { priv->m_tmpBufferStart = priv->m_tmpBuffer; priv->m_tmpBufferLen = 0; if (!priv->pkt_ptr || priv->pkt_len <1 ) { if (priv->packet.data) av_free_packet(&priv->packet); ret = av_read_frame(priv->formatContext, &priv->packet); if (ret<0) { dbg(1, "reached end of file."); break; } priv->pkt_len = priv->packet.size; priv->pkt_ptr = priv->packet.data; } if (priv->packet.stream_index != priv->audioStream) { priv->pkt_ptr = NULL; continue; } /* decode all chunks in packet */ int data_size= AVCODEC_MAX_AUDIO_FRAME_SIZE; #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 0, 0) /* This works but is not optimal (channels may not be planar/interleaved) */ AVFrame avf; // TODO statically allocate as poart of priv->.. memset(&avf, 0, sizeof(AVFrame)); // not sure if that is needed int got_frame = 0; ret = avcodec_decode_audio4(priv->codecContext, &avf, &got_frame, &priv->packet); data_size = avf.linesize[0]; memcpy(priv->m_tmpBuffer, avf.data[0], avf.linesize[0] * sizeof(uint8_t)); #elif LIBAVUTIL_VERSION_INT > AV_VERSION_INT(49, 15, 0) && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(52, 20, 1) // ?? // this was deprecated in LIBAVCODEC_VERSION_MAJOR 53 ret = avcodec_decode_audio3(priv->codecContext, priv->m_tmpBuffer, &data_size, &priv->packet); #else int len = priv->packet.size; uint8_t *ptr = priv->packet.data; ret = avcodec_decode_audio2(priv->codecContext, priv->m_tmpBuffer, &data_size, ptr, len); #endif if (ret < 0 || ret > priv->pkt_len) { #if 0 dbg(0, "audio decode error"); return -1; #endif priv->pkt_len=0; ret=0; continue; } priv->pkt_len -= ret; priv->pkt_ptr += ret; /* sample exact alignment */ if (priv->packet.pts != AV_NOPTS_VALUE) { priv->decoder_clock = priv->samplerate * av_q2d(priv->formatContext->streams[priv->audioStream]->time_base) * priv->packet.pts; } else { dbg(0, "!!! NO PTS timestamp in file"); priv->decoder_clock += (data_size>>1) / priv->channels; } if (data_size>0) { priv->m_tmpBufferLen+= (data_size>>1); // 2 bytes per sample } /* align buffer after seek. */ if (priv->seek_frame > 0) { const int diff = priv->output_clock-priv->decoder_clock; if (diff<0) { /* seek ended up past the wanted sample */ dbg(0, " !!! Audio seek failed."); return -1; } else if (priv->m_tmpBufferLen < (diff*priv->channels)) { /* wanted sample not in current buffer - keep going */ dbg(2, " !!! seeked sample was not in decoded buffer. frames-to-go: %li", diff); priv->m_tmpBufferLen = 0; } else if (diff!=0 && data_size > 0) { /* wanted sample is in current buffer but not at the beginnning */ dbg(2, " !!! sync buffer to seek. (diff:%i)", diff); priv->m_tmpBufferStart+= diff*priv->codecContext->channels; priv->m_tmpBufferLen -= diff*priv->codecContext->channels; #if 1 memmove(priv->m_tmpBuffer, priv->m_tmpBufferStart, priv->m_tmpBufferLen); priv->m_tmpBufferStart = priv->m_tmpBuffer; #endif priv->seek_frame=0; priv->decoder_clock += diff; } else if (data_size > 0) { dbg(2, "Audio exact sync-seek (%"PRIi64" == %"PRIi64")", priv->decoder_clock, priv->seek_frame); priv->seek_frame=0; } else { dbg(0, "Error: no audio data in packet"); } } //dbg(0, "PTS: decoder:%"PRIi64". - want: %"PRIi64, priv->decoder_clock, priv->output_clock); //dbg(0, "CLK: frame: %"PRIi64" T:%.3fs",priv->decoder_clock, (float) priv->decoder_clock/priv->samplerate); } } if (written!=frames) { dbg(2, "short-read"); } return written * priv->channels; } static int64_t ad_seek_ffmpeg(void *sf, int64_t pos) { ffmpeg_audio_decoder *priv = (ffmpeg_audio_decoder*) sf; if (!sf) return -1; if (pos == priv->output_clock) return pos; /* flush internal buffer */ priv->m_tmpBufferLen = 0; priv->seek_frame = pos; priv->output_clock = pos; priv->pkt_len = 0; priv->pkt_ptr = NULL; priv->decoder_clock = 0; #if 0 /* TODO seek at least 1 packet before target. * for mpeg compressed files, the * output may depend on past frames! */ if (pos > 8192) pos -= 8192; else pos = 0; #endif const int64_t timestamp = pos / av_q2d(priv->formatContext->streams[priv->audioStream]->time_base) / priv->samplerate; dbg(2, "seek frame:%"PRIi64" - idx:%"PRIi64, pos, timestamp); av_seek_frame(priv->formatContext, priv->audioStream, timestamp, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); avcodec_flush_buffers(priv->codecContext); return pos; } static int ad_eval_ffmpeg(const char *f) { char *ext = strrchr(f, '.'); if (!ext) return 10; // libavformat.. guess_format.. return 40; } #endif static const ad_plugin ad_ffmpeg = { #ifdef HAVE_FFMPEG &ad_eval_ffmpeg, &ad_open_ffmpeg, &ad_close_ffmpeg, &ad_info_ffmpeg, &ad_seek_ffmpeg, &ad_read_ffmpeg #else &ad_eval_null, &ad_open_null, &ad_close_null, &ad_info_null, &ad_seek_null, &ad_read_null #endif }; /* dlopen handler */ const ad_plugin * adp_get_ffmpeg() { #ifdef HAVE_FFMPEG static int ffinit = 0; if (!ffinit) { ffinit=1; #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 5, 0) avcodec_init(); #endif av_register_all(); avcodec_register_all(); if(ad_debug_level <= 1) av_log_set_level(AV_LOG_QUIET); else av_log_set_level(AV_LOG_VERBOSE); } #endif return &ad_ffmpeg; } silan-0.3.2/audio_decoder/ad_plugin.c000066400000000000000000000106751215320440300175210ustar00rootroot00000000000000/** Copyright (C) 2011-2013 Robin Gareus This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation; either version 2.1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config.h" #include #include #include #include #include #include #include "audio_decoder/ad_plugin.h" int ad_debug_level = 0; #define UNUSED(x) (void)(x) int ad_eval_null(const char *f) { UNUSED(f); return -1; } void * ad_open_null(const char *f, struct adinfo *n) { UNUSED(f); UNUSED(n); return NULL; } int ad_close_null(void *x) { UNUSED(x); return -1; } int ad_info_null(void *x, struct adinfo *n) { UNUSED(x); UNUSED(n); return -1; } int64_t ad_seek_null(void *x, int64_t p) { UNUSED(x); UNUSED(p); return -1; } ssize_t ad_read_null(void *x, float*d, size_t s) { UNUSED(x); UNUSED(d); UNUSED(s); return -1;} typedef struct { ad_plugin const *b; ///< decoder back-end void *d; ///< backend data } adecoder; /* samplecat api */ void ad_init() { /* global init */ } static ad_plugin const * choose_backend(const char *fn) { int max, val; ad_plugin const *b=NULL; max=0; val=adp_get_sndfile()->eval(fn); if (val>max) {max=val; b=adp_get_sndfile();} val=adp_get_ffmpeg()->eval(fn); if (val>max) {max=val; b=adp_get_ffmpeg();} return b; } void *ad_open(const char *fn, struct adinfo *nfo) { adecoder *d = (adecoder*) calloc(1, sizeof(adecoder)); ad_clear_nfo(nfo); d->b = choose_backend(fn); if (!d->b) { dbg(0, "fatal: no decoder backend available"); free(d); return NULL; } d->d = d->b->open(fn, nfo); if (!d->d) { free(d); return NULL; } return (void*)d; } int ad_info(void *sf, struct adinfo *nfo) { adecoder *d = (adecoder*) sf; if (!d) return -1; return d->b->info(d->d, nfo); } int ad_close(void *sf) { adecoder *d = (adecoder*) sf; if (!d) return -1; int rv = d->b->close(d->d); free(d); return rv; } int64_t ad_seek(void *sf, int64_t pos) { adecoder *d = (adecoder*) sf; if (!d) return -1; return d->b->seek(d->d, pos); } ssize_t ad_read(void *sf, float* out, size_t len){ adecoder *d = (adecoder*) sf; if (!d) return -1; return d->b->read(d->d, out, len); } /* * side-effects: allocates buffer */ ssize_t ad_read_mono_dbl(void *sf, struct adinfo *nfo, double* d, size_t len){ unsigned int c,f; unsigned int chn = nfo->channels; if (len<1) return 0; static float *buf = NULL; static size_t bufsiz = 0; if (!buf || bufsiz != len*chn) { bufsiz=len*chn; buf = (float*) realloc((void*)buf, bufsiz * sizeof(float)); } len = ad_read(sf, buf, bufsiz); for (f=0;f< (len/chn);f++) { double val=0.0; for (c=0;cmeta_data) free(nfo->meta_data); } void ad_dump_nfo(int dbglvl, struct adinfo *nfo) { dbg(dbglvl, "sample_rate: %u", nfo->sample_rate); dbg(dbglvl, "channels: %u", nfo->channels); dbg(dbglvl, "length: %"PRIi64" ms", nfo->length); dbg(dbglvl, "frames: %"PRIi64, nfo->frames); dbg(dbglvl, "bit_rate: %d", nfo->bit_rate); dbg(dbglvl, "bit_depth: %d", nfo->bit_depth); dbg(dbglvl, "channels: %u", nfo->channels); dbg(dbglvl, "meta-data: %s", nfo->meta_data?nfo->meta_data:"-"); } void ad_debug_printf(const char* func, int level, const char* format, ...) { va_list args; va_start(args, format); if (level <= ad_debug_level) { fprintf(stderr, "%s(): ", func); vfprintf(stderr, format, args); fprintf(stderr, "\n"); } va_end(args); } void ad_set_debuglevel(int lvl) { ad_debug_level = lvl; if (ad_debug_level<-1) ad_debug_level=-1; if (ad_debug_level>3) ad_debug_level=3; } silan-0.3.2/audio_decoder/ad_plugin.h000066400000000000000000000036121215320440300175170ustar00rootroot00000000000000/** Copyright (C) 2011-2013 Robin Gareus This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation; either version 2.1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __AD_PLUGIN_H__ #define __AD_PLUGIN_H__ #include #include "audio_decoder/ad.h" #define dbg(A, B, ...) ad_debug_printf(__func__, A, B, ##__VA_ARGS__) #ifndef __PRI64_PREFIX #if (defined __X86_64__ || defined __LP64__) # define __PRI64_PREFIX "l" #else # define __PRI64_PREFIX "ll" #endif #endif #ifndef PRIu64 # define PRIu64 __PRI64_PREFIX "u" #endif #ifndef PRIi64 # define PRIi64 __PRI64_PREFIX "i" #endif extern int ad_debug_level; void ad_debug_printf(const char* func, int level, const char* format, ...); typedef struct { int (*eval)(const char *); void * (*open)(const char *, struct adinfo *); int (*close)(void *); int (*info)(void *, struct adinfo *); int64_t (*seek)(void *, int64_t); ssize_t (*read)(void *, float *, size_t); } ad_plugin; int ad_eval_null(const char *); void * ad_open_null(const char *, struct adinfo *); int ad_close_null(void *); int ad_info_null(void *, struct adinfo *); int64_t ad_seek_null(void *, int64_t); ssize_t ad_read_null(void *, float*, size_t); /* hardcoded backends */ const ad_plugin * adp_get_sndfile(); const ad_plugin * adp_get_ffmpeg(); #endif silan-0.3.2/audio_decoder/ad_soundfile.c000066400000000000000000000111331215320440300202010ustar00rootroot00000000000000/** Copyright (C) 2011-2013 Robin Gareus This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation; either version 2.1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config.h" #include #include #include #include #include #include #include #include "audio_decoder/ad_plugin.h" /* internal abstraction */ typedef struct { SF_INFO sfinfo; SNDFILE *sffile; } sndfile_audio_decoder; static int parse_bit_depth(int format) { /* see http://www.mega-nerd.com/libsndfile/api.html */ switch (format&0x0f) { case SF_FORMAT_PCM_S8: return 8; case SF_FORMAT_PCM_16: return 16; /* Signed 16 bit data */ case SF_FORMAT_PCM_24: return 24; /* Signed 24 bit data */ case SF_FORMAT_PCM_32: return 32; /* Signed 32 bit data */ case SF_FORMAT_PCM_U8: return 8; /* Unsigned 8 bit data (WAV and RAW only) */ case SF_FORMAT_FLOAT : return 32; /* 32 bit float data */ case SF_FORMAT_DOUBLE: return 64; /* 64 bit float data */ default: break; } return 0; } static int ad_info_sndfile(void *sf, struct adinfo *nfo) { sndfile_audio_decoder *priv = (sndfile_audio_decoder*) sf; if (!priv) return -1; if (nfo) { nfo->channels = priv->sfinfo.channels; nfo->frames = priv->sfinfo.frames; nfo->sample_rate = priv->sfinfo.samplerate; nfo->length = priv->sfinfo.samplerate ? (priv->sfinfo.frames * 1000) / priv->sfinfo.samplerate : 0; nfo->bit_depth = parse_bit_depth(priv->sfinfo.format); nfo->bit_rate = nfo->bit_depth * nfo->channels * nfo->sample_rate; nfo->meta_data = NULL; } return 0; } static void *ad_open_sndfile(const char *fn, struct adinfo *nfo) { sndfile_audio_decoder *priv = (sndfile_audio_decoder*) calloc(1, sizeof(sndfile_audio_decoder)); priv->sfinfo.format=0; if(!(priv->sffile = sf_open(fn, SFM_READ, &priv->sfinfo))){ dbg(0, "unable to open file '%s'.", fn); puts(sf_strerror(NULL)); int e = sf_error(NULL); dbg(0, "error=%i", e); free(priv); return NULL; } ad_info_sndfile(priv, nfo); return (void*) priv; } static int ad_close_sndfile(void *sf) { sndfile_audio_decoder *priv = (sndfile_audio_decoder*) sf; if (!priv) return -1; if(!sf || sf_close(priv->sffile)) { dbg(0, "fatal: bad file close.\n"); return -1; } free(priv); return 0; } static int64_t ad_seek_sndfile(void *sf, int64_t pos) { sndfile_audio_decoder *priv = (sndfile_audio_decoder*) sf; if (!priv) return -1; return sf_seek(priv->sffile, pos, SEEK_SET); } static ssize_t ad_read_sndfile(void *sf, float* d, size_t len) { sndfile_audio_decoder *priv = (sndfile_audio_decoder*) sf; if (!priv) return -1; return sf_read_float (priv->sffile, d, len); } static int ad_eval_sndfile(const char *f) { char *ext = strrchr(f, '.'); if (!ext) return 5; /* see http://www.mega-nerd.com/libsndfile/ */ if (!strcasecmp(ext, ".wav")) return 100; if (!strcasecmp(ext, ".aiff")) return 100; if (!strcasecmp(ext, ".aifc")) return 100; if (!strcasecmp(ext, ".snd")) return 100; if (!strcasecmp(ext, ".au")) return 100; if (!strcasecmp(ext, ".paf")) return 100; if (!strcasecmp(ext, ".iff")) return 100; if (!strcasecmp(ext, ".svx")) return 100; if (!strcasecmp(ext, ".sf")) return 100; if (!strcasecmp(ext, ".vcc")) return 100; if (!strcasecmp(ext, ".w64")) return 100; if (!strcasecmp(ext, ".mat4")) return 100; if (!strcasecmp(ext, ".mat5")) return 100; if (!strcasecmp(ext, ".pvf5")) return 100; if (!strcasecmp(ext, ".xi")) return 100; if (!strcasecmp(ext, ".htk")) return 100; if (!strcasecmp(ext, ".pvf")) return 100; if (!strcasecmp(ext, ".sd2")) return 100; // libsndfile >= 1.0.18 if (!strcasecmp(ext, ".flac")) return 80; if (!strcasecmp(ext, ".ogg")) return 80; return 0; } static const ad_plugin ad_sndfile = { #if 1 &ad_eval_sndfile, &ad_open_sndfile, &ad_close_sndfile, &ad_info_sndfile, &ad_seek_sndfile, &ad_read_sndfile #else &ad_eval_null, &ad_open_null, &ad_close_null, &ad_info_null, &ad_seek_null, &ad_read_null #endif }; /* dlopen handler */ const ad_plugin * adp_get_sndfile() { return &ad_sndfile; } silan-0.3.2/audio_decoder/ffcompat.h000066400000000000000000000061311215320440300173530ustar00rootroot00000000000000/* ffmpeg compatibility wrappers * * Copyright 2012 Robin Gareus * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FFCOMPAT_H #define FFCOMPAT_H #include #include #include #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(50, 0, 0) #define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO #endif #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 2, 0) static inline int avformat_open_input(AVFormatContext **ps, const char *filename, void *fmt, void **options) { return av_open_input_file(ps, filename, NULL, 0, NULL); } #endif #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 5, 0) static inline AVCodecContext * avcodec_alloc_context3(AVCodec *codec __attribute__((unused))) { return avcodec_alloc_context(); } static inline AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c) { return av_new_stream(s,0); } static inline int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec) { avcodec_get_context_defaults(s); return 0; } #endif /* < 53.5.0 */ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 5, 6) static inline int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, void **options __attribute__((unused))) { return avcodec_open(avctx, codec); } #endif /* <= 53.5.6 */ #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 5, 0) static inline int avformat_find_stream_info(AVFormatContext *ic, void **options) { return av_find_stream_info(ic); } static inline void avformat_close_input(AVFormatContext **s) { av_close_input_file(*s); } #endif /* < 53.5.0 */ #endif /* FFCOMPAT_H */ silan-0.3.2/autogen.sh000077500000000000000000000001031215320440300146070ustar00rootroot00000000000000#!/bin/sh autoreconf --force -v --install || exit ./configure "$@" silan-0.3.2/configure.ac000066400000000000000000000056021215320440300151050ustar00rootroot00000000000000AC_PREREQ(2.59) AC_INIT([silan],[0.3.2],[robin@gareus.org]) AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADER([config.h]) AC_CANONICAL_HOST AC_CANONICAL_TARGET AC_COPYRIGHT([Copyright (C) Robin Gareus 2013]) AM_INIT_AUTOMAKE AC_PROG_INSTALL AC_PROG_CC AC_C_CONST AC_C_INLINE AC_HEADER_STDBOOL AC_TYPE_SIZE_T AC_PROG_LIBTOOL AM_PROG_LIBTOOL AM_PROG_CC_C_O AC_SYS_LARGEFILE LT_INIT # Check for debugging flag debug="no" AC_ARG_ENABLE(debug, [AS_HELP_STRING(--enable-debug, [Enable debugging (false)])], [debug="$enableval"]) if test "$debug" = "yes"; then CFLAGS="-O0 -g -DDEBUG" else CFLAGS="$CFLAGS -DNDEBUG" fi # default 'auto' configutaion AC_ARG_ENABLE(ffmpeg, AC_HELP_STRING([--disable-ffmpeg], [disable use of FFMPEG]), enable_ffmpeg=$enableval, enable_ffmpeg="auto") SILAN_LIBS="-lm" case $target_os in *darwin*) CFLAGS="$CFLAGS -fnested-functions" SILAN_LIBS="$SILAN_LIBS -Wl,-flat_namespace,-undefined,dynamic_lookup" ;; *linux*) ;; *) ;; esac AC_SUBST(SILAN_LIBS) AC_SUBST(SILAN_CFLAGS) # Check for strict flag strict="no" AC_ARG_ENABLE(strict, [AS_HELP_STRING(--enable-strict, [Enable strict compiler warnings and errors (false)])], [strict="$enableval"]) if test "$strict" = "yes"; then CFLAGS="$CFLAGS -ansi -Wall -Wextra -Wno-unused-parameter -Wconversion -Winit-self" CXXFLAGS="$CXXFLAGS -ansi -Wall -Wextra -Wno-unused-parameter -Wconversion -Winit-self -Woverloaded-virtual -Wsign-promo" fi dnl ----------------------------------------------------------------------------- AC_MSG_CHECKING([if -Wl,--as-needed works]) LDFLAGS_save=$LDFLAGS LDFLAGS="$LDFLAGS -Wl,--as-needed" AC_TRY_LINK([], [], [ AC_MSG_RESULT([yes]) LDFLAGS="$LDFLAGS -Wl,--as-needed" ], [AC_MSG_RESULT([no])]) LDFLAGS=$LDFLAGS_save dnl TODO: sndfile is optional if FFMPEG is avail PKG_CHECK_MODULES(SNDFILE, sndfile) AC_SUBST(SNDFILE_CFLAGS) AC_SUBST(SNDFILE_LIBS) dnl ----------------------------------------------------------------------------- AS_IF([test "$enable_ffmpeg" != "no"], [ PKG_CHECK_MODULES(FFMPEG, [libavformat >= 51.0.0 libavcodec >= 51.0.0 libavutil >= 49.0.0], enable_ffmpeg=yes, enable_ffmpeg=no) ]) if test "$enable_ffmpeg" = "yes"; then AC_DEFINE(HAVE_FFMPEG,1,[Use ffmpeg audio decoder]) fi AM_CONDITIONAL(ENABLE_FFMPEG, test "$enable_ffmpeg" = "yes") AC_SUBST(FFMPEG_CFLAGS) AC_SUBST(FFMPEG_LIBS) # Bolt on a few specific flags to CXXFLAGS that should always be used CXXFLAGS="$CXXFLAGS -pipe -fmessage-length=139 -fdiagnostics-show-location=every-line" CFLAGS="$CFLAGS -pipe -fmessage-length=139 -fdiagnostics-show-location=every-line" AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([src/Makefile]) AC_CONFIG_FILES([audio_decoder/Makefile]) AC_OUTPUT AC_MSG_RESULT([]) AC_MSG_RESULT([Audio decoders:]) AC_MSG_RESULT([ libsndfile: yes]) AC_MSG_RESULT([ ffmpeg decoder: $enable_ffmpeg]) AC_MSG_RESULT([]) silan-0.3.2/silan.1000066400000000000000000000050151215320440300140050ustar00rootroot00000000000000.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.40.4. .TH SILAN "1" "June 2013" "silan version 0.3.1" "User Commands" .SH NAME silan \- Soundfile Silence Analyzer .SH SYNOPSIS .B silan [ \fIOPTIONS \fR] \fI\fR .SH DESCRIPTION silan \- Audiofile Silence Analyzer. .SH OPTIONS .TP \fB\-h\fR, \fB\-\-help\fR display this help and exit .TP \fB\-b\fR, \fB\-\-bounds\fR skip silence mid file. print start/end boundaries only. .TP \fB\-B\fR, \fB\-\-fastbounds\fR same as \fB\-b\fR, except the sound\-off is detected by decoding backwards from the end. This is much faster but also inacurate. .TP \fB\-f\fR, \fB\-\-format\fR specify output format (default: 'txt') .TP \fB\-F\fR, \fB\-\-filter\fR high\-pass filter coefficient (default:0.98) disable: 1.0; range 0 < val <= 1.0 .TP \fB\-o\fR, \fB\-\-output\fR write data to file instead of stdout .TP \fB\-p\fR, \fB\-\-progress\fR show progress info on stderr .TP \fB\-q\fR, \fB\-\-quiet\fR inhibit error messages .TP \fB\-s\fR, \fB\-\-threshold\fR RMS signal threshold (default 0.001 ^= \fB\-60dB\fR) postfix with 'd' to specify decibels .TP \fB\-t\fR, \fB\-\-holdoff\fR holdoff time in seconds (default 0.5) .TP \fB\-u\fR, \fB\-\-unit\fR specify output unit (default: 'seconds') .TP \fB\-v\fR, \fB\-\-verbose\fR increase debug\-level (can be used multiple times) .TP \fB\-V\fR, \fB\-\-version\fR print version information and exit .PP This application reads a single audio file and analyzes it for silent periods. Timestamps/ranges of silence are printed to standard output. .PP Valid output formats are: txt, JSON, audacity (label file) .PP Valid output units are: samples, seconds (audacity format uses seconds regardless). .PP Sound is detected if the signal level exceeds a given threshold for a duration of at least time. Note that the returned timestamps are corrected for the holdoff\-time. .PP The fast boundary scan can decrease the time it takes to analyze a file at the cost of accuracy. Use \fB\-\-fastbounds\fR with care. Due to low\-pass filtering and RMS calculation the results will be different (+\- .1 sec), furthermore some codecs are not suitable for backwards decoding or sample\-accurate seeking and may skew the timestamp by one second or more. The fast boundary scan mode requires a seekable file and does not work with streams. .SH "REPORTING BUGS" Report bugs to Robin Gareus .br Website and manual: .SH COPYRIGHT Copyright \(co GPL 2012 Robin Gareus silan-0.3.2/src/000077500000000000000000000000001215320440300134035ustar00rootroot00000000000000silan-0.3.2/src/Makefile.am000066400000000000000000000005411215320440300154370ustar00rootroot00000000000000## Process this file with automake to produce Makefile.in AM_CFLAGS = \ -g -Wall -O2 \ -I$(top_srcdir) \ -I$(top_srcdir)/audio_decoder/ \ $(SILAN_CFLAGS) bin_PROGRAMS = silan silan_SOURCES = \ main.c \ $(top_srcdir)/audio_decoder/ad.h silan_LDADD = \ $(top_srcdir)/audio_decoder/libad.a \ $(SILAN_LIBS) \ $(SNDFILE_LIBS) \ $(FFMPEG_LIBS) silan-0.3.2/src/main.c000066400000000000000000000423301215320440300144750ustar00rootroot00000000000000/* silan - silence analyzer * * Copyright (C) 2012-2013 Robin Gareus * * 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, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include "ad.h" #include "config.h" int debug_level = 0; #define PERIODSIZE (1024) enum { B_EN = 1, ///< enable first/last mode B_FAST = 2,///< enable 'fast' mode (process backwards after finding sound-on) B_F1 = 4, ///< found first sound-on B_REV = 8, ///< reading/procssing backwards B_F2 = 16, ///< found last sound-off }; struct silan_settings { char *fn; float threshold; enum {PM_SAMPLES, PM_SECONDS} printmode; enum {PF_TXT = 0, PF_CSV, PF_JSON, PF_AUDACITY} printformat; float hpf_tc; float holdoff_sec; int progress; char *outfilename; FILE *outfile; int first_last_only; }; struct silan_state { float *hpf_x; // HPF buffer (per channel) float *hpf_y; // HPF buffer (per channel) double rms_sum; double *window; double *window_cur; double *window_end; int window_size; int state; // 0: silent, 1:non-silent int64_t holdoff; // holdoff frame counter int64_t prev_on; // frame-number of latest 'On' state - used for delayed print -- audacity only int64_t prev_off; // frame-number of latest 'Off' state - used for delayed print int first_last; // print only first & last int cnt; }; void print_time( struct silan_settings const * const ss, struct adinfo const * const nfo, const int indent, const int64_t frameno) { switch (ss->printmode) { case PM_SAMPLES: if (indent) fprintf(ss->outfile, "%9"PRIi64, frameno); else fprintf(ss->outfile, "%" PRIi64, frameno); break; case PM_SECONDS: default: if (indent) fprintf(ss->outfile, "%7lf", ((double)frameno/nfo->sample_rate) ); else fprintf(ss->outfile, "%lf", ((double)frameno/nfo->sample_rate) ); } } void format_time( struct silan_settings const * const ss, struct adinfo const * const nfo, struct silan_state * const st, const int64_t frameno) { switch (ss->printformat) { case PF_TXT: print_time(ss, nfo, 1, frameno); fprintf(ss->outfile, " Sound %s\n", (st->state&1)?"On":"Off"); break; case PF_JSON: if (st->state&1) { st->prev_on = frameno; } else if (st->prev_on>=0) { if (st->cnt++) fprintf(ss->outfile, ","); fprintf(ss->outfile, " [ "); print_time(ss, nfo, 0, st->prev_on); fprintf(ss->outfile, ", "); print_time(ss, nfo, 0, frameno); fprintf(ss->outfile, " ]"); st->prev_on = -1; } break; case PF_AUDACITY: if (st->state&1) { st->prev_on = frameno; } else if (st->prev_on>=0) { fprintf(ss->outfile, "%7lf\t%lf\tSound\n", (double)st->prev_on/nfo->sample_rate, (double)(frameno)/nfo->sample_rate); st->prev_on = -1; } break; default: break; } fflush(ss->outfile); } void process_audio( struct silan_settings const * const ss, struct adinfo const * const nfo, struct silan_state * const st, const unsigned int n_frames, const int64_t frame_cnt, float const * const buf ) { unsigned int i,c; const unsigned int n_channels = nfo->channels; const double t2 = (ss->threshold * ss->threshold) * st->window_size; const float a = ss->hpf_tc; const int64_t holdoff_threshold = (ss->holdoff_sec * nfo->sample_rate); i = st->first_last & B_REV ? n_frames - 1 : 0; /* process audio sample by sample */ while (1) { int above_threshold = 0; for (c=0; c < n_channels; ++c) { /* high pass filter */ const float x0 = buf[i * n_channels + c]; const float x1 = st->hpf_x[c]; const float y1 = st->hpf_y[c]; const float y0 = a * (y1 + x0 - x1); st->hpf_x[c] = x0; st->hpf_y[c] = y0; /* calculate RMS */ st->rms_sum -= *st->window_cur; *st->window_cur = y0 * y0; st->rms_sum += *st->window_cur; st->window_cur++; if (st->window_cur >= st->window_end) st->window_cur = st->window; if (st->rms_sum > t2) above_threshold |=1; } /* hold state */ if (above_threshold) { st->state|=2; } else { st->state&=~2; } if (((st->state&1)==1) ^ ((st->state&2)==2)) { if (++st->holdoff >= holdoff_threshold) { if ((st->state&2)) { st->state|=1; st->prev_off = -1; } else { st->state&=~1; st->prev_off = frame_cnt + i + 1 - st->holdoff; } if (!(st->first_last & B_F1)) { format_time(ss, nfo, st, frame_cnt + i + 1 - st->holdoff); } if (st->first_last & B_REV) { /* we're reading backwards * -> sound-start -> beginning of silence (when reading fwd) */ st->state ^= 1; format_time(ss, nfo, st, frame_cnt + i + 1 + st->holdoff); st->state ^= 1; st->first_last |= B_F2; break; } if ((st->first_last & B_EN) && (st->state&1) ) { st->first_last |= B_F1; if (st->first_last & B_FAST) { break; } } } } else { st->holdoff = 0; } /* loop: increment or decrement */ if (st->first_last & B_REV) { if (i == 0 ) break; else --i; } else { ++i; if (i == n_frames) break; } } /* end for each sample */ } static void reset_state(struct silan_state * const st, int nch) { st->holdoff = 0; st->state = 0; st->rms_sum = 0; st->prev_on = -1; st->prev_off = -1; memset(st->hpf_x, 0, nch * sizeof(float)); memset(st->hpf_y, 0, nch * sizeof(float)); memset(st->window, 0, st->window_size * sizeof(double)); st->window_cur = st->window; st->window_end = st->window + (st->window_size); } int doit(struct silan_settings const * const s) { int rv = 0; struct adinfo nfo; struct silan_state state; int64_t frame_cnt = 0; float * abuf = NULL; ad_clear_nfo(&nfo); void *sf = ad_open(s->fn, &nfo); if (!sf) { if (debug_level>=0) fprintf(stderr, "! cannot open audio file '%s'\n", s->fn); return 1; } ad_dump_nfo(1, &nfo); abuf = (float*) malloc(PERIODSIZE * nfo.channels * sizeof(float)); state.holdoff = 0; state.cnt = 0; state.state = 0; // start silent state.hpf_x = (float*) calloc(nfo.channels, sizeof(float)); state.hpf_y = (float*) calloc(nfo.channels, sizeof(float)); state.window_size = nfo.channels * nfo.sample_rate / 50; state.window = (double*) calloc(state.window_size, sizeof(double)); state.window_cur = state.window; state.window_end = state.window + (state.window_size); state.rms_sum = 0; state.prev_on = -1; state.prev_off = -1; state.first_last = s->first_last_only & (B_EN|B_FAST); if (!abuf || ! state.hpf_x || ! state.hpf_y || !state.window) { if (debug_level>=0) fprintf(stderr, "! out-of-memory\n"); rv=1; goto bailout; } /* output prefixes - if any */ switch (s->printformat) { case PF_JSON: fprintf(s->outfile, "{ \"sound\":["); default: break; } /* process audio file data */ while (1) { int rv = ad_read(sf, abuf, PERIODSIZE * nfo.channels); if (rv < 1) break; process_audio(s, &nfo, &state, rv / nfo.channels, frame_cnt, abuf); if ((state.first_last & (B_EN|B_FAST|B_F1)) == (B_EN|B_FAST|B_F1)) { /* first boundary found -- continue decoding backwards from end */ break; } frame_cnt += rv / nfo.channels; if (s->progress) { fprintf(stderr, " %3.1f%% \r", frame_cnt * 100.0 / nfo.frames); fflush(stderr); } } if ((state.first_last & (B_EN|B_FAST|B_F1)) == (B_EN|B_FAST|B_F1)) { /* reset state - prepare for backwards reading */ state.first_last |= B_REV; reset_state(&state, nfo.channels); int64_t pos = nfo.frames - PERIODSIZE; /* read audio file backwards from last frame */ while (1) { if (pos > 0 && pos < frame_cnt) { } if (pos < 0 || pos < frame_cnt || ad_seek(sf, pos) < 0) { break; } int rv = ad_read(sf, abuf, PERIODSIZE * nfo.channels); if (rv < 1) { break; } process_audio(s, &nfo, &state, rv / nfo.channels, pos, abuf); pos -= rv / nfo.channels; if ((state.first_last & B_F2)) { rv = 0; break; } if (s->progress) { fprintf(stderr, " ???.?f%% \r"); fflush(stderr); } } } if (((state.first_last & B_F2) && ((state.state&1) == 0)) || (state.first_last & (B_F2|B_REV)) == B_REV ) { /* reverse decoding failed */ reset_state(&state, nfo.channels); state.first_last &= ~B_EN; state.state = 1; /* resume forward decoding from where we left off */ if (ad_seek(sf, frame_cnt) < 0) { rv = 1; goto bailout; } while (1) { int rv = ad_read(sf, abuf, PERIODSIZE * nfo.channels); if (rv < 1) break; process_audio(s, &nfo, &state, rv / nfo.channels, frame_cnt, abuf); if ((state.first_last & (B_EN|B_FAST|B_F1)) == (B_EN|B_FAST|B_F1)) { /* first boundary found -- continue decoding backwards from end */ break; } frame_cnt += rv / nfo.channels; if (s->progress) { fprintf(stderr, " %3.1f%% \r", frame_cnt * 100.0 / nfo.frames); fflush(stderr); } } } if ((state.state & 1) && !(state.first_last & B_REV)) { /* close off combined on/off labels */ state.state = 0; format_time(s, &nfo, &state, nfo.frames); } else if ((state.first_last & (B_F1|B_F2)) == B_F1) { /* close off first/last only */ state.state = 0; format_time(s, &nfo, &state, state.prev_off >=0 ? state.prev_off : nfo.frames); } /* output postfixes - if any */ switch (s->printformat) { case PF_JSON: fprintf(s->outfile, "], \"file duration\":"); print_time(s, &nfo, 0, nfo.frames); fprintf(s->outfile, ", \"sample rate\":%d", nfo.sample_rate); fprintf(s->outfile, "}\n"); default: break; } if (s->progress) { fprintf(stderr," \n"); } if (debug_level > 1 && frame_cnt != nfo.frames) { fprintf(stderr, "Note: frame-count mismatch: %"PRIi64"/%"PRIi64"\n", frame_cnt, nfo.frames); } bailout: free(abuf); free(state.hpf_x); free(state.hpf_y); free(state.window); ad_close(sf); ad_free_nfo(&nfo); return rv; } /************************** * main application code */ static struct option const long_options[] = { {"bounds", no_argument, 0, 'b'}, {"fastbounds", no_argument, 0, 'B'}, {"format", required_argument, 0, 'f'}, {"filter", required_argument, 0, 'F'}, {"help", no_argument, 0, 'h'}, {"output", required_argument, 0, 'o'}, {"progress", no_argument, 0, 'p'}, {"quiet", no_argument, 0, 'q'}, {"threshold", required_argument, 0, 's'}, {"holdoff", required_argument, 0, 't'}, {"unit", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {NULL, 0, NULL, 0} }; static void usage (int status) { printf ("silan - Audiofile Silence Analyzer.\n\n"); printf ("Usage: silan [ OPTIONS ] \n\n"); printf ("Options:\n\ -h, --help display this help and exit\n\ -b, --bounds skip silence mid file.\n\ print start/end boundaries only.\n\ -B, --fastbounds same as -b, except the sound-off is detected by\n\ decoding backwards from the end.\n\ This is much faster but also inacurate.\n\ -f, --format specify output format (default: 'txt')\n\ -F, --filter high-pass filter coefficient (default:0.98)\n\ disable: 1.0; range 0 < val <= 1.0\n\ -o, --output write data to file instead of stdout\n\ -p, --progress show progress info on stderr\n\ -q, --quiet inhibit error messages\n\ -s, --threshold RMS signal threshold (default 0.001 ^= -60dB)\n\ postfix with 'd' to specify decibels\n\ -t, --holdoff holdoff time in seconds (default 0.5)\n\ -u, --unit specify output unit (default: 'seconds')\n\ -v, --verbose increase debug-level (can be used multiple times)\n\ -V, --version print version information and exit\n\ \n"); printf ("\n\ This application reads a single audio file and analyzes it for\n\ silent periods. Timestamps/ranges of silence are printed to standard output.\n\ \n\ Valid output formats are: txt, JSON, audacity (label file)\n\ \n\ Valid output units are: samples, seconds (audacity format uses seconds regardless).\n\ \n\ Sound is detected if the signal level exceeds a given threshold for a\n\ duration of at least time.\n\ Note that the returned timestamps are corrected for the holdoff-time.\n\ \n\ The fast boundary scan can decrease the time it takes to analyze a file\n\ at the cost of accuracy.\n\ Use --fastbounds with care. Due to low-pass filtering and RMS calculation\n\ the results will be different (+- .1 sec), furthermore some codecs are not\n\ suitable for backwards decoding or sample-accurate seeking and may skew the\n\ timestamp by one second or more.\n\ The fast boundary scan mode requires a seekable file and does not work with\n\ streams.\n\ \n"); printf ("Report bugs to Robin Gareus \n" "Website and manual: \n" ); exit (status); } static int decode_switches (struct silan_settings * const ss, int argc, char **argv) { int c; while ((c = getopt_long (argc, argv, "h" /* help */ "b" /* boundaries */ "B" /* boundaries */ "f:" /* output format */ "F:" /* high-pass filter cutoff */ "o:" /* outfile */ "p" /* progress */ "s:" /* signal threhold */ "t:" /* holdoff time */ "u:" /* unit */ "q" /* quiet */ "v" /* verbose */ "V", /* version */ long_options, (int *) 0)) != EOF) { switch (c) { case 'b': ss->first_last_only |= B_EN; break; case 'B': ss->first_last_only |= B_EN | B_FAST; break; case 'f': if (!strncasecmp(optarg, "txt" , strlen(optarg))) ss->printformat = PF_TXT; else if (!strncasecmp(optarg, "text" , strlen(optarg))) ss->printformat = PF_TXT; else if (!strncasecmp(optarg, "json", strlen(optarg))) ss->printformat = PF_JSON; else if (!strncasecmp(optarg, "audacity", strlen(optarg))) ss->printformat = PF_AUDACITY; else { fprintf(stderr, "! invalid output format specified\n"); usage(EXIT_FAILURE); } break; case 'u': if (!strncasecmp(optarg, "samples" , strlen(optarg))) ss->printmode = PM_SAMPLES; else if (!strncasecmp(optarg, "seconds" , strlen(optarg))) ss->printmode = PM_SECONDS; else { fprintf(stderr, "! invalid output unit specified\n"); usage(EXIT_FAILURE); } break; case 'F': ss->hpf_tc= atof(optarg); if (ss->hpf_tc<=0 || ss->hpf_tc > 1.0) { fprintf(stderr, "! invalid high-pass filter time constant. need: 0 < value <= 1.0\n"); usage(EXIT_FAILURE); } break; case 'o': free(ss->outfilename); ss->outfilename = strdup(optarg); break; case 'p': ss->progress = 1; break; case 's': { float v; if (strlen(optarg)> 0 && optarg[strlen(optarg)-1] == 'd') { v = pow(10.0, fabsf(atof(optarg))/-20.0); } else { v = atof(optarg); } if (v>=0 && v<=1) { fprintf(stderr, "Info: signal threshold: %f ^= %.3fdBFS\n", v, 20.0 * log10f(v)); // XXX ss->threshold = v; } else { fprintf(stderr, "! invalid signal threshold.\n"); usage(EXIT_FAILURE); } } break; case 't': ss->holdoff_sec = atof(optarg); if (ss->holdoff_sec < 0) ss->holdoff_sec = 0; break; case 'q': debug_level=-1; break; case 'v': if (debug_level>=0) debug_level++; break; case 'V': printf ("silan version %s\n\n", VERSION); printf ("Copyright (C) GPL 2012 Robin Gareus \n"); exit (0); case 'h': usage (0); default: usage (EXIT_FAILURE); break; } } return optind; } int main(int argc, char **argv) { int rv = 0; struct silan_settings settings; /* default values */ settings.printmode = PM_SECONDS; settings.printformat = PF_TXT; settings.threshold = 0.001; // 10^(db/20.0) with db < 0. settings.hpf_tc = .98; // 0..1 == RC / (RC + dt) // f = 1 / (2 M_PI RC) settings.holdoff_sec = 0.5; settings.fn = NULL; settings.outfile = NULL; settings.outfilename = NULL; settings.progress = 0; settings.first_last_only = 0; /* parse options */ int i = decode_switches (&settings, argc, argv); ad_set_debuglevel(debug_level); if (argc > i) { settings.fn = strdup(argv[i]); } else { usage(EXIT_FAILURE); } /* open output file - if any */ if (settings.outfilename) { settings.outfile = fopen(settings.outfilename, "w"); if (!settings.outfile) { if (debug_level >= 0) fprintf(stderr, "! cannot open output file '%s'.\n", settings.outfilename); rv=1; goto cleanup; } } else { settings.outfile = stdout; } /* initialize audio decoders */ ad_init(); /* all systems go */ rv = doit(&settings); cleanup: /* clean up*/ if (settings.fn) free(settings.fn); if (settings.outfilename && settings.outfile) { free(settings.outfilename); fclose(settings.outfile); } return rv; }