pax_global_header00006660000000000000000000000064125534562510014522gustar00rootroot0000000000000052 comment=61f68ecd6ea87936d1b6d554cfe20673d34a7382 yatm-0.9/000077500000000000000000000000001255345625100123445ustar00rootroot00000000000000yatm-0.9/CMakeLists.txt000066400000000000000000000023431255345625100151060ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8) project(YATM CXX) set(YATM_MAJOR_VERSION 0) set(YATM_MINOR_VERSION 8) set(YATM_VERSION ${YATM_MAJOR_VERSION}.${YATM_MINOR_VERSION}) find_package(PkgConfig REQUIRED) pkg_search_module(AO REQUIRED ao) pkg_search_module(MAD REQUIRED mad) pkg_search_module(OGG REQUIRED ogg) pkg_search_module(SLANG REQUIRED slang) pkg_search_module(SNDFILE REQUIRED sndfile>=1.0.18) pkg_search_module(SOUNDTOUCH REQUIRED soundtouch) pkg_search_module(SPEEX REQUIRED speex) include_directories(${AO_INCLUDE_DIRS}) include_directories(${MAD_INCLUDE_DIRS}) include_directories(${OGG_INCLUDE_DIRS}) include_directories(${SLANG_INCLUDE_DIRS}) include_directories(${SNDFILE_INCLUDE_DIRS}) include_directories(${SOUNDTOUCH_INCLUDE_DIRS}) include_directories(${SPEEX_INCLUDE_DIRS}) configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/config.h") include_directories("${PROJECT_BINARY_DIR}") add_executable(yatm yatm.cc) target_link_libraries(yatm ${AO_LIBRARIES} ${MAD_LIBRARIES} ${OGG_LIBRARIES} ${SLANG_LIBRARIES} ${SNDFILE_LIBRARIES} ${SOUNDTOUCH_LIBRARIES} ${SPEEX_LIBRARIES}) install(TARGETS yatm DESTINATION bin) install(FILES yatm.1 DESTINATION share/man/man1) yatm-0.9/COPYING000066400000000000000000000431101255345625100133760ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Library General Public License instead of this License. yatm-0.9/ChangeLog000066400000000000000000000063301255345625100141200ustar00rootroot000000000000002013-09-06 Mario Lang * yatm.cc: Honor -e when playing via libsndfile. Eliminate Vorbis playback support as it is done by libsndfile now. * CMakeLists.txt: Switched to CMake as build system, dropped autotools. 2007-11-26 Mario Lang * configure.in: Change version to 0.6. 2006-01-24 Mario Lang * configure.in: Increment version to 0.5. * Makefile.am: Link with -lslang. * yatm.cc: Redo keyboard input using libslang. Eliminate duplicated code. Add seeking (cursor left/right) for libsndfile backed files. Add command-line args -c (cents) and -s (semitones) for pitch transposition. Add realtime transposition change keys ('s' and 'S' for semitones and 'c' and 'C' for cents). 2005-11-05 Mario Lang * README: Updated. * configure.in: Go to version 0.4. * yatm.cc: Added pause (SPC) key for MPEG decoder. Added libsndfile support. 2005-08-22 Mario Lang * configure.in: Bump version to 0.3 * yatm.cc: G++ 4.0 fixes (stupid namespace garbage) 2005-03-18 Mario Lang * configure.in: Drop PKG_CONFIG check for libSoundTouch for now since latest libsoundtouch1-dev in Debian does not provide a .pc file anymore. * yatm.cc: Convert to use soundtouch::SAMPLETYPE to be compatible with latest libSoundTouch. 2004-06-11 Mario Lang * configure.in: Bump version to 0.2.3. * yatm.cc (play_vorbis): If we don't multiply the second channel by the same value, stereo playback is obviously broken, doh! * configure.in: Bump version number to 0.2.2 and release. * yatm.cc (play_speex): Add support for begin time seeking by decoding the stream, but ignoring sample output until total_samples >= skip_samples. 2004-06-10 Mario Lang * yatm.cc (play_speex): Move tty command handling deeper into the loop to make it more responsive. (play_speex): Use enhance_mode (whatever that does.) (play_vorbis): Renamed from play_ogg. (play_vorbis): Use the new play_ao function (same as with speex). (play_speex): Add comments/printf about the strange speex_decode_stereo bugs. (play_vorbis): Add support for seeking to a specific position (argument -b). Timed playback (-e) not yet done. (play_mpeg): Parse mad_time here, not in main(). * configure.in: Bump version to 0.2.1 and release this. * README: Updated. * yatm.cc (play_speex): New function, implementing the Speex codec. No seeking yet, but at least it appears to work fine. 2004-06-09 Mario Lang * configure.in: Bump version number to 0.2. * yatm.1: Update about Vorbis, and add info about the 'q' key. * yatm.cc: Add support for Vorbis audio files. No support for seeking or timed playback yet. 2004-06-08 Mario Lang * yatm.1: Update for -b and -e. * yatm.cc (print_version): Make -V actually work by including config.h and using the VERSION macro. (main): New options -b and -e. * configure.in: Bump version to 0.1.1. * yatm.1: Tell the user about interactive controls. * yatm.cc: Add interactive tempo controls. For now, the keys '+' and '-' adjust the playback speed. 2004-06-07 Mario Lang * yatm: initial version. yatm-0.9/README000066400000000000000000000021751255345625100132310ustar00rootroot00000000000000 yatm - Yet Another Time Machine Copyright (C) 2004, 2005, 2006, 2013 Mario Lang yatm 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA What is Yatm? Yatm is a simple command line audio player which can perform playback at a different speed than the original audio was recorded with. THis is done without changing the sounds pitch. yatm supports Speex, MPEG audio and all formats supported by libsndfile (OGG/Vorbis, FLAC, WAV, ...) input files. Comments are welcome. - Mario Lang yatm-0.9/config.h.in000066400000000000000000000001071255345625100143650ustar00rootroot00000000000000/* Version number of package */ #define YATM_VERSION "@YATM_VERSION@" yatm-0.9/yatm.1000066400000000000000000000043771255345625100134130ustar00rootroot00000000000000.\" hey, Emacs: -*- nroff -*- .\" yatm 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; see the file COPYING. If not, write to .\" the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. .\" .TH YATM 1 "June 7, 2004" .\" Please update the above date whenever this man page is modified. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins (default) .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME yatm \- Yet Another Time Machine .SH SYNOPSIS .B yatm .RI [ options ] .I file .SH DESCRIPTION \fByatm\fP plays Vorbis, Speex and MPEG audio files while allowing the user to choose a new tempo without changing the pitch. .PP The tempo can be interactively controlled by pressing '+' or '-', incrementing and decrementing the playback tempo by 1 percent respectively. Use "q" to stop playback. .SH OPTIONS \fByatm\fP accepts the following options: .TP .BR -b Begin playing at .IR time , given as an offset from the beginning of the file .RB ( 0:00:00 ). .TP .BR -e Stop after .IR duration seconds of audio have been decoded. .TP .BR -t Specify initial tempo as a floating point value, 1.0 is the default. .TP .BR -q Inhibit usual output. .TP .TP .BR -s Transpose .IR semitones .TP .BR -c Transpose .IR cents .TP .B -v, --verbose Print more information. .TP .B \-h, \-\-help Show summary of options. .TP .B \-V, \-\-version Show version of program. .\" .SH "SEE ALSO" .\" .BR madplay (1). .SH AUTHOR Mario Lang . yatm-0.9/yatm.cc000066400000000000000000000565221255345625100136370ustar00rootroot00000000000000/* * yatm - Yet Another Time Machine * Copyright (C) 2004, 2005, 2006, 2013 Mario Lang * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "config.h" static unsigned char verbosity = 1; static int initTTY () { SLtt_get_terminfo(); if (SLkp_init() != -1) { if (SLang_init_tty(-1,0,1) != -1) { return 1; } else { SLang_verror(SL_Open_Error, "Slang_init_tty failed."); } } else { SLang_verror(SL_Open_Error, "SLkp_init failed."); } return 0; } static char quit = 0; static float tempo = 1.0; static int pitchCentDelta = 0; using namespace soundtouch; static class SoundTouch *st; typedef void (*SeekFunc)(float delta); static void pollKeyboard (SeekFunc seekfunc) { if (SLang_input_pending(0) != 0) { switch (SLkp_getkey()) { case 'l': case SL_KEY_RIGHT: if (seekfunc) seekfunc(5); else if (verbosity) { printf("Seeking not implemented for this backend\n"); fflush(stdout); } break; case 'h': case SL_KEY_LEFT: if (seekfunc) seekfunc(-5); else if (verbosity) { printf("Seeking not implemented for this backend\n"); fflush(stdout); } break; case '+': if (tempo < 5.) st->setTempo(tempo += .01); break; case '-': if (tempo > 0.02) st->setTempo(tempo -= .01); break; case 'c': st->setPitch(powf(2.,(pitchCentDelta -= 1)/1200.)); break; case 'C': if (pitchCentDelta < 4800) st->setPitch(powf(2.,(pitchCentDelta += 1)/1200.)); break; case 's': case SL_KEY_DOWN: st->setPitch(powf(2.,(pitchCentDelta -= 100)/1200.)); break; case 'S': case SL_KEY_UP: if (pitchCentDelta < 4701) st->setPitch(powf(2.,(pitchCentDelta += 100)/1200.)); else st->setPitch(powf(2.,(pitchCentDelta = 4800)/1200.)); break; case 'q': case SL_KEY_F(10): quit = 1; break; } if (!quit && verbosity > 0) { printf("%3.0f%% speed %7d cents\r", tempo*100, pitchCentDelta); fflush(stdout); } } } static struct sigaction save_sigint, save_sigtstp; static void signal_handler (int signal); static int audio_driver; static ao_device *audio_device; static ao_sample_format audio_format; static void play_ao (int channels, int bufsize) { SAMPLETYPE samples[bufsize * channels]; SAMPLETYPE *ptr; char buffer[bufsize * channels * sizeof(signed int)]; char *byte; int outSamples; do { ptr = samples; byte = buffer; outSamples = st->receiveSamples(samples, bufsize); for (int i = 0; i < outSamples; i++) { signed int sample; for (int c = 0; c < channels; c++) { sample = (int)*ptr++; *byte++ = (sample >> 0) & 0xff; *byte++ = (sample >> 8) & 0xff; } } if (byte-buffer > 0) ao_play(audio_device, buffer, byte-buffer); } while (outSamples != 0); } static void print_version(); static int play_speex(int fd, char *begin); static int play_sndfile (int fd, char const *begin, char const *end); static int play_mpeg(int fd, char *begin, char *end); int main (int argc, char *argv[]) { int c; char *input_file = NULL; char *begin_time = NULL, *end_time = NULL; while ((c = getopt(argc, argv, "b:e:c:s:qt:vVh")) != -1) { switch (c) { case 'b': begin_time = strdup(optarg); break; case 'e': end_time = strdup(optarg); break; case 'c': pitchCentDelta = atoi(optarg); break; case 's': pitchCentDelta = atoi(optarg)*100; break; case 't': tempo = atof(optarg); break; case 'v': verbosity++; break; case 'q': verbosity = 0; break; case 'V': print_version(); return 0; case 'h': printf("%s [-b TIME] [-e TIME] [-t RATIO] [-s SEMITONES] [-c CENTS] FILENAME\n", argv[0]); exit(EXIT_FAILURE); } } if (optind < argc) { input_file = strdup(argv[optind++]); } if (optind < argc) { std::cout << "Excessive command line paramters, aborting..." << std::endl; exit(EXIT_FAILURE); } if (!input_file) { std::cout << "No input file specified, aborting..." << std::endl; exit(EXIT_FAILURE); } st = new SoundTouch(); struct sigaction action; int fd = open(input_file, O_RDONLY); if (fd == -1) { fprintf(stderr, "Can not open %s: %s, aborting...\n", input_file, strerror(errno)); exit(EXIT_FAILURE); } ao_initialize(); audio_driver = ao_default_driver_id(); if (sigaction(SIGTSTP, 0, &save_sigtstp) == -1) { fprintf(stderr, "Error saving sigtstp handler.\n"); exit(EXIT_FAILURE); } if (sigaction(SIGINT, 0, &save_sigint) == -1) { fprintf(stderr, "Error saving sigint handler.\n"); return 1; } action = save_sigtstp; action.sa_handler = signal_handler; sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGINT); action.sa_flags = 0; if (sigaction(SIGTSTP, &action, 0) == -1) { fprintf(stderr, "Error setting sigtstp handler.\n"); return 0; } action = save_sigint; action.sa_handler = signal_handler; sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGTSTP); action.sa_flags = 0; if (sigaction(SIGTSTP, &action, 0) == -1) { fprintf(stderr, "Error setting sigtstp handler.\n"); return 0; } initTTY(); st->setSetting(SETTING_USE_QUICKSEEK, 0); st->setSetting(SETTING_USE_AA_FILTER, 1); st->setPitch(powf(2.,pitchCentDelta/1200.)); st->setTempo(tempo); if (!play_sndfile(fd, begin_time, end_time)) if (!play_speex(fd, begin_time)) play_mpeg(fd, begin_time, end_time); if (begin_time) free(begin_time); if (end_time) free(end_time); close(fd); delete st; SLang_reset_tty(); return EXIT_SUCCESS; } /* MPEG */ /* * Private message structure for MAD decoder. */ struct player { #define PLAYER_OPTION_SKIP 0x01 #define PLAYER_OPTION_TIMED 0x02 int options; unsigned char const *start; unsigned long length; mad_timer_t absolute_time; mad_timer_t playback_time; mad_timer_t start_time; mad_timer_t duration; }; /* * (re)fill the stream buffer which is to be decoded */ static enum mad_flow input (void *data, struct mad_stream *stream) { struct player *player = (struct player *)data; if (!player->length) return MAD_FLOW_STOP; mad_stream_buffer(stream, player->start, player->length); player->length = 0; return MAD_FLOW_CONTINUE; } /* * decide whether to continue decoding based on header */ static enum mad_flow decode_header (void *data, struct mad_header const *header) { struct player *player = (struct player *)data; if ((player->options & PLAYER_OPTION_TIMED) && mad_timer_compare(player->playback_time, player->duration) > 0) return MAD_FLOW_STOP; mad_timer_add(&player->absolute_time, header->duration); if ((player->options & PLAYER_OPTION_SKIP) && mad_timer_compare(player->absolute_time, player->start_time) < 0) return MAD_FLOW_IGNORE; mad_timer_add(&player->playback_time, header->duration); return MAD_FLOW_CONTINUE; } /* * perform filtering on decoded frame */ static enum mad_flow decode_filter ( void *data, struct mad_stream const *stream, struct mad_frame *frame ) { pollKeyboard(NULL); if (quit) return MAD_FLOW_STOP; else return MAD_FLOW_CONTINUE; } /* * The following utility routine performs simple rounding, clipping, and * scaling of MAD's high-resolution samples down to 16 bits. It does not * perform any dithering or noise shaping, which would be recommended to * obtain any exceptional audio quality. It is therefore not recommended to * use this routine if high-quality output is desired. */ static inline signed int scale (mad_fixed_t sample) { /* round */ sample += (1L << (MAD_F_FRACBITS - 16)); /* clip */ if (sample >= MAD_F_ONE) sample = MAD_F_ONE - 1; else if (sample < -MAD_F_ONE) sample = -MAD_F_ONE; /* quantize */ return sample >> (MAD_F_FRACBITS + 1 - 16); } /* * This is the output callback function. It is called after each frame of * MPEG audio data has been completely decoded. The purpose of this callback * is to output (or play) the decoded PCM audio. */ static enum mad_flow process_output ( void *data, struct mad_header const *header, struct mad_pcm *pcm ) { unsigned int nchannels = pcm->channels, inSamples = pcm->length, rate = pcm->samplerate; mad_fixed_t const *left_ch = pcm->samples[0], *right_ch = pcm->samples[1]; SAMPLETYPE samples[nchannels * inSamples]; SAMPLETYPE *ptr = samples; if (!audio_device) { audio_format.bits = 16; audio_format.channels = nchannels; audio_format.rate = rate; audio_format.byte_format = AO_FMT_LITTLE; audio_device = ao_open_live(audio_driver, &audio_format, NULL); if (!audio_device) { fprintf(stderr, "Error opening audio device.\n"); return MAD_FLOW_BREAK; } } for (int i = 0; i < inSamples; i++) { SAMPLETYPE sample; sample = scale(*left_ch++); *ptr++ = sample; if (nchannels == 2) { sample = scale(*right_ch++); *ptr++ = sample; } } st->setSampleRate(rate); st->setChannels(nchannels); st->putSamples(samples, inSamples); play_ao(nchannels, inSamples); return MAD_FLOW_CONTINUE; } /* * This is the error callback function. It is called whenever a decoding * error occurs. The error is indicated by stream->error; the list of * possible MAD_ERROR_* errors can be found in the mad.h (or stream.h) * header file. */ static enum mad_flow decode_error (void *data, struct mad_stream *stream, struct mad_frame *frame) { struct player *player = (struct player *)data; fprintf(stderr, "decoding error 0x%04x (%s) at byte offset %ld\n", stream->error, mad_stream_errorstr(stream), stream->this_frame - player->start); /* return MAD_FLOW_BREAK here to stop decoding (and propagate an error) */ return MAD_FLOW_CONTINUE; } /* Parse time specification string to mad_timer_t */ static int parse_mad_time (mad_timer_t *timer, char const *str) { mad_timer_t time, accum = mad_timer_zero; signed long decimal; unsigned long seconds, fraction, fracpart; int minus; while (isspace((unsigned char) *str)) ++str; do { seconds = fraction = fracpart = 0; switch (*str) { case '-': ++str; minus = 1; break; case '+': ++str; default: minus = 0; } do { decimal = strtol(str, (char **) &str, 10); if (decimal < 0) return -1; seconds += decimal; if (*str == ':') { seconds *= 60; ++str; } } while (*str >= '0' && *str <= '9'); if (*str == '.') { char const *ptr; decimal = strtol(++str, (char **) &ptr, 10); if (decimal < 0) return -1; fraction = decimal; for (fracpart = 1; str != ptr; ++str) fracpart *= 10; } else if (*str == '/') { ++str; decimal = strtol(str, (char **) &str, 10); if (decimal < 0) return -1; fraction = seconds; fracpart = decimal; seconds = 0; } mad_timer_set(&time, seconds, fraction, fracpart); if (minus) mad_timer_negate(&time); mad_timer_add(&accum, time); } while (*str == '-' || *str == '+'); while (isspace((unsigned char) *str)) ++str; if (*str != 0) return -1; *timer = accum; return 0; } /* * This is the function called by main() above to perform all the decoding. * It instantiates a decoder object and configures it with the input, * output, and error callback functions above. A single call to * mad_decoder_run() continues until a callback function returns * MAD_FLOW_STOP (to stop decoding) or MAD_FLOW_BREAK (to stop decoding and * signal an error). */ static int play_mpeg(int fd, char *begin, char *end) { struct player player; struct mad_decoder decoder; struct stat stat; void *fdm; int result; if (fstat(fd, &stat) == -1 || stat.st_size == 0) return 0; fdm = mmap(0, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (fdm == MAP_FAILED) { fprintf(stderr, "mmap failed, aborting...\n"); return 0; } player.options = 0; player.start = (unsigned char *)fdm; player.length = stat.st_size; player.absolute_time = player.playback_time = player.start_time = player.duration = mad_timer_zero; if (begin) { if (parse_mad_time(&player.start_time, begin) == -1) { fprintf(stderr, "Failed to parse time spec %s\n", begin); return 1; } fprintf(stderr, "Setting skip time\n"); player.options |= PLAYER_OPTION_SKIP; } if (end) { if (parse_mad_time(&player.duration, end) == -1) { fprintf(stderr, "Failed to parse time spec %s\n", begin); return 1; } fprintf(stderr, "Setting end to %s\n", end); player.options |= PLAYER_OPTION_TIMED; } mad_decoder_init(&decoder, &player, input, decode_header, decode_filter, process_output, decode_error, 0 /* message */); result = mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC); mad_decoder_finish(&decoder); ao_close(audio_device); if (munmap((void *)player.start, stat.st_size) == -1) return 4; return result; } static int parse_double_time (double *timer, char const *str) { double time, accum = 0; signed long decimal; unsigned long seconds, fraction, fracpart; int minus; while (isspace(*str)) ++str; do { seconds = fraction = fracpart = 0; switch (*str) { case '-': ++str; minus = 1; break; case '+': ++str; default: minus = 0; } do { decimal = strtol(str, (char **) &str, 10); if (decimal < 0) return -1; seconds += decimal; if (*str == ':') { seconds *= 60; ++str; } } while (*str >= '0' && *str <= '9'); if (*str == '.') { char const *ptr; decimal = strtol(++str, (char **) &ptr, 10); if (decimal < 0) return -1; fraction = decimal; for (fracpart = 1; str != ptr; ++str) fracpart *= 10; } time = seconds; if (fraction) time += fraction / (double)fracpart; if (minus) time *= -1; accum += time; } while (*str == '-' || *str == '+'); while (isspace(*str)) ++str; if (*str != 0) return -1; *timer = accum; return 0; } static void print_version() { fprintf(stderr, "YATM " YATM_VERSION "\n"); } static int play_speex (int fd, char *begin) { FILE *fin; int frame_size = 0, packet_count = 0, stream_init = 0; void *stc = NULL; SpeexBits bits; ogg_sync_state oy; ogg_page og; ogg_packet op; ogg_stream_state os; int nframes=2; int eos=0; int total_samples=0, decoded_samples=0, played_samples=0, skip_samples=0; float loss_percent=-1; SpeexStereoState stereo = SPEEX_STEREO_STATE_INIT; int enhance_mode = 1; int channels=-1; int rate=0; int extra_headers; float output[2000]; fin = fdopen(dup(fd), "rb"); if (!fin) { perror("fdopen"); return 0; } /* Init Ogg data structure */ ogg_sync_init(&oy); speex_bits_init(&bits); while (!feof(fin)) { /* Main decoding loop */ char *data = ogg_sync_buffer(&oy, 200); int i, j, nb_read; /* Read bitstream from input file */ nb_read = fread(data, sizeof(char), 200, fin); ogg_sync_wrote(&oy, nb_read); /* Loop for all complete pages we got (most likely only one) */ while (ogg_sync_pageout(&oy, &og) == 1) { if (!stream_init) { ogg_stream_init(&os, ogg_page_serialno(&og)); stream_init = 1; } /* Add page to the bitstream */ ogg_stream_pagein(&os, &og); /* Extract all available packets */ while (!eos && ogg_stream_packetout(&os, &op) == 1) { if (packet_count == 0) { /* Speex header */ const SpeexMode *mode; SpeexHeader *header; int modeID; SpeexCallback callback; if (!(header = speex_packet_to_header((char*)op.packet, op.bytes))) { fprintf (stderr, "Cannot read Speex header.\n"); rewind(fin); fclose(fin); return 0; } if (header->mode >= SPEEX_NB_MODES) { fprintf (stderr, "Speex mode %d does not (yet/any longer) exist in this version\n", header->mode); return 1; } mode = speex_mode_list[header->mode]; if (header->speex_version_id > 1) { fprintf (stderr, "This file was encoded with Speex bit-stream version %d, which I don't know how to decode\n", header->speex_version_id); return 1; } if (mode->bitstream_version < header->mode_bitstream_version) { fprintf (stderr, "The file was encoded with a newer version of Speex. You need to upgrade in order to play it.\n"); return 1; } else if (mode->bitstream_version > header->mode_bitstream_version) { fprintf (stderr, "The file was encoded with an older version of Speex. You would need to downgrade the version in order to play it.\n"); return 1; } if (!(stc = speex_decoder_init(mode))) { fprintf (stderr, "Decoder initialization failed.\n"); rewind(fin); fclose(fin); return 0; } speex_decoder_ctl(stc, SPEEX_SET_ENH, &enhance_mode); speex_decoder_ctl(stc, SPEEX_GET_FRAME_SIZE, &frame_size); if (channels != 1) { callback.callback_id = SPEEX_INBAND_STEREO; callback.func = speex_std_stereo_request_handler; callback.data = &stereo; speex_decoder_ctl(stc, SPEEX_SET_HANDLER, &callback); } rate = header->rate; speex_decoder_ctl(stc, SPEEX_SET_SAMPLING_RATE, &rate); nframes = header->frames_per_packet; channels = header->nb_channels; fprintf(stderr, "Decoding %d Hz audio using %s mode", rate, mode->modeName); if (channels == 1) fprintf(stderr, " (mono"); else fprintf (stderr, " (stereo"); fprintf(stderr, header->vbr ? ", VBR)\n" : ")\n"); extra_headers = header->extra_headers; free(header); if (begin) { double time; if (parse_double_time(&time, begin) == -1) { fprintf(stderr, "Unable to parse time spec: %s\n", begin); goto close; } skip_samples = (int)(time * rate); } if (!nframes) nframes = 1; audio_format.bits = 16; audio_format.channels = channels; audio_format.rate = rate; audio_format.byte_format = AO_FMT_LITTLE; if (audio_device) { fprintf(stderr, "Audio device already open.\n"); fclose(fin); return 1; } audio_device = ao_open_live(audio_driver, &audio_format, NULL); if (!audio_device) { fprintf(stderr, "Error opening audio device: %d.\n", errno); fclose(fin); return 1; } st->setSampleRate(rate); st->setChannels(channels); } else if (packet_count == 1) { fprintf(stderr, "Ignoring comment packet.\n"); } else if (packet_count <= 1+extra_headers) { fprintf(stderr, "Ignoring extra headers.\n"); } else { int lost = 0; pollKeyboard(NULL); if (quit) goto close; if (loss_percent > 0 && 100 * ((float)rand())/RAND_MAX < loss_percent) lost = 1; if (op.e_o_s) eos = 1; /* Copy Ogg packet to Speex bitstream */ speex_bits_read_from(&bits, (char*)op.packet, op.bytes); for (j=0; j!=nframes; j++) { int ret; /* Decode frame */ if (!lost) ret = speex_decode(stc, &bits, output); else ret = speex_decode(stc, NULL, output); if (ret == -1) break; if (ret == -2) { fprintf(stderr, "Decoding error: corrupted stream?\n"); break; } if (speex_bits_remaining(&bits) < 0) { fprintf (stderr, "Decoding overflow: corrupted stream?\n"); break; } if (channels==2) { /* Due to some yet undetermined reason, the stereo decoding * symbols can not be found by the linker. * speex_decode_stereo(output, frame_size, &stereo); */ } if (total_samples >= skip_samples) { SAMPLETYPE samples[frame_size * channels]; for (i=0; i 32000) sample = 32000; else if (sample < -32000) sample = -32000; samples[i] = sample; } st->putSamples(samples, frame_size); play_ao(channels, frame_size); } total_samples+=frame_size; } } packet_count++; } } } close: if (stc) speex_decoder_destroy(stc); else { fprintf(stderr, "This doesn't look like a Speex file\n"); return 0; } speex_bits_destroy(&bits); if (stream_init) ogg_stream_clear(&os); ogg_sync_clear(&oy); fclose(fin); return 1; } #include SNDFILE *sndfile; SF_INFO sfinfo; static void seek_sndfile (float delta) { sf_seek(sndfile, (sf_count_t)(sfinfo.samplerate*delta), SEEK_CUR); } static int play_sndfile (int fd, char const *begin, char const *end) { sf_count_t maxFrames = 0; memset (&sfinfo, 0, sizeof (sfinfo)); if ((sndfile = sf_open_fd (dup(fd), SFM_READ, &sfinfo, 1))) { if (begin) { double time; if (parse_double_time(&time, begin) == -1) { fprintf(stderr, "Unable to parse time spec: %s\n", begin); goto close; } sf_seek(sndfile, (sf_count_t)(time * sfinfo.samplerate), SEEK_SET); } if (end) { double time; if (parse_double_time(&time, end) == -1) { fprintf(stderr, "Unable to parse end time spec: %s\n", end); goto close; } maxFrames = (sf_count_t)(time * sfinfo.samplerate); } audio_format.bits = 16; audio_format.channels = sfinfo.channels; audio_format.rate = sfinfo.samplerate; audio_format.byte_format = AO_FMT_LITTLE; if (audio_device) { fprintf(stderr, "Audio device already open.\n"); goto close; return 1; } audio_device = ao_open_live(audio_driver, &audio_format, NULL); if (!audio_device) { fprintf(stderr, "Error opening audio device: %d.\n", errno); goto close; return 1; } st->setSampleRate(sfinfo.samplerate); st->setChannels(sfinfo.channels); { float buf[512 * sfinfo.channels]; sf_count_t nFrames; sf_count_t readFrames = 0; while ((nFrames = sf_readf_float(sndfile, buf, 512)) > 0 && readFrames < maxFrames) { if (readFrames + nFrames > maxFrames) nFrames = maxFrames - readFrames; SAMPLETYPE samples[nFrames * sfinfo.channels]; int i; for (i=0; iputSamples(samples, nFrames); readFrames += nFrames; play_ao(sfinfo.channels, nFrames); pollKeyboard(seek_sndfile); if (quit) goto close; } } close: sf_close(sndfile); return 1; } else { fprintf(stderr, "libsndfile: %s\n", sf_strerror(NULL)); } lseek(fd,0,SEEK_SET); return 0; } static void signal_handler (int signal) { SLang_reset_tty(); kill(getpid(), signal); return; }