pax_global_header00006660000000000000000000000064143602510510014507gustar00rootroot0000000000000052 comment=0020688114bf1bd3411e07d1f07d5e2b0484559b tone-generator-1.6.1/000077500000000000000000000000001436025105100144455ustar00rootroot00000000000000tone-generator-1.6.1/AUTHORS000066400000000000000000000002011436025105100155060ustar00rootroot00000000000000Guido Berhoerster Marius Gripsgard Ratchanan Srirattanamet Ricardo Salveti De Araujo Rodney Dawes Tiago Salem Herrmann Tony Espy tone-generator-1.6.1/COPYING000066400000000000000000000636421436025105100155130ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 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. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, 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 and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, 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 library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete 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 distribute a copy of this License along with the Library. 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 Library or any portion of it, thus forming a work based on the Library, 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) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, 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 Library, 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 Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you 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. If distribution of 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 satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be 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. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library 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. 9. 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 Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library 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 with this License. 11. 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 Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library 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 Library. 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. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library 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. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser 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 Library 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 Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, 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 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "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 LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. 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 LIBRARY 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 LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), 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 Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. 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 library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! tone-generator-1.6.1/ChangeLog000066400000000000000000000041501436025105100162170ustar00rootroot000000000000002023-01-13 Mike Gabriel * Release 1.6.1 (HEAD -> main, tag: 1.6.1) 2022-04-22 Ratchanan Srirattanamet * Merge branch 'port-to-focal' into 'main' (4aaf711) 2022-02-11 Guido Berhoerster * Port to focal (9e2cd8e) 2021-05-20 Marius Gripsgard * Merge branch 'ubports/release-1.6.0' into 'main' (1f9e28e) 2021-05-20 Rodney Dawes * Release version 1.6.0. (a59026d) (tag: 1.6.0) * Remove old bzr-builddeb config. (3fcba0c) * Move Jenkinsfile to debian directory and update. (2fe1883) 2018-02-18 Marius Gripsgard * Imported to UBports (67bd41f) 2015-07-31 CI Train Bot * Releasing 1.5.4+15.10.20150731-0ubuntu1 (eb1a4ae) 2015-07-31 Tiago Salem Herrmann * Use phone role for busy and call waiting tones. Fixes: #1466963, #1476361 Approved by: Gustavo Pichorim Boiko (b1a6ba3) 2015-07-28 Tiago Salem Herrmann * notification props are not used (26ab3e3) * Use phone role for notifications like busy and waiting tone. (fe31003) 2014-09-05 CI bot * Releasing 1.5.4+14.10.20140905-0ubuntu1 (2bffadc) 2014-09-05 Ricardo Salveti de Araujo * Setting up the alert role for the dtmf sound (85d24dd) 2014-09-04 Ricardo Salveti de Araujo * Setting up the alert role for the dtmf sound (982714b) 2014-08-14 CI bot * Releasing 1.5.4+14.10.20140814-0ubuntu1 (77ba69c) 2014-08-14 Ricardo Salveti de Araujo * Lowering default dtmf volume (LP: #1356428); Fixing vcs entries in debian/control Approved by: Bill Filler (7449ed6) * Lowering default dtmf volume and fixing vcs entries in debian/control (a9298e9) 2014-07-31 CI bot * Releasing 1.5.4+14.10.20140731-0ubuntu1 (3c3311e) * This is a dummy commit used to seed this package for CI. Approved by: Tony Espy (eb3a225) 2014-07-31 Tony Espy * Add initial Debian/packaging (6a41d00) * Fixed packaging review comments. (1e43257) 2014-07-30 Tony Espy * Add initial Debian packaging. (2df1ce1) * Inital version of tone-generator daemon. (7f32726) tone-generator-1.6.1/Makefile.am000066400000000000000000000005741436025105100165070ustar00rootroot00000000000000SUBDIRS = src MAINTAINERCLEANFILES = \ Makefile.in src/Makefile.in config.h.in configure \ install-sh ltmain.sh missing mkinstalldirs \ config.log config.status config.guess config.sub config.h \ build-stamp compile depcomp acinclude.m4 aclocal.m4 \ stamp-h1 EXTRA_DIST = autogen.sh dist-hook: cp -va $(top_srcdir)/src/*.h $(top_distdir)/src tone-generator-1.6.1/README000066400000000000000000000044251436025105100153320ustar00rootroot00000000000000OVERVIEW -------- tone-generator (tonegend) generates telephony-related tones, and plays them via PulseAudio. In particular, it creates tones as defined in IETF RFC 4733 "RTP Payload for DTMF Digits, Telephony Tones, and Telephony Signals". tone-generator provides a D-Bus API to clients on the system bus. tone-generator is licensed under the GNU Lesser General Public License (LGPL) version 2.1. BUILDING ------- This package should be properly 'debianized' soon. (Note that there is an old Debian packaging, for the Maemo operating system, at https://gitorious.org/maemo-multimedia/tone-generator/commit/cb6cf3bfdd70e409a18b4fd9f3684371105d360f ). Until then: # install dependencies apt-get install automake libtool pkg-config libdbus-glib-1-dev libglib2.0-dev libpulse-dev # compile ./autogen.sh ./configure --sysconfdir=/etc make make install RUNNING ------- tone-generator runs as a daemon in a user session. An Upstart init script is provided (debian/tone-generator.conf). The --volume-dtmf parameter defines the default volume of generated DTMF sounds, as a percentage of the maximum volume. Changing the -b (buffer length in milliseconds) and -r (minimum request time in milliseconds) parameters is a tradeoff between responsiveness and memory consumption. EXAMPLE USAGE ------------- # Play a DTMF tone corresponding to key '5' dbus-send --system --print-reply --type=method_call --dest=com.Nokia.Telephony.Tones /com/Nokia/Telephony/Tones com.Nokia.Telephony.Tones.StartEventTone uint32:5 int32:0 uint32:0 sleep 3 dbus-send --system --print-reply --type=method_call --dest=com.Nokia.Telephony.Tones /com/Nokia/Telephony/Tones com.Nokia.Telephony.Tones.StopTone # Play a signalling tone corresponding to 'network congestion' for three seconds dbus-send --system --print-reply --type=method_call --dest=com.Nokia.Telephony.Tones /com/Nokia/Telephony/Tones com.Nokia.Telephony.Tones.StartEventTone uint32:73 int32:20 uint32:3000 HISTORY ------- tone-generator was written by Nokia, and it is used in devices based on the Maemo and MeeGo operating systems, see https://gitorious.org/maemo-multimedia/tone-generator . Maintenance of tone-generator was picked up by the Nemo Mobile project, and it is used in devices based on the Sailfish operating system, see https://github.com/nemomobile/tone-generator . tone-generator-1.6.1/autogen.sh000077500000000000000000000002721436025105100164470ustar00rootroot00000000000000#!/bin/sh echo "aclocal...." aclocal || exit 1 echo "autoconf...." autoconf || exit 3 echo "libtoolize" libtoolize --automake -c || exit 4 echo "automake...." automake -a -c || exit 5 tone-generator-1.6.1/configure.ac000066400000000000000000000014071436025105100167350ustar00rootroot00000000000000AC_COPYRIGHT([Copyright (C) 2008 Nokia Corporation]) AC_INIT([tone-generator], 1.6.1, [janos.f.kovacs@nokia.com]) AM_INIT_AUTOMAKE([foreign]) AC_PROG_CC AC_DISABLE_SHARED AC_PROG_LIBTOOL AC_C_RESTRICT CFLAGS="${CFLAGS} -Wall -Wextra -fno-omit-frame-pointer" PKG_CHECK_MODULES(DEPS, dbus-glib-1 dbus-1 gobject-2.0 glib-2.0 libpulse libpulse-mainloop-glib) AC_SUBST(DEPS_CFLAGS) AC_SUBST(DEPS_LIBS) AC_ARG_ENABLE([trace], AS_HELP_STRING([--enable-trace],[enable debug tracing.]), [ case "${enableval}" in yes) AC_DEFINE([ENABLE_TRACE], [1]) ;; no) ;; *) AC_MSG_ERROR(bad value ${enableval} for --enable-trace) ;; esac ]) AC_CONFIG_FILES([Makefile \ src/Makefile]) AC_OUTPUT tone-generator-1.6.1/debian/000077500000000000000000000000001436025105100156675ustar00rootroot00000000000000tone-generator-1.6.1/debian/Jenkinsfile000066400000000000000000000006511436025105100200550ustar00rootroot00000000000000@Library('ubports-build-tools') _ buildAndProvideDebianPackage() // Or if the package consists entirely of arch-independent packages: // (optional optimization, will confuse BlueOcean's live view at build stage) // buildAndProvideDebianPackage(/* isArchIndependent */ true) // Optionally, to skip building on some architectures (amd64 is always built): // buildAndProvideDebianPackage(false, /* ignoredArchs */ ['arm64']) tone-generator-1.6.1/debian/changelog000066400000000000000000000037311436025105100175450ustar00rootroot00000000000000tone-generator (1.6.1) unstable; urgency=medium * Upstream-provided Debian package for tone-generator. See upstream ChangeLog for recent changes. -- UBports developers Fri, 13 Jan 2023 13:40:32 +0100 tone-generator (1.6.0) UNRELEASED; urgency=medium [ Rodney Dawes ] * Release version 1.6.0. [ Guido Berhoerster ] * Update to dh version 12 * Use source format 3.0 (native) * Update Homepage, VCS URLs * Convert from upstart to systemd -- Rodney Dawes Thu, 20 May 2021 13:51:28 -0400 tone-generator (1.5.5+ubports) bionic; urgency=medium * Imported to UBports -- UBports auto importer Sun, 18 Feb 2018 19:19:55 +0100 tone-generator (1.5.4+15.10.20150731-0ubuntu1) wily; urgency=medium [ Tiago Salem Herrmann ] * Use phone role for busy and call waiting tones. (LP: #1476361, #1466963) -- CI Train Bot Fri, 31 Jul 2015 19:02:55 +0000 tone-generator (1.5.4+14.10.20140905-0ubuntu1) utopic; urgency=low [ Ricardo Salveti de Araujo ] * Setting up the alert role for the dtmf sound -- Ubuntu daily release Fri, 05 Sep 2014 01:19:08 +0000 tone-generator (1.5.4+14.10.20140814-0ubuntu1) utopic; urgency=low [ Ricardo Salveti de Araujo ] * Lowering default dtmf volume (LP: #1356428). Fixing vcs entries in debian/control . (LP: #1356428) -- Ubuntu daily release Thu, 14 Aug 2014 20:32:55 +0000 tone-generator (1.5.4+14.10.20140731-0ubuntu1) utopic; urgency=low [ Martti Piirainen ] * Initial release. Based on https://github.com/nemomobile/tone-generator [ Tony Espy ] * Inital version of tone-generator daemon. Forked from: https://github.com/nemomobile/tone-generator * Add initial Debian/packaging [ CI bot ] * This is a dummy commit used to seed this package for CI. -- Ubuntu daily release Thu, 31 Jul 2014 21:08:00 +0000 tone-generator-1.6.1/debian/control000066400000000000000000000023261436025105100172750ustar00rootroot00000000000000Source: tone-generator Section: sound Priority: optional Maintainer: UBports developers Build-Depends: autotools-dev, debhelper-compat (= 12), dh-autoreconf, libdbus-1-dev, libdbus-glib-1-dev, libglib2.0-dev, libpulse-dev, libtool, Standards-Version: 3.9.5 Homepage: https://gitlab.com/ubports/core/tone-generator Vcs-Git: https://gitlab.com/ubports/core/tone-generator.git Vcs-Browser: https://gitlab.com/ubports/core/tone-generator Package: tone-generator Architecture: any Depends: dbus, pulseaudio, ${misc:Depends}, ${shlibs:Depends}, Recommends: telephony-service, Description: Telephony Tone Generator (daemon) tone generator is simple daemon which provides generation of playback tones for DTMF (dialer keypad tones), call progress indication, and other miscellaneous telephony-related tones. . This package includes the core daemon. Package: tone-generator-scripts Architecture: all Depends: tone-generator (>= ${source:Version}), ${misc:Depends}, Description: Telephony Tone Generator (test scripts) tone generator is simple daemon which provides generation of playback tones for DTMF (dialer keypad tones), call progress indication, and other miscellaneous telephony-related tones. tone-generator-1.6.1/debian/copyright000066400000000000000000000020711436025105100176220ustar00rootroot00000000000000Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Source: https://launchpad.net/~phablet-team/tone-generator/ubuntu Comment: This package is a fork of: https://github.com/nemomobile/tone-generator Files: * Copyright: Copyright (C) 2010 Nokia Corporation License: LGPL-2.1 This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation version 2 of the License. . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. . You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA . On Debian systems, the complete text of the GNU Lesser General Public License can be found in `/usr/share/common-licenses/LGPL-2.1'. tone-generator-1.6.1/debian/rules000077500000000000000000000003151436025105100167460ustar00rootroot00000000000000#!/usr/bin/make -f #export DH_VERBOSE=1 CFLAGS += -Wl,-z,defs,--as-needed %: dh $@ override_dh_installsystemd: dh_installsystemd --no-stop-on-upgrade override_dh_missing: dh_missing --fail-missing tone-generator-1.6.1/debian/source/000077500000000000000000000000001436025105100171675ustar00rootroot00000000000000tone-generator-1.6.1/debian/source/format000066400000000000000000000000151436025105100203760ustar00rootroot000000000000003.0 (native) tone-generator-1.6.1/debian/tone-generator-scripts.install000066400000000000000000000000511436025105100236710ustar00rootroot00000000000000test/* /usr/share/tone-generator/scripts tone-generator-1.6.1/debian/tone-generator.install000066400000000000000000000000211436025105100222010ustar00rootroot00000000000000usr/bin/tonegend tone-generator-1.6.1/debian/tone-generator.user.service000066400000000000000000000010401436025105100231520ustar00rootroot00000000000000[Unit] Description=Tone generator daemon for call progress indication and DTMF Requires=pulseaudio.service pulseaudio.socket After=pulseaudio.socket After=graphical-session-pre.target [Service] Type=dbus BusName=com.Nokia.Telephony.Tones Environment=DTMF_VOLUME=8 Environment=TONE_STANDARD="cept" Environment=PULSE_PROP="media.role=alert" Environment=IND_PROPS="media.role=phone" ExecStart=/usr/bin/tonegend -s $TONE_STANDARD -b 100 -r 20 --volume-dtmf $DTMF_VOLUME -I $IND_PROPS Restart=always [Install] WantedBy=ubuntu-touch-session.target tone-generator-1.6.1/rpm/000077500000000000000000000000001436025105100152435ustar00rootroot00000000000000tone-generator-1.6.1/rpm/tone-generator.changes000066400000000000000000000005231436025105100215260ustar00rootroot00000000000000* Fri Nov 09 2012 Tom Swindell - 1.5 - Fixed issue in .service file for systemd startup * Tue Oct 30 2012 Tom Swindell - 1.5 - Added systemd startup file and removed packaging of xdg autostart file * Sun Jul 29 2012 Tom Swindell - 1.5 - Initial project import. tone-generator-1.6.1/rpm/tone-generator.service000066400000000000000000000006041436025105100215560ustar00rootroot00000000000000[Unit] Description=Tone generator daemon for call progress indication and DTMF Requires=dbus.socket pulseaudio.service After=pre-user-session.target [Service] ExecStart=/usr/bin/tonegend -b 100 -r 20 --volume-dtmf 15 --tag-dtmf media.role=dtmf-tone --tag-indicator media.role=indicator-tone --tag-notif media.role=notification-tone Restart=always [Install] WantedBy=user-session.target tone-generator-1.6.1/rpm/tone-generator.spec000066400000000000000000000032171436025105100210530ustar00rootroot00000000000000Name: tone-generator Summary: Tone generator daemon for call progress indication and DTMF Version: 1.5 Release: 1 Group: System/Daemons License: LGPLv2.1 URL: https://github.com/nemomobile/tone-generator Source0: %{name}-%{version}.tar.gz Source1: %{name}.service Source2: tonegend.desktop Requires: pulseaudio Requires: systemd Requires: systemd-user-session-targets BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(gobject-2.0) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libpulse) BuildRequires: pkgconfig(libpulse-mainloop-glib) %description Tone generator daemon for call progress indication and DTMF %prep %setup -q -n %{name}-%{version} %build %reconfigure --disable-static make %{?jobs:-j%jobs} %install rm -rf %{buildroot} %make_install mkdir -p %{buildroot}%{_libdir}/systemd/user/user-session.target.wants install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/user/ ln -s ../tone-generator.service %{buildroot}%{_libdir}/systemd/user/user-session.target.wants/ mkdir -p %{buildroot}/etc/xdg/autostart/ install -m 0644 %SOURCE2 %{buildroot}/etc/xdg/autostart/ %post if [ "$1" -ge 1 ]; then systemctl-user daemon-reload || : systemctl-user restart tone-generator.service || : fi %postun if [ "$1" -eq 0 ]; then systemctl-user stop tone-generator.service || : systemctl-user daemon-reload || : fi %files %defattr(-,root,root,-) /usr/bin/tonegend %config /etc/dbus-1/system.d/tone-generator.conf /usr/lib/systemd/user/%{name}.service /usr/lib/systemd/user/user-session.target.wants/%{name}.service %exclude /etc/xdg/autostart/tonegend.desktop tone-generator-1.6.1/rpm/tonegend.desktop000066400000000000000000000003331436025105100204400ustar00rootroot00000000000000[Desktop Entry] Type=Application Name=Tonegend Exec=/usr/bin/tonegend -b 100 -r 20 --volume-dtmf 50 Comment=Tone generator daemon for call progress indication and DTMF X-Moblin-Priority=Medium X-Meego-Watchdog=Restart tone-generator-1.6.1/src/000077500000000000000000000000001436025105100152345ustar00rootroot00000000000000tone-generator-1.6.1/src/Makefile.am000066400000000000000000000004511436025105100172700ustar00rootroot00000000000000AM_CFLAGS = -O0 -g3 -I$(top_srcdir)/src $(DEPS_CFLAGS) bin_PROGRAMS = tonegend tonegend_SOURCES = dbusif.c ausrv.c stream.c tone.c envelop.c indicator.c \ dtmf.c note.c rfc4733.c interact.c notification.c main.c tonegend_LDADD = $(DEPS_LIBS) -lm EXTRA_DIST = log/log.h trace/trace.h tone-generator-1.6.1/src/ausrv.c000066400000000000000000000215051436025105100165430ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include "stream.h" #include "ausrv.h" #if PA_API_VERSION < 9 #error Invalid PulseAudio API version #endif #define DISCONNECTED 0 #define CONNECTED 1 #define DEFAULT_SERVER "default Pulse Audio" #define CONNECT_DELAY 10 /* in seconds */ #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static void set_connection_status(struct ausrv *, int); static void context_callback(pa_context *, void *); static void event_callback(pa_context *, pa_subscription_event_type_t, uint32_t, void *); static void connect_server(struct ausrv *); static void restart_timer(struct ausrv *, int); static void cancel_timer(struct ausrv *); static char *pa_client_name; int ausrv_init(int argc, char **argv) { (void)argc; char *name = basename(argv[0]); pa_client_name = name ? strdup(name) : "tonegend"; return 0; } void ausrv_exit(void) { free(pa_client_name); pa_client_name = NULL; } struct ausrv *ausrv_create(struct tonegend *tonegend, char *server) { pa_glib_mainloop *mainloop = NULL; struct ausrv *ausrv; pa_mainloop_api *mainloop_api; if ((ausrv = malloc(sizeof(*ausrv))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); goto failed; } if ((mainloop = pa_glib_mainloop_new(NULL)) == NULL) { LOG_ERROR("%s(): pa_glib_mainloop_new() failed", __FUNCTION__); goto failed; } mainloop_api = pa_glib_mainloop_get_api(mainloop); if (pa_signal_init(mainloop_api) < 0) { LOG_ERROR("%s(): pa_signal_init() failed", __FUNCTION__); goto failed; } memset(ausrv, 0, sizeof(*ausrv)); ausrv->tonegend = tonegend; ausrv->server = strdup(server ? server : DEFAULT_SERVER); ausrv->mainloop = mainloop; connect_server(ausrv); return ausrv; failed: if (mainloop != NULL) pa_glib_mainloop_free(mainloop); if (ausrv != NULL) free(ausrv); return NULL; } void ausrv_destroy(struct ausrv *ausrv) { if (ausrv != NULL) { stream_kill_all(ausrv); if (ausrv->context != NULL) pa_context_unref(ausrv->context); if (ausrv->mainloop != NULL) pa_glib_mainloop_free(ausrv->mainloop); free(ausrv->server); free(ausrv); } } static void set_connection_status(struct ausrv *ausrv, int sts) { int connected = sts ? CONNECTED : DISCONNECTED; if ((ausrv->connected ^ connected)) { ausrv->connected = connected; if (connected) TRACE("Connected to '%s' server", ausrv->server); else TRACE("Disconnected from %s server", ausrv->server); } } static void context_callback(pa_context *context, void *userdata) { struct ausrv *ausrv = (struct ausrv *)userdata; int err = 0; const char *strerr; if (context == NULL) { LOG_ERROR("%s() called with zero context", __FUNCTION__); return; } if (ausrv == NULL || ausrv->context != context) { LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); return; } switch (pa_context_get_state(context)) { case PA_CONTEXT_CONNECTING: TRACE("ausrv: connecting to server"); set_connection_status(ausrv, DISCONNECTED); break; case PA_CONTEXT_AUTHORIZING: TRACE("ausrv: authorizing"); set_connection_status(ausrv, DISCONNECTED); break; case PA_CONTEXT_SETTING_NAME: TRACE("ausrv: setting name"); set_connection_status(ausrv, DISCONNECTED); break; case PA_CONTEXT_READY: TRACE("ausrv: connection established."); set_connection_status(ausrv, CONNECTED); cancel_timer(ausrv); LOG_INFO("Pulse Audio OK"); break; case PA_CONTEXT_TERMINATED: TRACE("ausrv: connection to server terminated"); goto disconnect; case PA_CONTEXT_FAILED: default: if ((err = pa_context_errno(context)) != 0) { if ((strerr = pa_strerror(err)) == NULL) strerr = ""; LOG_ERROR("ausrv: server connection failure: %s", strerr); } disconnect: set_connection_status(ausrv, DISCONNECTED); stream_kill_all(ausrv); restart_timer(ausrv, CONNECT_DELAY); } } static void event_callback(pa_context *context, pa_subscription_event_type_t type, uint32_t idx, void *userdata) { struct ausrv *ausrv = (struct ausrv *)userdata; (void)idx; if (ausrv == NULL || ausrv->context != context) LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); else { switch (type) { case PA_SUBSCRIPTION_EVENT_SINK: TRACE("Event sink"); break; case PA_SUBSCRIPTION_EVENT_SOURCE: TRACE("Event source"); break; case PA_SUBSCRIPTION_EVENT_SINK_INPUT: TRACE("Event sink input"); break; case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT: TRACE("Event source output"); break; default: TRACE("Event %d", type); break; } } } static void retry_connect(pa_mainloop_api *api, pa_time_event *event, const struct timeval *tv, void *data) { struct ausrv *ausrv = (struct ausrv *)data; (void)api; (void)tv; if (event != ausrv->timer) { LOG_ERROR("%s(): Called with unknown timer (%p != %p)", __FUNCTION__, event, ausrv->timer); return; } ausrv->timer = NULL; connect_server(ausrv); } static void restart_timer(struct ausrv *ausrv, int secs) { pa_mainloop_api *api = pa_glib_mainloop_get_api(ausrv->mainloop); struct timeval tv; gettimeofday(&tv, NULL); tv.tv_sec += secs; if (ausrv->timer != NULL) api->time_restart(ausrv->timer, &tv); else ausrv->timer = api->time_new(api, &tv, retry_connect, (void *)ausrv); } static void cancel_timer(struct ausrv *ausrv) { pa_mainloop_api *api; if (ausrv->timer != NULL) { api = pa_glib_mainloop_get_api(ausrv->mainloop); api->time_free(ausrv->timer); ausrv->timer = NULL; } } static void connect_server(struct ausrv *ausrv) { pa_mainloop_api *api = pa_glib_mainloop_get_api(ausrv->mainloop); char *server = ausrv->server; cancel_timer(ausrv); if (server != NULL && !strcmp(ausrv->server, DEFAULT_SERVER)) server = NULL; /* * Note: It is not possible to reconnect a context if it ever gets * disconnected. If we have a context here, get rid of it and * allocate a new one. */ if (ausrv->context != NULL) { pa_context_set_state_callback(ausrv->context, NULL, NULL); pa_context_set_subscribe_callback(ausrv->context, NULL, NULL); pa_context_unref(ausrv->context); ausrv->context = NULL; } if ((ausrv->context = pa_context_new(api, pa_client_name)) == NULL) { LOG_ERROR("%s(): pa_context_new() failed, exiting", __FUNCTION__); exit(1); } pa_context_set_state_callback(ausrv->context, context_callback, ausrv); pa_context_set_subscribe_callback(ausrv->context, event_callback, ausrv); LOG_INFO("Trying to connect to %s...", server ? server : DEFAULT_SERVER); pa_context_connect(ausrv->context, server, PA_CONTEXT_NOAUTOSPAWN, NULL); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/ausrv.h000066400000000000000000000031541436025105100165500ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_AUSRV_H__ #define __TONEGEND_AUSRV_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include #include struct tonegend; struct stream; struct ausrv { struct tonegend *tonegend; char *server; int connected; pa_glib_mainloop *mainloop; pa_context *context; pa_time_event *timer; int nextid; struct stream *streams; }; int ausrv_init(int, char **); void ausrv_exit(void); struct ausrv *ausrv_create(struct tonegend *, char *); void ausrv_destroy(struct ausrv *); #endif /* __TONEGEND_AUSRV_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/dbusif.c000066400000000000000000000202541436025105100166570ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include "tonegend.h" #include "dbusif.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static DBusHandlerResult handle_message(DBusConnection *,DBusMessage *,void *); static gchar *create_key(gchar *, gchar *, gchar *); static void destroy_key(gpointer); static char *path = "/com/Nokia/Telephony/Tones"; static char *service = "com.Nokia.Telephony.Tones"; int dbusif_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void dbsuif_exit(void) { } struct dbusif *dbusif_create(struct tonegend *tonegend) { static struct DBusObjectPathVTable method = { .message_function = &handle_message }; struct dbusif *dbusif = NULL; DBusConnection *conn = NULL; DBusError err; int ret; if ((dbusif = (struct dbusif *)malloc(sizeof(*dbusif))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); goto failed; } memset(dbusif, 0, sizeof(*dbusif)); dbus_error_init(&err); if ((conn = dbus_bus_get(DBUS_BUS_SESSION, &err)) == NULL) { LOG_ERROR("%s(): Can't connect to D-Bus daemon: %s", __FUNCTION__, err.message); dbus_error_free(&err); goto failed; } /* * The following will make us zombie if the system bus goes down. * However, for 'clean' shutdown operation it is useful, ie. the * shutdown sequence should not assure that we go before D-Bus go */ dbus_connection_set_exit_on_disconnect(conn, FALSE); dbus_connection_setup_with_g_main(conn, NULL); if (!dbus_connection_register_object_path(conn, path, &method, dbusif)) { LOG_ERROR("%s(): failed to register object path", __FUNCTION__); goto failed; } ret = dbus_bus_request_name(conn, service, DBUS_NAME_FLAG_REPLACE_EXISTING, &err); if (ret < 0) { LOG_ERROR("%s(): request name failed: %s", __FUNCTION__, err.message); dbus_error_free(&err); goto failed; } if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { LOG_ERROR("%s(): not a primary owner", __FUNCTION__); goto failed; } dbusif->tonegend = tonegend; dbusif->conn = conn; dbusif->hash = g_hash_table_new_full(g_str_hash, g_str_equal, destroy_key, NULL); LOG_INFO("D-Bus setup OK"); return dbusif; failed: if (dbusif != NULL) free(dbusif); return NULL; } void dbusif_destroy(struct dbusif *dbusif) { if (dbusif) { if (dbusif->hash != NULL) g_hash_table_destroy(dbusif->hash); free(dbusif); } } int dbusif_register_input_method(struct tonegend *tonegend, char *intf, char *memb, char *sig, int (*method)(DBusMessage*, struct tonegend*)) { struct dbusif *dbusif = tonegend->dbus_ctx; gchar *key; if (!memb || !sig || !method) { LOG_ERROR("%s(): Called with invalid argument(s)", __FUNCTION__); errno = EINVAL; return -1; } if (intf == NULL) intf = service; key = create_key((gchar *)memb, (gchar *)sig, (gchar *)intf); g_hash_table_insert(dbusif->hash, key, (gpointer)method); return 0; } int dbusif_unregister_input_method(struct tonegend *tonegend, char *intf, char *memb, char *sign) { (void)tonegend; (void)intf; (void)memb; (void)sign; return 0; } int dbusif_send_signal(struct tonegend *tonegend, char *intf, char *name, int first_arg_type, ...) { struct dbusif *dbusif = tonegend->dbus_ctx; DBusMessage *msg; va_list ap; int success; do { /* not a loop */ success = FALSE; if (name == NULL) { LOG_ERROR("%s(): Called with invalid argument", __FUNCTION__); errno = EINVAL; break; } if (intf == NULL) intf = service; if ((msg = dbus_message_new_signal(path, intf, name)) == NULL) { errno = ENOMEM; break; } va_start(ap, first_arg_type); if (dbus_message_append_args_valist(msg, first_arg_type, ap)) { success = dbus_connection_send(dbusif->conn, msg, NULL); } va_end(ap); dbus_message_unref(msg); } while(FALSE); return success ? 0 : -1; } static DBusHandlerResult handle_message(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct dbusif *dbusif = (struct dbusif *)user_data; struct tonegend *tonegend = dbusif->tonegend; DBusMessage *reply = NULL; uint32_t ser; int (*method)(DBusMessage *, struct tonegend *); const char *intf; const char *memb; const char *sig; gchar *key; const char *errname; char errdesc[256]; int success; (void)conn; if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_METHOD_CALL) TRACE("%s(): ignoring non method_call's", __FUNCTION__); else { intf = dbus_message_get_interface(msg); memb = dbus_message_get_member(msg); sig = dbus_message_get_signature(msg); ser = dbus_message_get_serial(msg); #if 0 TRACE("%s(): message no #%u received: '%s', '%s', '%s'", __FUNCTION__, ser, intf, memb, sig); #endif key = create_key((gchar *)memb, (gchar *)sig, (gchar *)intf); method = g_hash_table_lookup(dbusif->hash, key); g_free(key); success = method ? method(msg, tonegend) : FALSE; if (success) reply = dbus_message_new_method_return(msg); else { if (method) { errname = DBUS_ERROR_FAILED; snprintf(errdesc, sizeof(errdesc), "Internal error"); } else { errname = DBUS_ERROR_NOT_SUPPORTED; snprintf(errdesc, sizeof(errdesc), "Method '%s(%s)' " "not supported", memb, sig); } reply = dbus_message_new_error(msg, errname, errdesc); } dbus_message_set_reply_serial(msg, ser); if (!dbus_connection_send(dbusif->conn, reply, NULL)) LOG_ERROR("%s(): D-Bus message reply failure", __FUNCTION__); #if 0 else TRACE("%s(): message no #%u replied", __FUNCTION__, ser); #endif dbus_message_unref(reply); } return DBUS_HANDLER_RESULT_HANDLED; } static gchar *create_key(gchar *memb, gchar *sign, gchar *intf) { gchar *key = NULL; if (memb == NULL) memb = ""; if (sign == NULL) sign = ""; if (intf == NULL) intf = ""; key = g_strconcat(memb, "__", sign, "__", intf, NULL); return key; } static void destroy_key(gpointer key) { g_free(key); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/dbusif.h000066400000000000000000000033761436025105100166720ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_DBUSIF_H__ #define __TONEGEND_DBUSIF_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include #include #include struct tonegend; struct dbusif { struct tonegend *tonegend; DBusConnection *conn; GHashTable *hash; }; int dbusif_init(int, char **); void dbusif_exit(void); struct dbusif *dbusif_create(struct tonegend *); void dbusif_destroy(struct dbusif *); int dbusif_register_input_method(struct tonegend *, char *, char *, char *, int (*)(DBusMessage *, struct tonegend *)); int dbusif_unregister_input_method(struct tonegend *, char *, char *, char *); int dbusif_send_signal(struct tonegend *, char *, char *, int, ...); #endif /* __TONEGEND_DBUSIF_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/dtmf.c000066400000000000000000000153051436025105100163360ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include "ausrv.h" #include "stream.h" #include "tone.h" #include "indicator.h" #include "dtmf.h" #include "dbusif.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) #define MUTE_ON 1 #define MUTE_OFF 0 struct dtmf { char symbol; uint32_t low_freq; uint32_t high_freq; }; static struct dtmf dtmf_defs[DTMF_MAX] = { {'0', 941, 1336}, {'1', 697, 1209}, {'2', 697, 1336}, {'3', 697, 1477}, {'4', 770, 1209}, {'5', 770, 1336}, {'6', 770, 1477}, {'7', 852, 1209}, {'8', 852, 1336}, {'9', 852, 1477}, {'*', 941, 1209}, {'#', 941, 1477}, {'A', 697, 1633}, {'B', 770, 1633}, {'C', 852, 1633}, {'D', 941, 1633} }; static char *dtmf_stream = STREAM_DTMF; static void *dtmf_props = NULL; static int vol_scale = 100; static int mute = MUTE_OFF; static guint tmute_id; static void destroy_callback(void *); static void set_mute_timeout(struct ausrv *, guint); static gboolean mute_timeout_callback(gpointer); static void request_muting(struct ausrv *, dbus_bool_t); int dtmf_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void dtmf_play(struct ausrv *ausrv, uint type, uint32_t vol, int dur) { struct stream *stream = stream_find(ausrv, dtmf_stream); struct dtmf *dtmf = dtmf_defs + type; uint32_t per = dur; uint32_t play = dur > 60000 ? dur - 20000 : dur; int type_l = TONE_DTMF_L; int type_h = TONE_DTMF_H; uint32_t timeout; if (type >= DTMF_MAX || (dur != 0 && dur < 10000)) return; if (!dur) { /* * These types will make the DTMF tone as 'indicator' * i.e. the indicator_stop() will work on them */ type_l = TONE_DTMF_IND_L; type_h = TONE_DTMF_IND_H; per = play = 1000000; } if (stream != NULL) { if (!dur) { indicator_stop(ausrv, KILL_STREAM); dtmf_stop(ausrv); } } else { stream = stream_create(ausrv, dtmf_stream, NULL, 0, tone_write_callback, destroy_callback, dtmf_props, NULL); if (stream == NULL) { LOG_ERROR("%s(): Can't create stream", __FUNCTION__); return; } } vol = (vol_scale * vol) / 100; tone_create(stream, type_l, dtmf->low_freq , vol/2, per,play, 0,dur); tone_create(stream, type_h, dtmf->high_freq, vol/2, per,play, 0,dur); timeout = dur ? dur + (30 * 1000000) : (1 * 60 * 1000000); stream_set_timeout(stream, timeout); request_muting(ausrv, MUTE_ON); set_mute_timeout(ausrv, 0); } void dtmf_stop(struct ausrv *ausrv) { struct stream *stream = stream_find(ausrv, dtmf_stream); struct tone *tone; struct tone *next; TRACE("%s() stream=%s", __FUNCTION__, stream ? stream->name:""); if (stream != NULL) { for (tone = (struct tone *)stream->data; tone; tone = next) { next = tone->next; switch (tone->type) { case TONE_DTMF_IND_L: case TONE_DTMF_IND_H: /* in the future a linear ramp-down enevlop can be set */ tone_destroy(tone, KILL_CHAIN); break; default: if (!tone_chainable(tone->type)) tone_destroy(tone, KILL_CHAIN); break; } } if (stream->data == NULL) stream_clean_buffer(stream); stream_set_timeout(stream, 10 * 1000000); set_mute_timeout(ausrv, 2 * 1000000); } } void dtmf_set_properties(char *propstring) { dtmf_props = stream_parse_properties(propstring); } void dtmf_set_volume(uint32_t volume) { vol_scale = volume; } static void destroy_callback(void *data) { struct tone *tone = (struct tone *)data; struct stream *stream; struct ausrv *ausrv; set_mute_timeout(NULL, 0); if (mute && tone != NULL) { stream = tone->stream; ausrv = stream->ausrv; request_muting(ausrv, MUTE_OFF); mute = MUTE_OFF; } tone_destroy_callback(data); } static void set_mute_timeout(struct ausrv *ausrv, guint interval) { if (interval) TRACE("add %d usec mute timeout", interval); else if (tmute_id) TRACE("remove mute timeout"); if (tmute_id != 0) { g_source_remove(tmute_id); tmute_id = 0; } if (interval > 0 && ausrv != NULL) { tmute_id = g_timeout_add(interval/1000, mute_timeout_callback, ausrv); } } static gboolean mute_timeout_callback(gpointer data) { struct ausrv *ausrv = (struct ausrv *)data; TRACE("mute timeout fired"); request_muting(ausrv, MUTE_OFF); tmute_id = 0; return FALSE; } static void request_muting(struct ausrv *ausrv, dbus_bool_t new_mute) { int sts; new_mute = new_mute ? MUTE_ON : MUTE_OFF; if (ausrv != NULL && mute != new_mute) { sts = dbusif_send_signal(ausrv->tonegend, NULL, "Mute", DBUS_TYPE_BOOLEAN, &new_mute, DBUS_TYPE_INVALID); if (sts != 0) LOG_ERROR("failed to send mute signal"); else { TRACE("sent signal to turn mute %s", new_mute ? "on" : "off"); mute = new_mute; } } } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/dtmf.h000066400000000000000000000033331436025105100163410ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_DTMF_H__ #define __TONEGEND_DTMF_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #define DTMF_0 0 #define DTMF_1 1 #define DTMF_2 2 #define DTMF_3 3 #define DTMF_4 4 #define DTMF_5 5 #define DTMF_6 6 #define DTMF_7 7 #define DTMF_8 8 #define DTMF_9 9 #define DTMF_ASTERISK 10 #define DTMF_HASHMARK 11 #define DTMF_A 12 #define DTMF_B 13 #define DTMF_C 14 #define DTMF_D 15 #define DTMF_MAX 16 int dtmf_init(int, char **); void dtmf_play(struct ausrv *, uint, uint32_t, int); void dtmf_stop(struct ausrv *); void dtmf_set_properties(char *); void dtmf_set_volume(uint32_t); #endif /* __TONEGEND_DTMF_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/envelop.c000066400000000000000000000111531436025105100170510ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #include #include #include #include #include #include #include #include "envelop.h" #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static inline union envelop *ramp_create(int type, uint32_t length, uint32_t start, uint32_t end) { union envelop *envelop; struct envelop_ramp *ramp; struct envelop_ramp_def *up; struct envelop_ramp_def *down; if ((envelop = malloc(sizeof(struct envelop_ramp))) != NULL) { ramp = &envelop->ramp; up = &ramp->up; down = &ramp->down; memset(ramp, 0, sizeof(*ramp)); ramp->type = type; up->k1 = 100; up->k2 = length / up->k1; up->start = start; up->end = start + length; if (end < start + (length * 2)) { down->k1 = 1; down->k2 = 1; down->start = -1; down->end = -1; } else { down->k1 = 100; down->k2 = length / down->k1; down->start = end - length; down->end = end; } } return envelop; } static inline void ramp_update(union envelop *envelop, uint32_t length, uint32_t end) { struct envelop_ramp_def *down = &envelop->ramp.down; down->k1 = 100; down->k2 = length / down->k1; down->start = end - length; down->end = end; } static inline void ramp_destroy(union envelop *envelop) { (void) envelop; } static inline int32_t ramp_apply(union envelop *envelop, int32_t in,uint32_t t) { struct envelop_ramp_def *up = &envelop->ramp.up; struct envelop_ramp_def *down = &envelop->ramp.down; int32_t k3; if (t > up->start && t < up->end) { k3 = (int32_t)(t - up->start) / up->k1; return (in * k3) / up->k2; } if (t > down->start && t < down->end) { k3 = (int32_t)(down->end -t) / down->k1; return (in * k3) / down->k2; } return in; } int envelop_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } union envelop *envelop_create(int type, uint32_t length, uint32_t start, uint32_t end) { union envelop *env = NULL; switch (type) { case ENVELOP_RAMP_LINEAR: env = ramp_create(type, length, start, end); break; default: break; } return env; } void envelop_update(union envelop *envelop, uint32_t length, uint32_t end) { if (envelop != NULL) { switch (envelop->type) { case ENVELOP_RAMP_LINEAR: ramp_update(envelop, length, end); break; default: break; } } } void envelop_destroy(union envelop *envelop) { if (envelop != NULL) { switch (envelop->type) { case ENVELOP_RAMP_LINEAR: ramp_destroy(envelop); break; default: break; } free(envelop); } } int32_t envelop_apply(union envelop *envelop, int32_t in, uint32_t t) { uint32_t out = in; if (envelop != NULL) { switch (envelop->type) { case ENVELOP_RAMP_LINEAR: out = ramp_apply(envelop, in, t); break; default: out = in; break; } } return out; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/envelop.h000066400000000000000000000034651436025105100170650ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_ENVELOP_H__ #define __TONEGEND_ENVELOP_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #define ENVELOP_UNKNOWN 0 #define ENVELOP_RAMP_LINEAR 1 struct envelop_ramp_def { int32_t k1; int32_t k2; uint32_t start; uint32_t end; }; struct envelop_ramp { int type; /* must be ENVELOP_RAMP_xxx */ struct envelop_ramp_def up; /* ramp-up */ struct envelop_ramp_def down; /* ramp-down */ }; union envelop { int type; struct envelop_ramp ramp; }; int envelop_init(int, char **); union envelop *envelop_create(int, uint32_t, uint32_t, uint32_t); void envelop_update(union envelop *, uint32_t, uint32_t); void envelop_destroy(union envelop *); int32_t envelop_apply(union envelop *, int32_t, uint32_t); #endif /* __TONEGEND_ENVELOP_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/indicator.c000066400000000000000000000204621436025105100173600ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include "ausrv.h" #include "stream.h" #include "tone.h" #include "indicator.h" #define MAX_TONE_LENGTH (1 * 60 * 1000000) /* Special case for shorter tones, because we don't want to keep a silent * stream around for a long time after playing the actual tone. */ #define MAX_SHORT_TONE_LENGTH (1 * 5 * 1000000) #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static char *ind_stream = STREAM_INDICATOR; static int standard = STD_CEPT; static void *ind_props = NULL; static uint32_t vol_scale = 100; int indicator_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void indicator_play(struct ausrv *ausrv, int type, uint32_t vol, int dur) { struct stream *stream = stream_find(ausrv, ind_stream); uint32_t timeout = dur ? dur : MAX_TONE_LENGTH; if (stream != NULL) { dtmf_stop(ausrv); indicator_stop(ausrv, PRESERVE_STREAM); } else { stream = stream_create(ausrv, ind_stream, NULL, 0, tone_write_callback, tone_destroy_callback, ind_props, NULL); if (stream == NULL) { LOG_ERROR("%s(): Can't create stream", __FUNCTION__); return; } } vol = (vol_scale * vol) / 100; switch (type) { case TONE_DIAL: switch (standard) { case STD_CEPT: tone_create(stream, type, 425, vol, 1000000, 1000000, 0,0); break; case STD_ANSI: case STD_ATNT: tone_create(stream, type, 350, (vol*7)/10, 1000000, 1000000, 0,0); tone_create(stream, type, 440, (vol*7)/10, 1000000, 1000000, 0,0); break; case STD_JAPAN: tone_create(stream, type, 400, vol, 1000000, 1000000, 0,0); break; } timeout = MAX_TONE_LENGTH; break; case TONE_BUSY: switch (standard) { case STD_CEPT: tone_create(stream, type, 425, vol, 1000000, 500000, 0,dur); break; case STD_ANSI: case STD_ATNT: tone_create(stream, type, 480, (vol*7)/10, 1000000, 500000, 0,dur); tone_create(stream, type, 620, (vol*7)/10, 1000000, 500000, 0,dur); break; case STD_JAPAN: tone_create(stream, type, 400, vol, 1000000, 500000, 0,dur); break; } break; case TONE_CONGEST: switch (standard) { case STD_CEPT: tone_create(stream, type, 425, vol, 400000, 200000, 0,dur); break; case STD_ANSI: case STD_ATNT: tone_create(stream, type, 480, (vol*7)/10, 500000, 250000, 0,dur); tone_create(stream, type, 620, (vol*7)/10, 500000, 250000, 0,dur); break; case STD_JAPAN: /* * this is non-standard, but * we play busy tone instead of being silent */ tone_create(stream, type, 400, vol, 1000000, 500000, 0,dur); break; } break; case TONE_RADIO_ACK: switch (standard) { case STD_CEPT: case STD_ANSI: case STD_ATNT: tone_create(stream, type, 425, vol, 200000, 200000, 0,200000); timeout = MAX_SHORT_TONE_LENGTH; break; case STD_JAPAN: tone_create(stream, type, 400, vol, 3000000, 1000000, 0,0); /* The Japan standard tone is repeating, so I guess we need to wait 60s anyway. */ timeout = MAX_TONE_LENGTH; break; } break; case TONE_RADIO_NA: switch (standard) { case STD_CEPT: case STD_ANSI: case STD_ATNT: tone_create(stream, type, 425, vol, 400000, 200000, 0,1200000); break; case STD_JAPAN: break; } timeout = MAX_SHORT_TONE_LENGTH; break; case TONE_ERROR: switch (standard) { case STD_CEPT: case STD_ANSI: case STD_ATNT: tone_create(stream, type, 900, vol, 2000000, 333333, 0,dur); tone_create(stream, type, 1400, vol, 2000000, 332857, 333333,dur); tone_create(stream, type, 1800, vol, 2000000, 300000, 666190,dur); break; case STD_JAPAN: /* * this is non-standard, but * we play busy tone instead of being silent */ tone_create(stream, type, 400, vol, 1000000, 500000, 0,dur); break; } break; case TONE_WAIT: switch (standard) { case STD_CEPT: tone_create(stream,type, 425, vol, 800000,200000, 0,1000000); tone_create(stream,type, 425, vol, 800000,200000, 4000000,1000000); break; case STD_ANSI: tone_create(stream,type, 440, vol, 300000,300000, 0,300000); tone_create(stream,type, 440, vol, 10000000,100000, 10000000,0); tone_create(stream,type, 440, vol, 10000000,100000, 10200000,0); break; case STD_ATNT: tone_create(stream, type, 440, vol, 4000000, 200000, 0, 0); tone_create(stream, type, 440, vol, 4000000, 200000, 500000, 0); break; case STD_JAPAN: break; } timeout = MAX_TONE_LENGTH; break; case TONE_RING: switch (standard) { case STD_CEPT: tone_create(stream, type, 425, vol, 5000000, 1000000, 0,0); break; case STD_ANSI: case STD_ATNT: tone_create(stream, type, 440, (vol*7)/10, 6000000, 2000000, 0,0); tone_create(stream, type, 480, (vol*7)/10, 6000000, 2000000, 0,0); break; case STD_JAPAN: break; } timeout = MAX_TONE_LENGTH; break; default: LOG_ERROR("%s(): invalid type %d", __FUNCTION__, type); break; } stream_set_timeout(stream, timeout); } void indicator_stop(struct ausrv *ausrv, int kill_stream) { struct stream *stream = stream_find(ausrv, ind_stream); struct tone *tone; struct tone *hd; TRACE("%s(kill_stream=%s) stream=%s", __FUNCTION__, kill_stream ? "true":"false", stream ? stream->name:""); if (stream != NULL) { if (kill_stream) stream_destroy(stream); else { /* destroy all but DTMF tones */ for (hd = (struct tone *)&stream->data; hd; hd = hd->next) { while ((tone=hd->next) != NULL && !tone_chainable(tone->type)) tone_destroy(tone, KILL_CHAIN); } } } } void indicator_set_standard(int std) { if (std <= STD_UNKNOWN || std >= STD_MAX) LOG_ERROR("%s(): invalid standard %d", __FUNCTION__, std); else standard = std; } void indicator_set_properties(char *propstring) { ind_props = stream_parse_properties(propstring); } void indicator_set_volume(uint32_t volume) { vol_scale = volume; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/indicator.h000066400000000000000000000031231436025105100173600ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_INDICATOR_H__ #define __TONEGEND_INDICATOR_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #define PRESERVE_STREAM 0 #define KILL_STREAM 1 #define STD_UNKNOWN 0 #define STD_CEPT 1 #define STD_ANSI 2 #define STD_JAPAN 3 #define STD_ATNT 4 #define STD_MAX 5 int indicator_init(int, char **); void indicator_play(struct ausrv *, int, uint32_t, int); void indicator_stop(struct ausrv *, int); void indicator_set_standard(int); void indicator_set_properties(char *); void indicator_set_volume(uint32_t); #endif /* __TONEGEND_INDICATOR_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/interact.c000066400000000000000000000147431436025105100172220ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include #include "tonegend.h" #include "ausrv.h" #include "tone.h" #include "indicator.h" #include "dtmf.h" #include "interact.h" #define DISCONNECTED 0 #define CONNECTED 1 #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static gboolean handle_input(GIOChannel *, GIOCondition, gpointer); /********************* Temporary *************************/ #include "note.h" static void ringtone(struct ausrv *ausrv) { struct ndef {int dur; int note;}; static struct ndef ndef[] = { {32, NOTE_PAUSE}, {8, NOTE_G}, {8, NOTE_PAUSE}, {16, NOTE_Ab}, {8, NOTE_PAUSE}, {16, NOTE_G}, {16, NOTE_PAUSE}, {16, NOTE_G}, {8, NOTE_C}, {8, NOTE_G}, {8, NOTE_F}, {8, NOTE_G}, {8, NOTE_PAUSE}, {16, NOTE_D}, {0, 0} }; /*8p,16g,16p,16g,8d#6,8d6,8a#,8g,8d6,8g6, 16g,16f,16p,16f,8d,8a#,2g,p,SS,16f6,8d6,8c6,8a#,g,8a#.,16g, 16p,16g,8c6,8g,8f,g,8d.6,16g,16p,16g,8d#6,8d6,8a#,8g,8d6, 8g6,16g,16f,16p,16f,8d,8a#,2g*/ struct ndef *nd; for (nd = ndef; nd->dur; nd++) { note_play(ausrv, nd->note, 5, 30, 1, nd->dur, 60, 0); } } /****************** End of Temporary *********************/ int interact_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } struct interact *interact_create(struct tonegend *tonegend, int fd) { struct interact *interact = NULL; if ((interact = (struct interact *)malloc(sizeof(*interact))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); goto failed; } memset(interact, 0, sizeof(*interact)); interact->tonegend = tonegend; if ((interact->chan = g_io_channel_unix_new(fd)) == NULL) { LOG_ERROR("%s(): Can't make G-I/O channel", __FUNCTION__); goto failed; } interact->evsrc = g_io_add_watch(interact->chan, G_IO_IN|G_IO_HUP|G_IO_ERR, handle_input, interact); return interact; failed: if (interact != NULL) { free(interact); } return NULL; } void interact_destroy(struct interact *interact) { if (interact) { g_io_channel_shutdown(interact->chan, TRUE, NULL); g_io_channel_unref(interact->chan); g_source_remove(interact->evsrc); free(interact); } } static gboolean handle_input(GIOChannel *ch, GIOCondition cond, gpointer data) { #define PRINT(f, args...) printf(f "\n", ##args) #define TONE(t) indicator_play(ausrv, t, 95, 0) #define STOP indicator_stop(ausrv, KILL_STREAM) #define STANDARD(s) indicator_set_standard(STD_##s) #define DTMF(t) dtmf_play(ausrv, DTMF_##t, 100, 300000) struct interact *interact = (struct interact *)data; struct tonegend *tonegend = interact->tonegend; struct ausrv *ausrv = tonegend->ausrv_ctx; int cnt; char cmd; (void)ch; (void)cond; for (;;) { if ((cnt = read(0, &cmd, 1)) != 1) { if (errno == EINTR) continue; else return FALSE; } switch (cmd) { case 'D': PRINT("Dial tone"); TONE(TONE_DIAL); break; case 'B': PRINT("Busy tone"); TONE(TONE_BUSY); break; case 'C': PRINT("Cong.tone"); TONE(TONE_CONGEST); break; case 'A': PRINT("Radio Ack. tone"); TONE(TONE_RADIO_ACK); break; case 'N': PRINT("Radio N/A tone"); TONE(TONE_RADIO_NA); break; case 'E': PRINT("Error tone"); TONE(TONE_ERROR); break; case 'W': PRINT("Wait tone"); TONE(TONE_WAIT); break; case 'R': PRINT("Ring tone"); TONE(TONE_RING); break; case 'S': PRINT("Stop tone"); STOP; break; case '0': PRINT("DTMF: 0"); DTMF(0); break; case '1': PRINT("DTMF: 1"); DTMF(1); break; case '2': PRINT("DTMF: 2"); DTMF(2); break; case '3': PRINT("DTMF: 3"); DTMF(3); break; case '4': PRINT("DTMF: 4"); DTMF(4); break; case '5': PRINT("DTMF: 5"); DTMF(5); break; case '6': PRINT("DTMF: 6"); DTMF(6); break; case '7': PRINT("DTMF: 7"); DTMF(7); break; case '8': PRINT("DTMF: 8"); DTMF(8); break; case '9': PRINT("DTMF: 9"); DTMF(9); break; case '*': PRINT("DTMF: *"); DTMF(ASTERISK); break; case '#': PRINT("DTMF: #"); DTMF(HASHMARK); break; case 'a': PRINT("ANSI standard"); STANDARD(ANSI); break; case 'e': PRINT("EU standard"); STANDARD(CEPT); break; case 'j': PRINT("Japan standard"); STANDARD(JAPAN); break; case '!': PRINT("Play ..."); ringtone(ausrv); break; default: break; } return TRUE; } #undef DTMF #undef STANDARD #undef STOP #undef TONE #undef PRINT } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/interact.h000066400000000000000000000026071436025105100172230ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_INTERACT_H__ #define __TONEGEND_INTERACT_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include struct tonegend; struct interact { struct tonegend *tonegend; GIOChannel *chan; guint evsrc; }; int interact_init(int, char **); void interact_destroy(struct interact *); struct interact *interact_create(struct tonegend *, int); #endif /* __TONEGEND_INTERACT_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/log/000077500000000000000000000000001436025105100160155ustar00rootroot00000000000000tone-generator-1.6.1/src/log/log.h000066400000000000000000000023341436025105100167510ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __NOTIF_LOG_H__ #define __NOTIF_LOG_H__ #include #define log_error(c, f, args...) printf(f "\n", ##args) #define log_info(c, f, args...) printf(f "\n", ##args) #define log_warning(c, f, args...) printf(f "\n", ##args) #endif /* __NOTIF_LOG_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/main.c000066400000000000000000000271751436025105100163400ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tonegend.h" #include "dbusif.h" #include "ausrv.h" #include "stream.h" #include "tone.h" #include "envelop.h" #include "indicator.h" #include "dtmf.h" #include "note.h" #include "rfc4733.h" #include "notification.h" #include "interact.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) struct cmdopt { int daemon; /* */ int uid; char *path; int standard; int interactive; int sample_rate; int statistics; int buflen; int minreq; char *dtmf_tags; char *notif_tags; char *ind_tags; uint32_t dtmf_volume; uint32_t notif_volume; uint32_t ind_volume; }; static void usage(int, char **, int); static void parse_options(int, char **, struct cmdopt *); static void signal_handler(int, siginfo_t *, void *); static int daemonize(uid_t uid, const char *path); static char *pa_server_name; static GMainLoop *main_loop; int main(int argc, char **argv) { struct sigaction sa; struct tonegend tonegend; struct cmdopt cmdopt; cmdopt.daemon = 0; cmdopt.uid = -1; cmdopt.path = NULL; cmdopt.standard = STD_CEPT; cmdopt.interactive = 0; cmdopt.sample_rate = 48000; cmdopt.statistics = 0; cmdopt.buflen = 0; cmdopt.minreq = 0; cmdopt.dtmf_tags = NULL; cmdopt.ind_tags = NULL; cmdopt.notif_tags = NULL; cmdopt.dtmf_volume = 100; cmdopt.ind_volume = 100; cmdopt.notif_volume = 100; parse_options(argc, argv, &cmdopt); memset(&tonegend, 0, sizeof(tonegend)); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = signal_handler; sa.sa_flags = SA_SIGINFO; if (sigaction(SIGHUP , &sa, NULL) < 0 || sigaction(SIGTERM, &sa, NULL) < 0 || sigaction(SIGINT , &sa, NULL) < 0 ) { LOG_ERROR("Failed to install signal handlers"); return errno; } if (dbusif_init(argc, argv) < 0 || ausrv_init(argc, argv) < 0 || stream_init(argc, argv) < 0 || tone_init(argc, argv) < 0 || envelop_init(argc, argv) < 0 || indicator_init(argc, argv) < 0 || dtmf_init(argc, argv) < 0 || note_init(argc, argv) < 0 || interact_init(argc, argv) < 0 || rfc4733_init(argc, argv) < 0 || notif_init(argc, argv) < 0) { LOG_ERROR("Error during initialization"); return EINVAL; } stream_set_default_samplerate(cmdopt.sample_rate); stream_print_statistics(cmdopt.statistics); stream_buffering_parameters(cmdopt.buflen, cmdopt.minreq); dtmf_set_properties(cmdopt.dtmf_tags); indicator_set_properties(cmdopt.ind_tags); notif_set_properties(cmdopt.notif_tags); dtmf_set_volume(cmdopt.dtmf_volume); indicator_set_volume(cmdopt.ind_volume); notif_set_volume(cmdopt.notif_volume); if (cmdopt.daemon) daemonize(cmdopt.uid, cmdopt.path); if ((main_loop = g_main_loop_new(NULL, FALSE)) == NULL) { LOG_ERROR("Can't create main loop"); return EIO; } if ((tonegend.dbus_ctx = dbusif_create(&tonegend)) == NULL) { LOG_ERROR("D-Bus setup failed"); return EIO; } if ((tonegend.ausrv_ctx = ausrv_create(&tonegend,pa_server_name)) == NULL){ LOG_ERROR("Pulse Audio setup failed"); return EIO; } if (rfc4733_create(&tonegend) < 0) { LOG_ERROR("Can't setup rfc4733 interface on D-Bus"); return EIO; } if (notif_create(&tonegend) < 0) { LOG_ERROR("Can't setup notification interface on D-Bus"); return EIO; } if (!cmdopt.daemon && cmdopt.interactive) { if (!(tonegend.intact_ctx = interact_create(&tonegend,fileno(stdin)))){ LOG_ERROR("Can't setup interactive console"); return EIO; } printf("Running in interactive mode\n"); } indicator_set_standard(cmdopt.standard); g_main_loop_run(main_loop); LOG_INFO("Exiting now ..."); ausrv_destroy(tonegend.ausrv_ctx); dbusif_destroy(tonegend.dbus_ctx); interact_destroy(tonegend.intact_ctx); if (main_loop != NULL) g_main_loop_unref(main_loop); ausrv_exit(); return 0; } static void usage(int argc, char **argv, int exit_code) { (void)argc; printf("usage: %s [-h] [-d] [-u username] " "[-s {cept | ansi | japan | atnt }] " "[-b buflen_in_ms] [-r min_req_time_in_ms] [-i] [-8] [-S] " "[--tag-dtmf tags] [--tag-indicator tags] [--tag-notif tags] " "[--volume-dtmf volume] [--volume-indicator volume] " "[--volume-notif volume]" "\n", basename(argv[0])); exit(exit_code); } static uint32_t parse_volume(char *volstr) { char *end; uint32_t vol; vol = strtoul(volstr, &end, 10); if (*end) { LOG_ERROR("%s(): ignoring invalid volume '%s'", __FUNCTION__, volstr); return (uint32_t)100; } return vol; } static void parse_options(int argc, char **argv, struct cmdopt *cmdopt) { struct option options[] = { { "help" , no_argument , NULL, 'h' }, { "daemon" , no_argument , NULL, 'd' }, { "interactive" , no_argument , NULL, 'i' }, { "8kHz" , no_argument , NULL, '8' }, { "user" , required_argument, NULL, 'u' }, { "standard" , required_argument, NULL, 's' }, { "buflen" , required_argument, NULL, 'b' }, { "minreq" , required_argument, NULL, 'r' }, { "statistics" , no_argument , NULL, 'S' }, { "tag-dtmf" , required_argument, NULL, 'D' }, { "tag-indicator" , required_argument, NULL, 'I' }, { "tag-notif" , required_argument, NULL, 'N' }, { "volume-dtmf" , required_argument, NULL, '1' }, { "volume-indicator", required_argument, NULL, '2' }, { "volume-notif" , required_argument, NULL, '3' }, #define OPTS "du:s:b:r:hi8SD:I:N:" { NULL , 0 , NULL, 0 } }; int option; struct passwd *pwd; long int t; char *e; while ((option = getopt_long(argc, argv, OPTS, options, NULL)) != -1) { switch (option) { case 'h': usage(argc, argv, 0); break; case 'd': cmdopt->daemon = 1; break; case 'i': cmdopt->interactive = 1; break; case '8': cmdopt->sample_rate = 8000; break; case 'u': if (!optarg && !*optarg) usage(argc, argv, EINVAL); cmdopt->uid = -1; while ((pwd = getpwent()) != NULL) { if (!strcmp(optarg, pwd->pw_name)) { cmdopt->uid = pwd->pw_uid; break; } } if (cmdopt->uid < 0) { printf("invalid username: %s\n", optarg); usage(argc, argv, EINVAL); } break; case 's': if (!strcmp(optarg, "cept")) cmdopt->standard = STD_CEPT; else if (!strcmp(optarg, "ansi")) cmdopt->standard = STD_ANSI; else if (!strcmp(optarg, "japan")) cmdopt->standard = STD_JAPAN; else if (!strcmp(optarg, "atnt")) cmdopt->standard = STD_ATNT; else { printf("invalid standard '%s'\n", optarg); usage(argc, argv, EINVAL); } break; case 'b': t = strtol(optarg, &e, 10); if (*e == '\0' && t > 0 && t <= 10000) cmdopt->buflen = t; else { printf("invalid buffer length '%s' msec\n", optarg); usage(argc, argv, EINVAL); } break; case 'r': t = strtol(optarg, &e, 10); if (*e == '\0' && t > 0 && t <= 1000) cmdopt->minreq = t; else { printf("invalid min.request length '%s' msec\n", optarg); usage(argc, argv, EINVAL); } break; case 'S': cmdopt->statistics = 1; break; case 'D': cmdopt->dtmf_tags = optarg; break; case 'I': cmdopt->ind_tags = optarg; break; case 'N': cmdopt->notif_tags = optarg; break; case '1': cmdopt->dtmf_volume = parse_volume(optarg); break; case '2': cmdopt->ind_volume = parse_volume(optarg); break; case '3': cmdopt->notif_volume = parse_volume(optarg); break; default: usage(argc, argv, EINVAL); break; } } if (!cmdopt->daemon && cmdopt->uid > 0) { printf("Warning: -d is not present; ignoring -u option\n"); } } static void signal_handler(int signo, siginfo_t *info, void *data) { #if 0 ucontext_t *uc = (ucontext_t *)data; #endif (void)info; (void)data; switch (signo) { case SIGHUP: case SIGTERM: case SIGINT: if (main_loop != NULL) { g_main_loop_quit(main_loop); break; } /* intentional fall over */ default: exit(EINTR); } } static int daemonize(uid_t uid, const char *path) { pid_t pid; int fd; if ((pid = fork()) < 0) return -1; else if (pid > 0) _Exit(0); /* parent exits */ else { /* child continues */ if (setsid() < 0) /* new child session; get rid of ctty */ return -1; if (uid > 0 && setuid(uid) < 0) return -1; if (path && chdir(path) < 0) return -1; if ((fd = open("/dev/null", O_RDWR, 0)) < 0) return -1; if (dup2(fd, fileno(stdin)) < 0 || dup2(fd, fileno(stdout)) < 0 || dup2(fd, fileno(stderr)) < 0 ) return -1; if (fd != fileno(stdin) && fd != fileno(stdout) && fd != fileno(stderr) ) close(fd); } return 0; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/note.c000066400000000000000000000073771436025105100163630ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include "stream.h" #include "tone.h" #include "note.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static char *note_stream = STREAM_NOTES; static uint32_t frequencies[OCTAVE_DIM][NOTE_DIM] = { /* Ab A B H C Db D Eb E F Gb G*/ {0, 0, 220, 233, 247, 262, 277, 294, 311, 338, 349, 370, 392}, {0, 416, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784}, {0, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1488, 1568}, {0,1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136}, {0,3322, 3520, 3729, 3951, 4186, 4434, 4698, 4978, 5274, 5588, 5920, 6272}, {0,6644, 7040, 7458, 7902, 8372, 8870, 9396, 9956,10548,11176,11840,12544} }; static int types[] = { TONE_NOTE_0, }; static uint32_t play_percent[STYLE_DIM] = { 30, /* Staccato */ 60, /* Natural */ 100 /* Continous */ }; int note_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void note_play(struct ausrv *ausrv, int note, int scale, int beat, int style, int fract, uint32_t vol, int idx) { struct stream *stream = stream_find(ausrv, note_stream); int octave = scale - 3; int type; uint32_t freq; uint32_t period; uint32_t play; uint32_t dur; if (note < 0 || note >= NOTE_DIM || octave < 0 || octave >= OCTAVE_DIM || beat < 0 || beat >= 200 || style < 0 || style >= STYLE_DIM || fract < 1 || fract > 32 || vol < 1 || vol > 100 || idx < 0 || idx >= (int)(sizeof(types)/sizeof(types[0]))) { return; } if (stream == NULL) { stream = stream_create(ausrv, note_stream, NULL, 0, tone_write_callback, tone_destroy_callback, NULL, NULL); if (stream == NULL) { LOG_ERROR("%s(): Can't create stream", __FUNCTION__); return; } } type = types[idx]; freq = frequencies[octave][note]; dur = 60000000 / (beat * fract); period = dur; play = (period * play_percent[style]) / 100; TRACE("%s(): freq %u period %u", __FUNCTION__, freq, period); tone_create(stream, type, freq, vol, period, play, 0, dur); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/note.h000066400000000000000000000034101436025105100163500ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_NOTE_H__ #define __TONEGEND_NOTE_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #define NOTE_PAUSE 0 #define NOTE_Ab 1 #define NOTE_A 2 #define NOTE_B 3 #define NOTE_H 4 #define NOTE_C 5 #define NOTE_Db 6 #define NOTE_D 7 #define NOTE_Eb 8 #define NOTE_E 9 #define NOTE_F 10 #define NOTE_Gb 11 #define NOTE_G 12 #define NOTE_DIM 13 #define OCTAVE_3 0 #define OCTAVE_4 1 #define OCTAVE_5 2 #define OCTAVE_6 3 #define OCTAVE_7 4 #define OCTAVE_8 5 #define OCTAVE_DIM 6 #define STYLE_STACCATO 0 #define STYLE_NATURAL 1 #define STYLE_CONTINOUS 2 #define STYLE_DIM 3 int note_init(int, char **); void note_play(struct ausrv *, int, int, int, int, int, uint32_t, int); #endif /* __TONEGEND_NOTE_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/notification.c000066400000000000000000000167761436025105100201070ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include "tonegend.h" #include "dbusif.h" #include "tone.h" #include "stream.h" #include "notification.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static char *notif_stream = STREAM_NOTIFICATION; struct method { char *intf; /* interface name */ char *memb; /* method name */ char *sig; /* signature */ int (*func)(DBusMessage *, struct tonegend *); /* implementing function */ }; static int start_notif_tone(DBusMessage *, struct tonegend *); static int stop_tone(DBusMessage *, struct tonegend *); static uint32_t linear_volume(int); static void notif_play(struct ausrv *ausrv, int type, uint32_t vol, int dur); static void notif_stop(struct ausrv *ausrv, int kill_stream); static struct method method_defs[] = { {NOTIF_INTERFACE, "StartNotificationTone", "uiu", start_notif_tone}, {NOTIF_INTERFACE, "StopTone", "", stop_tone}, {NULL, NULL, NULL, NULL} }; static void *notif_props = NULL; static uint32_t vol_scale = 100; int notif_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } int notif_create(struct tonegend *tonegend) { struct method *m; int err; int sts; for (m = method_defs, err = 0; m->memb != NULL; m++) { sts = dbusif_register_input_method(tonegend, m->intf, m->memb, m->sig, m->func); if (sts < 0) { LOG_ERROR("%s(): Can't register D-Bus method '%s'", __FUNCTION__, m->memb); err = -1; } } return err; } static int start_notif_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; uint32_t event; int32_t dbm0; uint32_t duration; uint32_t volume; int beeptype; int success; success = dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &event, DBUS_TYPE_INT32 , &dbm0, DBUS_TYPE_UINT32, &duration, DBUS_TYPE_INVALID); if (!success) { LOG_ERROR("%s(): Can't parse arguments", __FUNCTION__); return FALSE; } volume = linear_volume(dbm0); TRACE("%s(): event %u volume %d dbm0 (%u) duration %u msec", __FUNCTION__, event, dbm0, volume, duration); switch (event) { case 66: beeptype = TONE_DIAL; break; case 72: beeptype = TONE_BUSY; break; case 73: beeptype = TONE_CONGEST; break; case 256: beeptype = TONE_RADIO_ACK; break; case 257: beeptype = TONE_RADIO_NA; break; case 74: beeptype = TONE_ERROR; break; case 79: beeptype = TONE_WAIT; break; case 70: beeptype = TONE_RING; break; default: LOG_ERROR("%s(): invalid event %d", __FUNCTION__, event); return FALSE; } notif_play(ausrv, beeptype, volume, duration * 1000); return TRUE; } static int stop_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; (void)msg; TRACE("%s()", __FUNCTION__); notif_stop(ausrv, TRUE); return TRUE; } /* * This function maps the RFC4733 defined * power level of 0dbm0 - -63dbm0 * to the linear range of 0 - 100 */ static uint32_t linear_volume(int dbm0) { double volume; /* volume on the scale 0-100 */ if (dbm0 > 0) dbm0 = 0; if (dbm0 < -63) dbm0 = -63; volume = pow(10.0, (double)(dbm0 + 63) / 20.0) / 14.125375446; return (vol_scale * (uint32_t)(volume + 0.5)) / 100; } static void notif_play(struct ausrv *ausrv, int type, uint32_t vol, int dur) { struct stream *stream = stream_find(ausrv, notif_stream); if (stream != NULL) notif_stop(ausrv, FALSE); else { stream = stream_create(ausrv, notif_stream, NULL, 0, tone_write_callback, tone_destroy_callback, notif_props, NULL); if (stream == NULL) { LOG_ERROR("%s(): Can't create stream", __FUNCTION__); return; } } switch (type) { case TONE_DIAL: tone_create(stream, type, 425, vol, 1000000, 1000000, 0,0); break; case TONE_BUSY: tone_create(stream, type, 425, vol, 1000000, 500000, 0,dur); break; case TONE_CONGEST: tone_create(stream, type, 425, vol, 400000, 200000, 0,dur); break; case TONE_RADIO_ACK: tone_create(stream, type, 425, vol, 200000, 200000, 0,200000); break; case TONE_RADIO_NA: tone_create(stream, type, 425, vol, 400000, 200000, 0,1200000); break; case TONE_ERROR: tone_create(stream, type, 900, vol, 2000000, 333333, 0,dur); tone_create(stream, type, 1400, vol, 2000000, 332857, 333333,dur); tone_create(stream, type, 1800, vol, 2000000, 300000, 666190,dur); break; case TONE_WAIT: tone_create(stream,type, 425, vol, 800000,200000, 0,1000000); tone_create(stream,type, 425, vol, 800000,200000, 4000000,1000000); break; case TONE_RING: tone_create(stream, type, 425, vol, 5000000, 1000000, 0,0); break; default: LOG_ERROR("%s(): invalid type %d", __FUNCTION__, type); break; } } static void notif_stop(struct ausrv *ausrv, int kill_stream) { struct stream *stream = stream_find(ausrv, notif_stream); struct tone *tone; struct tone *hd; if (stream != NULL) { if (kill_stream) stream_destroy(stream); else { /* destroy all but DTMF tones */ for (hd = (struct tone *)&stream->data; hd; hd = hd->next) { while ((tone=hd->next) != NULL && !tone_chainable(tone->type)) tone_destroy(tone, KILL_CHAIN); } } } } void notif_set_properties(char *propstring) { notif_props = stream_parse_properties(propstring); } void notif_set_volume(uint32_t volume) { vol_scale = volume; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/notification.h000066400000000000000000000023721436025105100200770ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_NOTIFICATION_H__ #define __TONEGEND_NOTIFICATION_H__ #define NOTIF_INTERFACE "com.Nokia.Notification" struct tonegend; int notif_init(int, char **); int notif_create(struct tonegend *); void notif_set_properties(char *); void notif_set_volume(uint32_t); #endif /* __NOTFIFD_NOTIF_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/rfc4733.c000066400000000000000000000161011436025105100164720ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include "tonegend.h" #include "dbusif.h" #include "tone.h" #include "indicator.h" #include "dtmf.h" #include "rfc4733.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) struct method { char *intf; /* interface name */ char *memb; /* method name */ char *sig; /* signature */ int (*func)(DBusMessage *, struct tonegend *); /* implementing function */ }; static int start_event_tone(DBusMessage *, struct tonegend *); static int stop_tone(DBusMessage *, struct tonegend *); static int stop_event_tone(DBusMessage *, struct tonegend *); static uint32_t linear_volume(int); #define TONE_INDICATOR 0 #define TONE_DTMF 1 #define DBUS_SENDER_MAXLEN 16 static char tone_sender[2][DBUS_SENDER_MAXLEN]; static struct method method_defs[] = { {NULL, "StartEventTone", "uiu", start_event_tone}, {NULL, "StartNotificationTone", "uiu", start_event_tone}, /* backward compatible */ {NULL, "StopTone", "", stop_tone}, {NULL, "StopEventTone", "u", stop_event_tone}, {NULL, NULL, NULL, NULL} }; int rfc4733_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } int rfc4733_create(struct tonegend *tonegend) { struct method *m; int err; int sts; for (m = method_defs, err = 0; m->memb != NULL; m++) { sts = dbusif_register_input_method(tonegend, m->intf, m->memb, m->sig, m->func); if (sts < 0) { LOG_ERROR("%s(): Can't register D-Bus method '%s'", __FUNCTION__, m->memb); err = -1; } } return err; } static int start_event_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; uint32_t event; int32_t dbm0; uint32_t duration; uint32_t volume; int indtype; int success; char *sender; success = dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &event, DBUS_TYPE_INT32 , &dbm0, DBUS_TYPE_UINT32, &duration, DBUS_TYPE_INVALID); if (!success) { LOG_ERROR("%s(): Can't parse arguments", __FUNCTION__); return FALSE; } volume = linear_volume(dbm0); TRACE("%s(): event %u volume %d dbm0 (%u) duration %u msec", __FUNCTION__, event, dbm0, volume, duration); sender = (char *)dbus_message_get_sender(msg); if (event < DTMF_MAX) { if (tone_sender[TONE_DTMF][0]) TRACE("%s(): got request to play the second DTMF tone", __FUNCTION__); strncpy(tone_sender[TONE_DTMF], sender, DBUS_SENDER_MAXLEN); dtmf_play(ausrv, event, volume, 0); } else { switch (event) { case 66: indtype = TONE_DIAL; break; case 72: indtype = TONE_BUSY; break; case 73: indtype = TONE_CONGEST; break; case 256: indtype = TONE_RADIO_ACK; break; case 257: indtype = TONE_RADIO_NA; break; case 74: indtype = TONE_ERROR; break; case 79: indtype = TONE_WAIT; break; case 70: indtype = TONE_RING; break; default: LOG_ERROR("%s(): invalid event %d", __FUNCTION__, event); return FALSE; } if (tone_sender[TONE_INDICATOR][0]) TRACE("%s(): got request to play the second indicator tone", __FUNCTION__); strncpy(tone_sender[TONE_INDICATOR], sender, DBUS_SENDER_MAXLEN); indicator_play(ausrv, indtype, volume, duration * 1000); } return TRUE; } static int stop_event_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; uint32_t event; int success; success = dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &event, DBUS_TYPE_INVALID); if (!success) { LOG_ERROR("%s(): Can't parse arguments", __FUNCTION__); return FALSE; } TRACE("%s(): stop %d tone", __FUNCTION__, event); if (event < DTMF_MAX) { dtmf_stop(ausrv); tone_sender[TONE_DTMF][0] = 0; } else { indicator_stop(ausrv, KILL_STREAM); tone_sender[TONE_INDICATOR][0] = 0; } return TRUE; } static int stop_tone(DBusMessage *msg, struct tonegend *tonegend) { struct ausrv *ausrv = tonegend->ausrv_ctx; char *sender; (void)msg; sender = (char *)dbus_message_get_sender(msg); if (!strncmp(sender, tone_sender[TONE_DTMF], DBUS_SENDER_MAXLEN)) { TRACE("%s(): stop DTMF tone", __FUNCTION__); dtmf_stop(ausrv); tone_sender[TONE_DTMF][0] = 0; } else if (!strncmp(sender, tone_sender[TONE_INDICATOR], DBUS_SENDER_MAXLEN)) { TRACE("%s(): stop indicator tone", __FUNCTION__); indicator_stop(ausrv, KILL_STREAM); tone_sender[TONE_INDICATOR][0] = 0; } else { /* In fallback the safest variant is to stop both type of streams */ TRACE("%s(): stop DTMF and/or indicator tones", __FUNCTION__); dtmf_stop(ausrv); indicator_stop(ausrv, KILL_STREAM); tone_sender[TONE_DTMF][0] = 0; tone_sender[TONE_INDICATOR][0] = 0; } return TRUE; } /* * This function maps the RFC4733 defined * power level of 0dbm0 - -63dbm0 * to the linear range of 0 - 100 */ static uint32_t linear_volume(int dbm0) { double volume; /* volume on the scale 0-100 */ if (dbm0 > 0) dbm0 = 0; if (dbm0 < -63) dbm0 = -63; volume = pow(10.0, (double)(dbm0 + 63) / 20.0) / 14.125375446; return (uint32_t)(volume + 0.5); } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/rfc4733.h000066400000000000000000000022001436025105100164720ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_RFC4733_H__ #define __TONEGEND_RFC4733_H__ struct tonegend; int rfc4733_init(int, char **); int rfc4733_create(struct tonegend *); #endif /* __NOTFIFD_RFC4733_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/stream.c000066400000000000000000000556301436025105100167040ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include "ausrv.h" #include "stream.h" #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) static void state_callback(pa_stream *, void *); static void underflow_callback(pa_stream *, void *); static void suspended_callback(pa_stream *, void *); static void write_callback(pa_stream *, size_t, void *); static void flush_callback(pa_stream *, int, void *); static void drain_callback(pa_stream *, int, void *); static void write_samples(struct stream *, int16_t *,size_t, uint32_t *); static uint32_t default_rate = 48000; static int print_statistics = 0; static int target_buflen = 1000; /* 1000msec ie. 1sec */ static int min_bufreq = 200; /* 200msec */ int stream_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } void stream_set_default_samplerate(uint32_t rate) { default_rate = rate; } void stream_print_statistics(int print) { print_statistics = print; } void stream_buffering_parameters(int tlen, int minreq) { if (!tlen && !minreq) { target_buflen = 0; min_bufreq = 0; } else { if (tlen < 20 || minreq < 10 || minreq > tlen - 10) { LOG_ERROR("Ignoring invalid buffering parameters %d %d", tlen, minreq); } else { target_buflen = tlen; min_bufreq = minreq; } } } struct stream *stream_create(struct ausrv *ausrv, char *name, char *sink, uint32_t sample_rate, uint32_t (*write)(struct stream*,int16_t*,int), void (*destroy)(void*), void *proplist, void *data) { struct stream *stream; pa_buffer_attr battr; pa_stream_flags_t flags; pa_sample_spec spec; struct timeval tv; uint64_t start; struct stream_stat *stat; uint32_t bufsize; uint32_t tlength; char tlstr[32]; char bfstr[32]; if (!ausrv->connected) { LOG_ERROR("Can't create stream '%s': no server connected", name); return NULL; } if (name == NULL) name = "generated tone"; if (sample_rate == 0) sample_rate = default_rate; memset(&spec, 0, sizeof(spec)); spec.format = PA_SAMPLE_S16LE; spec.rate = sample_rate; spec.channels = 1; /* e.g. MONO */ if (min_bufreq > 0) bufsize = pa_usec_to_bytes(min_bufreq * PA_USEC_PER_MSEC, &spec); else bufsize = (uint32_t)-1; if (target_buflen > 0) tlength = pa_usec_to_bytes(target_buflen * PA_USEC_PER_MSEC, &spec); else tlength = (uint32_t)-1; gettimeofday(&tv, NULL); start = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; if ((stream = (struct stream *)malloc(sizeof(*stream))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); return NULL; } memset(stream, 0, sizeof(*stream)); stream->next = ausrv->streams; stream->ausrv = ausrv; stream->id = ausrv->nextid++; stream->name = strdup(name); stream->rate = sample_rate; stream->pastr = pa_stream_new_with_proplist(ausrv->context, name, &spec, NULL, (pa_proplist *)proplist); stream->start = start; stream->flush = TRUE; stream->bufsize = bufsize; stream->write = write; stream->destroy = destroy; stream->data = data; if (print_statistics) { stat = &stream->stat; stat->wrtime = start; stat->minbuf = -1; stat->mingap = -1; stat->mincalc = -1; } if (stream->pastr == NULL) { free(stream->name); free(stream); TRACE("%s(): stream creation of '%s' failed", __FUNCTION__, name); return NULL; } /* these are for the 48Khz mono 16bit streams */ battr.maxlength = -1; /* default (4MB) */ battr.tlength = tlength; battr.minreq = bufsize; battr.prebuf = -1; /* default (tlength) */ battr.fragsize = -1; /* default (tlength) */ flags = PA_STREAM_ADJUST_LATENCY; pa_stream_set_state_callback(stream->pastr, state_callback,(void*)stream); pa_stream_set_underflow_callback(stream->pastr, underflow_callback, (void *)stream); pa_stream_set_suspended_callback(stream->pastr, suspended_callback, (void *)stream); pa_stream_set_write_callback(stream->pastr, write_callback,(void *)stream); pa_stream_connect_playback(stream->pastr, sink, &battr, flags, NULL, NULL); ausrv->streams = stream; TRACE("%s(): stream '%s' created", __FUNCTION__, stream->name); if (print_statistics) { if (battr.tlength == (uint32_t)-1) snprintf(tlstr, sizeof(tlstr), ""); else snprintf(tlstr, sizeof(tlstr), "%u", battr.tlength); if (battr.minreq == (uint32_t)-1) snprintf(bfstr, sizeof(tlstr), ""); else snprintf(bfstr, sizeof(tlstr), "%u", battr.minreq); TRACE("Requested buffer attributes:\n" " tlength %s\n" " minreq %s", tlstr, bfstr); } return stream; } void stream_destroy(struct stream *stream) { struct ausrv *ausrv = stream->ausrv; struct stream *prev; pa_stream *pastr; const pa_buffer_attr *battr; struct stream_stat *stat; pa_operation *oper; struct timeval tv; uint64_t stop; double upt; double strt; double dur; double freq; double flow; uint32_t avbuf; uint32_t avcalc; uint32_t avcpu; uint32_t avgap; TRACE("%s(): destroying stream '%s'", __FUNCTION__, stream->name); if (stream->killed) { TRACE("%s(): stream is already killed", __FUNCTION__); return; } gettimeofday(&tv, NULL); stop = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; for (prev=(struct stream *)&ausrv->streams; prev->next; prev=prev->next){ if (prev->next == stream) { pastr = stream->pastr; battr = pa_stream_get_buffer_attr(pastr); stat = &stream->stat; if (stream->flush) oper = pa_stream_flush(pastr, flush_callback, (void *)stream); else oper = pa_stream_drain(pastr, drain_callback, (void *)stream); if (oper == NULL) return; pa_operation_unref(oper); prev->next = stream->next; stream->next = NULL; stream->killed = TRUE; if (stream->destroy != NULL) stream->destroy(stream->data); stream->ausrv = NULL; free(stream->buf.samples); pa_stream_set_write_callback(pastr, NULL,NULL); if (print_statistics && stat->wrcnt > 0) { if (battr != NULL) { TRACE("Buffer attributes:\n" " maxlength %u\n" " tlength %u\n" " prebuf %u\n" " minreq %u", battr->maxlength, battr->tlength, battr->prebuf, battr->minreq); } upt = (double)(stop - stream->start) / 1000000.0; strt = (double)(stream->time) / 1000000.0; dur = (double)(stat->wrtime - stat->firstwr)/1000000.0 + 0.01; freq = (double)stat->wrcnt / dur; flow = (double)stream->bcnt / dur; avbuf = stream->bcnt / stat->wrcnt; avcpu = (stat->cpucalc / stat->wrcnt) / 1000; avcalc = (uint32_t)(stat->sumcalc/(uint64_t)stat->wrcnt)/1000; avgap = (uint32_t)(stat->sumgap /(uint64_t)stat->wrcnt)/1000; TRACE("stream '%s' killed. Statistics:\n" " up %.3lfsec tone %.3lfsec\n" " flow %.0lf byte/sec (excluding pre-buffering)\n" " write freq %.2lf buf/sec (every %.0lf msec)\n" " bufsize %u - %u - %u\n" " calc.time %u - %u - %u msec\n" " avarage cpu / buffer %u msec\n" " cpu load for all buffer calculation %.2lf%%\n" " gaps %u - %u - %u msec\n" " underflows %u\n" " %u buffer was late out of %u (%u%%)", stream->name, upt, strt, flow, freq, 1000.0/freq, stat->minbuf, avbuf, stat->maxbuf, stat->mincalc / 1000, avcalc, stat->maxcalc / 1000, avcpu, ((double)avcpu * freq) / 10.0, stat->mingap / 1000, avgap, stat->maxgap / 1000, stat->underflows, stat->late, stat->wrcnt, (stat->late * 100) / stat->wrcnt); } return; } } LOG_ERROR("%s(): Can't find stream '%s'", __FUNCTION__, stream->name); } void stream_set_timeout(struct stream *stream, uint32_t timeout) { if (timeout == 0) stream->end = 0; else stream->end = stream->time + timeout; } void stream_kill_all(struct ausrv *ausrv) { struct stream *stream; while ((stream = ausrv->streams) != NULL) { ausrv->streams = stream->next; stream->next = NULL; stream->killed = TRUE; if (stream->destroy != NULL) stream->destroy(stream->data); stream->ausrv = NULL; pa_stream_set_state_callback(stream->pastr, NULL,NULL); pa_stream_set_underflow_callback(stream->pastr, NULL,NULL); pa_stream_set_suspended_callback(stream->pastr, NULL,NULL); pa_stream_set_write_callback(stream->pastr, NULL,NULL); free(stream->name); free(stream); } } void stream_clean_buffer(struct stream *stream) { struct timeval tv; uint64_t now; uint32_t bcnt; uint32_t dcnt; size_t offs; size_t len; int i,j; int32_t sample; gettimeofday(&tv, NULL); now = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; bcnt = ((now - stream->start) * (uint64_t)stream->rate) / 1000000ULL; bcnt *= 2; dcnt = (10000ULL * (uint64_t)stream->rate) / 1000000ULL; if (stream->buf.samples != NULL) { offs = bcnt >= stream->bcnt ? bcnt - stream->bcnt : 0; if (offs < stream->buf.buflen) { len = stream->buf.buflen - offs; if (len < dcnt * 2) { TRACE("%s(): resetting %u bytes in write-ahead-buffer", __FUNCTION__, len); memset((char *)stream->buf.samples + offs, 0, len); } else { for (i = 0, j = offs / 2; i < dcnt; i++, j++) { sample = stream->buf.samples[j]; sample = (sample * ((int32_t)dcnt - i-1)) / (int32_t)dcnt; if (sample > 32767) stream->buf.samples[j] = 32767; else if (sample < -32767) stream->buf.samples[j] = -32767; else stream->buf.samples[j] = sample; } len -= dcnt * 2; offs += dcnt * 2; TRACE("%s(): ramping down %u and resetting %u bytes in " "write-ahead-buffer", __FUNCTION__, dcnt * 2, len); if (len > 0) memset((char *)stream->buf.samples + offs, 0, len); } } } } struct stream *stream_find(struct ausrv *ausrv, char *name) { struct stream *stream; for (stream = ausrv->streams; stream != NULL; stream = stream->next) { if (!strcmp(name, stream->name)) break; } return stream; } void *stream_parse_properties(char *propstring) { pa_proplist *proplist; char *key, *val, *next, keybuf[128]; int keylen, vallen; if (propstring == NULL) return NULL; if ((proplist = pa_proplist_new()) == NULL) { LOG_ERROR("%s(): Failed to allocate property list", __FUNCTION__); return NULL; } key = propstring; while (key != NULL) { if ((val = strchr(key, '=')) == NULL) { LOG_ERROR("%s(): Invalid property string '%s'", __FUNCTION__, propstring); goto error; } keylen = val - key; if (keylen >= (int)sizeof(keybuf)) { LOG_ERROR("%s(): property key '%*.*s' too long", __FUNCTION__, keylen, keylen, key); goto error; } strncpy(keybuf, key, keylen); keybuf[keylen] = '\0'; val++; if ((next = strchr(val, ',')) != NULL) { vallen = next - val; next++; } else vallen = strlen(val); pa_proplist_setf(proplist, keybuf, "%*.*s", vallen, vallen, val); key = next; } return (void *)proplist; error: pa_proplist_free(proplist); return NULL; } void stream_free_properties(void *proplist) { if (proplist) pa_proplist_free((pa_proplist *)proplist); } static void state_callback(pa_stream *pastr, void *userdata) { struct stream *stream = (struct stream *)userdata; if (!stream || stream->pastr != pastr) { LOG_ERROR("%s(): confused with data structures", __FUNCTION__); return; } switch (pa_stream_get_state(pastr)) { case PA_STREAM_UNCONNECTED: TRACE("%s(): stream '%s' unconnected", __FUNCTION__, stream->name); break; case PA_STREAM_CREATING: TRACE("%s(): stream '%s' creating", __FUNCTION__, stream->name); break; case PA_STREAM_READY: TRACE("%s(): stream '%s' ready", __FUNCTION__, stream->name); break; case PA_STREAM_TERMINATED: TRACE("%s(): stream '%s' terminated", __FUNCTION__, stream->name); free(stream->name); free(stream); break; default: case PA_STREAM_FAILED: LOG_ERROR("%s(): Stream error: %s", __FUNCTION__, pa_strerror(pa_context_errno(pa_stream_get_context(pastr)))); break; } } static void underflow_callback(pa_stream *pastr, void *userdata) { (void)pastr; struct stream *stream = (struct stream *)userdata; if (!stream || !stream->name) LOG_ERROR("Stream underflow"); else { LOG_ERROR("Stream '%s' underflow", stream->name); stream->stat.underflows++; stream_destroy(stream); } } static void suspended_callback(pa_stream *pastr, void *userdata) { (void)pastr; struct stream *stream = (struct stream *)userdata; if (!stream || !stream->name) LOG_ERROR("Stream suspended"); else { LOG_ERROR("Stream '%s' suspended", stream->name); } } static void write_callback(pa_stream *pastr, size_t bytes, void *userdata) { struct stream *stream = (struct stream *)userdata; struct stream_stat *stat = &stream->stat; const pa_buffer_attr *battr; int16_t *samples; size_t buflen; int16_t *extra; size_t extlen; struct timeval tv; uint32_t start; uint32_t gap; uint32_t calcend; uint32_t calc; uint32_t period; uint32_t cpu; if (!stream || stream->pastr != pastr) { LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); return; } if (stream->killed) return; if (print_statistics) { gettimeofday(&tv, NULL); start = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; gap = start - stat->wrtime; } #if 0 TRACE("%s(): %d bytes", __FUNCTION__, bytes); #endif if (stream->buf.samples == NULL) { buflen = (bytes + 1) & (~1U); samples = (int16_t *)malloc(buflen); if (samples != NULL) write_samples(stream, samples,buflen, &cpu); else { LOG_ERROR("%s(): failed to allocate memory", __FUNCTION__); return; } } else { if (bytes <= stream->buf.buflen) { buflen = stream->buf.buflen; samples = stream->buf.samples; cpu = stream->buf.cpu; } else { buflen = (bytes + 1) & (~1U); samples = (int16_t *)realloc(stream->buf.samples, buflen); extra = samples + (stream->buf.buflen / 2); extlen = buflen - stream->buf.buflen; if (samples != NULL) { TRACE("%s(): extending write-ahead-buffer %u butes (%u -> %u)", __FUNCTION__, extlen, stream->buf.buflen, buflen); write_samples(stream, extra,extlen, &cpu); cpu += stream->buf.cpu; } else { LOG_ERROR("%s(): failed to allocate memory", __FUNCTION__); return; } } stream->buf.samples = NULL; stream->buf.cpu = 0; } if (samples != NULL) { if (print_statistics) { gettimeofday(&tv, NULL); calcend = (uint64_t)tv.tv_sec * (uint64_t)1000000 + (uint64_t)tv.tv_usec; calc = calcend - start; period = (calcend - stat->wrtime) / 1000; stat->wrtime = calcend; if (stream->bcnt == 0 /* && buflen > stream->bufsize */) { TRACE("Stream '%s' pre-buffers of %u bytes", stream->name, buflen); stat->firstwr = stat->wrtime; } else { stat->wrcnt ++; stat->sumgap += gap; stat->sumcalc += calc; stat->cpucalc += cpu; if (buflen < stat->minbuf) stat->minbuf = buflen; if (buflen > stat->maxbuf) stat->maxbuf = buflen; if (gap < stat->mingap) stat->mingap = gap; if (gap > stat->maxgap) stat->maxgap = gap; if (calc < stat->mincalc) stat->mincalc = calc; if (calc > stat->maxcalc) stat->maxcalc = calc; #if 0 TRACE("Buffer writting period %umsec", period); #endif if (period > (uint32_t)min_bufreq) { stat->late++; #if 0 TRACE("Buffer is late %umsec in stream '%s'", period - min_bufreq, stream->name); #endif } } } pa_stream_write(stream->pastr, (void*)samples,buflen, free, 0,PA_SEEK_RELATIVE); stream->bcnt += buflen; #if 0 TRACE("stream time %09umsec end %09umsec", stream->time / 1000, stream->end / 1000); #endif if (stream->end && stream->time >= stream->end) stream_destroy(stream); else { if (stream->bufsize == (uint32_t)-1) { if ((battr = pa_stream_get_buffer_attr(pastr)) != NULL) stream->bufsize = battr->minreq; } if (stream->bufsize != (uint32_t)-1) { stream->buf.samples = (int16_t *)malloc(stream->bufsize); stream->buf.buflen = stream->bufsize; if (stream->buf.samples == NULL) LOG_ERROR("%s(): failed to allocate memory", __FUNCTION__); else { write_samples(stream, stream->buf.samples,stream->bufsize, &stream->buf.cpu); } } } } } static void flush_callback(pa_stream *pastr, int success, void *userdata) { struct stream *stream = (struct stream *)userdata; if (stream->pastr != pastr) { LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); return; } if (!success) LOG_ERROR("%s(): Can't flush stream '%s'", __FUNCTION__, stream->name); else TRACE("%s(): stream '%s' flushed", __FUNCTION__, stream->name); pa_stream_disconnect(pastr); pa_stream_unref(pastr); } static void drain_callback(pa_stream *pastr, int success, void *userdata) { struct stream *stream = (struct stream *)userdata; if (stream->pastr != pastr) { LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); return; } if (!success) LOG_ERROR("%s(): Can't drain stream '%s'", __FUNCTION__, stream->name); else TRACE("%s(): stream '%s' drained", __FUNCTION__, stream->name); pa_stream_disconnect(pastr); pa_stream_unref(pastr); } static void write_samples(struct stream *stream, int16_t *samples, size_t bytes, uint32_t *cpu) { int length; clock_t cpubeg; clock_t cpuend; length = bytes/2; cpubeg = print_statistics ? clock() : 0; stream->time = stream->write(stream, samples, length); cpuend = print_statistics ? clock() : 0; *cpu = cpuend - cpubeg; return; } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/stream.h000066400000000000000000000073271436025105100167110ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_STREAM_H__ #define __TONEGEND_STREAM_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #define STREAM_INDICATOR "indtone" #define STREAM_DTMF "dtmf" #define STREAM_NOTES "ringtone" #define STREAM_NOTIFICATION "notiftone" #define PROP_STREAM_RESTORE "module-stream-restore.id" #define PROP_MEDIA_ROLE "media.role" #define ID_KEYPRESS "x-maemo-key-pressed" #define ID_PHONE "phone" #define INPUT_BY_ROLE "sink-input-by-media-role" struct ausrv; struct stream_stat { uint64_t firstwr; /* first writting time */ uint64_t wrtime; /* time of last writting */ uint32_t wrcnt; /* write count */ uint32_t minbuf; uint32_t maxbuf; uint32_t mingap; uint32_t maxgap; uint64_t sumgap; uint32_t mincalc; uint32_t maxcalc; uint64_t sumcalc; uint32_t cpucalc; uint32_t underflows; uint32_t late; }; struct stream { struct stream *next; struct ausrv *ausrv; int id; /* stream id */ char *name; /* stream name */ uint32_t rate; /* sample rate */ pa_stream *pastr; /* pulse audio stream */ uint64_t start; /* wall clock time of stream creation */ uint32_t time; /* buffer time in usecs */ uint32_t end; /* buffer timeout for the stream in usec */ int flush; /* flush on destroy */ int killed; uint32_t bufsize; /* write-ahead-buffer size (ie. minreq) */ uint32_t bcnt; /* byte count */ uint32_t (*write)(struct stream *, int16_t *, int); void (*destroy)(void *); void *data; /* extension */ struct stream_stat stat; /* statistics */ struct { int16_t *samples; size_t buflen; uint32_t cpu; } buf; }; int stream_init(int, char **); void stream_set_default_samplerate(uint32_t); void stream_print_statistics(int); void stream_buffering_parameters(int, int); struct stream *stream_create(struct ausrv *, char *, char *, uint32_t, uint32_t (*)(struct stream *, int16_t*, int), void (*)(void*), void *, void *); void stream_destroy(struct stream *); void stream_set_timeout(struct stream *, uint32_t); void stream_kill_all(struct ausrv *); void stream_clean_buffer(struct stream *); struct stream *stream_find(struct ausrv *, char *); void *stream_parse_properties(char *); void stream_free_properties(void *); #endif /* __TONEGEND_STREAM_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/tone.c000066400000000000000000000212351436025105100163500ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include #include "stream.h" #include "envelop.h" #include "tone.h" #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define LOG_ERROR(f, args...) log_error(logctx, f, ##args) #define LOG_INFO(f, args...) log_error(logctx, f, ##args) #define LOG_WARNING(f, args...) log_error(logctx, f, ##args) #define TRACE(f, args...) trace_write(trctx, trflags, trkeys, f, ##args) #define AMPLITUDE SHRT_MAX /* 32767 */ #define OFFSET 8192 #define SCALE 1024ULL static inline void singen_init(struct singen *singen, uint32_t freq, uint32_t rate, uint32_t volume) { double w = 2.0 * M_PI * ((double)freq / (double)rate); #if 0 if (volume < 0 ) volume = 0; #endif if (volume > 100) volume = 100; singen->m = 2.0 * cos(w) * (AMPLITUDE * OFFSET); singen->n0 = -sin(w) * (AMPLITUDE * OFFSET); singen->n1 = 0; singen->offs = volume ? (OFFSET * 100) / volume : LONG_MAX; } static inline int32_t singen_write(struct singen *singen) { uint64_t n2 = (singen->m * singen->n1) / (AMPLITUDE * OFFSET) - singen->n0; singen->n0 = singen->n1; singen->n1 = n2; return (int32_t)(singen->n0 / singen->offs); } static void setup_envelop_for_tone(struct tone *, int, uint32_t, uint32_t); int tone_init(int argc, char **argv) { (void)argc; (void)argv; return 0; } struct tone *tone_create(struct stream *stream, int type, uint32_t freq, uint32_t volume, uint32_t period, uint32_t play, uint32_t start, uint32_t duration) { struct tone *link = NULL; uint32_t time = stream->time; struct tone *next = (struct tone *)stream->data; struct tone *tone; if (!volume || !period || !play) return NULL; if ((tone = (struct tone *)malloc(sizeof(*tone))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); return NULL; } memset(tone, 0, sizeof(*tone)); if (tone_chainable(type) && duration > 0) { for (link = (struct tone *)stream->data; link; link = link->next) { if (link->type == type) { while (link->chain) link = link->chain; next = NULL; time = link->end / SCALE; break; } } } TRACE("%s(): %s", __FUNCTION__, link ? "chain" : "don't chain"); tone->next = next; tone->stream = stream; tone->type = type; tone->period = period; tone->play = play; tone->start = (uint64_t)(time + start) * SCALE; tone->end = duration ? tone->start + (uint64_t)(duration * SCALE) : 0; setup_envelop_for_tone(tone, type, play, duration); if (!freq) tone->backend = BACKEND_UNKNOWN; else { tone->backend = BACKEND_SINGEN; singen_init(&tone->singen, freq, stream->rate, volume); } if (link) link->chain = tone; else stream->data = (void *)tone; if (duration) stream->flush = FALSE; return tone; } void tone_destroy(struct tone *tone, int kill_chain) { struct stream *stream = tone->stream; struct tone *prev; struct tone *link; struct tone *chain; for (prev = (struct tone *)&stream->data; prev; prev = prev->next) { if (prev->next == tone) { TRACE("%s(%s_chain)", __FUNCTION__, kill_chain?"kill":"preserve"); if ((link = tone->chain) == NULL) prev->next = tone->next; else { if (kill_chain) { for (link = tone->chain; link; link = chain) { chain = link->chain; envelop_destroy(link->envelop); free(link); } prev->next = tone->next; } else { prev->next = link; link->next = tone->next; } } envelop_destroy(tone->envelop); free(tone); return; } } LOG_ERROR("%s(): Can't find the stream to be destoyed", __FUNCTION__); } int tone_chainable(int type) { switch (type) { case TONE_DTMF_L: case TONE_DTMF_H: case TONE_NOTE_0: return 1; default: return 0; } } uint32_t tone_write_callback(struct stream *stream, int16_t *buf, int len) { struct tone *tone; struct tone *next; uint64_t t, dt; uint32_t abst; uint32_t relt; int32_t sine; int32_t sample; int i; t = (uint64_t)stream->time * SCALE; dt = (1000000ULL * SCALE) / (uint64_t)stream->rate; if (stream->data == NULL) { memset(buf, 0, len*sizeof(*buf)); t += dt * (uint64_t)len; } else { for (i = 0; i < len; i++) { sample = 0; for (tone=(struct tone *)stream->data; tone!=NULL; tone=next) { next = tone->next; if (tone->end && tone->end < t) tone_destroy(tone, PRESERVE_CHAIN); else if (t > tone->start) { abst = (uint32_t)((t - tone->start) / SCALE); relt = abst % tone->period; if (relt < tone->play) { switch (tone->backend) { case BACKEND_SINGEN: sine = singen_write(&tone->singen); sample += envelop_apply(tone->envelop, sine, tone->reltime ? relt:abst); break; } } } } /* for */ #if 0 if (sample < SHRT_MIN || sample > SHRT_MAX) { TRACE("sample %d is out of range (%d - %d)", sample, SHRT_MIN, SHRT_MAX); } #endif if (sample > SHRT_MAX) buf[i] = SHRT_MAX; else if (sample < SHRT_MIN) buf[i] = SHRT_MIN; else buf[i] = sample; t += dt; } } return (uint32_t)(t / SCALE); } void tone_destroy_callback(void *data) { struct stream *stream; struct tone *tone; if ((tone = (struct tone *)data) != NULL) { stream = tone->stream; if (stream->data != data) LOG_ERROR("%s(): Confused with data structures", __FUNCTION__); else { while ((tone = (struct tone *)stream->data) != NULL) tone_destroy(tone, KILL_CHAIN); } } } static void setup_envelop_for_tone(struct tone *tone, int type, uint32_t play, uint32_t duration) { switch (type) { case TONE_DIAL: case TONE_DTMF_IND_L: case TONE_DTMF_IND_H: tone->reltime = FALSE; tone->envelop = envelop_create(ENVELOP_RAMP_LINEAR, 10000, 0,duration); break; case TONE_BUSY: case TONE_CONGEST: case TONE_RADIO_ACK: case TONE_RADIO_NA: case TONE_WAIT: case TONE_RING: case TONE_DTMF_L: case TONE_DTMF_H: tone->reltime = TRUE; tone->envelop = envelop_create(ENVELOP_RAMP_LINEAR, 10000, 0, play); break; case TONE_ERROR: tone->reltime = TRUE; tone->envelop = envelop_create(ENVELOP_RAMP_LINEAR, 3000, 0, play); break; default: break; } } /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/tone.h000066400000000000000000000052701436025105100163560ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_TONE_H__ #define __TONEGEND_TONE_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #define PRESERVE_CHAIN 0 #define KILL_CHAIN 1 /* * predefined tone types */ #define TONE_UNDEFINED 0 #define TONE_DIAL 1 #define TONE_BUSY 2 #define TONE_CONGEST 3 #define TONE_RADIO_ACK 4 #define TONE_RADIO_NA 5 #define TONE_ERROR 6 #define TONE_WAIT 7 #define TONE_RING 8 #define TONE_DTMF_IND_L 9 #define TONE_DTMF_IND_H 10 #define TONE_DTMF_L 11 #define TONE_DTMF_H 12 #define TONE_NOTE_0 13 #define TONE_SINGEN_END 14 #define BACKEND_UNKNOWN 0 #define BACKEND_SINGEN 1 struct stream; union envelop; struct singen { int64_t m; int64_t n0; int64_t n1; int64_t offs; }; struct tone { struct tone *next; struct stream *stream; struct tone *chain; int type; uint32_t period; /* period (ie. play+pause) length */ uint32_t play; /* how long to play the sine */ uint64_t start; uint64_t end; int backend; union { struct singen singen; }; int reltime; /* relative time to be passed to env. func's */ union envelop *envelop; }; int tone_init(int, char **); struct tone *tone_create(struct stream *, int, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); void tone_destroy(struct tone *, int); int tone_chainable(int); uint32_t tone_write_callback(struct stream *, int16_t *, int); void tone_destroy_callback(void *); #endif /* __TONEGEND_TONE_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/tonegend.h000066400000000000000000000024271436025105100172150ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __TONEGEND_TONEGEND_H__ #define __TONEGEND_TONEGEND_H__ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include struct dbusif; struct ausrv; struct interact; struct tonegend { struct dbusif *dbus_ctx; struct ausrv *ausrv_ctx; struct interact *intact_ctx; }; #endif /* __TONEGEND_TONEGEND_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/src/trace/000077500000000000000000000000001436025105100163325ustar00rootroot00000000000000tone-generator-1.6.1/src/trace/trace.h000066400000000000000000000023061436025105100176020ustar00rootroot00000000000000/************************************************************************* This file is part of tone-generator Copyright (C) 2010 Nokia Corporation. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *************************************************************************/ #ifndef __NOTIF_TRACE_H__ #define __NOTIF_TRACE_H__ #include #ifdef ENABLE_TRACE #define trace_write(c, l, t, f, args...) printf(f "\n", ##args) #else #define trace_write(c, l, t, f, args...) do {} while(0) #endif #endif /* __NOTIF_TRACE_H__ */ /* * Local Variables: * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ tone-generator-1.6.1/test/000077500000000000000000000000001436025105100154245ustar00rootroot00000000000000tone-generator-1.6.1/test/test-dtmf000077500000000000000000000011321436025105100172560ustar00rootroot00000000000000#!/bin/bash if [ -z "$1" ] then echo "Usage: $0 [duration]" echo "Valid keys: 0..9, 10 (*), 11 (#)" echo "Default duration: 3 seconds" exit 1 fi TONE=$1 DURATION=3 if [ "$2" ] then DURATION=$2 fi echo "Playing DTMF tone $TONE for $DURATION seconds." dbus-send --session --type=method_call --dest=com.Nokia.Telephony.Tones /com/Nokia/Telephony/Tones com.Nokia.Telephony.Tones.StartEventTone uint32:$TONE int32:0 uint32:0 sleep $DURATION dbus-send --session --type=method_call --dest=com.Nokia.Telephony.Tones /com/Nokia/Telephony/Tones com.Nokia.Telephony.Tones.StopTone tone-generator-1.6.1/test/test-signal000077500000000000000000000012701436025105100176040ustar00rootroot00000000000000#!/bin/bash if [ -z "$1" ] then echo "Usage: $0 [duration]" echo "Valid signals:" echo " 66: Dial" echo " 70: Ring" echo " 72: Busy" echo " 73: Congestion" echo " 74: Error" echo " 79: Wait" echo " 256: Radio Ack" echo " 257: Radio N/A" echo "Default duration: 3 seconds" exit 1 fi TONE=$1 DURATION=3 if [ "$2" ] then DURATION=$2 fi echo "Playing signal tone $TONE for $DURATION seconds." let DURATION=(1000*$DURATION) dbus-send --session --type=method_call --dest=com.Nokia.Telephony.Tones /com/Nokia/Telephony/Tones com.Nokia.Telephony.Tones.StartNotificationTone uint32:$TONE int32:20 uint32:$DURATION tone-generator-1.6.1/test/tonegen-test.sh000077500000000000000000000006641436025105100204050ustar00rootroot00000000000000#:bin/bash echo "" for i in 1 2 3 4 5 6 7 8 9 10 ; do echo -n "$i " dbus-send --system --type=method_call --dest=com.Nokia.Telephony.Tones \ /com/Nokia/Telephony/Tones com.Nokia.Telephony.Tones.StartEventTone \ uint32:66 int32:0 uint32:3000 sleep 2 dbus-send --system --type=method_call --dest=com.Nokia.Telephony.Tones \ /com/Nokia/Telephony/Tones com.Nokia.Telephony.Tones.StopTone sleep 3 done echo ""