morse-x-0.20060903/0000755000175000017500000000000010476673214013065 5ustar sbeyersbeyermorse-x-0.20060903/errors.c0000644000175000017500000000514410471367370014547 0ustar sbeyersbeyer/* errors.c ****************************************************************************** Author: Stephan Beyer Description of this file: this file contains error handling routines with everything I need * addition: SDL-specific errors Copyright (C) GPL, 2000-2006 Stephan Beyer - s-beyer@gmx.net 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include /* errno ... */ #include /* fprintf... */ #include /* exit ... */ #include /* strerror ... */ #include #include "errors.h" /* comment out next line, if there are problems */ extern char *strerror_r(int __errnum, char *__buf, size_t __buflen); /* prints an error message to stderr and exits with given nr, * doesn't exit when nr==0 */ void ErrorMsg(signed int nr, const char *msg) { fprintf(stderr, "Error: %s\n", msg); if (nr) { puts(ERROCCMSG); exit(nr); } } /* Usage: HandleError("function", __FILE__, __LINE__, 0) * - nr specifies the exit code (if nonzero) * if zero, it won't exit... */ void HandleError(const char *def, char *file, unsigned int line, signed int nr) { char buffer[255]; int err = errno; const char *separator; if (def == NULL || *def == '\0') def = separator = ""; else separator = " - "; if(nr < errSDL) fprintf(stderr, "%s%s%s (in file %s, line %d)\n", def, separator, strerror_r(err, buffer, sizeof(buffer)), file, line); else fprintf(stderr, "%s%s%s (in file %s, line %d)\n", def, separator, SDL_GetError(), file, line); if (nr) { puts(ERROCCMSG); exit(nr); } } morse-x-0.20060903/icons/0000755000175000017500000000000010476671220014173 5ustar sbeyersbeyermorse-x-0.20060903/icons/morse1.xpm0000644000175000017500000000264510065664653016144 0ustar sbeyersbeyer/* XPM */ static char * icon_xpm[] = { "35 35 2 1", " c None", ". c #FF0000", " ", " ......... ......... ", " ......... ......... ", " ......... ......... ", " ", " ......... ......... ......... ", " ......... ......... ......... ", " ......... ......... ......... ", " ", " ... ......... ... ", " ... ......... ... ", " ... ......... ... ", " ", " ... ... ... ", " ... ... ... ", " ... ... ... ", " ", " ... ", " ... ", " ... ", " ", " ", " ", " ", " ", " ......... ... ... ......... ", " ......... ... ... ......... ", " ......... ... ... ......... ", " ", " ", " ", " ", " ", " ", " "}; morse-x-0.20060903/icons/morse2.xpm0000644000175000017500000000266410065664653016146 0ustar sbeyersbeyer/* XPM */ static char * icon_xpm[] = { "35 35 3 1", " c None", ". c #000000", "+ c #FF0000", " ......... ", " ............... ", " ................... ", " ..................... ", " .+++++++++...+++++++++. ", " ..+++++++++...+++++++++.. ", " ...+++++++++...+++++++++... ", " ............................. ", " +++++++++...+++++++++...+++++++++ ", " +++++++++...+++++++++...+++++++++ ", " +++++++++...+++++++++...+++++++++ ", " ................................. ", " ......+++...+++++++++...+++...... ", ".......+++...+++++++++...+++.......", ".......+++...+++++++++...+++.......", "...................................", "..........+++...+++...+++..........", "..........+++...+++...+++..........", "..........+++...+++...+++..........", "...................................", "................+++................", "................+++................", " ...............+++............... ", " ................................. ", " ................................. ", " ............................... ", " ............................... ", " ............................. ", " +++++++++...+++...+++...+++++++++ ", " +++++++++...+++...+++...+++++++++ ", " +++++++++...+++...+++...+++++++++ ", " ..................... ", " ................... ", " ............... ", " ......... "}; morse-x-0.20060903/icons/morse3.xpm0000644000175000017500000000266410065664653016147 0ustar sbeyersbeyer/* XPM */ static char * icon_xpm[] = { "35 35 3 1", " c None", ". c #000000", "+ c #FF0000", " ......... ", " ............... ", " ................... ", " ..................... ", " ..+++++++.....+++++++.. ", " ..+++++++++...+++++++++.. ", " ....+++++++.....+++++++.... ", " ............................. ", " +++++++.....+++++++.....+++++++ ", " +++++++++...+++++++++...+++++++++ ", " .+++++++.....+++++++.....+++++++. ", " ................................. ", " .......+.....+++++++.....+....... ", ".......+++...+++++++++...+++.......", "........+.....+++++++.....+........", "...................................", "...........+.....+.....+...........", "..........+++...+++...+++..........", "...........+.....+.....+...........", "...................................", ".................+.................", "................+++................", " ................+................ ", " ................................. ", " ................................. ", " ............................... ", " ............................... ", " ............................. ", " +++++++.....+.....+.....+++++++ ", " +++++++++...+++...+++...+++++++++ ", " +++++++.....+.....+.....+++++++ ", " ..................... ", " ................... ", " ............... ", " ......... "}; morse-x-0.20060903/icons/morse4.xpm0000644000175000017500000000270310065664653016142 0ustar sbeyersbeyer/* XPM */ static char * icon_xpm[] = { "35 35 4 1", " c None", ". c #000000", "+ c #FF0000", "- c #800000", " ......... ", " ............... ", " ................... ", " ..................... ", " ..+++++++.....+++++++.. ", " ..+++++++++...+++++++++.. ", " ....+++++++.....+++++++.... ", " ............................. ", " +++++++.....+++++++.....+++++++ ", " +++++++++...+++++++++...+++++++++ ", " .+++++++.....+++++++.....+++++++. ", " ................................. ", " ......-+-....+++++++....-+-...... ", ".......+++...+++++++++...+++.......", ".......-+-....+++++++....-+-.......", "...................................", "..........-+-...-+-...-+-..........", "..........+++...+++...+++..........", "..........-+-...-+-...-+-..........", "...................................", "................-+-................", "................+++................", " ...............-+-............... ", " ................................. ", " ................................. ", " ............................... ", " ............................... ", " ............................. ", " +++++++....-+-...-+-....+++++++ ", " +++++++++...+++...+++...+++++++++ ", " +++++++....-+-...-+-....+++++++ ", " ..................... ", " ................... ", " ............... ", " ......... "}; morse-x-0.20060903/icons/morse-x.xpm0000644000175000017500000000236010471430201016277 0ustar sbeyersbeyer/* XPM */ static char * icon32_xpm[] = { "32 32 4 1", " c None", ". c #000000", "+ c #FF0000", "@ c #800000", " ....... ", " ............. ", " +++++++.....+++++++ ", " +++++++++...+++++++++ ", " .+++++++.....+++++++. ", " ....................... ", " +++++++....+++++++....+++++++ ", "+++++++++..+++++++++..+++++++++ ", " +++++++....+++++++....+++++++ ", " ............................. ", " ....@+@....+++++++....@+@.... ", " ....+++...+++++++++...+++.... ", ".....@+@....+++++++....@+@..... ", "............................... ", "........@+@...@+@...@+@........ ", "........+++...+++...+++........ ", "........@+@...@+@...@+@........ ", "............................... ", "..............@+@.............. ", " .............+++............. ", " .............@+@............. ", " ............................. ", " ........................... ", " ........................... ", " ......................... ", " ....................... ", " +++++++...@+@...@+@...+++++++ ", "+++++++++..+++...+++..+++++++++ ", " +++++++...@+@...@+@...+++++++ ", " ............. ", " ....... ", " "}; morse-x-0.20060903/COPYING0000644000175000017500000004310310444336174014115 0ustar sbeyersbeyer 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. morse-x-0.20060903/ChangeLog0000644000175000017500000000526610476671302014644 0ustar sbeyersbeyer2006-09-03 Stephan Beyer * main.c: * -t option stuff * removed use of calibration file, wpm number is used instead, so added -w option * -c now got a slightly different meaning (calibrate -> check wpm) * main.h: version numbering change: . * calibrate.[ch]: removed * morse.c (showTable): added for -t option * morse.c (checkWPM): added, modified variant of Calibrate() from calibrate.c * morse-x.1: updated * debian/: removed so that package doesn't become a native one, also reset changelog file because version numbering changed and I do not want to start a new epoch. * icons/icon32.xpm: renamed to icons/morse-x.xpm 2006-08-19 Stephan Beyer * general,main.c: "port" from Xlib to libSDL (almost rewrite) * common.c,common.h,xcommon.h,options.c,options.h: removed, content moved to other files, mainly main. * calibrate.c: calibration with orders in main window * errors.c: added SDL_GetError() handling * audio.c: audio support! * icons/icon32.xpm: 32x32 icon created, xpm is not used but the image is *generated* within main.c (SetWMStuff) * morse-x.1: description rewritten, options updated, bugs from Xlib version removed * COPYING: took GPL2 text with new FSF office address * TAGS: debtags tags I considered useful for morse-x * debian/control: updated, took new description from manual page 2004-07-13 Stephan Beyer * morse-x.1: generated using manedit 2004-04-15 Stephan Beyer * common.c, main.c: made exitable via window manager * general: code "cleanup" (restructurized) and split into several modules (new are common, morse and options) 2004-04-14 Stephan Beyer * general: some small restructurizing, infos for first start * main.c (main): reset old keyboard auto repeat state * calibrate.c: calibration routines, file reading and writing 2004-04-13 Stephan Beyer * main.c (EventLoop): print translated characters * main.c (main): added -s option 2004-03-02 Stephan Beyer * main.c (EventLoop): pressing 'q' (not 'Q'!) quits; printing dashes and dots and spaces with a fixed 2004-02-29 Stephan Beyer * main.c (EventLoop): only react on KeyRelease if the pressed key releases; calculate and print KeyPress duration * morse.h: first chars for morse tree 2004-02-28 Stephan Beyer * errors.c, errors.h: copied from IMine project * icons/morse[1234].xpm: created with The Gimp * main.c (main, EventLoop), main.h: whole X stuff, window, Xpm icon, Focus and KeyEvents; -d, -g, -h and -r options * Makefile, ChangeLog: created * COPYING: created (GPL v2) morse-x-0.20060903/Makefile0000644000175000017500000000161610476640424014526 0ustar sbeyersbeyerCC = gcc LINKER = gcc LIBS = `sdl-config --libs` -lm CFL_W = -Wno-sign-compare -Wpointer-arith -Wno-system-headers -Wshadow -Wbad-function-cast -Werror -Wunreachable-code CFLAGS = -ansi -pedantic -pedantic-errors -Wall $(CFLAGS_W) `sdl-config --cflags` LDFLAGS = -s OBJ = errors.o morse.o audio.o main.o BINARY = morse-x CLEAN = *~ *.bak *.o $(BINARY) Makefile.headers .SUFFIXES: .c .o all: $(OBJ) $(LINKER) $(LIBS) $(LDFLAGS) -o "$(BINARY)" $(OBJ) include Makefile.headers # strange, but nice ;) taken from IMine Makefile.headers: grep '^#include *".*"' *.c | sed 's/\(.*\).c:#include *"\(.*\)".*/\1.o: \2/' > Makefile.headers %o: %c $(CC) $(CFLAGS) -c -o $@ $< clean: rm -f $(CLEAN) install: strip "$(BINARY)" install -d $(DESTDIR)/usr/bin install $(BINARY) $(DESTDIR)/usr/bin deb: dpkg-buildpackage -rfakeroot deb-clean: rm -rf debian/morse-x debian/files debian/*substvars $(MAKE) clean morse-x-0.20060903/TODO0000644000175000017500000000037410476642641013561 0ustar sbeyersbeyerTODO? - add missing morse characters (e.g. SOS) - use SDLconsole (perhaps too bloated) or something to avoid needed usage of a terminal or x-terminal-emulator (then I can think of a Windows port) TODO! - trainers for transmitting *and* receiving morse-x-0.20060903/main.h0000644000175000017500000000120410476641461014156 0ustar sbeyersbeyer/* main.h * (C) Stephan Beyer, 2004, 2006 GPL */ #ifndef MAIN_H #define MAIN_H #define TITLE "Morse" #define VERSION "0.20060903" #define DEFAULT_RATE 44100 #define DEFAULT_FREQ 441 #define DEFAULT_VOLUME 0.7 #define DEFAULT_WPM 15 int KeyPressLoop(unsigned int *); /* global-needed options */ typedef struct { unsigned checkwpm : 1; /* -c */ unsigned showgfx : 1; /* -g */ unsigned show : 1; /* -s */ unsigned mute : 1; /* -m */ int rate; /* -r rate */ int freq; /* -f freq */ float vol; /* -v vol */ int wpm; /* -w wpm */ } Opt; Opt opt; void paint(char *); #endif morse-x-0.20060903/errors.h0000644000175000017500000000071610471374604014552 0ustar sbeyersbeyer/* errors.h * (C) Stephan Beyer, 2003-2006 GPL */ #ifndef ERRORS_H #define ERRORS_H #define ERROCCMSG "an error occured" #define DoAndErr(COND,STR,ERR) if (COND) HandleError(#STR, __FILE__, __LINE__, ERR); enum errorcodes { errNO = 0, errMEMORY, errARGS, errFILE, errSDL, errSDLvideo, errSDLaudio, errUNDEFINED }; void ErrorMsg(signed int nr, const char *msg); void HandleError(const char *def, char *file, unsigned int line, signed int nr); #endif morse-x-0.20060903/main.c0000644000175000017500000002522410476673144014164 0ustar sbeyersbeyer/* main.c ****************************************************************************** Morse Author: Stephan Beyer Copyright (C) 2004,2006 Stephan Beyer - s-beyer@gmx.net 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include /* atoi(), atof() ... */ #include /* puts(), printf()... */ #include #include "audio.h" #include "main.h" #include "morse.h" #include "errors.h" /* global variables and constants */ SDL_Surface *screen; const Uint16 dawpx[] = { 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00 }; const Uint16 ditpx[] = { 0x7F,0xFF,0x7F, 0xFF,0xFF,0xFF, 0x7F,0xFF,0x7F }; SDL_Surface *daw, *dit; /* print information about possible options */ void Usage(char *binary) { printf( "Usage: %s [options]\n\n" "Possible options are:\n" "\t-c try to check sending wpm\n" "\t-f freq set sound frequency [%d]\n" "\t-g like -s, but in main window\n" "\t-h print this usage information\n" "\t-m mute, no sounds are played\n" "\t-r rate set audio sample rate [%d]\n" "\t-s show dits (as '.') and daws (as '-')\n" "\t-t show morse code table and exit\n" "\t-v vol sound volume between 0 and 1 [%.1f]\n" "\t-w wpm set words per minute [%d]\n" "The '-' prefix to options is optional.\n", binary, DEFAULT_FREQ, DEFAULT_RATE, DEFAULT_VOLUME, DEFAULT_WPM); } /* handle options and open display */ void HandleOptions(int argc, char **argv) { char **i; /* help pointer to process arguments */ /* option defaults */ opt.checkwpm = 0; opt.showgfx = 0; opt.show = 0; opt.mute = 0; opt.freq = DEFAULT_FREQ; opt.rate = DEFAULT_RATE; opt.vol = DEFAULT_VOLUME; opt.wpm = DEFAULT_WPM; /* go through the arguments */ i = argv+1; while (*i) { if (**i == '-') /* optional '-' */ (*i)++; switch(**i) { case 'c': opt.checkwpm = 1; break; case 'f': i++; if(*i) { opt.freq = atoi(*i); if(opt.freq < 200 || opt.freq > 2000) ErrorMsg(errARGS, "Frequency must be a value between 200 and 2000 Hz!"); } else ErrorMsg(errARGS,"-f option needs frequency!"); break; case 'g': opt.showgfx = 1; break; case 'h': Usage(*argv); exit(0); case 'm': opt.mute = 1; break; case 'r': i++; if(*i) { opt.rate = atoi(*i); if(opt.rate < 4000) ErrorMsg(errARGS, "Sample rate must be at least 4000 Hz!"); } else ErrorMsg(errARGS,"-r option needs sample rate!"); break; case 's': opt.show = 1; break; case 't': showTable(); exit(0); case 'v': i++; if(*i) { opt.vol = atof(*i); if(opt.vol < 0 || opt.vol > 1) ErrorMsg(errARGS, "Volume must be a value between 0 and 1!"); } else ErrorMsg(errARGS,"-v option needs volume!"); break; case 'w': i++; if(*i) { opt.wpm = atoi(*i); if(opt.wpm < 1 || opt.wpm > 60) ErrorMsg(errARGS, "WPM must be an integer between 1 and 60!"); } else ErrorMsg(errARGS,"-w option needs number of words per minute!"); break; default: ErrorMsg(errARGS, "Wrong arguments. Use -h option for help!"); } i++; } } /* paint a "daw" ;) */ void paintDaw(SDL_Surface *s, int x, int y) { SDL_Rect dest; dest.x = x; dest.y = y; dest.w = 9; dest.h = 3; SDL_BlitSurface(daw,NULL,s,&dest); } /* ...and a "dit" */ void paintDit(SDL_Surface *s, int x, int y) { SDL_Rect dest; dest.x = x; dest.y = y; dest.w = 3; dest.h = 3; SDL_BlitSurface(dit,NULL,s,&dest); } void paint(char *txt) { char *t; int x, width = 0, height = screen->h/2-1; /* first: get total width */ for(t=txt; *t; t++) { if(*t=='-' || *t==' ') width += 11; else if(*t=='.') width += 5; } /* second: paint dits and daws into rectangle */ x = 1+(screen->w-width)/2; for(t=txt; *t; t++) if(*t=='-') { paintDaw(screen, x, height); x += 11; } else if(*t==' ') x += 11; else if(*t=='.') { paintDit(screen, x, height); x += 5; } SDL_Flip(screen); } void initDitDaw(void) { daw = SDL_CreateRGBSurfaceFrom(&dawpx, 9, 3, 16, 18 /* = width*bpp/8 */, 255,0,0,0); dit = SDL_CreateRGBSurfaceFrom(&ditpx, 3, 3, 16, 6 /* = width*bpp/8 */, 255,0,0,0); /* never SDL_FreeSurface() them, because of dawpx and ditpx */ /* we could free() them, but we could also let the operating system * do this at program exit ;P */ } void SetWMStuff(void) { SDL_Surface *icon = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 8, 255, 0, 0, 0); Uint8 mask[] = { 0, 15, 224, 0, 0, 127, 252, 0, 3, 255, 255, 128, 7, 255, 255, 192, 7, 255, 255, 192, 15, 255, 255, 224, 127, 255, 255, 252, 255, 255, 255, 254, 127, 255, 255, 252, 127, 255, 255, 252, 127, 255, 255, 252, 127, 255, 255, 252, 255, 255, 255, 254, 255, 255, 255, 254, 255, 255, 255, 254, 255, 255, 255, 254, 255, 255, 255, 254, 255, 255, 255, 254, 255, 255, 255, 254, 127, 255, 255, 252, 127, 255, 255, 252, 127, 255, 255, 252, 63, 255, 255, 248, 63, 255, 255, 248, 31, 255, 255, 240, 15, 255, 255, 224, 127, 255, 255, 252, 255, 255, 255, 254, 127, 255, 255, 252, 0, 127, 252, 0, 0, 15, 224, 0, 0, 0, 0, 0 }; /* this was: (converted to array using some regexps and Ruby) * 00000000 00001111 11100000 00000000 * 00000000 01111111 11111100 00000000 * 00000011 11111111 11111111 10000000 * 00000111 11111111 11111111 11000000 * 00000111 11111111 11111111 11000000 * 00001111 11111111 11111111 11100000 * 01111111 11111111 11111111 11111100 * 11111111 11111111 11111111 11111110 * 01111111 11111111 11111111 11111100 * 01111111 11111111 11111111 11111100 * 01111111 11111111 11111111 11111100 * 01111111 11111111 11111111 11111100 * 11111111 11111111 11111111 11111110 * 11111111 11111111 11111111 11111110 * 11111111 11111111 11111111 11111110 * 11111111 11111111 11111111 11111110 * 11111111 11111111 11111111 11111110 * 11111111 11111111 11111111 11111110 * 11111111 11111111 11111111 11111110 * 01111111 11111111 11111111 11111100 * 01111111 11111111 11111111 11111100 * 01111111 11111111 11111111 11111100 * 00111111 11111111 11111111 11111000 * 00111111 11111111 11111111 11111000 * 00011111 11111111 11111111 11110000 * 00001111 11111111 11111111 11100000 * 01111111 11111111 11111111 11111100 * 11111111 11111111 11111111 11111110 * 01111111 11111111 11111111 11111100 * 00000000 01111111 11111100 00000000 * 00000000 00001111 11100000 00000000 * 00000000 00000000 00000000 00000000 */ /* Creating icon, I'm insane! * Hardcode icon like this: * First: everything black */ SDL_FillRect(icon,NULL,0); /* Second: a daw is: a dit is: * 011111110 212 0=black (0,0,0) * 111111111 111 1=red (255,0,0) * 011111110 212 2=darkred (128,0,0) */ initDitDaw(); /* Put daws at: */ paintDaw(icon,5,2); paintDaw(icon,18,2); paintDaw(icon,0,6); paintDaw(icon,11,6); paintDaw(icon,22,6); paintDaw(icon,11,10); paintDaw(icon,0,26); paintDaw(icon,22,26); /* And dits at: */ paintDit(icon,5,10); paintDit(icon,23,10); paintDit(icon,8,14); paintDit(icon,14,14); paintDit(icon,20,14); paintDit(icon,14,18); paintDit(icon,11,26); paintDit(icon,17,26); /* That's it ;) */ SDL_WM_SetIcon(icon, mask); SDL_WM_SetCaption(TITLE,TITLE); } /* fills screen with black (== 0) or white (== 1) */ void Fill(int white) { SDL_FillRect(screen, NULL, (white ? -1 : 0 )); SDL_Flip(screen); } /* wait for press and release of one key * - return pressing duration * - return -1 to exit (on q or DestroyEvent) * - return KeyRelease time (argument) if adress is non-NULL */ int KeyPressLoop(unsigned int *rtime) { unsigned int keypressed = 0; int dur = 0; Uint32 time = 0; Uint32 eventtime; while(!dur) { SDL_Event event; SDL_WaitEvent(&event); eventtime = SDL_GetTicks(); switch(event.type) { case SDL_QUIT: return -1; /* ? */ case SDL_KEYDOWN: /* key pressed? */ /* exit if it is 'q' */ if(event.key.keysym.sym==SDLK_q) return -1; keypressed++; /* if no other key currently pressed */ if(keypressed==1) { time = eventtime; /* fill with white and play tone */ Fill(1); if(!opt.mute) playAudio(1); } break; case SDL_KEYUP: /* key released? */ if(!keypressed) break; keypressed--; /* are all pressed keys released? */ if(!keypressed) { /* calculate KeyPressed duration */ dur = eventtime - time; /* return KeyRelease time, if nonNULL */ if (rtime) *rtime = eventtime; /* fill with black and stop tone */ Fill(0); if(!opt.mute) playAudio(0); } break; case SDL_VIDEORESIZE: /* window resized? */ SDL_SetVideoMode(event.resize.w, event.resize.h, screen->format->BitsPerPixel, screen->flags); break; } } return dur; } /* main routine */ int main(int argc, char **argv) { /* introduction message */ printf("%s version %s\n", TITLE, VERSION); puts("(C) 2004, 2006, Stephan Beyer, s-beyer@gmx.net\tGPL\n"); /* handle options and open display */ HandleOptions(argc, argv); /* init SDL */ DoAndErr(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER), SDL_Init, errSDL); atexit(SDL_Quit); if(!opt.mute) /* init audio */ initAudio(opt.rate,1); /* set wm stuff */ SetWMStuff(); /* init video */ screen = SDL_SetVideoMode(32, 32, 24, SDL_HWSURFACE | SDL_RESIZABLE); DoAndErr(!screen, SDL_SetVideoMode, errSDLvideo); SDL_PauseAudio(0); MainProgram(); SDL_Quit(); return 0; } morse-x-0.20060903/morse.c0000644000175000017500000001676410476640404014367 0ustar sbeyersbeyer/* morse.c ****************************************************************************** This file is part of morse-x! Author: Stephan Beyer Description of this file: morse code functions Copyright (C) GPL, 2004, 2006 Stephan Beyer - s-beyer@gmx.net 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include /* putchar(), printf()... */ #include /* malloc(), free(), ... */ #include "main.h" /* the morse code */ /* How I did it: * I use an array as a binary tree, that means, if the array index * i is the root, so the index 2*i is the left, and 2*i + 1 is the * right knot. I decided that 'dit' ('.') is accessable with 2*i, and * 'daw' ('-') is 2*i+1, in general. * Because array indeces begin with 0 in C, and because one root * element is missing, you have to substract 2 for the right index, * when - and ONLY when - accessing. * Summarized in pseudo code: * i = 1; * ... * if DIT then * i = 2*i; * ... -> morse[i-2]; * if DAW then * i = 2*i+1; * ... -> morse[i-2]; */ static const char* morse[] = { /* this tree contains ISO-8859-1 characters */ /* . */ "E", /* - */ "T", /* .. */ "I", /* .- */ "A", /* -. */ "N", /* -- */ "M", /* ... */ "S", /* ..- */ "U", /* .-. */ "R", /* .-- */ "W", /* -.. */ "D", /* -.- */ "K", /* --. */ "G", /* --- */ "O", /* .... */ "H", /* ...- */ "V", /* ..-. */ "F", /* ..-- */ "Ü", /* .-.. */ "L", /* .-.- */ "Ä", /* .--. */ "P", /* .--- */ "J", /* -... */ "B", /* -..- */ "X", /* -.-. */ "C", /* -.-- */ "Y", /* --.. */ "Z", /* --.- */ "Q", /* ---. */ "Ö", /* ---- */ "CH", /* ..... */ "5", /* ....- */ "4", /* ...-. */ " SN ", /* ...-- */ "3", /* ..-.. */ "É", /* ..-.- */ NULL, /* ..--. */ "!", /* ..--- */ "2", /* .-... */ " AS ", /* .-..- */ NULL, /* .-.-. */ " AR ", /* often "+" */ /* .-.-- */ NULL, /* .--.. */ NULL, /* .--.- */ "{áå}", /* .---. */ NULL, /* .---- */ "1", /* -.... */ "6", /* -...- */ " BT ", /* separator, often "=" */ /* -..-. */ "/", /* (fraction bar) */ /* -..-- */ NULL, /* -.-.. */ NULL, /* -.-.- */ " KA ", /* -.--. */ "(", /* -.--- */ "#", /* --... */ "7", /* --..- */ NULL, /* --.-. */ NULL, /* --.-- */ "Ñ", /* ---.. */ "8", /* ---.- */ NULL, /* ----. */ "9", /* ----- */ "0", /* ...... */ NULL, /* .....- */ NULL, /* ....-. */ NULL, /* ....-- */ NULL, /* ...-.. */ "|", /* ...-.- */ " SK ", /* ...--. */ NULL, /* ...--- */ NULL, /* ..-... */ NULL, /* ..-..- */ NULL, /* ..-.-. */ NULL, /* ..-.-- */ NULL, /* ..--.. */ "?", /* ..--.- */ "_", /* ..---. */ NULL, /* ..---- */ NULL, /* .-.... */ NULL, /* .-...- */ NULL, /* .-..-. */ "\"", /* .-..-- */ NULL, /* .-.-.. */ NULL, /* .-.-.- */ ".", /* .-.--. */ NULL, /* .-.--- */ NULL, /* .--... */ NULL, /* .--..- */ NULL, /* .--.-. */ "@", /* .--.-- */ NULL, /* .---.. */ NULL, /* .---.- */ NULL, /* .----. */ "'", /* .----- */ NULL, /* -..... */ "\\", /* -....- */ "-", /* -...-. */ NULL, /* -...-- */ NULL, /* -..-.. */ NULL, /* -..-.- */ NULL, /* -..--. */ NULL, /* -..--- */ NULL, /* -.-... */ NULL, /* -.-..- */ NULL, /* -.-.-. */ NULL, /* -.-.-- */ NULL, /* -.--.. */ NULL, /* -.--.- */ ")", /* -.---. */ NULL, /* -.---- */ NULL, /* --.... */ NULL, /* --...- */ NULL, /* --..-. */ NULL, /* --..-- */ ",", /* --.-.. */ NULL, /* --.-.- */ NULL, /* --.--. */ NULL, /* --.--- */ NULL, /* ---... */ ":", /* ---..- */ NULL, /* ---.-. */ NULL, /* ---.-- */ NULL, /* ----.. */ NULL, /* ----.- */ NULL, /* -----. */ "*", /* ------ */ NULL }; #if 0 /* etc...: */ /* ....... */ " ERROR ", /* ...--.. */ "ß", /* ...---... */ " SOS " #endif #define LENGTH (sizeof(morse) / sizeof(char *)) /* prints the character(s) of the given morse tree index i */ void PrintChar(int i) { if(opt.show) putchar(' '); if((i-2 < LENGTH) && morse[i-2]) printf("%s", morse[i-2]); else printf("%%not defined%%"); if(opt.show) putchar(' '); } /* returns ".-"-like C string for num */ char * ditdaw_str(int num) { char *ret; int retlen = 0; int t; num += 2; t = num; do { retlen++; t >>= 1; } while(t); ret = malloc(retlen); for(t = 0; t < retlen; t++) ret[t] = ((num>>(retlen-2-t))&1 ? '-' : '.'); ret[t-1] = 0; return ret; } /* for -t */ void showTable(void) { int i; for(i = 0; i < LENGTH; i++) { if(morse[i]) { char *x = ditdaw_str(i); printf("%s\t%s\n",x,morse[i]); free(x); } } } /* for -c, returns new durunit or -1 if an exit was suggested */ int checkWPM(void) { int dur = 0; /* the average duration */ int n; /* duration of one loop */ /* info */ puts("WPM Check\n---------\n\nNow please morse:\n"); #define PRESS n = KeyPressLoop(NULL); \ if (n < 0) \ return n; #define DIT PRESS dur += n*3; #define DAW PRESS dur += n; /* orders */ puts("\t* 'A' ('dit daw' / .-)"); paint(".-"); DIT paint("-"); DAW puts("\t* 'N' ('daw dit' / -.)"); paint("-."); DAW paint("."); DIT puts("\t* 'S' ('dit dit dit' / ...)"); paint("..."); DIT paint(".."); DIT paint("."); DIT puts("\t* 'O' ('daw daw daw' / ---)"); paint("---"); DAW paint("--"); DAW paint("-"); DAW dur /= 30; puts("\nFinished.\n"); return dur; } void MainProgram(void) { int dur = 0; /* keypress duration */ int i = 1; /* morse tree index, see intro comment */ unsigned int time = 0; int durunit = 1200/opt.wpm; /* duration of a 'dit' */ /* checkwpm */ if (opt.checkwpm || (durunit < 0)) durunit = checkWPM(); dur = durunit; /* just for exit check */ if(dur >= 0) { printf("Using %d words per minute.\n\n" "Press 'q' in the main window to exit. Any other key morses.\n" "Text:\n", 1200/durunit); /* should equal opt.wpm */ } while (dur >= 0) /* main loop */ { unsigned int oldtime = time; /* time of previous KeyRelease */ dur = KeyPressLoop(&time); if (oldtime && (dur >= 0)) { /* new morse character? (3-dit-pause?) */ if (time - dur - oldtime >= 3*durunit) { PrintChar(i); fflush(stdout); i = 1; /* reset index */ } if (time - dur - oldtime >= 7*durunit) { if (opt.show) putchar('\n'); else putchar(' '); } } if (dur >= 0) /* not -1 */ { /* duration of 3 dits? => daw */ if (dur >= durunit * 3) { if(opt.showgfx) paint("-"); /* paint */ if(opt.show) putchar('-'); i = 2*i + 1; } else { /* a dit */ if(opt.showgfx) paint("."); /* paint */ if(opt.show) putchar('.'); i *= 2; } fflush(stdout); } } if (i > 1) PrintChar(i); puts("\nBye!"); } morse-x-0.20060903/TAGS0000644000175000017500000000041310471733257013543 0ustar sbeyersbeyerTag: accessibility::screen-reader, field::special:todo, game::toys, hardware::hamradio, interface::text-mode, interface::x11, made-of::lang:c, role::sw:application, uitoolkit::sdl, use::learning, use::converting, works-with::audio, works-with::text, x11::application morse-x-0.20060903/audio.h0000644000175000017500000000022210471453457014333 0ustar sbeyersbeyer/* audio.h * (C) Stephan Beyer, 2006 GPL */ #ifndef AUDIO_H #define AUDIO_H void initAudio(int,int); void playAudio(int); #endif /* AUDIO_H */ morse-x-0.20060903/audio.c0000644000175000017500000001306010471676224014331 0ustar sbeyersbeyer/* audio.c ****************************************************************************** This file is part of morse-x! Author: Stephan Beyer Description of this file: audio functions, using libSDL Copyright (C) GPL, 2006 Stephan Beyer - s-beyer@gmx.net 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include /* memcpy() */ #include #include /* M_PI, sinf */ #include "main.h" /* options */ #include "errors.h" #include "audio.h" #ifndef _GNU_SOURCE # define mempcpy(A,B,C) ((Uint8*)memcpy(A,B,C)+C) #endif /* types */ typedef struct _sndData { void *pstream; /* prepared stream data */ Uint32 len; /* len of prepared stream data */ Uint32 pos; /* last position in stream */ } sndData; /* globals */ int play; /* boolean if playing or not */ /* sound callback */ void sndcb(void *userdata, Uint8 *stream, int len) { sndData *base = userdata; Uint8 *pstream = base->pstream; Uint32 plen = base->len - base->pos; pstream += base->pos; if(play) /* play tone */ while(len > 0) { if(len > plen) { stream = mempcpy(stream,pstream,plen); len -= plen; base->pos = 0; pstream = base->pstream; plen = base->len; } else { stream = mempcpy(stream,pstream,len); base->pos += len; len = 0; } } else /* generate silence without snapping */ if(base->pos) { if(len > plen) { stream = mempcpy(stream,pstream,plen); base->pos = 0; } else { stream = mempcpy(stream,pstream,len); base->pos += len; } } } SDL_AudioSpec * specNew(int srate, Uint8 channels, void *userdata) { SDL_AudioSpec *ret; ret = malloc(sizeof(SDL_AudioSpec)); ret->freq = srate; ret->format = AUDIO_S16SYS; ret->channels = channels; ret->silence = 0; /* I really don't know what this is here ;) */ /* the following seemed to be good values: */ ret->samples = (srate > 80000 ? 2048 : (srate > 40000 ? 1024 : (srate > 20000 ? 512 : (srate > 10000 ? 256 : (srate > 5000 ? 128 : 64))))); ret->size = ret->samples*channels*2; ret->callback = sndcb; ret->userdata = userdata; return ret; } /* opens the audio device with given options */ SDL_AudioSpec * openAudio(int srate, Uint8 channels, void *userdata) { SDL_AudioSpec *obtained = malloc(sizeof(SDL_AudioSpec)), *desired = specNew(srate,channels,userdata); DoAndErr(SDL_OpenAudio(desired,obtained), SDL_OpenAudio, errSDLaudio); if(!obtained) return desired; free(desired); return obtained; } /* creates a wave stream and write base->pstream and base->len */ void createWave(sndData *base, SDL_AudioSpec *spec) { Uint32 samples = spec->freq / opt.freq; Uint32 len = samples * spec->channels; Uint32 i; Uint16 amp = 32767; Uint8 *stream; printf("Morse sound frequency set to %d Hz.\n", spec->freq / samples); if(spec->format == AUDIO_U8 || spec->format == AUDIO_S8) amp >>= 8; else len *= 2; /* this works as long as 32 bit audio format is not supported by SDL */ stream = malloc(len); base->pstream = stream; for(i = 0; i < samples; i++) { Uint8 c = 0; float x = amp*(opt.vol*sinf(2*i*M_PI/samples)+1); for(c = 0; c < spec->channels; c++) { Sint32 t = x; switch(spec->format) { case AUDIO_U8: *stream = (Uint8)x; break; case AUDIO_S8: *stream = (Sint8)x - amp; break; case AUDIO_S16LSB: t -= amp; case AUDIO_U16LSB: *stream = (Uint8)t; stream++; *stream = (Uint8)(t>>8); break; case AUDIO_S16MSB: t -= amp; case AUDIO_U16MSB: *stream = (Uint8)(t>>8); stream++; *stream = (Uint8)t; break; default: ErrorMsg(errSDLaudio,"Audio format not supported!"); } stream++; } } base->len = len; } void initAudio(int srate, int channels) { sndData *base = malloc(sizeof(sndData)); SDL_AudioSpec *sndspec = openAudio(srate,channels,base); /* note: we'll never free() this manually */ printf("Opened audio device using\n\t%i Hz sample rate,\n\t%d channel%s,\n\t%s format.\n", sndspec->freq, sndspec->channels, (sndspec->channels==2?"s":""), (sndspec->format==AUDIO_S16LSB ? "signed 16-bit little-endian" : (sndspec->format==AUDIO_S16MSB ? "signed 16-bit big-endian" : (sndspec->format==AUDIO_U16LSB ? "unsigned 16-bit little-endian" : (sndspec->format==AUDIO_U16MSB ? "unsigned 16-bit big-endian" : (sndspec->format==AUDIO_U8 ? "unsigned 8-bit" : (sndspec->format==AUDIO_S8 ? "signed 8-bit" : "unknown"))))))); play = 0; base->pos = 0; createWave(base,sndspec); puts(""); } void playAudio(int yes) { play = yes; } morse-x-0.20060903/morse.h0000644000175000017500000000023610476620030014350 0ustar sbeyersbeyer/* morse.h * (C) Stephan Beyer, 2004, GPL */ #ifndef MORSE_H #define MORSE_H /*void PrintChar(int);*/ void MainProgram(void); void showTable(void); #endif morse-x-0.20060903/morse-x.10000644000175000017500000000364410476673213014547 0ustar sbeyersbeyer.TH "morse-x" "1" "0.20060903" "Stephan Beyer" "hamradio" .SH "NAME" morse\-x \- morse practicing tool .SH "SYNTAX" .B morse\-x [\fIoptions\fP] .SH "DESCRIPTION" .LP In .B morse\-x you can use any key on your keyboard as morse key (except \fBq\fR, which exits) and then it displays your morsed stuff as readable text on stdout. (You should execute morse\-x in an X terminal.) .SH "OPTIONS" .LP Of course, morse\-x takes some options, some with arguments. See the following list. A preceding dash (\-) is optional. .LP .TP \fBc\fR Tries to find out your number of words per minute. (In fact, it is like the calibration function in former versions, except that it does not save the result, it just tells you your the number of your words per minute.) .TP \fBf\fR \fIfrequency\fP Set sound frequency. .TP \fBg\fR Show dits as red dots and daws as red lines in the main window. .TP \fBh\fR Print usage information, the same you can read here. Hopefully. .TP \fBm\fR Mute audio. No audio device will be opened. .TP \fBr\fR \fIsamplerate\fP Set audio sample rate. .TP \fBs\fR Show dits as dots and daws as dashes on stdout. .TP \fBt\fR Show used morse code table and exit. If you have suggestions on that table, please let me know. .TP \fBv\fR \fIvolume\fP Set sound volume. This must be a value between 0 and 1. .TP \fBw\fR \fIwpm\fP Set words per minute. This must be an integer between 1 and 60. .LP Note that older versions (2004*) were written using Xlib instead of libSDL and thus had some other options and no audio output. By the way, the .morse-x file of earlier versions is no longer needed. You may remove it. .SH "BUGS" None so far. Please report some. .SH "COPYRIGHT" Copyright \(co 2004, 2006 Stephan Beyer .LP This is free software. You may redistribute copies of it under the terms of the GNU General Public License . There is NO WARRANTY, to the extent permitted by law.