first commit

This commit is contained in:
Xavier 2025-10-20 20:11:21 +02:00
commit cbf3c258e0
318 changed files with 41712 additions and 0 deletions

674
LICENSE Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

27
Makefile Normal file
View File

@ -0,0 +1,27 @@
VERSION := 173
CXXFLAGS = -Wall -O3 -std=c++0x -Wno-write-strings -Wno-narrowing -DDRIVER_SERIAL=$(VERSION) $(RASPI)
LDFLAGS = -lpthread -lrt -lm -liio -lliquid -lad9361 -lfftw3 -lfftw3_threads -lsndfile -lasound -lsoundio -lgpiod
OBJ = qo100trx.o rx.o tx.o fft.o\
kmlib/kmtimer.o kmlib/km_helper.o kmlib/kmfifo.o kmlib/rotary.o\
udp/udp.o\
liquid/liquiddrv.o liquid/liquiddrv_modulator.o\
pluto/pluto_finder.o pluto/pluto_driver.o pluto/pluto_setup.o pluto/pluto_run.o\
libkmaudio/libkmaudio_fifo.o libkmaudio/libkmaudio_getDevices.o libkmaudio/libkmaudio_getDevices_Linux.o\
libkmaudio/libkmaudio_init.o libkmaudio/libkmaudio_init_linux.o libkmaudio/libkmaudio_interface.o libkmaudio/libkmaudio_capture_linux.o\
libkmaudio/libkmaudio_playback_linux.o libkmaudio/libkmaudio_resampler.o
default: $(OBJ)
g++ $(CXXFLAGS) -o Release/trxdriver $(OBJ) $(LDFLAGS)
echo $(VERSION) > version.txt
rm -rf Release/*.config Release/*.pdb
chmod 755 Release/startQO100trx
clean:
rm -rf *.o
rm -rf kmlib/*.o
rm -rf pluto/*.o
rm -rf udp/*.o
rm -rf liquid/*.o
rm -rf libkmaudio/*.o
rm -rf Release/trxdriver

103
README.md Normal file
View File

@ -0,0 +1,103 @@
# QO100_Transceiver
QO-100 Software Transceiver using an Adalm-Pluto and an SBC (Raspberry, Odroid ...), also works on Linux-Desktop PCs
This project is a fully functional software based transceiver for QO-100
Version Status:\
V1.0 ... May, 28 2021 ... Now fully working, Setup via Setup Menu.\
V1.1 ... May, 31 2021 ... Pluto USB/ETH setup, speech compressor\
V1.2 ... June, 2 2021 ... Audio Filter, Muting, new user interface\
V1.4 ... June, 6 2021 ... calibration for Pluto and LNB\
V1.5 ... June,11 2021 ... Major Upgrade (!) PLEASE CHECK YOUR SETUP (frequencies have been changed)\
V1.6 ... June,12 2021 ... various bug fixes (Sound card name, now working on 64bit Raspi)\
V1.63 .. June,16 2021 ... new settings: Pluto TX power, Screen Size\
V1.64 .. June,17 2021 ... many more Screen Sizes, new languages\
V1.66 .. June,25 2021 ... cleanup in the GUI, new RX/TX QRG settings, now usable also by touch screens. Stores RX-to-TX offset.\
V1.67 .. June,28 2021 ... first version which officially runs on Rapberry PI-3B+ (choose smaller screen size i.e. 1024x768, and disable beacon lock (important !) the lock symbol must show "FREE"). Also works on Orange PC+. \
V1.67 .. July,19 2021 ... Install files updated\
V1.68 .. July,26 2021 ... PTT control implemented, needs F5OEO firmware 2021 or later (version from 2019 does not work ! Pluto Rev.C needs also a patch)\
V1.69 ...August, 9 2021 ... rotary enocder for raspberry (frequency and RX volume), details see documentation\
V1.70 ...August, 23 2021 ... new screen size 1600x1050, 800Hz Test Tone (see left buttons), PTT output (and input), Mute input on Raspi GPIO, changes in installation scripts\
V1.71 ...September, 14 2021 ... HF-Loop corrected, Level (dB) display, Auto-QSO-Sync (see Setup), Microphone TX levels modified to avoid splatter\
V1.72 ...September, 18 2021 ... new AUDIO menu, new AGC, allows full output even with weak microphones\
January 13, 2022 ... modified installation procedure to get it running on raspberry OS "bullseye"\
V1.73 ...April, 2 2022 ... when restarting: uses last RX/TX qrg. This makes it easier to continue a QSO if the software was stopped or crashed.\
V1.73a...November, 16 2022 ... extended the install script for the ubuntu version vanessa. The TRX is the same as 1.73, just the installation has been extended.\
![alt text](https://github.com/dj0abr/QO100_Transceiver/blob/main/trxGui/Properties/sampleGUI.png)
## Hardware requirements
* Pluto SDR (connected via USB or Eth/USB Adapter)
* SBC like Raspberry PI-4, Odroid C4, Odroid N2 or Desktop-PC (Debuian based, Ubuntu, Mint...) and many others
* USB sound stick (if the SBC does not have a microphone connector)
* Satellite-Dish, QO-100 Feed and 2,4 GHz Amplifier (i.e. Amsat-DL 46dB Amp)
## Documentation
this software was developed for Amsat-DL. You can find the detailed documentation in the Amsat-Wiki:
http://wiki.amsat-dl.org/doku.php?id=en:plutotrx:overview
## Installation
The complete installation (and upgrading) is done by one single install file:
https://raw.githubusercontent.com/dj0abr/QO100_Transceiver/main/install
(no need to clone this github project, all is done automatically by this install file)
open a terminal and run these commands:
```
wget https://raw.githubusercontent.com/dj0abr/QO100_Transceiver/main/install
chmod 755 install
./install
```
that's all. There is nothing more to do than to run this install file.
The install script was made for debian/ubuntu based Linux systems. If you are using another system then please do these steps manually:
* clone this project
* in the script QO100_Transceiver/sctipts/prepare_ubuntu_pluto look for the installation of several libraries and install them for your OS.
* Install the latest version of the mono project (see prepare_mono as an example)
* make clean and make the transceiver software
## run the software
the software has two parts:
trxdriver .... this is the part doing all the work, without the GUI\
trxGui.exe ... the user interface
After installation both files are located in the folder\
.../QO100_Transceiver/Release
Additionally a start script was created
* start the software by entering: ./startQO100trx
this opens the user interface and automatically starts the background jobs
## configuration
click the SETUP button
* enter how the pluto is connected
* choose the sound device where microphone and loud speaker are connected
* enter the correct RX and TX frequencies. See the examples on the screen.
#### Audio on Raspberry PI OS:
Raspi OS shows many many audio devices nobody really needs.\
It is highly recommended to choose Pulseaudio for loudspeaker and microphone and then use the sound mixer pavucontrol (is installed) to select devices and control volume.
## Linux OS issues
In general this software runs on all linux distributions.
The script prepare_ubuntu_pluto contains the installation for all required libraries.
But different distributions may use different names for their libraries. The script was developed for Ubuntu based systems, like Ubuntu, Mint, Raspbery-OS and many others.
If you try to run prepare_ubuntu_pluto on different platforms like Suse, Fedora... you maybe need to change the name of some libraries.

BIN
Release/ColorSlider.dll Executable file

Binary file not shown.

BIN
Release/SOInstLin.sh Normal file

Binary file not shown.

13
Release/bcn_fftcfg Normal file
View File

@ -0,0 +1,13 @@
(fftw-3.3.10 fftw_wisdom #x3c273403 #x192df114 #x4d08727c #xe98e9b9d
(fftw_codelet_t1fv_4_avx 1 #x11bdd #x11bdd #x0 #x3faffd6c #x36c48939 #x2b89344c #x07d800dd)
(fftw_codelet_t2fv_20_avx 0 #x11bdd #x11bdd #x0 #x587c66c4 #x4f76fdef #xceb21d82 #xa0de1395)
(fftw_codelet_t2fv_25_sse2 1 #x11bdd #x11bdd #x0 #x5ecdb41b #x076a3fa6 #x4b08f138 #x4d35e39a)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x437baa88 #x22931f52 #xd4baa3df #x89d10f69)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x4cd32709 #xcef8290a #x90af32c9 #xefa6f35c)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #xfd422625 #x3b710790 #xb20b63af #x07bc3484)
(fftw_codelet_t1fv_5_avx 0 #x11bdd #x11bdd #x0 #xd9f832de #xb911c57e #xb0878a3f #x59d43138)
(fftw_codelet_n1fv_20_avx 0 #x11bdd #x11bdd #x0 #xdc55ecc0 #x01886d93 #x75a23ccf #x95afb0b0)
(fftw_codelet_n1fv_14_avx 0 #x11bdd #x11bdd #x0 #xc521610b #x38693a8a #x5257754a #xcc97d2ef)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x6c8cc274 #xb6b23efe #x536976d9 #xba7dfb58)
(fftw_codelet_t1fv_16_sse2 1 #x11bdd #x11bdd #x0 #x0356ef58 #xd4323bdf #xbb447b08 #x9e812fce)
)

9
Release/fftcfg Normal file
View File

@ -0,0 +1,9 @@
(fftw-3.3.10 fftw_wisdom #x3c273403 #x192df114 #x4d08727c #xe98e9b9d
(fftw_codelet_n1fv_14_avx 0 #x11bdd #x11bdd #x0 #xc521610b #x38693a8a #x5257754a #xcc97d2ef)
(fftw_codelet_t2fv_20_avx 0 #x11bdd #x11bdd #x0 #x587c66c4 #x4f76fdef #xceb21d82 #xa0de1395)
(fftw_codelet_t1fv_5_avx 0 #x11bdd #x11bdd #x0 #xd9f832de #xb911c57e #xb0878a3f #x59d43138)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x6c8cc274 #xb6b23efe #x536976d9 #xba7dfb58)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #xfd422625 #x3b710790 #xb20b63af #x07bc3484)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x437baa88 #x22931f52 #xd4baa3df #x89d10f69)
(fftw_codelet_t1fv_16_sse2 1 #x11bdd #x11bdd #x0 #x0356ef58 #xd4323bdf #xbb447b08 #x9e812fce)
)

BIN
Release/qo100trx.exe Executable file

Binary file not shown.

2
Release/startQO100trx Executable file
View File

@ -0,0 +1,2 @@
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/arm-linux-gnueabihf
mono qo100trx.exe

BIN
Release/trxdriver Executable file

Binary file not shown.

BIN
ai.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

484
fft.cpp Normal file
View File

@ -0,0 +1,484 @@
/*
* Adalm Pluto Driver
* ==================
* Author: DJ0ABR
*
* (c) DJ0ABR
* www.dj0abr.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* =========================
* FFT for Spectrum/Waterfall
* =========================
*
*/
#include "qo100trx.h"
#include <fftw3.h>
void fftinit();
void calc_fft(uint8_t *data, int len);
void findSignal(uint16_t *p16, int anz);
void* fft_threadfunction(void* param);
void init_fft()
{
fftinit();
pthread_t fftthread;
pthread_create(&fftthread, NULL, fft_threadfunction, NULL);
}
void* fft_threadfunction(void* param)
{
int ph = 0;
pthread_detach(pthread_self());
printf("entering FFT loop, *** PID:%ld ***\n",syscall(SYS_gettid));
while(keeprunning)
{
uint8_t data[PLUTOBUFSIZE*4];
if(read_fifo(FFTfifo, data, PLUTOBUFSIZE*4))
{
if(++ph >= 2) // uncomment to reduce cpu load
{
ph=0;
calc_fft(data, PLUTOBUFSIZE*4);
}
}
usleep(1000);
}
printf("exit FFT loop\n");
pthread_exit(NULL); // self terminate this thread
return NULL;
}
fftw_complex *din = NULL;
fftw_complex *cpout = NULL;
fftw_plan plan = NULL;
#define FFT_RESOLUTION 25 // Hz per bin
#define FFT_LENGTH (SAMPRATE / FFT_RESOLUTION) // 560kS/s / 25 = 22400
void fftinit()
{
int numofcpus = sysconf(_SC_NPROCESSORS_ONLN); // Get the number of logical CPUs.
if(numofcpus > 1)
{
printf("found %d cores, running FFT in multithreading mode\n",numofcpus);
fftw_init_threads();
fftw_plan_with_nthreads(numofcpus);
}
fftw_import_wisdom_from_filename("fftcfg");
din = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * FFT_LENGTH);
cpout = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * FFT_LENGTH);
plan = fftw_plan_dft_1d(FFT_LENGTH, din, cpout, FFTW_FORWARD, FFTW_MEASURE);
fftw_export_wisdom_to_filename("fftcfg");
printf("fft init ok\n");
}
void close_fft()
{
if(din) fftw_free(din);
din = NULL;
if(cpout) fftw_free(cpout);
cpout = NULL;
}
// convert a frequency offset (starting at ,470 and the kHz part only) to the bin index
int FreqToBinIdx(int freq)
{
// bins: 0.. 22400
// freq: 0..560000
return freq * 224 / 5600;
}
void calc_fft(uint8_t *data, int len)
{
static int din_idx = 0;
double real, imag;
// values for small WF, calculate only once per loop
int span = FFT_RESOLUTION*1120; // size of small waterfall in Hz (28000Hz, +/-14kHz)
int start = FreqToBinIdx(RXoffsetfreq - span/2);
int end = FreqToBinIdx(RXoffsetfreq + span/2);
// bin position of RX signal at 0.2-2.8kHz above RXoffsetfreq
int qsostart = FreqToBinIdx(RXoffsetfreq + 200);
int qsoend = FreqToBinIdx(RXoffsetfreq + 2800);
for(int i=0; i<len; i+=4)
{
// convert Pluto samples to fftw3 complex samples
int16_t xi = data[i+1];
xi <<= 8;
xi += data[i];
int16_t xq = data[i+3];
xq <<= 8;
xq += data[i+2];
din[din_idx][0] = (double)xi;
din[din_idx][1] = (double)xq;
din_idx++;
if(din_idx >= FFT_LENGTH)
{
din_idx = 0;
// if fftspeed > 0 then ignore every n fft line
// this helps to run this software on slow SBCs
static int fdel = 0;
if(fdel++ < fftspeed) continue;
fdel = 0;
// the fft input buffer is full, now lets execute the fft
fftw_execute(plan);
// the FFT delivers FFT_LENGTH values (44800 bins)
// but we only use the first half of them, which is the full range with the
// requested resolution of 25 Hz per bin (22400 bins)
int numbins = FFT_LENGTH; // 22400 (22400*25=560k)
// the FFT generates the upper half folloed by the lower half
// the tuned freq is in the center
// range centerfreq(,750) - 560k/2 to +560k/2
// is ,470 ... 1,030
float bin[numbins];
int binidx = 0;
// lower half
for(int i=numbins/2; i<numbins; i++)
{
real = cpout[i][0];
imag = cpout[i][1];
// calc magnitude
double v = sqrt((real * real) + (imag * imag));
// convert to dB scale
if(v <=0) v=0.01;
bin[binidx] = log(v);
bin[binidx] *= 1000;
if(bin[binidx] > 32768) printf("reduce multiplicator %f\n",bin[binidx]);
binidx++;
}
// upper half
for(int i=0; i<numbins/2; i++)
{
real = cpout[i][0];
imag = cpout[i][1];
// calc magnitude
double v = sqrt((real * real) + (imag * imag));
// convert to dB scale
if(v <=0) v=0.01;
bin[binidx] = log(v);
bin[binidx] *= 1000;
if(bin[binidx] > 32768) printf("reduce multiplicator %f\n",bin[binidx]);
binidx++;
}
// bins are in the range 0..32767 (16 bit)
// ======== noise level ==========
// measure the noise level on freq: ,475 to ,490 MHz, just below the lower beacon
// ,470 is index 0, steps 25 Hz
// ,475 is index 200 and ,490 is index 800
// so we calc the mid value if this range
float gval = 0;
float maxgval = 0;
int gstart = FreqToBinIdx(485000 - 470000);
int gend = FreqToBinIdx(495000 - 470000);
// mean noise level
for(int g=gstart; g<gend; g++)
gval += bin[g];
gval /= (gend-gstart);
// max noise level
for(int g=gstart; g<gend; g++)
if(bin[g] > maxgval) maxgval = bin[g];
// bring down a little, looks nicer
gval = gval * 100 / 99;
// and make the mid value over 10 values
#define GMIDLEN 10
static float gmid[GMIDLEN];
static int gmididx = 0;
gmid[gmididx] = gval;
if(++gmididx >= GMIDLEN) gmididx = 0;
float gvalmid = 0;
for(int g=0; g<GMIDLEN; g++)
gvalmid += gmid[g];
gvalmid /= GMIDLEN;
uint32_t gvalmid_u = (uint32_t)gvalmid;
uint32_t gvalmax_u = (uint32_t)maxgval;
// ======== beacon level ==========
// measure the max beacon level of BPSK beacon
// max of 749 - 751
float mval = 0;
int mstart = FreqToBinIdx(749000 - 470000);
int mend = FreqToBinIdx(751000 - 470000);
for(int m=mstart; m<mend; m++)
if(bin[m] > mval) mval = bin[m];
// and make the mid value over 10 values
#define MMIDLEN 10
static float mmid[MMIDLEN];
static int mmididx = 0;
mmid[mmididx] = mval;
if(++mmididx >= MMIDLEN) mmididx = 0;
float mvalmid = 0;
for(int m=0; m<MMIDLEN; m++)
mvalmid += mmid[m];
mvalmid /= MMIDLEN;
uint32_t mvalmid_u = (uint32_t)mvalmid;
// ======== QSO: measure max audio level 0-3kHz ==========
float qmval = 0;
for(int m=qsostart; m<qsoend; m++)
if(bin[m] > qmval) qmval = bin[m];
uint32_t qmvalmid_u = (uint32_t)qmval; //qmvalmid;
// ======= QSO level above noise max level =======
float qdlev = qmval - (maxgval + gvalmid)/2;
// and make the mean value
#define DIFFMIDLEN 50
static float diffmid[DIFFMIDLEN];
static int diffmididx = 0;
diffmid[diffmididx] = qdlev;
if(++diffmididx >= DIFFMIDLEN) diffmididx = 0;
float diffvalmid = 0;
for(int m=0; m<DIFFMIDLEN; m++)
diffvalmid += diffmid[m];
diffvalmid /= DIFFMIDLEN;
uint32_t diffvalmid_u = (uint32_t)diffvalmid;
uint8_t levels[22];
levels[0] = 5;
levels[1] = gvalmid_u >> 24;
levels[2] = gvalmid_u >> 16;
levels[3] = gvalmid_u >> 8;
levels[4] = gvalmid_u & 0xff;
levels[5] = mvalmid_u >> 24;
levels[6] = mvalmid_u >> 16;
levels[7] = mvalmid_u >> 8;
levels[8] = mvalmid_u & 0xff;
levels[9] = qmvalmid_u >> 24;
levels[10] = qmvalmid_u >> 16;
levels[11] = qmvalmid_u >> 8;
levels[12] = qmvalmid_u & 0xff;
levels[13] = gvalmax_u >> 24;
levels[14] = gvalmax_u >> 16;
levels[15] = gvalmax_u >> 8;
levels[16] = gvalmax_u & 0xff;
levels[17] = diffvalmid_u >> 24;
levels[18] = diffvalmid_u >> 16;
levels[19] = diffvalmid_u >> 8;
levels[20] = diffvalmid_u & 0xff;
levels[21] = ptt;
sendUDP(gui_ip, GUI_UDPPORT, levels, 22);
// ======== BIG Waterfall ========
// the big waterfall has a screen resulution of 1120 pixel
// FFT_RESOLUTION=25 Hz/bin
// the FFT delivers 1,12MS/s / 25 / 2 = 22400 values
// so the BIG WF resolution is 22400 / 1120 = 20
static const int bigres = numbins / 1120;
static const int midlen = 15;
static uint32_t bigmid[midlen][FFT_LENGTH];
static int bmididx = 0;
int didx = 0;
for(int i=0; i<numbins; i+=bigres)
{
float max = 0;
for(int j=0; j<bigres; j++)
{
float fbin = bin[i+j];
if(fbin > max) max = fbin;
}
bigmid[bmididx][didx++] = (uint32_t)max;
if(max > 32768) printf("16bit overflow %f\n",max);
}
uint8_t bigline[1 + 2 * (numbins/bigres)];
uint8_t biglineraw[1 + 2 * (numbins/bigres)];
int bigidx = 0;
bigline[bigidx] = 0; // ID for big spectrum
biglineraw[bigidx] = 2; // ID for big waterfall
bigidx++;
for(int i=0; i<(numbins/bigres); i++)
{
uint32_t uv = 0;
for(int j=0; j<midlen; j++)
uv += bigmid[j][i];
uv /= midlen;
if((bmididx+1) >= (int)sizeof(biglineraw))
printf("+++++++++++++++++++++++ %d %d\n",bmididx, numbins/bigres);
biglineraw[bigidx] = bigmid[bmididx][i] >> 8;
biglineraw[bigidx+1] = bigmid[bmididx][i] & 0xff;
bigline[bigidx] = uv >> 8;
bigline[bigidx+1] = uv & 0xff;
bigidx+=2;
}
if(++bmididx >= midlen) bmididx = 0;
// send the big fft bins to the GUI
// raw values, no mid val, for waterfall
sendUDP(gui_ip, GUI_UDPPORT, biglineraw, bigidx);
// send the big fft bins to the GUI
// mid vals for spectrum
sendUDP(gui_ip, GUI_UDPPORT, bigline, bigidx);
// ======== SMALL Waterfall ========
// the small waterfall is a piece of some kHz around the mid RX frequency "RXoffsetfreq"
// RXoffsetfreq is in kHz above the left margin which is 750-280= 470k
// the bin-index of RXoffsetfreq is: RXoffsetfreq/10
static const int small_midlen = 15;
static uint32_t smallmid[small_midlen][FFT_LENGTH];
static int smididx = 0;
for(int i=start; i<end; i++)
{
if(i>=0 && i<FFT_LENGTH)
smallmid[smididx][i] = (uint32_t)bin[i];
}
uint8_t smallline[1+(end-start)*2];
uint8_t smalllineraw[1+(end-start)*2];
int smallidx = 0;
smallline[smallidx] = 1; // ID for small waterfall
smalllineraw[smallidx] = 3; // ID for small waterfall
smallidx++;
for(int i=start; i<end; i++)
{
uint32_t uv = 0;
if(i>=0 && i<FFT_LENGTH)
{
for(int j=0; j<small_midlen; j++)
uv = uv + smallmid[j][i]+smallmid[j][i-1]+smallmid[j][i+1];
uv /= (small_midlen*3);
if((smallidx+1) >= (int)sizeof(smalllineraw)) printf("*********************** %d %d %d\n",smallidx, start,end);
smalllineraw[smallidx] = smallmid[smididx][i] >> 8;
smalllineraw[smallidx+1] = smallmid[smididx][i] & 0xff;
smallline[smallidx] = uv >> 8;
smallline[smallidx+1] = uv & 0xff;
}
else
{
smalllineraw[smallidx] = 0;
smalllineraw[smallidx+1] = 0;
smallline[smallidx] = 0;
smallline[smallidx+1] = 0;
}
smallidx += 2;
}
if(++smididx >= small_midlen) smididx = 0;
findSignal((uint16_t *)smallline,smallidx/2);
// send the small fft bins to the GUI
sendUDP(gui_ip, GUI_UDPPORT, smalllineraw, smallidx);
// send the small fft bins to the GUI
sendUDP(gui_ip, GUI_UDPPORT, smallline, smallidx);
}
}
}
#define SRCHANZ 20
int srch[SRCHANZ];
int srchpos = 0;
void findSignal(uint16_t *p16, int anz)
{
// measure frequency of a signal within +/-4kHz of the RXfrequency
int st12 = (14000-6000)*1120/28000; // -4kHz
int en12 = (14000+6000)*1120/28000; // +4kHz
uint32_t mv16=0;
// measure mean value over 28 kHz
for(int i=0; i<anz; i++)
mv16 += p16[i];
mv16 /= anz;
// filter out the signal
uint16_t vt=100, vb=96; // level factors to filter
int filtval = 0;
int filtanz = 0;
for(int i=st12+1; i<en12-1; i++)
{
if( p16[i-1] > (mv16*vt/vb) &&
p16[i] > (mv16*vt/vb) &&
p16[i+1] > (mv16*vt/vb))
{
filtval += i;
filtanz++;
}
}
// calculate the mid frequency of the signal
if(filtanz > 0)
{
filtval /= filtanz;
int freq = filtval * 25 - 14000;
srch[srchpos] = freq;
if(++srchpos >= SRCHANZ) srchpos = 0;
// calculate a mean value of the found frequency
int srchmid = 0;
for(int i=0; i<SRCHANZ; i++)
srchmid += srch[i];
srchmid /= SRCHANZ;
if(srchpos == 0)
{
int korrfact = 1350 - srchmid;
//printf("%d, corr by: %d\n",srchmid,korrfact);
// send correction value to GUI
uint8_t cf[5];
cf[0] = 9;
cf[1] = korrfact >> 24;
cf[2] = korrfact >> 16;
cf[3] = korrfact >> 8;
cf[4] = korrfact & 0xff;
sendUDP(gui_ip, GUI_UDPPORT, cf, 5);
}
}
}

BIN
fft.o Normal file

Binary file not shown.

35
fftcfg Normal file
View File

@ -0,0 +1,35 @@
(fftw-3.3.8 fftw_wisdom #x3c273403 #x192df114 #x4d08727c #xe98e9b9d
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x35500318 #xa2053218 #x9432ec0f #x87073922)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x7f68e9fa #x7bad3d01 #x98dafd20 #xcdb6b7ce)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x3c7290dd #x1d739c0c #xa05436a1 #xf127d781)
(fftw_codelet_t1fv_7_avx 0 #x11bdd #x11bdd #x0 #x8730deaa #xb4423bfd #xf2c34131 #x945d59f7)
(fftw_codelet_n1fv_25_avx 0 #x11bdd #x11bdd #x0 #x10c82991 #xd13397bb #x911f3bcd #x9a0aac9d)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x73f2196a #xb7039b28 #x543344bd #xc5d57c2e)
(fftw_codelet_t1fuv_7_avx 0 #x11bdd #x11bdd #x0 #x91a3d5b1 #x71a7404e #x48b7e1ae #x9d253d8e)
(fftw_codelet_n1fv_14_avx 0 #x11bdd #x11bdd #x0 #xe6cf6c3f #xd07b6475 #x8d35d10b #xa15f720d)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x00e91bf9 #x18dbc270 #x1de439e6 #x1a48325e)
(fftw_codelet_t1fv_7_avx 0 #x11bdd #x11bdd #x0 #x94b1535d #x464eb909 #xbb1d6ae9 #xc97b824a)
(fftw_codelet_n1fv_25_avx 0 #x11bdd #x11bdd #x0 #x2aa7ed75 #xa9e5dff5 #x81285df6 #xe9ac14fa)
(fftw_codelet_t2fv_10_avx 0 #x11bdd #x11bdd #x0 #xb76f3788 #x7be6dae5 #xc3f94ec6 #x648cbd8e)
(fftw_codelet_t1fuv_10_avx 0 #x11bdd #x11bdd #x0 #x03171678 #xebaa405d #x03f48716 #x4140fb61)
(fftw_codelet_t2fv_10_avx 0 #x11bdd #x11bdd #x0 #x766ce6ab #x100d658e #xc75adcb3 #xfefbee0c)
(fftw_codelet_t3fv_16_avx 1 #x11bdd #x11bdd #x0 #x9dc31525 #xa7b2f94b #xac1cc9df #xaaa77f45)
(fftw_codelet_t1fv_64_avx 1 #x11bdd #x11bdd #x0 #x3550de6a #x2d8f363f #x24a26c56 #x1e578d59)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x9a6f97a3 #xd526ccb4 #xf3f9e9a6 #x810686ae)
(fftw_codelet_t1fv_32_avx 1 #x11bdd #x11bdd #x0 #x8048e739 #x6d9eef36 #x57776ea1 #x73b49435)
(fftw_codelet_t1fv_32_avx 1 #x11bdd #x11bdd #x0 #x27f49072 #x8acb2efd #xd50279ca #x457292fa)
(fftw_codelet_t1fv_7_avx 0 #x11bdd #x11bdd #x0 #xd9f832de #xb911c57e #xb0878a3f #x59d43138)
(fftw_codelet_t2fv_16_avx 1 #x11bdd #x11bdd #x0 #xd4d39737 #x36e690cf #x36d4c10c #x64f4ef7c)
(fftw_codelet_t2fv_10_avx 0 #x11bdd #x11bdd #x0 #x2c0ddf29 #x02d7f1b0 #x1f788f28 #x1c6eca0e)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x2ffc6c7e #x04642ea9 #xd059ca7e #xc3bf3501)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #xcd395e7b #x704347eb #x93fba7b1 #x1f8e8683)
(fftw_dft_thr_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x6f619c66 #xb9dcd1c8 #xc74e9a5c #x82ce38a4)
(fftw_codelet_n1fv_20_avx 0 #x11bdd #x11bdd #x0 #x3db87a70 #x7c5108ec #x2580e3b5 #xbf99f2dd)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x7f000442 #x58e4dd05 #xa3b6bd4b #x8e39c722)
(fftw_codelet_t1fuv_10_avx 0 #x11bdd #x11bdd #x0 #xccaa18a4 #x0ad043df #x96b3e0fb #xa29ecc39)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #xf66ff4c6 #x77e7b389 #x4a1777f4 #xa9d87b9f)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #xad5917a6 #xc3718057 #x519be636 #x6e895acb)
(fftw_codelet_t1fv_5_avx 0 #x11bdd #x11bdd #x0 #x28df877c #xf3587663 #x562a5896 #x1c47bd8e)
(fftw_dft_vrank_geq1_register 0 #x11bdd #x11bdd #x0 #x12559e03 #x58c96dec #x2a4ced70 #xb7d49335)
(fftw_codelet_n1fv_20_avx 0 #x11bdd #x11bdd #x0 #x936acb7d #xd96def60 #x5c99c8f9 #xa8f5af47)
)

17
install Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
echo "==== complete install QO100 Transceiver ===="
echo "full update, upgrade and installation"
set -e
cd ~
echo "update system by running apt-get update"
sudo apt-get update
echo "install git"
sudo apt-get install git -y
cd ~/QO100_Transceiver/scripts
./prepare_ubuntu_pluto
cd ~/QO100_Transceiver/scripts
./makeall
echo "==== Installation: OK ===="
cd ~/QO100_Transceiver/Release
echo "==== Start the Transceiver in the folder QO100_Transceiver/Release ===="
echo "==== by entering ./startQO100trx ===="

428
kmlib/km_helper.cpp Normal file
View File

@ -0,0 +1,428 @@
/*
* Raspberry PI / Zero AddOn Board specially for Ham Radio Applications
* ====================================================================
* Author: DJ0ABR
*
* (c) DJ0ABR
* www.dj0abr.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
kmhelper.cpp
===========
useful functions
*
*/
#include "../qo100trx.h"
#include <pwd.h>
int keeprunning = 1; // set to 0 at program end to exit all processes
char configfile[512] = {0};
// check if it is already running
int isRunning(char *prgname)
{
int num = 0;
char s[256];
sprintf(s,"ps -e | grep %s",prgname);
FILE *fp = popen(s,"r");
if(fp)
{
// gets the output of the system command
while (fgets(s, sizeof(s)-1, fp) != NULL)
{
if(strstr(s,prgname) && !strstr(s,"grep"))
{
if(++num == 2)
{
printf("%s is already running, do not start twice !\n",prgname);
pclose(fp);
return 1;
}
}
}
pclose(fp);
}
return 0;
}
void (*sigfunc)();
// signal handler
void sighandler(int signum)
{
//printf("\n\nprogram stopped by signal\n");
(*sigfunc)();
}
void install_signal_handler(void (*signalfunction)())
{
sigfunc = signalfunction;
// signal handler, mainly used if the user presses Ctrl-C
struct sigaction sigact;
sigact.sa_handler = sighandler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGINT, &sigact, NULL);
sigaction(SIGTERM, &sigact, NULL);
sigaction(SIGQUIT, &sigact, NULL);
sigaction(SIGABRT, &sigact, NULL); // assert() error
//sigaction(SIGSEGV, &sigact, NULL);
// switch off signal 13 (broken pipe)
// instead handle the return value of the write or send function
signal(SIGPIPE, SIG_IGN);
}
void getParameters(int argc, char *argv[])
{
int opt;
while ((opt = getopt(argc, argv, "c:")) != -1)
{
switch (opt)
{
case 'c':
// specify config file name
if(optarg && strlen(optarg) > 2 && strlen(optarg) < (sizeof(configfile)-1))
{
strcpy(configfile,optarg);
}
else
{
printf("invalid Config File Parameter [-c Configfilename]: %s\n", optarg);
exit(0);
}
break;
}
}
}
// run external program and return it's output
char *runProgram(char *parameter, int maxlen)
{
//printf("run:<%s>\n",parameter);
FILE *fp = popen(parameter,"r");
if(fp)
{
*parameter = 0;
while (fgets(parameter+strlen(parameter), maxlen-1-strlen(parameter), fp) != NULL)
{
//printf("returns:<%s>\n", parameter);
}
pclose(fp);
return parameter;
}
else
printf("ERROR: cannot run: %s\n",parameter);
return NULL;
}
void showbitstring(char* title, uint8_t* data, int totallen, int anz)
{
printf("%s. len %d: ", title, totallen);
for (int i = 0; i < anz; i++)
printf("%01X ", data[i]);
printf("\n");
}
void showbytestring(char *title, uint8_t *data, int totallen, int anz)
{
printf("%s. len % 4d: ",title, totallen);
for(int i=0; i<anz; i++)
printf("%02X ",data[i]);
printf("\n");
}
void showbytestring16(char *title, uint16_t *data, int anz)
{
printf("%s. len %d: ",title,anz);
for(int i=0; i<anz; i++)
printf("%04X ",data[i]);
printf("\n");
}
void showbytestring32(char* title, uint32_t* data, int anz)
{
printf("%s. len %d: ", title, anz);
for (int i = 0; i < anz; i++)
printf("%08X ", data[i]);
printf("\n");
}
void showbytestringf(char* title, float* data, int totallen, int anz)
{
printf("%s. len %d: ", title, totallen);
for (int i = 0; i < anz; i++)
printf("%7.4f ", data[i]);
printf("\n");
}
// get own IP adress
char* ownIP()
{
static char ip[20] = { 0 };
struct ifaddrs* ifaddr, * ifa;
int s;
char host[NI_MAXHOST];
if (getifaddrs(&ifaddr) == -1)
{
printf("cannot read own IP address, getifaddrs faield. Check Networking\n");
return ip;
}
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
if (ifa->ifa_addr == NULL)
continue;
s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (ifa->ifa_addr->sa_family == AF_INET)
{
if (s != 0)
{
printf("getnameinfo() failed: %s\n", gai_strerror(s));
printf("cannot read own IP address, getnameinfo failed: %s. Check Networking\n", gai_strerror(s));
break;
}
if (strncmp(host, "127", 3) != 0)
{
strcpy(ip, host);
break;
}
}
}
freeifaddrs(ifaddr);
return ip;
}
char* cleanStr(char *s)
{
if(s[0] > ' ')
{
// remove trailing crlf
for(size_t j=0; j<strlen(s); j++)
if(s[j] == '\n' || s[j] == '\r') s[j] = 0;
return s; // nothing to do
}
for(size_t i=0; i<strlen(s); i++)
{
if(s[i] >= '0')
{
// i is on first character
memmove(s,s+i,strlen(s)-i);
s[strlen(s)-i] = 0;
// remove trailing crlf
for(size_t j=0; j<strlen(s); j++)
if(s[j] == 'n' || s[j] == '\r') s[j] = 0;
return s;
}
}
return NULL; // no text found in string
}
char *getword(char *s, int idx)
{
if(idx == 0)
{
for(size_t i=0; i<strlen(s); i++)
{
if(s[i] < '0')
{
s[i] = 0;
return s;
}
}
return NULL;
}
for(size_t j=0; j<strlen(s); j++)
{
if(s[j] > ' ')
{
char *start = s+j;
for(size_t k=0; k<strlen(start); k++)
{
if(start[k] == ' ' || start[k] == '\r' || start[k] == '\n')
{
start[k] = 0;
return start;
}
}
return start;
}
}
return NULL;
}
// read the value of an element from the config file
// Format:
// # ... comment
// ElementName-space-ElementValue
// the returned value is a static string and must be copied somewhere else
// before this function can be called again
char *getConfigElement(char *elemname)
{
if(strlen(configfile) < 2) return NULL;
static char s[501];
int found = 0;
char fn[1024];
if(strlen(configfile) > 512)
{
printf("config file path+name too long: %s\n",configfile);
exit(0);
}
strcpy(fn,configfile);
if(fn[0] == '~')
{
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
sprintf(fn,"%s%s",homedir,configfile+1);
}
//printf("read Configuration file %s\n",fn);
FILE *fr = fopen(fn,"rb");
if(!fr)
{
printf("!!! Configuration file %s not found !!!\n",fn);
exit(0);
}
while(1)
{
if(fgets(s,500,fr) == NULL) break;
// remove leading SPC or TAB
if(cleanStr(s) == 0) continue;
// check if its a comment
if(s[0] == '#') continue;
// get word on index
char *p = getword(s,0);
if(!p) break;
if(strcmp(p, elemname) == 0)
{
char val[500];
if(*(s+strlen(p)+1) == 0) continue;
p = getword(s+strlen(p)+1,1);
if(!p) break;
// replace , with .
char *pkomma = strchr(p,',');
if(pkomma) *pkomma = '.';
strcpy(val,p);
strcpy(s,val);
found = 1;
break;
}
}
fclose(fr);
if(found == 0) return NULL;
return s;
}
void getConfigElement_double(char *elemname, double *pv, double multiplier)
{
char *p = getConfigElement(elemname);
if(p) *pv = atof(p) * multiplier;
}
void getConfigElement_longlong(char *elemname, long long *pv, double multiplier)
{
char *p = getConfigElement(elemname);
if(p) *pv = (long long)(atof(p) * multiplier);
}
void getConfigElement_int(char *elemname, int *pv, double multiplier)
{
char *p = getConfigElement(elemname);
if(p) *pv = (int)(atof(p) * multiplier);
}
float measure_samplerate(int id, int samp, int prt)
{
static unsigned long lastus[10];
static unsigned long samples[10];
static int f[10];
static int cnt[10];
static int first=1;
if(first)
{
first = 0;
for(int i=0; i<10; i++)
{
f[i] = 1;
cnt[i] = 0;
}
}
// measure sample rate
struct timeval tv;
gettimeofday(&tv, NULL);
if(f[id])
{
f[id] = 0;
lastus[id] = tv.tv_sec * 1000000 + tv.tv_usec;
samples[id] = samp;
}
samples[id] += samp;
unsigned long tnow = tv.tv_sec * 1000000 + tv.tv_usec;
float sr = 0;
if(++(cnt[id]) >= prt)
{
cnt[id] = 0;
sr = (samples[id]*1e6)/(tnow - lastus[id]);
printf("%d: %.6f\n",id,sr/1e6);
}
return sr;
}
int measure_maxval(double v, int anz)
{
static double max = - 99999999;
static int cnt = 0;
v = fabs(v);
if(v > max)
{
max = v;
//printf("maxval: %f\n",max);
}
if(++cnt >= anz)
{
printf("maxval: %f\n",max);
max = - 99999999;
cnt = 0;
return 1;
}
return 0;
}

27
kmlib/km_helper.h Normal file
View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <netdb.h>
int isRunning(char *prgname);
void install_signal_handler(void (*signalfunction)());
void showbitstring(char* title, uint8_t* data, int totallen, int anz);
void showbytestring(char *title, uint8_t *data, int totallen, int anz);
void showbytestring16(char *title, uint16_t *data, int anz);
void showbytestring32(char* title, uint32_t* data, int anz);
void showbytestringf(char* title, float* data, int totallen, int anz);
char* ownIP();
char *getConfigElement(char *elemname);
void getConfigElement_double(char *elemname, double *pv, double multiplier);
void getConfigElement_longlong(char *elemname, long long *pv, double multiplier);
void getConfigElement_int(char *elemname, int *pv, double multiplier);
float measure_samplerate(int id, int samp, int prt);
int measure_maxval(double v, int anz);
char *runProgram(char *parameter, int maxlen);
extern int keeprunning;

BIN
kmlib/km_helper.o Normal file

Binary file not shown.

173
kmlib/kmfifo.cpp Normal file
View File

@ -0,0 +1,173 @@
/*
* Raspberry PI / Zero AddOn Board specially for Ham Radio Applications
* ====================================================================
* Author: DJ0ABR
*
* (c) DJ0ABR
* www.dj0abr.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* universal thread safe fifo, used by many drivers and applications
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <pthread.h>
#include "kmfifo.h"
FIFOOBJ fifo[MAXFIFOS];
int fifonum = 0;
#define LOCK(id) pthread_mutex_lock(&fifo[id].crit_sec)
#define UNLOCK(id) pthread_mutex_unlock(&fifo[id].crit_sec)
// creates a new fifo
// maxelem_num ... max. number of elements in fifo
// maxelem_len ... max. length of one element (shorter elements are allowed)
// returns: ID of a fifo object, to be used for fifo functions
int create_fifo(int maxelem_num, int maxelem_len)
{
// create the fifo memory and init variables
fifo[fifonum].fifomem = malloc(maxelem_num * maxelem_len);
fifo[fifonum].plen = (int *)malloc(maxelem_num * sizeof(int));
fifo[fifonum].maxelemlen =maxelem_len;
fifo[fifonum].maxelem = maxelem_num;
fifo[fifonum].rdidx = 0;
fifo[fifonum].wridx = 0;
pthread_mutex_init(&fifo[fifonum].crit_sec, NULL);
int id = fifonum;
fifonum++;
return id;
}
void destroy_fifos()
{
for(int i=0; i<fifonum; i++)
{
free(fifo[fifonum].fifomem);
free(fifo[fifonum].plen);
if (&fifo[fifonum].crit_sec != NULL) pthread_mutex_destroy(&fifo[fifonum].crit_sec);
}
}
// write into the fifo
// ignore data if the fifo is full
void write_fifo(int id, uint8_t *pdata, int len)
{
FIFOOBJ *pfo = &fifo[id];
if(len > pfo->maxelemlen)
{
printf("element too long\n");
return;
}
LOCK(id);
if (((pfo->wridx + 1) % pfo->maxelem) == pfo->rdidx)
{
printf("cannot WRITE fifo %d full\n",id);
UNLOCK(id);
return;
}
// insert length of new data
*(pfo->plen) = len; // real length of the element
// insert new data
void *dst = (void *)((uint8_t *)pfo->fifomem + pfo->wridx * pfo->maxelemlen);
memcpy(dst, pdata, len);
if(++pfo->wridx >= pfo->maxelem) pfo->wridx = 0;
UNLOCK(id);
}
// read from the fifo
// return: number of bytes read
int read_fifo(int id, uint8_t* pdata, int maxlen)
{
FIFOOBJ *pfo = &fifo[id];
LOCK(id);
if(pfo->rdidx == pfo->wridx)
{
// Fifo empty, no data available
//printf("read: no data\n");
UNLOCK(id);
return 0;
}
// read length
int len = *pfo->plen; // length of an element
if (len > maxlen)
{
printf("read_fifo: %d, pdata too small. Need:%d has:%d\n", id, len, maxlen);
return 0; // pdata too small
}
// read data
void *src = (void *)((uint8_t *)pfo->fifomem + pfo->rdidx * pfo->maxelemlen);
memcpy(pdata, src, len);
if (++pfo->rdidx >= pfo->maxelem) pfo->rdidx = 0;
UNLOCK(id);
return len;
}
void fifo_clear(int id)
{
fifo[id].wridx = fifo[id].rdidx = 0;
}
int fifo_freespace(int id)
{
int freebuf = 0;
LOCK(id);
int elemInFifo = (fifo[id].wridx + fifo[id].maxelem - fifo[id].rdidx) % fifo[id].maxelem;
freebuf = fifo[id].maxelem - elemInFifo;
UNLOCK(id);
return freebuf;
}
int fifo_dataavail(int id)
{
LOCK(id);
if (fifo[id].rdidx == fifo[id].wridx)
{
// Fifo empty, no data available
UNLOCK(id);
return 0;
}
UNLOCK(id);
return 1;
}
int fifo_usedspace(int id)
{
int us = fifo[id].maxelem - fifo_freespace(id);
return us;
}

21
kmlib/kmfifo.h Normal file
View File

@ -0,0 +1,21 @@
// max number of fifo, just a high number, never really used
#define MAXFIFOS 200
typedef struct _FIFOOBJ_ {
int maxelem;
int maxelemlen;
int rdidx;
int wridx;
void *fifomem;
int *plen; // real length of an element
pthread_mutex_t crit_sec;
} FIFOOBJ;
int create_fifo(int elem_num, int elem_len);
void destroy_fifos();
void write_fifo(int id, uint8_t *pdata, int len);
int read_fifo(int id, uint8_t* pdata, int maxlen);
void fifo_clear(int id);
int fifo_freespace(int id);
int fifo_dataavail(int id);
int fifo_usedspace(int id);

BIN
kmlib/kmfifo.o Normal file

Binary file not shown.

114
kmlib/kmtimer.cpp Normal file
View File

@ -0,0 +1,114 @@
/*
* Linux multithreaded timer
* =========================
* Author: DJ0ABR
*
* (c) DJ0ABR
* www.dj0abr.de
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*
* Repeatable Timer for various needs
* ==================================
*
*/
#include "kmtimer.h"
/*
usage:
// this function is called every time_in_ms milliseconds
void timerhandler_function(void)
{
// called every time_in_ms
}
// start a new timer
int timernum = start_timer(time_in_ms, &timerhandler_function);
stop_timer(timernum);
*/
typedef struct _TIMERDEF_ {
int to_ms; // timeout value in ms
timer_t timerid;
void(*timer_func_handler_pntr)(void); // this user supplied function is called on timeout
struct itimerspec in, out;
} TIMERDEF;
#define MAXTIMERS 20
TIMERDEF timers[MAXTIMERS];
int timernum = 0;
// callback function. The timer number is in val.sival_int
void sighler (union sigval val)
{
int tnum = val.sival_int;
timers[tnum].timer_func_handler_pntr();
}
int start_timer(int mSec, void(*timer_func_handler)(void))
{
timers[timernum].timer_func_handler_pntr = timer_func_handler;
timers[timernum].to_ms = mSec;
pthread_attr_t attr;
pthread_attr_init( &attr );
struct sched_param parm;
parm.sched_priority = 255;
pthread_attr_setschedparam(&attr, &parm);
struct sigevent sig;
sig.sigev_notify = SIGEV_THREAD;
sig.sigev_notify_function = sighler;
sig.sigev_value.sival_int = timernum;
sig.sigev_notify_attributes = &attr;
int ret = timer_create(CLOCK_REALTIME, &sig, &(timers[timernum].timerid));
if (ret == 0)
{
timers[timernum].in.it_value.tv_sec = mSec / 1000;
timers[timernum].in.it_value.tv_nsec = (mSec % 1000) * 1000000;
timers[timernum].in.it_interval.tv_sec = mSec / 1000;
timers[timernum].in.it_interval.tv_nsec = (mSec % 1000) * 1000000;
ret = timer_settime(timers[timernum].timerid, 0, &timers[timernum].in, &timers[timernum].out);
if(ret == -1)
{
printf("timer_settime() failed with %d\n", errno);
return -1;
}
}
else
{
printf("timer_create() failed with %d\n", errno);
return -1;
}
int r = timernum;
timernum++;
return r;
}
void stop_timer(int timer)
{
timer_delete(timers[timer].timerid);
}

13
kmlib/kmtimer.h Normal file
View File

@ -0,0 +1,13 @@
#include <time.h>
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
int start_timer(int mSec, void(*timer_func_handler)(void));
void stop_timer(int timer);
void sleep_ms(int ms);

BIN
kmlib/kmtimer.o Normal file

Binary file not shown.

393
kmlib/rotary.cpp Normal file
View File

@ -0,0 +1,393 @@
/*
this is an extract from kmclib (see github, dj0abr repos)
it works on raspberry pi only
* Raspberry PI / Zero AddOn Board specially for Ham Radio Applications
* ====================================================================
* Author: DJ0ABR
*
* (c) DJ0ABR
* www.dj0abr.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
encoder.cpp
===========
function to handle rotary encoder
Usage:
======
initialize and assign ports to the encoders
-------------------------------------------
up to 3 encoders are supported, If not used, then assign port nunmber -1
init_rotencoder(int portA1, int portB1, int portA2, int portB2, int portA3, int portB3)
see gpio.h _INPUTS_ for valid port numbers
read encoder:
-------------
int getEncSteps(int idx)
idx ... encoder number 0,1 or 2
returns the number of steps since last read
*
*/
#include "../qo100trx.h"
int init_gpio();
int getPort(char *port);
#define NUM_OF_ENCODERS 2
pthread_mutex_t rotenc_crit_sec;
#define LOCK pthread_mutex_lock(&(rotenc_crit_sec))
#define UNLOCK pthread_mutex_unlock(&(rotenc_crit_sec))
void *rotencproc(void *);
char portA[NUM_OF_ENCODERS][3] = {"fa","va"};
char portB[NUM_OF_ENCODERS][3] = {"fb","vb"};
int encsteps[NUM_OF_ENCODERS];
pthread_t rotenc_tid;
// port numbers see gpio.h _INPORTS_
// -1 if not used
void init_rotencoder()
{
// use the rotary encoder on a raspberry board only
// RASPI is passed to the Makefile as: make RASPI='-DRASPI'
#ifndef RASPI
return;
#endif
if(init_gpio() == -1) return;
memset(&encsteps, 0, sizeof(int)*NUM_OF_ENCODERS);
int pret = pthread_create(&rotenc_tid,NULL,rotencproc, NULL);
if(pret)
{
printf("rotenc process NOT started\n");
exit(0);
}
}
int getEncSteps(int idx)
{
int v;
LOCK;
v = encsteps[idx];
encsteps[idx] = 0;
UNLOCK;
return v;
}
void *rotencproc(void *pdata)
{
pthread_detach(pthread_self());
printf("rotenc process started\n");
int aval[NUM_OF_ENCODERS];
int bval[NUM_OF_ENCODERS];
int oldaval[NUM_OF_ENCODERS]={0,0};
while(keeprunning)
{
for(int i=0; i<NUM_OF_ENCODERS; i++)
{
aval[i] = getPort(portA[i]);
bval[i] = getPort(portB[i]);
if(aval[i]==1 && oldaval[i]==0)
{
// falling edge of port A
int dir = -1;
if(bval[i] == 1) dir = 1;
LOCK;
encsteps[i] += dir;
UNLOCK;
}
oldaval[i] = aval[i];
}
usleep(100);
}
printf("exit rotenc thread\n");
pthread_exit(NULL);
}
// 0=RX, 1=TX, 2=just released, 3=just pressed
int test_ptt_gpio()
{
#ifndef RASPI
return -1;
#endif
static int gold = -1;
int ret = 0;
int ptt = getPort("p");
if(gold != -1)
{
if(ptt == 0)
{
// PTT is pressed
if(gold == 0) ret = 1;
else ret = 3;
}
else
{
// PTT is released
if(gold == 0) ret = 2;
else ret = 0;
}
}
gold = ptt;
return ret;
}
// 0=unmuted, 1=muted, 2=just unmuted, 3=just muted
int test_mute_gpio()
{
#ifndef RASPI
return -1;
#endif
static int gold = -1;
int ret = 0;
int mute = getPort("m");
if(gold != -1)
{
if(mute == 0)
{
// mute is pressed
if(gold == 0) ret = 1;
else ret = 3;
}
else
{
// mute is released
if(gold == 0) ret = 2;
else ret = 0;
}
}
gold = mute;
return ret;
}
/* ============= Linux GPIO interface =============
requires packages: gpiod libgpiod-dev
command line interface see:
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README
C-Functions see: /usr/include/gpiod.h
connect rotary encoders to these pins:
frequency-encoder A ... GPIO17 (Pin11)
frequency-encoder B ... GPIO27 (Pin13)
volume -encoder A ... GPIO4 (Pin 7)
volume -encoder B ... GPIO22 (Pin15)
PTT input ... GPIO18 (Pin12)
Mute ... GPIO23 (Pin16)
PTT output ... GPIO24 (Pin18)
*/
#include <gpiod.h>
struct gpiod_chip *chip = NULL;
struct gpiod_line *fa = NULL;
struct gpiod_line *fb = NULL, *va = NULL, *vb = NULL, *gptt = NULL, *gmute = NULL, *pttout = NULL;
int init_gpio()
{
int ret;
chip= gpiod_chip_open("/dev/gpiochip0");
if(!chip)
{
printf("cannot open GPIO chip\n");
return -1;
}
//fa= gpiod_chip_get_info(chip,17);
if (!fa) {
printf("cannot access GPIO17\n");
gpiod_chip_close(chip);
return -1;
}
//fb= gpiod_chip_get_line(chip,27);
if (!fb) {
printf("cannot access GPIO27\n");
gpiod_chip_close(chip);
return -1;
}
//va= gpiod_chip_get_line(chip,4);
if (!va) {
printf("cannot access GPIO4\n");
gpiod_chip_close(chip);
return -1;
}
//vb= gpiod_chip_get_line(chip,22);
if (!vb) {
printf("cannot access GPIO22\n");
gpiod_chip_close(chip);
return -1;
}
//gptt = gpiod_chip_get_line(chip,18);
if (!gptt) {
printf("cannot access GPIO18\n");
gpiod_chip_close(chip);
return -1;
}
//gmute = gpiod_chip_get_line(chip,23);
if (!gmute) {
printf("cannot access GPIO23\n");
gpiod_chip_close(chip);
return -1;
}
//pttout = gpiod_chip_get_line(chip,24);
if (!pttout) {
printf("cannot access GPIO24\n");
gpiod_chip_close(chip);
return -1;
}
//ret = gpiod_line_request_get_fd(fa, "huhu");
if (ret) {
printf("cannot init GPIO17 for input\n");
gpiod_chip_close(chip);
return -1;
}
//ret = gpiod_line_request_input(fb, "huhu");
if (ret) {
printf("cannot init GPIO27 for input\n");
gpiod_chip_close(chip);
return -1;
}
//ret = gpiod_line_request_input(va, "huhu");
if (ret) {
printf("cannot init GPIO4 for input\n");
gpiod_chip_close(chip);
return -1;
}
//ret = gpiod_line_request_input(vb, "huhu");
if (ret) {
printf("cannot init GPIO22 for input\n");
gpiod_chip_close(chip);
return -1;
}
//ret = gpiod_line_request_input(gptt, "huhu");
if (ret) {
printf("cannot init GPIO18 for input\n");
gpiod_chip_close(chip);
return -1;
}
//ret = gpiod_line_request_input(gmute, "huhu");
if (ret) {
printf("cannot init GPIO23 for input\n");
gpiod_chip_close(chip);
return -1;
}
//ret = gpiod_line_request_get_fd(pttout, "huhu", 0);
if (ret) {
printf("cannot init GPIO24 for output\n");
gpiod_chip_close(chip);
return -1;
}
printf("GPIOs initialized\n");
return 0;
}
void close_gpio()
{
/* if(fa) gpiod_line_request(fa);
if(fb) gpiod_line_request(fb);
if(va) gpiod_line_request(va);
if(vb) gpiod_line_request(vb);
if(gptt) gpiod_line_request(gptt);
if(gmute) gpiod_line_request(gmute);
*/
if(chip) gpiod_chip_close(chip);
}
// get status of physical port
int getPort(char *port)
{
#ifndef RASPI
return 0;
#endif
if(port[0] == 'f')
{
//if(port[1] == 'a') return gpiod_line_value(fa);
//return gpiod_line_value(fb);
}
if(port[0] == 'v')
{
//if(port[1] == 'a') return gpiod_line_value(va);
//return gpiod_line_value(vb);
}
//if(port[0] == 'p')
//return gpiod_line_value(gptt);
//if(port[0] == 'm')
//return gpiod_line_value(gmute);
return 0;
}
void setPort(char *port, int value)
{
#ifndef RASPI
return;
#endif
if(port[0] == 'p')
{
//gpiod_line_value(pttout,value);
}
}

7
kmlib/rotary.h Normal file
View File

@ -0,0 +1,7 @@
void init_rotencoder();
void close_gpio();
int getEncSteps(int idx);
int test_ptt_gpio();
int test_mute_gpio();
void setPort(char *port, int value);
int getPort(char *port);

BIN
kmlib/rotary.o Normal file

Binary file not shown.

661
libkmaudio/LICENSE Normal file
View File

@ -0,0 +1,661 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

22
libkmaudio/Makefile Normal file
View File

@ -0,0 +1,22 @@
# Make file for libkmaudio
# make clean ... clean up intermediate files
# make ... generate libkmaudio as executable for testing purposes
# and also creates the static library libkmaudio.a to be linked with another program
# when linking to another program also include "-lliquid -lsoundio" to your linker
CXXFLAGS = -Wall -O3 -std=c++0x -Wno-write-strings -Wno-narrowing
LDFLAGS = -lliquid -lsoundio
OBJM = libkmaudio.o
OBJ = libkmaudio_fifo.o libkmaudio_getDevices.o libkmaudio_getDevices_Linux.o libkmaudio_init.o libkmaudio_init_linux.o libkmaudio_interface.o libkmaudio_capture_linux.o libkmaudio_playback_linux.o libkmaudio_resampler.o
default: $(OBJ) $(OBJM)
g++ $(CXXFLAGS) -o libkmaudio $(OBJ) $(OBJM) $(LDFLAGS)
ar rcs libkmaudio.a $(OBJ)
clean:
rm -f *.o libkmaudio.a
-rm -rf ./Release/*
-rmdir Release
-rm -rf ./Debug/*
-rmdir Debug

48
libkmaudio/README.md Normal file
View File

@ -0,0 +1,48 @@
# libkmaudio
## very simple to use audio library for Linux and Windows
I was looking for an audio soultion working on both, Linux and Windows.
It was impossible to find a reliable open source solution.
If you have no problem using a commercial closed source library, then I recommend "bass"
which worked nicely for me, but I need open source to fulfil the requirements of GPL V3.
## My solution:
**portaudio:** works fine under Windows. Does not work under Linux because it does not support
pulseaudio and takes all these cryptical Alsa device names.
**libsoundio:** works well under Linux and supports pulseaudio, uses excellent device names.
But has problems under Windows, distortions and stuttering, so not usable on Windows.
So I wrote this library which uses portaudio for windows and libsoundio for Linux putting
all in a very simple to use library.
## highlights
* a capture or playback stream can be opened for every soundcard available in the computer simultaneously
* each stream gets its own fifo. So we do not have to work with streams, we just put our samples into a fifo or read samples from a fifo.
* Except the soundcard name we do not need to know anything about sound, all is done by this library.
* the library is thread safe and can be used in multithreading environments
## Restrictions
this library was written to be used with SDR receivers/transmitters or for signal analysis purposes. Therefore it supports 1 channel and two sample rates (44100 and 48000).
However, the 1-channel limit is just the fifo. So if someone needs stereo, adjust the routines to write both channels to the fifo.
## Windows
compatible with Visual Studio. All required Windows-Shared Libraries are included and must be copied to the path of the executable file.
## Linux
run "make" to compile the library. The shared libraries (supplied for PC 64bit or ARM 64 bit) must be copied to the folder where Linux searches for shared libraries on your computer. To find this folder you can use this command:
*find /usr -name libc.so | head -1*
## Documentation
There are only very few functions needed. They are described in libkmaudio.h
## Example
An example how to init the sound system, record from microphone and play back to loadspeaker can be found in libkmaudio.cpp. For use in another project simply remove main().

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

97
libkmaudio/endian.h Normal file
View File

@ -0,0 +1,97 @@
/*
* Copyright (c) 2015 Andrew Kelley
*
* This file is part of libsoundio, which is MIT licensed.
* See http://opensource.org/licenses/MIT
*/
#ifndef SOUNDIO_ENDIAN_H
#define SOUNDIO_ENDIAN_H
#if defined(__BIG_ENDIAN__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__ARMEB__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__THUMBEB__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__AARCH64EB__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(_MIPSEB)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__MIPSEB)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__MIPSEB__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(_BIG_ENDIAN)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__sparc)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__sparc__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(_POWER)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__powerpc__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__ppc__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__hpux)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__hppa)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(_POWER)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__s390__)
#define SOUNDIO_OS_BIG_ENDIAN
#elif defined(__LITTLE_ENDIAN__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__ARMEL__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__THUMBEL__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__AARCH64EL__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(_MIPSEL)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__MIPSEL)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__MIPSEL__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(_LITTLE_ENDIAN)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__i386__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__alpha__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__ia64)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__ia64__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(_M_IX86)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(_M_IA64)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(_M_ALPHA)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__amd64)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__amd64__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(_M_AMD64)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__x86_64)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__x86_64__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(_M_X64)
#define SOUNDIO_OS_LITTLE_ENDIAN
#elif defined(__bfin__)
#define SOUNDIO_OS_LITTLE_ENDIAN
#else
#error unable to detect endianness
#endif
#endif

BIN
libkmaudio/libkmaudio Normal file

Binary file not shown.

96
libkmaudio/libkmaudio.cpp Normal file
View File

@ -0,0 +1,96 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
* Usage Example: see main() in this file
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio.cpp ... main() for test purposes only
* usually this library is linked to another program, in this case
* comment-out #define LIBTEST
*
*/
#include "libkmaudio.h"
int kmaudio_getDeviceList_test();
int keeprunning = 1;
/*
* main()
* for testing purposes only
* for library generation comment out: LIBTEST
*/
#define LIBTEST
#ifdef LIBTEST
int main()
{
// initialize sound system
// must be called once after program start
// if called during program run, this will reset the sound system, so better don't do it
kmaudio_init();
// read list of devices
// call as often as needed
// if a user pluggs-in an USB device on the fly then the running stream may
// be redirected by the OS. In this case closing/opening the stream
// may be required.
kmaudio_getDeviceList();
// start capture and/or playback streams
// Parameter: the device name and the sample rate (44100 or 48000 are supported)
// these function return the fifo-index, which is used to access the data in the
// coresponding fifo
int capidx = kmaudio_startCapture((char *)"Line 2 (Virtual Audio Cable)", 48000);
int pbidx = kmaudio_startPlayback((char *)"Line 2 (Virtual Audio Cable)", 48000);
float f[1100];
while (1)
{
// make a loop: record from Mic and play to Speaker
int done = 0;
// read samples from the capture fifo
int anz = kmaudio_readsamples(capidx, f, 1000, 1.0f, 0);
if (anz > 0)
{
// if samples are available, send them to playback fifo
//printf("write %d samples from %d to %d\n", anz, capidx, pbidx);
kmaudio_playsamples(pbidx, f, anz,1.0f);
done = 1;
}
}
// free resources. This will never happen in this example
// but should be done in the final program
kmaudio_close();
return 0;
}
#endif // LIBTEST

275
libkmaudio/libkmaudio.h Normal file
View File

@ -0,0 +1,275 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#pragma once
#ifdef WIN32
// ignore senseless warnings invented by M$ to confuse developers
#pragma warning( disable : 4091 )
#pragma warning( disable : 4003 )
#endif
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <wchar.h>
#ifdef WIN32
#include "Winsock2.h"
#include "io.h"
#include <Windows.h>
#include <iostream>
#include <process.h>
#include <Tlhelp32.h>
#include <winbase.h>
#include <Shlobj.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include "portaudio.h"
#include "pa_win_wasapi.h"
#pragma comment(lib, "portaudio_x86.lib")
#pragma comment(lib, "libliquid.lib")
#else
#include <sys/socket.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <sys/file.h>
#include <pthread.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <pwd.h>
#include <math.h>
#include "soundio.h"
#endif
#include "liquid.h"
/*
* Sample usage:
* init sound system
* 1. kmaudio_init();
* 2. kmaudio_getDeviceList();
*
* start a capture and a playback stream
* 3. kmaudio_startCapture() using a device name returned by io_getAudioDevicelist()
* 4. kmaudio_startPlayback() using a device name returned by io_getAudioDevicelist()
*
* now everything runs in the background, no more need for the user program
* to handle sound specific data
* now we can read/write sound samples as needed by our application
* as an example: get sound from microphone and send to speaker
* process in a loop:
* 5. kmaudio_readsamples()
* 6. kmaudio_playsamples()
*
* for a working example see main(), you will need to
* replace the device names with the names in your computer
*/
/*
* initialize the audio library, create required processes
* call only once when your application starts
* returns: 0 = OK, -1 = error
*/
int kmaudio_init();
/*
* closes and frees all resources
* call only when the application exits
*/
void kmaudio_close();
/*
* read a list of all available audio devices into devlist
* the list can then be read by calling io_getAudioDevicelist()
* call any time to find new plugged in/out devices
* returns: 0=OK, -1 if error
*/
int kmaudio_getDeviceList();
/*
* starts a capturing stream from devname with samprate
* returns: id of the capture stream or -1 = error
*/
int kmaudio_startCapture(char* devname, int samprate);
/*
* starts a playback stream to devname with samprate
* returns: id of the playback stream or -1 = error
*/
int kmaudio_startPlayback(char* devname, int samprate);
/*
* plays len samples from psamp to device id
* returns: 0=ok, -1=error
* id ... device id returned by kmaudio_startPlayback
* psamp ... float array of length len with the audio data (mono)
* len ... number of float values in psamp
* volume ... 0.0f..2.0f will be multiplied with the output sample
*/
int kmaudio_playsamples(int id, float* psamp, int len, float volume);
/*
* reads len samples from device id into psamp
* returns: 0=ok, -1=error
* id ... device id returned by kmaudio_startCapture
* psamp ... float array of length len getting the audio data (mono)
* len ... number of float values to write into psamp
* volume ... 0.0f..2.0f will be multiplied with the input sample
* wait ... 1=wait for data, 0=return if not enough data available (in this case psamp will return 0,0,0...)
*/
int kmaudio_readsamples(int id, float* psamp, int len, float volume, int wait);
/*
* reads the names of detected sound devices
* *len...length of the returned string
* returns: pointer to device string
* Format of the device string:
* first byte = 3 ... ID of this string, followed by pure text:
* Active status of the following device "0" or "1"
* Name of playback devices, followed by ~
* separator ^
* Active status of the following device "0" or "1"
* Name of capture devices, followed by ~
* these names are used for calls to kmaudio_startCapture and kmaudio_startPlayback
* to select the device
*/
uint8_t* io_getAudioDevicelist(int* len);
/*
* returns the max level (within 1 second) of this stream in % (0..100)
* if the level >= 100 the signal will get clipped and distorted
*/
uint8_t kmaudio_maxlevel(int id);
/*
* closes a stream which was started by
* kmaudio_startCapture or kmaudio_startPlayback
* id ... stream ID which was returned by kmaudio_startCapture or kmaudio_startPlayback
*/
void close_stream(int id);
/*
* handle the FIFO which is used to buffer audio data
* pipenum ... stream ID which was returned by kmaudio_startCapture or kmaudio_startPlayback
* IMPORTANT: this information MUST be used to synchonize the data flow into
* the fifo. The speed is always defined by the audio sample rate
* by checking the fifo an application knows when it has to put more audio samples
* into the fifo
*/
// returns number of remaining elements (audio 16 bit short values)
int io_fifo_freespace(int pipenum);
// returns number of used elements (audio 16 bit short values)
int io_fifo_usedspace(int pipenum);
// like before, but returns a number between 0 and 100 %
int io_fifo_usedpercent(int pipenum);
// clear the fifo
void io_fifo_clear(int pipenum);
// -------- functions for internal use only --------
#define MAXDEVICES 200
#define MAXDEVNAMELENGTH 150
typedef struct _DEVLIST_ {
int index = 0; // index to this list
int active = 0; // 1=device valid, 0=possibly disconencted
char name[MAXDEVNAMELENGTH] = { 0 };// real name
int in_out = 0; // 0=capture device, 1=playback device, 2=both
int supports_44100 = 0; // 1 if supported
int supports_48000 = 0; // 1 if supported
int requested_samprate = 0; // sample rate requested by caller
int real_samprate = 0; // real sample rate of the device
int working = 0; // 0=not running, 1=initialized and working
#ifdef WIN32 // Windows using portaudio
int devnum = -1; // port audio device number
PaStreamParameters inputParameters;
PaStreamParameters outputParameters;
PaStream* capStream = NULL;
PaStream* pbStream = NULL;
#else // Linux using libsoundio
struct SoundIoDevice* io_pb_device = NULL;
struct SoundIoDevice* io_cap_device = NULL;
struct SoundIoInStream* instream = NULL;
struct SoundIoOutStream* outstream = NULL;
int stereo_mono = 2; // 1=mono, 2=stereo
char id[1000] = { 0 };
#endif
} DEVLIST;
int searchDevice(char* devname, int io);
void measure_speed_bps(int len);
void sleep_ms(int ms);
void io_write_fifo(int pipenum, float sample);
void io_write_fifo_short(int pipenum, int16_t sample);
void io_fifo_clear(int pipenum);
void init_pipes();
int io_read_fifo_num(int pipenum, float* data, int num);
int io_read_fifo(int pipenum, float* data);
int getRealSamprate(int idx);
int io_fifo_elems_avail(int pipenum);
void sleep_ms(int ms);
void io_buildAudioDevString();
void resampler_create(int devidx);
float* resample(int id, float* psamp, int len, int* pnewlen);
uint64_t getms();
void init_maxarray();
void kmaudio_detectDropouts(int id);
int io_read_fifo_num_short(int pipenum, int16_t* data, int num);
void close_capture_stream(int idx);
void close_playback_stream(int idx);
extern DEVLIST devlist[MAXDEVICES];
extern int devanz;
extern int keeprunning;
#ifndef WIN32 // Linux
int kmaudio_init_linux();
void kmaudio_close_linux();
char* getDevID(char* devname, int io, int* pidx);
extern struct SoundIo* soundio;
#endif // ndef WIN32

77
libkmaudio/libkmaudio.sln Normal file
View File

@ -0,0 +1,77 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libkmaudio", "libkmaudio.vcxproj", "{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
64bit|Any CPU = 64bit|Any CPU
64bit|Mixed Platforms = 64bit|Mixed Platforms
64bit|Win32 = 64bit|Win32
64bit|x64 = 64bit|x64
64bit|x86 = 64bit|x86
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x64 = Release|x64
Release|x86 = Release|x86
ReleaseMinDependency|Any CPU = ReleaseMinDependency|Any CPU
ReleaseMinDependency|Mixed Platforms = ReleaseMinDependency|Mixed Platforms
ReleaseMinDependency|Win32 = ReleaseMinDependency|Win32
ReleaseMinDependency|x64 = ReleaseMinDependency|x64
ReleaseMinDependency|x86 = ReleaseMinDependency|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|Any CPU.ActiveCfg = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|Any CPU.Build.0 = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|Mixed Platforms.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|Mixed Platforms.Build.0 = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|Win32.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|Win32.Build.0 = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|x64.ActiveCfg = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|x64.Build.0 = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|x86.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.64bit|x86.Build.0 = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|Any CPU.ActiveCfg = Debug|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|Win32.ActiveCfg = Debug|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|Win32.Build.0 = Debug|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|x64.ActiveCfg = Debug|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|x64.Build.0 = Debug|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|x86.ActiveCfg = Debug|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Debug|x86.Build.0 = Debug|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|Any CPU.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|Mixed Platforms.Build.0 = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|Win32.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|Win32.Build.0 = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|x64.ActiveCfg = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|x64.Build.0 = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|x86.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.Release|x86.Build.0 = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|Any CPU.ActiveCfg = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|Any CPU.Build.0 = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|Mixed Platforms.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|Mixed Platforms.Build.0 = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|Win32.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|Win32.Build.0 = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|x64.ActiveCfg = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|x64.Build.0 = Release|x64
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|x86.ActiveCfg = Release|Win32
{47EECFB7-1F9E-409C-B8AD-0A2BCCA9CB34}.ReleaseMinDependency|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D885561A-FFA2-42EF-A790-D54EB24B2E82}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{47eecfb7-1f9e-409c-b8ad-0a2bcca9cb34}</ProjectGuid>
<RootNamespace>libkmaudio</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="libkmaudio.cpp" />
<ClCompile Include="libkmaudio_capture.cpp" />
<ClCompile Include="libkmaudio_capture_linux.cpp" />
<ClCompile Include="libkmaudio_fifo.cpp" />
<ClCompile Include="libkmaudio_getDevices.cpp" />
<ClCompile Include="libkmaudio_getDevices_Linux.cpp" />
<ClCompile Include="libkmaudio_init.cpp" />
<ClCompile Include="libkmaudio_init_linux.cpp" />
<ClCompile Include="libkmaudio_interface.cpp" />
<ClCompile Include="libkmaudio_playback.cpp" />
<ClCompile Include="libkmaudio_playback_linux.cpp" />
<ClCompile Include="libkmaudio_resampler.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="libkmaudio.h" />
<ClInclude Include="pa_win_wasapi.h" />
<ClInclude Include="pa_win_waveformat.h" />
<ClInclude Include="soundio.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Quelldateien">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Headerdateien">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Ressourcendateien">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="libkmaudio.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_init.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_getDevices.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_capture.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_fifo.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_playback.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_interface.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_getDevices_Linux.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_init_linux.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_capture_linux.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_playback_linux.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="libkmaudio_resampler.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="libkmaudio.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="pa_win_wasapi.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="pa_win_waveformat.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="soundio.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -0,0 +1,157 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_capture.cpp ...
* starts a portaudio capture stream and a callback routine. Writes the
* received audio samples into the fifo (Windows only)
*/
#include "libkmaudio.h"
#define FRAMES_PER_BUFFER 512
int recordCallback(const void* inputBuffer, void* outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void* userData);
void close_capture_stream(int idx)
{
if (devlist[idx].capStream != NULL)
{
Pa_CloseStream(devlist[idx].capStream);
devlist[idx].capStream = NULL;
}
}
int kmaudio_startCapture(char* devname, int samprate)
{
printf("Start request for CAP stream:%s\n", devname);
if (devname == NULL || strlen(devname) < 3) // no devices defined yet
{
printf("no capture devices specified\n");
return -1;
}
int idx = searchDevice(devname, 0);
if (idx == -1)
{
printf("Device:<%s> not found\n", devname);
return -1;
}
devlist[idx].working = 0;
close_capture_stream(idx);
printf("Starting CAP stream:%s [%d]\n", devname, idx);
io_fifo_clear(idx);
devlist[idx].requested_samprate = samprate;
if(getRealSamprate(idx) == -1)
{
printf("Samplerate %d not supported by device:<%s>\n", samprate, devname);
return -1;
}
if (devlist[idx].requested_samprate != devlist[idx].real_samprate)
resampler_create(idx);
struct PaWasapiStreamInfo wasapiInfo;
memset(&wasapiInfo, 0, sizeof(PaWasapiStreamInfo));
wasapiInfo.size = sizeof(PaWasapiStreamInfo);
wasapiInfo.hostApiType = paWASAPI;
wasapiInfo.version = 1;
wasapiInfo.flags = (paWinWasapiExclusive | paWinWasapiThreadPriority);
wasapiInfo.threadPriority = eThreadPriorityProAudio;
devlist[idx].inputParameters.hostApiSpecificStreamInfo = (&wasapiInfo);
int e = Pa_IsFormatSupported(&devlist[idx].inputParameters, NULL, (double)devlist[idx].real_samprate);
printf("err:%d device:%d PAdev:%d samprate: %f\n", e,idx, devlist[idx].devnum,(double)devlist[idx].real_samprate);
devlist[idx].index = idx;
int err = Pa_OpenStream(
&devlist[idx].capStream,
&devlist[idx].inputParameters,
NULL,
(double)devlist[idx].real_samprate,
FRAMES_PER_BUFFER,
paClipOff,
recordCallback,
&(devlist[idx].index));
if (err != paNoError)
{
printf("cannot open capture stream for device:<%s> %d\n", devname,err);
return -1;
}
err = Pa_StartStream(devlist[idx].capStream);
if (err != paNoError)
{
printf("cannot start capture stream for device:<%s>\n", devname);
return -1;
}
printf("Capture started sucessfully\n");
devlist[idx].working = 1;
return idx;
}
int recordCallback( const void* inputBuffer,
void* outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void* userData)
{
const int16_t* rptr = (const int16_t*)inputBuffer;
int devidx = *((int *)userData);
int chans = devlist[devidx].inputParameters.channelCount;
//printf("%ld captured %d frames. Flag: %X\n", (long)rptr,framesPerBuffer, statusFlags);
//measure_speed_bps(framesPerBuffer);
//printf("%d %d\n", chans, rptr[0]);
for (unsigned int i = 0; i < framesPerBuffer; i++)
io_write_fifo_short(devidx, rptr[i * chans]);
// Prevent unused variable warnings
(void)outputBuffer;
(void)timeInfo;
(void)statusFlags;
if(keeprunning == 1)
return paContinue;
return paComplete;
}

View File

@ -0,0 +1,222 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_capture.cpp ...
* starts a libsoundio capture stream and a callback routine. Writes the
* received audio samples into the fifo (Linux only)
*/
#ifndef WIN32
#include "libkmaudio.h"
char* getDevID(char* devname, int io, int *pidx)
{
for (int i = 0; i < devanz; i++)
{
//printf("%s: %d %d\n", devlist[i].name, io, devlist[i].in_out);
if (!strcmp(devname, devlist[i].name) && io == devlist[i].in_out)
{
*pidx = i;
return devlist[i].id;
}
}
return NULL;
}
int min_int(int a, int b)
{
return (a < b) ? a : b;
}
void read_callback(struct SoundIoInStream* instream, int frame_count_min, int frame_count_max)
{
int err;
if (instream == NULL || soundio == NULL) return;
//printf("cap: %d %d\n", frame_count_min, frame_count_max);
//int chans = instream->layout.channel_count;
//printf("cap:%d\n", instream->sample_rate);
int idx = *((int *)(instream->userdata));
struct SoundIoChannelArea* areas;
// samples are in areas.ptr
int frames_left = frame_count_max; // take all
while (keeprunning)
{
int frame_count = frames_left;
if ((err = soundio_instream_begin_read(instream, &areas, &frame_count)))
{
fprintf(stderr, "begin read error: %s", soundio_strerror(err));
return;
}
if (!frame_count)
break;
//printf("write %d samples to fifo %d. Channels:%d\n", frame_count, idx, instream->layout.channel_count);
for (int frame = 0; frame < frame_count; frame += 1)
{
for (int ch = 0; ch < instream->layout.channel_count; ch += 1)
{
float frxdata;
memcpy(&frxdata, areas[ch].ptr, instream->bytes_per_sample);
areas[ch].ptr += areas[ch].step;
if (ch == 0)
{
io_write_fifo(idx, frxdata);
}
}
}
//measure_speed_bps(frame_count);
if ((err = soundio_instream_end_read(instream)))
{
printf("end read error: %s", soundio_strerror(err));
return;
}
frames_left -= frame_count;
if (frames_left <= 0)
break;
}
}
void overflow_callback(struct SoundIoInStream* instream)
{
static int count = 0;
printf("overflow %d\n", ++count);
}
void close_capture_stream(int idx)
{
if (devlist[idx].instream != NULL)
{
soundio_instream_destroy(devlist[idx].instream);
devlist[idx].instream = NULL;
}
}
int kmaudio_startCapture(char* devname, int samprate)
{
printf("Start request for CAP stream:%s\n", devname);
if (devname == NULL || strlen(devname) < 3) // no devices defined yet
{
printf("no capture devices specified\n");
return -1;
}
int idx = 0; // index into devlist
char* capdevid = getDevID(devname, 0, &idx);
if (capdevid == NULL)
{
printf("CAP: Device ID not found\n");
return -1;
}
// if an old stream is open, close it
close_capture_stream(idx);
printf("Starting CAP stream:%s [%d]\n", devname, idx);
io_fifo_clear(idx);
devlist[idx].working = 0;
// define the capture device
soundio_flush_events(soundio);
for (int i = 0; i < soundio_input_device_count(soundio); i++)
{
devlist[idx].io_cap_device = NULL;
struct SoundIoDevice* device = soundio_get_input_device(soundio, i);
if (strcmp(device->id, capdevid) == 0)
{
devlist[idx].io_cap_device = device;
break;
}
soundio_device_unref(device);
}
if (!devlist[idx].io_cap_device)
{
printf("Invalid device id: %s\n", capdevid);
return -1;
}
if (devlist[idx].io_cap_device->probe_error)
{
printf("Unable to probe device: %s\n", soundio_strerror(devlist[idx].io_cap_device->probe_error));
return -1;
}
// create capture callback
devlist[idx].instream = soundio_instream_create(devlist[idx].io_cap_device);
if (!devlist[idx].instream) {
printf("capture: out of memory\n");
return -1;
}
devlist[idx].requested_samprate = samprate;
if (getRealSamprate(idx) == -1)
{
printf("Samplerate %d not supported by device:<%s>\n", samprate, devname);
return -1;
}
if (devlist[idx].requested_samprate != devlist[idx].real_samprate)
resampler_create(idx);
devlist[idx].instream->format = SoundIoFormatFloat32NE;
devlist[idx].instream->sample_rate = devlist[idx].real_samprate;
devlist[idx].instream->software_latency = 0.1f;
devlist[idx].instream->read_callback = read_callback;
devlist[idx].instream->overflow_callback = overflow_callback;
devlist[idx].instream->userdata = &(devlist[idx].index);
int err = 0;
if ((err = soundio_instream_open(devlist[idx].instream))) {
printf("unable to open input stream: %d: %s", err, soundio_strerror(err));
return -1;
}
if ((err = soundio_instream_start(devlist[idx].instream))) {
printf("unable to start input device: %s", soundio_strerror(err));
return -1;
}
printf("selected CAPTURE device:\nname:%s\nid :%s\n", devlist[idx].name, capdevid);
printf("physical capture rate:%d, requested capture rate:%d\n", devlist[idx].real_samprate, devlist[idx].requested_samprate);
printf("format: %s\n\n", soundio_format_string(devlist[idx].instream->format));
devlist[idx].working = 1;
return idx;
}
#endif // #ifndef WIN32

Binary file not shown.

View File

@ -0,0 +1,252 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_fifo.cpp ... thread safe FIFOs, used to interface the
* audio callback routines to the other program
*
*/
#include "libkmaudio.h"
#define NUM_OF_PIPES 20
#ifdef WIN32
CRITICAL_SECTION audio_crit_sec[NUM_OF_PIPES];
#define LOCK(pn) EnterCriticalSection(&(audio_crit_sec[pn]))
void UNLOCK(int pn)
{
if (&(audio_crit_sec[pn]) != NULL)
LeaveCriticalSection(&(audio_crit_sec[pn]));
}
#else
pthread_mutex_t audio_crit_sec[NUM_OF_PIPES];
#define LOCK(pn) pthread_mutex_lock(&(audio_crit_sec[pn]))
#define UNLOCK(pn) pthread_mutex_unlock(&(audio_crit_sec[pn]))
#endif
#define AUDIO_FIFOFLEN 48000
int io_wridx[NUM_OF_PIPES];
int io_rdidx[NUM_OF_PIPES];
int16_t io_buffer[NUM_OF_PIPES][AUDIO_FIFOFLEN];
void init_pipes()
{
// init pipes only once
static int f = 1;
if (f)
{
f = 0;
for (int i = 0; i < NUM_OF_PIPES; i++)
{
#ifdef WIN32
if (&(audio_crit_sec[i]) != NULL) DeleteCriticalSection(&(audio_crit_sec[i]));
InitializeCriticalSection(&(audio_crit_sec[i]));
#else
if (&(audio_crit_sec[i]) != NULL) pthread_mutex_destroy(&(audio_crit_sec[i]));
pthread_mutex_init(&(audio_crit_sec[i]), NULL);
#endif
}
}
for (int i = 0; i < NUM_OF_PIPES; i++)
io_fifo_clear(i);
}
// write one sample into the fifo
// ignore data if the fifo is full
void io_write_fifo(int pipenum, float sample)
{
if (pipenum < 0 || pipenum >= NUM_OF_PIPES) return;
LOCK(pipenum);
if (((io_wridx[pipenum] + 1) % AUDIO_FIFOFLEN) == io_rdidx[pipenum])
{
//printf("cannot float WRITE fifo %d full\n",pipenum);
UNLOCK(pipenum);
return;
}
io_buffer[pipenum][io_wridx[pipenum]] = (int16_t)(sample * 32768.0f);
if (++io_wridx[pipenum] >= AUDIO_FIFOFLEN) io_wridx[pipenum] = 0;
UNLOCK(pipenum);
}
void io_write_fifo_short(int pipenum, int16_t sample)
{
if (pipenum < 0 || pipenum >= NUM_OF_PIPES) return;
LOCK(pipenum);
if (((io_wridx[pipenum] + 1) % AUDIO_FIFOFLEN) == io_rdidx[pipenum])
{
//printf("cannot short WRITE fifo %d full\n", pipenum);
UNLOCK(pipenum);
return;
}
io_buffer[pipenum][io_wridx[pipenum]] = sample;
if (++io_wridx[pipenum] >= AUDIO_FIFOFLEN) io_wridx[pipenum] = 0;
UNLOCK(pipenum);
}
int io_read_fifo(int pipenum, float* data)
{
if (pipenum < 0 || pipenum >= NUM_OF_PIPES) return 0;
LOCK(pipenum);
if (io_rdidx[pipenum] == io_wridx[pipenum])
{
// Fifo empty, no data available
UNLOCK(pipenum);
return 0;
}
int16_t id = io_buffer[pipenum][io_rdidx[pipenum]];
if (++io_rdidx[pipenum] >= AUDIO_FIFOFLEN) io_rdidx[pipenum] = 0;
UNLOCK(pipenum);
*data = (float)id / 32768;
return 1;
}
// read num elements
// if num elems not avail, return all what fifo has stored
int io_read_fifo_num(int pipenum, float* data, int num)
{
if (pipenum < 0 || pipenum >= NUM_OF_PIPES) return 0;
LOCK(pipenum);
int elemInFifo = (io_wridx[pipenum] + AUDIO_FIFOFLEN - io_rdidx[pipenum]) % AUDIO_FIFOFLEN;
elemInFifo -= 1;
/*if (num > elemInFifo)
{
// Fifo not enough data available
//printf("only %d elements available\n", elemInFifo);
UNLOCK(pipenum);
return 0;
}*/
if (num > elemInFifo) num = elemInFifo;
int16_t id;
for (int i = 0; i < num; i++)
{
id = io_buffer[pipenum][io_rdidx[pipenum]];
*data++ = (float)id / 32768;
if (++io_rdidx[pipenum] >= AUDIO_FIFOFLEN) io_rdidx[pipenum] = 0;
}
UNLOCK(pipenum);
return num;
}
int io_read_fifo_num_short(int pipenum, int16_t* data, int num)
{
if (pipenum < 0 || pipenum >= NUM_OF_PIPES) return 0;
LOCK(pipenum);
int elemInFifo = (io_wridx[pipenum] + AUDIO_FIFOFLEN - io_rdidx[pipenum]) % AUDIO_FIFOFLEN;
elemInFifo -= 1;
/*if (num > elemInFifo)
{
// Fifo not enough data available
//printf("only %d elements available\n", elemInFifo);
UNLOCK(pipenum);
return 0;
}*/
if (num > elemInFifo) num = elemInFifo;
for (int i = 0; i < num; i++)
{
*data++ = io_buffer[pipenum][io_rdidx[pipenum]];
if (++io_rdidx[pipenum] >= AUDIO_FIFOFLEN) io_rdidx[pipenum] = 0;
}
UNLOCK(pipenum);
return num;
}
void io_fifo_clear(int pipenum)
{
if (pipenum < 0 || pipenum >= NUM_OF_PIPES) return;
io_wridx[pipenum] = io_rdidx[pipenum] = 0;
}
int io_fifo_freespace(int pipenum)
{
if (pipenum < 0 || pipenum >= NUM_OF_PIPES) return 0;
int freebuf = 0;
LOCK(pipenum);
int elemInFifo = (io_wridx[pipenum] + AUDIO_FIFOFLEN - io_rdidx[pipenum]) % AUDIO_FIFOFLEN;
freebuf = AUDIO_FIFOFLEN - elemInFifo -1;
UNLOCK(pipenum);
return freebuf;
}
int io_fifo_elems_avail(int pipenum)
{
if (pipenum < 0 || pipenum >= NUM_OF_PIPES) return 0;
int elems = 0;
LOCK(pipenum);
elems = (io_wridx[pipenum] + AUDIO_FIFOFLEN - io_rdidx[pipenum]) % AUDIO_FIFOFLEN;
UNLOCK(pipenum);
elems -= 10;
return elems;
}
int io_fifo_usedspace(int pipenum)
{
return AUDIO_FIFOFLEN - io_fifo_freespace(pipenum);
}
int io_fifo_usedpercent(int pipenum)
{
int used = AUDIO_FIFOFLEN - io_fifo_freespace(pipenum);
int percent = (used * 100) / AUDIO_FIFOFLEN;
//printf("idx:%d used:%d size:%d percent:%d\n", pipenum, used, AUDIO_FIFOFLEN, percent);
return percent;
}

Binary file not shown.

View File

@ -0,0 +1,298 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_getDevices.cpp
* read audio device list via portaudio (which is only used for Windows)
* prepare a device name string which can be read by another program
* in order to present the devices to use user for selection
*
*/
#include "libkmaudio.h"
void io_buildAudioDevString();
// number of detected devices, updated after a call to kmaudio_getDeviceList()
int devanz = 0;
// devlist contains all information for all detected devices
// the list is filled by a call to kmaudio_getDeviceList()
DEVLIST devlist[MAXDEVICES];
double latency = 0.2; // WASAPI latency in seconds
#ifdef WIN32
/*static double standardSampleRates[] = {
8000.0, 9600.0, 11025.0, 12000.0, 16000.0,
22050.0, 24000.0, 32000.0, 44100.0, 48000.0,
88200.0, 96000.0, 192000.0, -1 };*/
static double standardSampleRates[] = {44100.0, 48000.0, -1};
int getDevlistIndex(const char* name, int ichans, int ochans)
{
for (int i = 0; i < devanz; i++)
{
// check if already exists
if (!strcmp(devlist[i].name, name) &&
devlist[i].inputParameters.channelCount == ichans &&
devlist[i].outputParameters.channelCount == ochans)
return i;
}
int newidx = devanz;
devanz++;
//printf("New Dev:%s Idx:%d\n", name, newidx);
return newidx;
}
int kmaudio_getDeviceList()
{
int numDevices = Pa_GetDeviceCount();
if (numDevices < 0)
{
printf("ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices);
return -1;
}
//printf("%d Devices found\n", numDevices);
for (int i = 0; i < devanz; i++)
devlist[i].active = 0;
int didx;
for (int i = 0; i < numDevices; i++)
{
const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(i);
const PaHostApiInfo *ai = Pa_GetHostApiInfo(deviceInfo->hostApi);
// Windows: use WASAPI devices only
if (strstr(ai->name, "WASAPI") != NULL)
{
didx = getDevlistIndex(deviceInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
devlist[didx].devnum = i;
snprintf(devlist[didx].name, MAXDEVNAMELENGTH - 1, "%s", deviceInfo->name);
//printf("------%s-------\n", deviceInfo->name);
devlist[didx].inputParameters.device = i;
devlist[didx].inputParameters.channelCount = deviceInfo->maxInputChannels;
devlist[didx].inputParameters.sampleFormat = paInt16;
devlist[didx].inputParameters.suggestedLatency = latency;
devlist[didx].inputParameters.hostApiSpecificStreamInfo = NULL;
devlist[didx].outputParameters.device = i;
devlist[didx].outputParameters.channelCount = deviceInfo->maxOutputChannels;
devlist[didx].outputParameters.sampleFormat = paInt16;
devlist[didx].outputParameters.suggestedLatency = latency;
devlist[didx].outputParameters.hostApiSpecificStreamInfo = NULL;
if (devlist[didx].inputParameters.channelCount > 0 && devlist[devanz].outputParameters.channelCount > 0)
devlist[didx].in_out = 2;
else if (devlist[didx].inputParameters.channelCount > 0)
devlist[didx].in_out = 0;
else if (devlist[didx].outputParameters.channelCount > 0)
devlist[didx].in_out = 1;
devlist[didx].index = didx;
devlist[didx].active = 1;
for (int j = 0; standardSampleRates[j] > 0; j++)
{
PaError err = 0;
//if (devlist[didx].inputParameters.channelCount > 0 && devlist[didx].outputParameters.channelCount > 0)
// err = Pa_IsFormatSupported(&devlist[didx].inputParameters, &devlist[didx].outputParameters, standardSampleRates[j]);
if (devlist[didx].inputParameters.channelCount > 0)
err = Pa_IsFormatSupported(&devlist[didx].inputParameters, NULL, standardSampleRates[j]);
if (devlist[didx].outputParameters.channelCount > 0)
err = Pa_IsFormatSupported(NULL, &devlist[didx].outputParameters, standardSampleRates[j]);
// portaudio cannot detect if a device was removed, instead it delivers errors
if (err == paInvalidDevice)
devlist[didx].active = 0;
else if (err == paFormatIsSupported)
{
if (j == 0) devlist[didx].supports_44100 = 1;
if (j == 1) devlist[didx].supports_48000 = 1;
}
}
}
}
io_buildAudioDevString();
// close stream if a device does not exist any more
for (int i = 0; i < devanz; i++)
{
if (devlist[i].active == 0)
{
if (devlist[i].capStream != NULL)
{
printf("capture device %s disconnected, stop stream\n", devlist[i].name);
Pa_CloseStream(devlist[i].capStream);
devlist[i].capStream = NULL;
devlist[i].working = 0;
}
if (devlist[i].pbStream != NULL)
{
printf("playback device %s disconnected, stop stream\n", devlist[i].name);
Pa_CloseStream(devlist[i].pbStream);
devlist[i].pbStream = NULL;
devlist[i].working = 0;
}
}
}
static int csum = 0;
int sum = 0;
uint8_t* p = (uint8_t*)&(devlist[0].index);
for (int i = 0; i < (int)sizeof(devlist); i++)
sum += *p++;
if (csum != sum)
{
csum = sum;
printf("Windows Devices found:\n");
for (int i = 0; i < devanz; i++)
{
printf("Portaudio ID: %d\n", devlist[i].index);
printf("Name: %s\n", devlist[i].name);
printf("Cap/PB: %d\n", devlist[i].in_out);
printf("Channels: i:%d o:%d\n", devlist[i].inputParameters.channelCount, devlist[i].outputParameters.channelCount);
printf("SR 44100: %d\n", devlist[i].supports_44100);
printf("SR 48000: %d\n", devlist[i].supports_48000);
printf("is active: %s\n", devlist[i].active ? "yes" : "no");
}
}
return 0;
}
#endif //WIN32
// find a device in devlist
// returns: list index or -1 if error
int searchDevice(char* devname, int io)
{
for (int i = 0; i < devanz; i++)
{
if (strcmp(devname, devlist[i].name) == 0 && (devlist[i].in_out == io || devlist[i].in_out == 2))
return i;
}
return -1;
}
// choose physical, real sample rate for a device
// returns: 0=ok, -1=error: no sample rate supported
int getRealSamprate(int idx)
{
if (devlist[idx].requested_samprate == 44100)
{
if (devlist[idx].supports_44100) devlist[idx].real_samprate = 44100;
else if (devlist[idx].supports_48000) devlist[idx].real_samprate = 48000;
else return -1;
}
else if (devlist[idx].requested_samprate == 48000)
{
if (devlist[idx].supports_48000) devlist[idx].real_samprate = 48000;
else if (devlist[idx].supports_44100) devlist[idx].real_samprate = 44100;
else return -1;
}
else
{
if (devlist[idx].supports_48000) devlist[idx].real_samprate = 48000;
else if (devlist[idx].supports_44100) devlist[idx].real_samprate = 44100;
else return -1;
}
return 0;
}
// build string of audio device name, to be sent to application as response to Broadcast search
// starting with PB devices, sperarator ^, capture devices
// separator between devices: ~
#define MAXDEVSTRLEN (MAXDEVICES * (MAXDEVNAMELENGTH + 2) + 10)
uint8_t io_devstring[MAXDEVSTRLEN];
void io_buildAudioDevString()
{
memset(io_devstring, 0, sizeof(io_devstring));
io_devstring[0] = ' '; // placeholder for other data
io_devstring[1] = ' ';
io_devstring[2] = ' ';
io_devstring[3] = ' ';
io_devstring[4] = ' ';
// playback devices
for (int i = 0; i < devanz; i++)
{
if (devlist[i].active == 0) continue;
if (strlen((char *)io_devstring) > MAXDEVSTRLEN)
{
printf("io_devstring too small:%d / %d. Serious error, abort program\n", MAXDEVSTRLEN, (int)strlen((char*)io_devstring));
exit(0);
}
if (devlist[i].in_out == 1)
{
strcat((char*)io_devstring, devlist[i].name);
strcat((char*)io_devstring, "~"); // audio device separator
}
}
strcat((char*)(io_devstring + 1), "^"); // PB, CAP separator
// capture devices
for (int i = 0; i < devanz; i++)
{
if (devlist[i].active == 0) continue;
if (strlen((char*)io_devstring) > MAXDEVSTRLEN)
{
printf("io_devstring too small:%d / %d. Serious error, abort program\n", MAXDEVSTRLEN, (int)strlen((char*)io_devstring));
exit(0);
}
if (devlist[i].in_out == 0)
{
strcat((char*)io_devstring, devlist[i].name);
strcat((char*)io_devstring, "~"); // audio device separator
}
}
//printf("<%s>\n", (char *)io_devstring);
}
uint8_t* io_getAudioDevicelist(int* len)
{
*len = strlen((char*)(io_devstring + 1)) + 1;
return io_devstring;
}

Binary file not shown.

View File

@ -0,0 +1,228 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_getDevices_linux.cpp
* like libkmaudio_getDevices.cpp, but uses libsoundio under Linux
* to get the device list. Portaudio does not work under Linux because
* it does not support pulseaudio. Therefore the linux functions
* use libsoundio
*
*/
#ifndef WIN32 // Linux
#include "libkmaudio.h"
int scan_devices();
int kmaudio_getDeviceList()
{
if (soundio == NULL)
{
printf("kmaudio_getDeviceList: soundio not initialized\n");
return -1;
}
soundio_flush_events(soundio); // to get actual data
if (scan_devices() == -1) // read devices
{
printf("cannot read audio devices\n");
return -1;
}
io_buildAudioDevString();
// close stream if a device does not exist any more
for (int i = 0; i < devanz; i++)
{
if (devlist[i].active == 0)
{
if (devlist[i].instream != NULL)
{
printf("capture device %s disconnected, stop stream\n", devlist[i].name);
soundio_instream_destroy(devlist[i].instream);
devlist[i].instream = NULL;
devlist[i].working = 0;
}
if (devlist[i].outstream != NULL)
{
printf("playback device %s disconnected, stop stream\n", devlist[i].name);
soundio_outstream_destroy(devlist[i].outstream);
devlist[i].outstream = NULL;
devlist[i].working = 0;
}
}
}
static int csum = 0;
int sum = 0;
uint8_t *p = (uint8_t *)&(devlist[0].index);
for (int i = 0; i < (int)sizeof(devlist); i++)
sum += *p++;
if (csum != sum)
{
csum = sum;
/*printf("====== Linux Devices found: ======\n");
for (int i = 0; i < devanz; i++)
{
printf("Index: %d\n", devlist[i].index);
printf("Name: %s\n", devlist[i].name);
printf("ID: %s\n", devlist[i].id);
printf("Cap/PB: %d\n", devlist[i].in_out);
printf("Channels: %d\n", devlist[i].stereo_mono);
printf("SR 44100: %d\n", devlist[i].supports_44100);
printf("SR 48000: %d\n", devlist[i].supports_48000);
printf("is active: %s\n", devlist[i].active ? "yes" : "no");
printf("--------------------------------------\n");
}*/
}
return 0;
}
static void get_channel_layout(const struct SoundIoChannelLayout *layout)
{
if (layout->name)
{
if (strstr(layout->name, "ereo"))
devlist[devanz].stereo_mono = 2;
if (strstr(layout->name, "ono"))
devlist[devanz].stereo_mono = 1;
}
}
int getDeviceParameters(int idx, struct SoundIoDevice *device)
{
strncpy(devlist[idx].id, device->id, sizeof(devlist[0].id) - 1);
devlist[idx].id[sizeof(devlist[0].id) - 1] = 0;
strncpy(devlist[idx].name, device->name, sizeof(devlist[0].name) - 1);
devlist[idx].name[sizeof(devlist[0].name) - 1] = 0;
for (int i = 0; i < device->layout_count; i++)
get_channel_layout(&device->layouts[i]);
int min = 999999, max = 0;
for (int i = 0; i < device->sample_rate_count; i++)
{
struct SoundIoSampleRateRange *range = &device->sample_rates[i];
if (range->min < min)
min = range->min;
if (range->max > max)
max = range->max;
}
if (min <= 44100)
devlist[idx].supports_44100 = 1;
if (max >= 48000)
devlist[idx].supports_48000 = 1;
if (devlist[idx].supports_44100 == 0 && devlist[idx].supports_48000 == 0)
return 0;
return 1;
}
int getDevlistIndex(char *name, char *id)
{
/* !!! Achtung: das hier filtert Devices raus die auf PB und CAP gleiche Daten haben !!!
noch nach PB und CAP unterscheiden
for (int i = 0; i < devanz; i++)
{
// check if already exists
if (!strcmp(devlist[i].id, id) && !strcmp(devlist[i].name, name))
return i;
}*/
int newidx = devanz;
devanz++;
//printf("New Dev:%s Idx:%d\n", name, newidx);
return newidx;
}
int scan_devices()
{
for (int i = 0; i < devanz; i++)
devlist[i].active = 0;
int didx;
for (int i = 0; i < soundio_input_device_count(soundio); i++)
{
struct SoundIoDevice *device = soundio_get_input_device(soundio, i);
if (device == NULL)
continue;
if (strstr(device->name, "onitor"))
continue;
if (device->probe_error)
continue;
didx = getDevlistIndex(device->name, device->id);
if (getDeviceParameters(didx, device) == 1)
{
printf("%d %d %d ====CAP: name:<%s>\n", i, devanz, didx, device->name);
devlist[didx].in_out = 0;
devlist[didx].index = didx;
devlist[didx].active = 1;
}
else
{
*devlist[didx].name = 0;
*devlist[didx].id = 0;
}
soundio_device_unref(device);
}
for (int i = 0; i < soundio_output_device_count(soundio); i++)
{
struct SoundIoDevice *device = soundio_get_output_device(soundio, i);
if (device == NULL)
continue;
if (strstr(device->name, "onitor"))
continue;
if (device->probe_error)
continue;
didx = getDevlistIndex(device->name, device->id);
if (getDeviceParameters(didx, device) == 1)
{
printf("%d %d %d ====PB : name:<%s>\n", i, devanz, didx, device->name);
devlist[didx].in_out = 1;
devlist[didx].index = didx;
devlist[didx].active = 1;
}
else
{
*devlist[didx].name = 0;
*devlist[didx].id = 0;
}
soundio_device_unref(device);
}
return 0;
}
#endif // ifndef WIN32

Binary file not shown.

View File

@ -0,0 +1,166 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_init.cpp ... initialize portaudio (Windows only)
*
*/
#include "libkmaudio.h"
void kmaudio_close();
int kmaudio_init()
{
kmaudio_close();
sleep_ms(100);
printf("libkmaudio_init\n");
init_pipes(); // init fifo
init_maxarray(); // init array for maxlevel measurement
#ifdef WIN32
int err = Pa_Initialize();
if (err != paNoError)
{
printf("ERROR: Pa_Initialize returned 0x%x\n", err);
return -1;
}
printf("PortAudio version: 0x%08X\n", Pa_GetVersion());
#else
return kmaudio_init_linux();
#endif
return 0;
}
void kmaudio_close()
{
printf("libkmaudio_close\n");
#ifdef WIN32
for (int i = 0; i < devanz; i++)
{
if (devlist[i].capStream != NULL)
{
Pa_CloseStream(devlist[i].capStream);
devlist[i].capStream = NULL;
}
if (devlist[i].pbStream != NULL)
{
Pa_CloseStream(devlist[i].pbStream);
devlist[i].pbStream = NULL;
}
}
Pa_Terminate();
#else
kmaudio_close_linux();
#endif
}
// diagonstic routines for development
#define MAXSPDARR 10
int spdarr[MAXSPDARR];
int spdarrbps[MAXSPDARR];
#ifdef _LINUX_
uint64_t getms()
{
struct timeval tv;
gettimeofday(&tv, NULL);
uint64_t at = tv.tv_sec * 1000000 + tv.tv_usec;
at = at / 1000;
return at;
}
#endif
#ifdef WIN32
uint64_t getms()
{
// get time in 100ns resolution
FILETIME ft_now;
GetSystemTimeAsFileTime(&ft_now);
// convert to full 64 bit time
uint64_t ll_now = (uint64_t)ft_now.dwLowDateTime + ((uint64_t)(ft_now.dwHighDateTime) << 32LL);
// convert to Milliseconds
ll_now /= (10 * 1000); // still needs 64 bit integer
return ll_now;
}
#else
uint64_t getms()
{
struct timeval tv;
gettimeofday(&tv, NULL);
uint64_t at = tv.tv_sec * 1000000 + tv.tv_usec;
at = at / 1000;
return at;
}
#endif
void measure_speed_bps(int len)
{
static uint64_t lasttim = 0;
static int elems = 0;
uint64_t tim = getms();
int timespan = (int)(tim - lasttim);
if (timespan < 0)
{
lasttim = tim;
return;
}
elems += len;
if (timespan < 1000) return;
double dspd = elems;
dspd = dspd * 1e3 / timespan;
int speed = (int)dspd;
// here we have number of elements after 1s
printf(" ======================= %d bit/s\n", speed);
elems = 0;
lasttim = tim;
}
void sleep_ms(int ms)
{
#ifdef WIN32
Sleep(ms);
#else
usleep(ms * 1000);
#endif
}

Binary file not shown.

View File

@ -0,0 +1,79 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_init_linux.cpp ... initialize libsoundio (Linux only)
*
*/
#include "libkmaudio.h"
struct SoundIo* soundio = NULL;
#ifndef WIN32 // Linux
int kmaudio_init_linux()
{
int err;
// prepare and connect to libsoundio
soundio = soundio_create();
if (!soundio) {
printf("soundio_create: out of memory\n");
return -1;
}
if ((err = soundio_connect(soundio))) {
printf("soundio_connect: %s\n", soundio_strerror(err));
return -1;
}
printf("linux libkmaudio_init finished\n");
return 0;
}
void kmaudio_close_linux()
{
for (int i = 0; i < devanz; i++)
{
if (devlist[i].instream) soundio_instream_destroy(devlist[i].instream);
devlist[i].instream = NULL;
if (devlist[i].outstream) soundio_outstream_destroy(devlist[i].outstream);
devlist[i].outstream = NULL;
if (devlist[i].io_pb_device) soundio_device_unref(devlist[i].io_pb_device);
devlist[i].io_pb_device = NULL;
if (devlist[i].io_cap_device) soundio_device_unref(devlist[i].io_cap_device);
devlist[i].io_cap_device = NULL;
}
if (soundio) soundio_destroy(soundio);
soundio = NULL;
}
#endif // ndef WIN32

Binary file not shown.

View File

@ -0,0 +1,179 @@
#include "libkmaudio.h"
void getMax(int id, float fv);
void close_stream(int id)
{
#ifdef WIN32
if (devlist[id].capStream != NULL)
close_capture_stream(id);
if (devlist[id].pbStream != NULL)
close_playback_stream(id);
#else
if (devlist[id].instream != NULL)
close_capture_stream(id);
if (devlist[id].outstream != NULL)
close_playback_stream(id);
#endif
}
/*
* reads len samples from device id into psamp
* returns: number of values written to psamp , -1=error
* id ... device id returned by kmaudio_startCapture
* psamp ... float array of length len getting the audio data (mono)
* len ... number of float values to write into psamp
* volume ... 0.0f..2.0f will be multiplied with the input sample
* wait ... 1=wait for data, 0=return if not enough data available (in this case psamp will return 0,0,0...)
*
* if resampling is required the number of returned samples may differ from the number of requested samples
* it can be larger, so the buffer psamp should be larger than "len" by factor 1.1
*/
int kmaudio_readsamples(int id, float* psamp, int len, float volume, int wait)
{
int e = io_fifo_elems_avail(id);
if (e < len) return 0;
if (devlist[id].requested_samprate == devlist[id].real_samprate)
{
// data rate is ok, take samples as is
int nl = io_read_fifo_num(id, psamp, len);
for (int i = 0; i < nl; i++)
{
psamp[i] *= volume;
getMax(id, psamp[i]);
//kmaudio_detectDropouts(id);
}
return nl;
}
// resampling is required
int num = io_read_fifo_num(id, psamp, len);
if (num == 0) return 0;
int newlen = 0;
float *f = resample(id, psamp, len, &newlen);
for (int i = 0; i < newlen; i++)
{
psamp[i] = f[i] * volume;
getMax(id, psamp[i]);
}
return newlen;
}
/*
* plays len samples from psamp to device id
* returns: 0=ok, -1=error
* id ... device id returned by kmaudio_startPlayback
* psamp ... float array of length len with the audio data (mono)
* len ... number of float values in psamp
* volume ... 0.0f..2.0f will be multiplied with the output sample
*/
int kmaudio_playsamples(int id, float* psamp, int len, float volume)
{
// check if resampling is required
//printf("%d %d len:%d\n", devlist[id].requested_samprate , devlist[id].real_samprate,len);
/* Diagnostic: print buffer usage
static int xxx=0;
if(++xxx >= 10000)
{
xxx = 0;
printf("Pluto->sndcard fifo usage: %d\n",io_fifo_usedspace(id));
}*/
if (devlist[id].requested_samprate == devlist[id].real_samprate)
{
// sampling rate is ok, just play samples
for (int i = 0; i < len; i++)
{
io_write_fifo(id, psamp[i] * volume);
getMax(id, psamp[i] * volume);
}
return 0;
}
// resampling is required
int newlen = 0;
float *f = resample(id, psamp, len, &newlen);
for (int i = 0; i < newlen; i++)
{
io_write_fifo(id, f[i] * volume);
getMax(id, f[i] * volume);
}
return 0;
}
#define MCHECK 48000 // abt. 1s of samples
float farr[MAXDEVICES][MCHECK];
int farridx[MAXDEVICES];
void init_maxarray()
{
// initialize arrays
for (int md = 0; md < MAXDEVICES; md++)
{
farridx[md] = 0;
for (int i = 0; i < MCHECK; i++)
farr[md][i] = 0;
}
}
void getMax(int id, float fv)
{
// put value into array
farr[id][farridx[id]] = fv;
if (++farridx[id] == MCHECK)
farridx[id] = 0;
}
/*
* returns the max level (within 1 second) of this stream in % (0..100)
* if the level >= 100 the signal will get clipped and distorted
*/
uint8_t kmaudio_maxlevel(int id)
{
float max = 0;
for (int i = 0; i < MCHECK; i++)
if (farr[id][i] > max) max = farr[id][i];
return (uint8_t)(max * 100);
}
void kmaudio_detectDropouts(int id)
{
int stat = 0;
int drlen = 0;
for (int i = 0; i < MCHECK; i++)
{
switch (stat)
{
case 0: // search beginning of dropout
if (farr[id][i] == 0.0f)
stat = 1;
break;
case 1: // count length of dropout
if (farr[id][i] == 0.0f) drlen++;
else
{
// end of dropout
if (drlen > 0)
{
printf("Dropout len:%d\n", drlen);
}
drlen = 0;
stat = 0;
}
break;
}
}
}

Binary file not shown.

View File

@ -0,0 +1,173 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_playback.cpp ...
* starts a portaudio playback stream and a callback routine. Plays the
* audio samples coming via the fifo (Windows only)
*/
#include "libkmaudio.h"
#define FRAMES_PER_BUFFER 512
int playCallback(const void* inputBuffer,
void* outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void* userData);
void close_playback_stream(int idx)
{
if (devlist[idx].pbStream != NULL)
{
Pa_CloseStream(devlist[idx].pbStream);
devlist[idx].pbStream = NULL;
}
}
int kmaudio_startPlayback(char* devname, int samprate)
{
printf("Start request for PB stream:%s\n", devname);
if (devname == NULL || strlen(devname) < 3) // no devices defined yet
{
printf("no PB devices specified\n");
return -1;
}
int idx = searchDevice(devname, 1);
if (idx == -1)
{
printf("Playback Device:<%s> not found\n", devname);
return -1;
}
devlist[idx].working = 0;
close_playback_stream(idx);
printf("Starting PB stream:%s [%d]\n", devname, idx);
io_fifo_clear(idx);
devlist[idx].requested_samprate = samprate;
if (getRealSamprate(idx) == -1)
{
printf("Samplerate %d not supported by device:<%s>\n", samprate, devname);
return -1;
}
if (devlist[idx].requested_samprate != devlist[idx].real_samprate)
resampler_create(idx);
struct PaWasapiStreamInfo wasapiInfo;
memset(&wasapiInfo, 0, sizeof(PaWasapiStreamInfo));
wasapiInfo.size = sizeof(PaWasapiStreamInfo);
wasapiInfo.hostApiType = paWASAPI;
wasapiInfo.version = 1;
wasapiInfo.flags = (paWinWasapiExclusive | paWinWasapiThreadPriority);
wasapiInfo.threadPriority = eThreadPriorityProAudio;
devlist[idx].outputParameters.hostApiSpecificStreamInfo = (&wasapiInfo);
PaError e = Pa_IsFormatSupported(&devlist[idx].outputParameters, NULL, (double)devlist[idx].real_samprate);
printf("Playback : err:%d device:%d PAdev:%d samprate: %f chans:%d\n", e, idx, devlist[idx].devnum, (double)devlist[idx].real_samprate, devlist[idx].outputParameters.channelCount);
devlist[idx].index = idx;
int err = Pa_OpenStream(
&devlist[idx].pbStream,
NULL,
&devlist[idx].outputParameters,
(double)devlist[idx].real_samprate,
FRAMES_PER_BUFFER,
paClipOff,
playCallback,
&(devlist[idx].index));
if (err != paNoError)
{
printf("cannot open playback stream for device:<%s> %d\n", devname, err);
return -1;
}
err = Pa_StartStream(devlist[idx].pbStream);
if (err != paNoError)
{
printf("cannot start playback stream for device:<%s>\n", devname);
return -1;
}
printf("Playback started sucessfully\n");
devlist[idx].working = 1;
return idx;
}
int playCallback( const void* inputBuffer,
void* outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void* userData)
{
int16_t* rptr = (int16_t*)outputBuffer;
int devidx = *((int*)userData);
int chans = devlist[devidx].outputParameters.channelCount;
//measure_speed_bps(framesPerBuffer);
int16_t f[FRAMES_PER_BUFFER];
memset(f, 0, sizeof(int16_t) * FRAMES_PER_BUFFER);
unsigned int num = io_read_fifo_num_short(devidx, f, framesPerBuffer);
if (num < framesPerBuffer)
{
//printf("got %d from fifo, requested %d\n", num, framesPerBuffer);
}
int av = io_fifo_elems_avail(devidx);
for (unsigned int i = 0; i < framesPerBuffer; i++)
{
if (chans == 1) rptr[i] = f[i];
else
{
rptr[i * 2] = f[i];
rptr[i * 2 + 1] = f[i];
}
}
// Prevent unused variable warnings
(void)inputBuffer;
(void)timeInfo;
(void)statusFlags;
if (keeprunning == 1)
return paContinue;
return paComplete;
}

View File

@ -0,0 +1,244 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_playback.cpp ...
* starts a libsoundio playback stream and a callback routine. Plays the
* audio samples coming via the fifo (Linux only)
*/
#ifndef WIN32
#include "libkmaudio.h"
// #define SINEWAVETEST
#ifdef SINEWAVETEST
static const double PI = 3.14159265358979323846264338328;
static double seconds_offset = 0.0;
#endif
void write_sample_float32ne(char* ptr, double sample)
{
float* buf = (float*)ptr;
*buf = (float)sample;
}
static void write_callback(struct SoundIoOutStream* outstream, int frame_count_min, int frame_count_max)
{
if (outstream == NULL || soundio == NULL) return;
//printf("pb: %d %d\n", frame_count_min, frame_count_max);
//printf("pb :%d\n", outstream->sample_rate);
int idx = *((int*)(outstream->userdata));
#ifdef SINEWAVETEST
double float_sample_rate = outstream->sample_rate;
double seconds_per_frame = 1.0 / float_sample_rate;
double pitch = 440.0;
double radians_per_second = pitch * 2.0 * PI;
#endif
struct SoundIoChannelArea* areas;
int err;
int frames_left = 4800;
if (frame_count_max < frames_left)
frames_left = frame_count_max;
for (;;) {
int frame_count = frames_left;
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
fprintf(stderr, "write_callback unrecoverable soundio_outstream_begin_write error: %s\n", soundio_strerror(err));
return;
}
if (!frame_count)
break;
//printf("ck: %d read from fifo:%d\n", frame_count,idx);
if (frame_count >= 10000)
{
printf("frame count >= 1000: %d\n", frame_count);
exit(0);
}
float f[10000];
memset(f, 0, sizeof(float) * frame_count);
if (io_fifo_elems_avail(idx) >= frame_count)
{
// if fifo does not have enough data, don't take any
// this gives the fifo a chance to fill up a bit
io_read_fifo_num(idx, f, frame_count);
}
//measure_speed_bps(frame_count);
const struct SoundIoChannelLayout* layout = &outstream->layout;
for (int frame = 0; frame < frame_count; frame += 1)
{
#ifdef SINEWAVETEST
double sample = sin((seconds_offset + frame * seconds_per_frame) * radians_per_second);
#endif
for (int channel = 0; channel < layout->channel_count; channel += 1)
{
float ftx = f[frame];
//getTXMax(f[frame]);
#ifdef SINEWAVETEST
write_sample_float32ne(areas[channel].ptr, sample); // sine wave test tone
#endif
write_sample_float32ne(areas[channel].ptr, ftx);
areas[channel].ptr += areas[channel].step;
}
}
#ifdef SINEWAVETEST
seconds_offset = fmod(seconds_offset + seconds_per_frame * frame_count, 1.0);
#endif
if ((err = soundio_outstream_end_write(outstream))) {
if (err == SoundIoErrorUnderflow)
return;
fprintf(stderr, "unrecoverable stream error: %s\n", soundio_strerror(err));
return;
}
frames_left -= frame_count;
if (frames_left <= 0)
break;
}
}
void underflow_callback(struct SoundIoOutStream* outstream)
{
static int count = 0;
printf("audio output underflow %d\n", count++);
}
void close_playback_stream(int idx)
{
if (devlist[idx].outstream != NULL)
{
soundio_outstream_destroy(devlist[idx].outstream);
devlist[idx].outstream = NULL;
}
}
int kmaudio_startPlayback(char* devname, int samprate)
{
printf("Start request for PB stream:%s\n", devname);
if (devname == NULL || strlen(devname) < 3) // no devices defined yet
{
printf("no PB devices specified\n");
return -1;
}
int idx = 0; // index into devlist
char* pbdevid = getDevID(devname, 1, &idx);
if (pbdevid == NULL)
{
printf("PB: Device ID not found\n");
return -1;
}
close_playback_stream(idx);
printf("Starting PB stream:%s [%d]\n", devname, idx);
io_fifo_clear(idx);
devlist[idx].working = 0;
// define the capture device
soundio_flush_events(soundio);
for (int i = 0; i < soundio_output_device_count(soundio); i++)
{
devlist[idx].io_pb_device = NULL;
struct SoundIoDevice* device = soundio_get_output_device(soundio, i);
if (strcmp(device->id, pbdevid) == 0)
{
devlist[idx].io_pb_device = device;
break;
}
soundio_device_unref(device);
}
if (!devlist[idx].io_pb_device)
{
printf("Invalid device id: %s\n", pbdevid);
return -1;
}
if (devlist[idx].io_pb_device->probe_error)
{
printf("Unable to probe device: %s\n", soundio_strerror(devlist[idx].io_pb_device->probe_error));
return -1;
}
// create playback callback
devlist[idx].outstream = soundio_outstream_create(devlist[idx].io_pb_device);
if (!devlist[idx].outstream) {
printf("soundio_outstream_create: out of memory\n");
return 0;
}
devlist[idx].requested_samprate = samprate;
if (getRealSamprate(idx) == -1)
{
printf("Samplerate %d not supported by device:<%s>\n", samprate, devname);
return -1;
}
//printf("requested SR:%d, real SR:%d\n",devlist[idx].requested_samprate, devlist[idx].real_samprate);
if (devlist[idx].requested_samprate != devlist[idx].real_samprate)
resampler_create(idx);
devlist[idx].outstream->format = SoundIoFormatFloat32NE;
devlist[idx].outstream->sample_rate = devlist[idx].real_samprate;
devlist[idx].outstream->software_latency = 0.1f;
devlist[idx].outstream->write_callback = write_callback;
devlist[idx].outstream->underflow_callback = underflow_callback;
devlist[idx].outstream->userdata = &(devlist[idx].index);
int err = 0;
if ((err = soundio_outstream_open(devlist[idx].outstream))) {
printf("unable to open output stream: %s", soundio_strerror(err));
return -1;
}
if ((err = soundio_outstream_start(devlist[idx].outstream))) {
printf("unable to start output device: %s", soundio_strerror(err));
return -1;
}
printf("selected PLAYBACK device:\nname:%s\nid :%s\n", devname, pbdevid);
printf("physical playback rate:%d, requested capture rate:%d\n", devlist[idx].real_samprate, devlist[idx].requested_samprate);
printf("format: %s\n\n", soundio_format_string(devlist[idx].outstream->format));
devlist[idx].working = 1;
return idx;
}
#endif // ndef WIN32

Binary file not shown.

View File

@ -0,0 +1,111 @@
/*
* Audio Library for Linux and Windows
* ===================================
* Author: DJ0ABR
*
* Author: Kurt Moraw, Ham radio: DJ0ABR, github: dj0abr
* License: GPL-3
*
* compilation:
* Windows ... Visual Studio
* Linux ... make
*
* Documentation see: libkmaudio.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* libkmaudio_resampler.cpp ... converts audio streams
* between 44100 and 48000 samples/s in both directions
* uses the libliquid library
*/
#include "libkmaudio.h"
#define MAXRLEN 10000
resamp_crcf q[MAXDEVICES];
float fresamp[MAXDEVICES][MAXRLEN];
unsigned int h_len = 13; // filter semi-length (filter delay)
float r = 0.9f; // resampling rate (output/input)
float bw = 0.45f; // resampling filter bandwidth
float slsl = 60.0f; // resampling filter sidelobe suppression level
unsigned int npfb = 32; // number of filters in bank (timing resolution)
void resampler_create(int devidx)
{
static int f = 1;
if(f)
{
f = 0;
for (int i = 0; i < MAXDEVICES; i++)
q[i] = NULL;
}
printf("create resampler %d real %d req %d\n", devidx, devlist[devidx].real_samprate, devlist[devidx].requested_samprate);
if (q[devidx] != NULL) resamp_crcf_destroy(q[devidx]);
int src_rate = 0;
int dst_rate = 0;
if (devlist[devidx].in_out == 0)
{
// capture device:
src_rate = devlist[devidx].real_samprate;
dst_rate = devlist[devidx].requested_samprate;
}
else
{
// playback device:
src_rate = devlist[devidx].requested_samprate;
dst_rate = devlist[devidx].real_samprate;
}
r = (float)dst_rate / (float)src_rate;
//printf("%f %f %f\n", r, (float)dst_rate, (float)src_rate);
q[devidx] = resamp_crcf_create(r, h_len, bw, slsl, npfb);
}
float* resample(int id, float*psamp, int len, int *pnewlen)
{
int didx = 0;
for (int i = 0; i < len; i++)
{
unsigned int num_written = 0;
liquid_float_complex in;
liquid_float_complex out[10];
in.real = psamp[i];
in.imag = 0;
resamp_crcf_execute(q[id], in, out, &num_written);
for (unsigned int r = 0; r < num_written; r++)
{
if (didx < MAXRLEN)
fresamp[id][didx++] = out[r].real;
else
printf("MAXRLEN too small\n");
}
}
*pnewlen = didx;
return fresamp[id];
}

Binary file not shown.

BIN
libkmaudio/libliquid.lib Normal file

Binary file not shown.

8823
libkmaudio/liquid.h Normal file

File diff suppressed because it is too large Load Diff

443
libkmaudio/pa_win_wasapi.h Normal file
View File

@ -0,0 +1,443 @@
#ifndef PA_WIN_WASAPI_H
#define PA_WIN_WASAPI_H
/*
* $Id: $
* PortAudio Portable Real-Time Audio Library
* DirectSound specific extensions
*
* Copyright (c) 1999-2007 Ross Bencina and Phil Burk
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/
/** @file
@ingroup public_header
@brief WASAPI-specific PortAudio API extension header file.
*/
#include "portaudio.h"
#include "pa_win_waveformat.h"
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
/* Setup flags */
typedef enum PaWasapiFlags
{
/* puts WASAPI into exclusive mode */
paWinWasapiExclusive = (1 << 0),
/* allows to skip internal PA processing completely */
paWinWasapiRedirectHostProcessor = (1 << 1),
/* assigns custom channel mask */
paWinWasapiUseChannelMask = (1 << 2),
/* selects non-Event driven method of data read/write
Note: WASAPI Event driven core is capable of 2ms latency!!!, but Polling
method can only provide 15-20ms latency. */
paWinWasapiPolling = (1 << 3),
/* forces custom thread priority setting, must be used if PaWasapiStreamInfo::threadPriority
is set to a custom value */
paWinWasapiThreadPriority = (1 << 4)
}
PaWasapiFlags;
#define paWinWasapiExclusive (paWinWasapiExclusive)
#define paWinWasapiRedirectHostProcessor (paWinWasapiRedirectHostProcessor)
#define paWinWasapiUseChannelMask (paWinWasapiUseChannelMask)
#define paWinWasapiPolling (paWinWasapiPolling)
#define paWinWasapiThreadPriority (paWinWasapiThreadPriority)
/* Host processor. Allows to skip internal PA processing completely.
You must set paWinWasapiRedirectHostProcessor flag to PaWasapiStreamInfo::flags member
in order to have host processor redirected to your callback.
Use with caution! inputFrames and outputFrames depend solely on final device setup.
To query maximal values of inputFrames/outputFrames use PaWasapi_GetFramesPerHostBuffer.
*/
typedef void (*PaWasapiHostProcessorCallback) (void *inputBuffer, long inputFrames,
void *outputBuffer, long outputFrames,
void *userData);
/* Device role. */
typedef enum PaWasapiDeviceRole
{
eRoleRemoteNetworkDevice = 0,
eRoleSpeakers,
eRoleLineLevel,
eRoleHeadphones,
eRoleMicrophone,
eRoleHeadset,
eRoleHandset,
eRoleUnknownDigitalPassthrough,
eRoleSPDIF,
eRoleHDMI,
eRoleUnknownFormFactor
}
PaWasapiDeviceRole;
/* Jack connection type. */
typedef enum PaWasapiJackConnectionType
{
eJackConnTypeUnknown,
eJackConnType3Point5mm,
eJackConnTypeQuarter,
eJackConnTypeAtapiInternal,
eJackConnTypeRCA,
eJackConnTypeOptical,
eJackConnTypeOtherDigital,
eJackConnTypeOtherAnalog,
eJackConnTypeMultichannelAnalogDIN,
eJackConnTypeXlrProfessional,
eJackConnTypeRJ11Modem,
eJackConnTypeCombination
}
PaWasapiJackConnectionType;
/* Jack geometric location. */
typedef enum PaWasapiJackGeoLocation
{
eJackGeoLocUnk = 0,
eJackGeoLocRear = 0x1, /* matches EPcxGeoLocation::eGeoLocRear */
eJackGeoLocFront,
eJackGeoLocLeft,
eJackGeoLocRight,
eJackGeoLocTop,
eJackGeoLocBottom,
eJackGeoLocRearPanel,
eJackGeoLocRiser,
eJackGeoLocInsideMobileLid,
eJackGeoLocDrivebay,
eJackGeoLocHDMI,
eJackGeoLocOutsideMobileLid,
eJackGeoLocATAPI,
eJackGeoLocReserved5,
eJackGeoLocReserved6,
}
PaWasapiJackGeoLocation;
/* Jack general location. */
typedef enum PaWasapiJackGenLocation
{
eJackGenLocPrimaryBox = 0,
eJackGenLocInternal,
eJackGenLocSeparate,
eJackGenLocOther
}
PaWasapiJackGenLocation;
/* Jack's type of port. */
typedef enum PaWasapiJackPortConnection
{
eJackPortConnJack = 0,
eJackPortConnIntegratedDevice,
eJackPortConnBothIntegratedAndJack,
eJackPortConnUnknown
}
PaWasapiJackPortConnection;
/* Thread priority. */
typedef enum PaWasapiThreadPriority
{
eThreadPriorityNone = 0,
eThreadPriorityAudio, //!< Default for Shared mode.
eThreadPriorityCapture,
eThreadPriorityDistribution,
eThreadPriorityGames,
eThreadPriorityPlayback,
eThreadPriorityProAudio, //!< Default for Exclusive mode.
eThreadPriorityWindowManager
}
PaWasapiThreadPriority;
/* Stream descriptor. */
typedef struct PaWasapiJackDescription
{
unsigned long channelMapping;
unsigned long color; /* derived from macro: #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) */
PaWasapiJackConnectionType connectionType;
PaWasapiJackGeoLocation geoLocation;
PaWasapiJackGenLocation genLocation;
PaWasapiJackPortConnection portConnection;
unsigned int isConnected;
}
PaWasapiJackDescription;
/** Stream category.
Note:
- values are equal to WASAPI AUDIO_STREAM_CATEGORY enum
- supported since Windows 8.0, noop on earler versions
- values 1,2 are deprecated on Windows 10 and not included into enumeration
@version Available as of 19.6.0
*/
typedef enum PaWasapiStreamCategory
{
eAudioCategoryOther = 0,
eAudioCategoryCommunications = 3,
eAudioCategoryAlerts = 4,
eAudioCategorySoundEffects = 5,
eAudioCategoryGameEffects = 6,
eAudioCategoryGameMedia = 7,
eAudioCategoryGameChat = 8,
eAudioCategorySpeech = 9,
eAudioCategoryMovie = 10,
eAudioCategoryMedia = 11
}
PaWasapiStreamCategory;
/** Stream option.
Note:
- values are equal to WASAPI AUDCLNT_STREAMOPTIONS enum
- supported since Windows 8.1, noop on earler versions
@version Available as of 19.6.0
*/
typedef enum PaWasapiStreamOption
{
eStreamOptionNone = 0, //!< default
eStreamOptionRaw = 1, //!< bypass WASAPI Audio Engine DSP effects, supported since Windows 8.1
eStreamOptionMatchFormat = 2 //!< force WASAPI Audio Engine into a stream format, supported since Windows 10
}
PaWasapiStreamOption;
/* Stream descriptor. */
typedef struct PaWasapiStreamInfo
{
unsigned long size; /**< sizeof(PaWasapiStreamInfo) */
PaHostApiTypeId hostApiType; /**< paWASAPI */
unsigned long version; /**< 1 */
unsigned long flags; /**< collection of PaWasapiFlags */
/** Support for WAVEFORMATEXTENSIBLE channel masks. If flags contains
paWinWasapiUseChannelMask this allows you to specify which speakers
to address in a multichannel stream. Constants for channelMask
are specified in pa_win_waveformat.h. Will be used only if
paWinWasapiUseChannelMask flag is specified.
*/
PaWinWaveFormatChannelMask channelMask;
/** Delivers raw data to callback obtained from GetBuffer() methods skipping
internal PortAudio processing inventory completely. userData parameter will
be the same that was passed to Pa_OpenStream method. Will be used only if
paWinWasapiRedirectHostProcessor flag is specified.
*/
PaWasapiHostProcessorCallback hostProcessorOutput;
PaWasapiHostProcessorCallback hostProcessorInput;
/** Specifies thread priority explicitly. Will be used only if paWinWasapiThreadPriority flag
is specified.
Please note, if Input/Output streams are opened simultaniously (Full-Duplex mode)
you shall specify same value for threadPriority or othervise one of the values will be used
to setup thread priority.
*/
PaWasapiThreadPriority threadPriority;
/** Stream category.
@see PaWasapiStreamCategory
@version Available as of 19.6.0
*/
PaWasapiStreamCategory streamCategory;
/** Stream option.
@see PaWasapiStreamOption
@version Available as of 19.6.0
*/
PaWasapiStreamOption streamOption;
}
PaWasapiStreamInfo;
/** Returns default sound format for device. Format is represented by PaWinWaveFormat or
WAVEFORMATEXTENSIBLE structure.
@param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
@param nFormatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
@param nDevice Device index.
@return Non-negative value indicating the number of bytes copied into format decriptor
or, a PaErrorCode (which are always negative) if PortAudio is not initialized
or an error is encountered.
*/
int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, PaDeviceIndex nDevice );
/** Returns device role (PaWasapiDeviceRole enum).
@param nDevice device index.
@return Non-negative value indicating device role or, a PaErrorCode (which are always negative)
if PortAudio is not initialized or an error is encountered.
*/
int/*PaWasapiDeviceRole*/ PaWasapi_GetDeviceRole( PaDeviceIndex nDevice );
/** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread
which makes calls to Pa_WriteStream/Pa_ReadStream.
@param hTask Handle to pointer to priority task. Must be used with PaWasapi_RevertThreadPriority
method to revert thread priority to initial state.
@param nPriorityClass Id of thread priority of PaWasapiThreadPriority type. Specifying
eThreadPriorityNone does nothing.
@return Error code indicating success or failure.
@see PaWasapi_RevertThreadPriority
*/
PaError PaWasapi_ThreadPriorityBoost( void **hTask, PaWasapiThreadPriority nPriorityClass );
/** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread
which makes calls to Pa_WriteStream/Pa_ReadStream.
@param hTask Task handle obtained by PaWasapi_BoostThreadPriority method.
@return Error code indicating success or failure.
@see PaWasapi_BoostThreadPriority
*/
PaError PaWasapi_ThreadPriorityRevert( void *hTask );
/** Get number of frames per host buffer. This is maximal value of frames of WASAPI buffer which
can be locked for operations. Use this method as helper to findout maximal values of
inputFrames/outputFrames of PaWasapiHostProcessorCallback.
@param pStream Pointer to PaStream to query.
@param nInput Pointer to variable to receive number of input frames. Can be NULL.
@param nOutput Pointer to variable to receive number of output frames. Can be NULL.
@return Error code indicating success or failure.
@see PaWasapiHostProcessorCallback
*/
PaError PaWasapi_GetFramesPerHostBuffer( PaStream *pStream, unsigned int *nInput, unsigned int *nOutput );
/** Get number of jacks associated with a WASAPI device. Use this method to determine if
there are any jacks associated with the provided WASAPI device. Not all audio devices
will support this capability. This is valid for both input and output devices.
@param nDevice device index.
@param jcount Number of jacks is returned in this variable
@return Error code indicating success or failure
@see PaWasapi_GetJackDescription
*/
PaError PaWasapi_GetJackCount(PaDeviceIndex nDevice, int *jcount);
/** Get the jack description associated with a WASAPI device and jack number
Before this function is called, use PaWasapi_GetJackCount to determine the
number of jacks associated with device. If jcount is greater than zero, then
each jack from 0 to jcount can be queried with this function to get the jack
description.
@param nDevice device index.
@param jindex Which jack to return information
@param KSJACK_DESCRIPTION This structure filled in on success.
@return Error code indicating success or failure
@see PaWasapi_GetJackCount
*/
PaError PaWasapi_GetJackDescription(PaDeviceIndex nDevice, int jindex, PaWasapiJackDescription *pJackDescription);
/*
IMPORTANT:
WASAPI is implemented for Callback and Blocking interfaces. It supports Shared and Exclusive
share modes.
Exclusive Mode:
Exclusive mode allows to deliver audio data directly to hardware bypassing
software mixing.
Exclusive mode is specified by 'paWinWasapiExclusive' flag.
Callback Interface:
Provides best audio quality with low latency. Callback interface is implemented in
two versions:
1) Event-Driven:
This is the most powerful WASAPI implementation which provides glitch-free
audio at around 3ms latency in Exclusive mode. Lowest possible latency for this mode is
3 ms for HD Audio class audio chips. For the Shared mode latency can not be
lower than 20 ms.
2) Poll-Driven:
Polling is another 2-nd method to operate with WASAPI. It is less efficient than Event-Driven
and provides latency at around 10-13ms. Polling must be used to overcome a system bug
under Windows Vista x64 when application is WOW64(32-bit) and Event-Driven method simply
times out (event handle is never signalled on buffer completion). Please note, such WOW64 bug
does not exist in Vista x86 or Windows 7.
Polling can be setup by speciying 'paWinWasapiPolling' flag. Our WASAPI implementation detects
WOW64 bug and sets 'paWinWasapiPolling' automatically.
Thread priority:
Normally thread priority is set automatically and does not require modification. Although
if user wants some tweaking thread priority can be modified by setting 'paWinWasapiThreadPriority'
flag and specifying 'PaWasapiStreamInfo::threadPriority' with value from PaWasapiThreadPriority
enum.
Blocking Interface:
Blocking interface is implemented but due to above described Poll-Driven method can not
deliver lowest possible latency. Specifying too low latency in Shared mode will result in
distorted audio although Exclusive mode adds stability.
Pa_IsFormatSupported:
To check format with correct Share Mode (Exclusive/Shared) you must supply
PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
PaStreamParameters::hostApiSpecificStreamInfo structure.
Pa_OpenStream:
To set desired Share Mode (Exclusive/Shared) you must supply
PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
PaStreamParameters::hostApiSpecificStreamInfo structure.
*/
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* PA_WIN_WASAPI_H */

View File

@ -0,0 +1,199 @@
#ifndef PA_WIN_WAVEFORMAT_H
#define PA_WIN_WAVEFORMAT_H
/*
* PortAudio Portable Real-Time Audio Library
* Windows WAVEFORMAT* data structure utilities
* portaudio.h should be included before this file.
*
* Copyright (c) 2007 Ross Bencina
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/
/** @file
@ingroup public_header
@brief Windows specific PortAudio API extension and utilities header file.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
The following #defines for speaker channel masks are the same
as those in ksmedia.h, except with PAWIN_ prepended, KSAUDIO_ removed
in some cases, and casts to PaWinWaveFormatChannelMask added.
*/
typedef unsigned long PaWinWaveFormatChannelMask;
/* Speaker Positions: */
#define PAWIN_SPEAKER_FRONT_LEFT ((PaWinWaveFormatChannelMask)0x1)
#define PAWIN_SPEAKER_FRONT_RIGHT ((PaWinWaveFormatChannelMask)0x2)
#define PAWIN_SPEAKER_FRONT_CENTER ((PaWinWaveFormatChannelMask)0x4)
#define PAWIN_SPEAKER_LOW_FREQUENCY ((PaWinWaveFormatChannelMask)0x8)
#define PAWIN_SPEAKER_BACK_LEFT ((PaWinWaveFormatChannelMask)0x10)
#define PAWIN_SPEAKER_BACK_RIGHT ((PaWinWaveFormatChannelMask)0x20)
#define PAWIN_SPEAKER_FRONT_LEFT_OF_CENTER ((PaWinWaveFormatChannelMask)0x40)
#define PAWIN_SPEAKER_FRONT_RIGHT_OF_CENTER ((PaWinWaveFormatChannelMask)0x80)
#define PAWIN_SPEAKER_BACK_CENTER ((PaWinWaveFormatChannelMask)0x100)
#define PAWIN_SPEAKER_SIDE_LEFT ((PaWinWaveFormatChannelMask)0x200)
#define PAWIN_SPEAKER_SIDE_RIGHT ((PaWinWaveFormatChannelMask)0x400)
#define PAWIN_SPEAKER_TOP_CENTER ((PaWinWaveFormatChannelMask)0x800)
#define PAWIN_SPEAKER_TOP_FRONT_LEFT ((PaWinWaveFormatChannelMask)0x1000)
#define PAWIN_SPEAKER_TOP_FRONT_CENTER ((PaWinWaveFormatChannelMask)0x2000)
#define PAWIN_SPEAKER_TOP_FRONT_RIGHT ((PaWinWaveFormatChannelMask)0x4000)
#define PAWIN_SPEAKER_TOP_BACK_LEFT ((PaWinWaveFormatChannelMask)0x8000)
#define PAWIN_SPEAKER_TOP_BACK_CENTER ((PaWinWaveFormatChannelMask)0x10000)
#define PAWIN_SPEAKER_TOP_BACK_RIGHT ((PaWinWaveFormatChannelMask)0x20000)
/* Bit mask locations reserved for future use */
#define PAWIN_SPEAKER_RESERVED ((PaWinWaveFormatChannelMask)0x7FFC0000)
/* Used to specify that any possible permutation of speaker configurations */
#define PAWIN_SPEAKER_ALL ((PaWinWaveFormatChannelMask)0x80000000)
/* DirectSound Speaker Config */
#define PAWIN_SPEAKER_DIRECTOUT 0
#define PAWIN_SPEAKER_MONO (PAWIN_SPEAKER_FRONT_CENTER)
#define PAWIN_SPEAKER_STEREO (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT)
#define PAWIN_SPEAKER_QUAD (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT)
#define PAWIN_SPEAKER_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_BACK_CENTER)
#define PAWIN_SPEAKER_5POINT1 (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \
PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT)
#define PAWIN_SPEAKER_7POINT1 (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \
PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT | \
PAWIN_SPEAKER_FRONT_LEFT_OF_CENTER | PAWIN_SPEAKER_FRONT_RIGHT_OF_CENTER)
#define PAWIN_SPEAKER_5POINT1_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \
PAWIN_SPEAKER_SIDE_LEFT | PAWIN_SPEAKER_SIDE_RIGHT)
#define PAWIN_SPEAKER_7POINT1_SURROUND (PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_RIGHT | \
PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_LOW_FREQUENCY | \
PAWIN_SPEAKER_BACK_LEFT | PAWIN_SPEAKER_BACK_RIGHT | \
PAWIN_SPEAKER_SIDE_LEFT | PAWIN_SPEAKER_SIDE_RIGHT)
/*
According to the Microsoft documentation:
The following are obsolete 5.1 and 7.1 settings (they lack side speakers). Note this means
that the default 5.1 and 7.1 settings (KSAUDIO_SPEAKER_5POINT1 and KSAUDIO_SPEAKER_7POINT1 are
similarly obsolete but are unchanged for compatibility reasons).
*/
#define PAWIN_SPEAKER_5POINT1_BACK PAWIN_SPEAKER_5POINT1
#define PAWIN_SPEAKER_7POINT1_WIDE PAWIN_SPEAKER_7POINT1
/* DVD Speaker Positions */
#define PAWIN_SPEAKER_GROUND_FRONT_LEFT PAWIN_SPEAKER_FRONT_LEFT
#define PAWIN_SPEAKER_GROUND_FRONT_CENTER PAWIN_SPEAKER_FRONT_CENTER
#define PAWIN_SPEAKER_GROUND_FRONT_RIGHT PAWIN_SPEAKER_FRONT_RIGHT
#define PAWIN_SPEAKER_GROUND_REAR_LEFT PAWIN_SPEAKER_BACK_LEFT
#define PAWIN_SPEAKER_GROUND_REAR_RIGHT PAWIN_SPEAKER_BACK_RIGHT
#define PAWIN_SPEAKER_TOP_MIDDLE PAWIN_SPEAKER_TOP_CENTER
#define PAWIN_SPEAKER_SUPER_WOOFER PAWIN_SPEAKER_LOW_FREQUENCY
/*
PaWinWaveFormat is defined here to provide compatibility with
compilation environments which don't have headers defining
WAVEFORMATEXTENSIBLE (e.g. older versions of MSVC, Borland C++ etc.
The fields for WAVEFORMATEX and WAVEFORMATEXTENSIBLE are declared as an
unsigned char array here to avoid clients who include this file having
a dependency on windows.h and mmsystem.h, and also to to avoid having
to write separate packing pragmas for each compiler.
*/
#define PAWIN_SIZEOF_WAVEFORMATEX 18
#define PAWIN_SIZEOF_WAVEFORMATEXTENSIBLE (PAWIN_SIZEOF_WAVEFORMATEX + 22)
typedef struct{
unsigned char fields[ PAWIN_SIZEOF_WAVEFORMATEXTENSIBLE ];
unsigned long extraLongForAlignment; /* ensure that compiler aligns struct to DWORD */
} PaWinWaveFormat;
/*
WAVEFORMATEXTENSIBLE fields:
union {
WORD wValidBitsPerSample;
WORD wSamplesPerBlock;
WORD wReserved;
} Samples;
DWORD dwChannelMask;
GUID SubFormat;
*/
#define PAWIN_INDEXOF_WVALIDBITSPERSAMPLE (PAWIN_SIZEOF_WAVEFORMATEX+0)
#define PAWIN_INDEXOF_DWCHANNELMASK (PAWIN_SIZEOF_WAVEFORMATEX+2)
#define PAWIN_INDEXOF_SUBFORMAT (PAWIN_SIZEOF_WAVEFORMATEX+6)
/*
Valid values to pass for the waveFormatTag PaWin_InitializeWaveFormatEx and
PaWin_InitializeWaveFormatExtensible functions below. These must match
the standard Windows WAVE_FORMAT_* values.
*/
#define PAWIN_WAVE_FORMAT_PCM (1)
#define PAWIN_WAVE_FORMAT_IEEE_FLOAT (3)
#define PAWIN_WAVE_FORMAT_DOLBY_AC3_SPDIF (0x0092)
#define PAWIN_WAVE_FORMAT_WMA_SPDIF (0x0164)
/*
returns PAWIN_WAVE_FORMAT_PCM or PAWIN_WAVE_FORMAT_IEEE_FLOAT
depending on the sampleFormat parameter.
*/
int PaWin_SampleFormatToLinearWaveFormatTag( PaSampleFormat sampleFormat );
/*
Use the following two functions to initialize the waveformat structure.
*/
void PaWin_InitializeWaveFormatEx( PaWinWaveFormat *waveFormat,
int numChannels, PaSampleFormat sampleFormat, int waveFormatTag, double sampleRate );
void PaWin_InitializeWaveFormatExtensible( PaWinWaveFormat *waveFormat,
int numChannels, PaSampleFormat sampleFormat, int waveFormatTag, double sampleRate,
PaWinWaveFormatChannelMask channelMask );
/* Map a channel count to a speaker channel mask */
PaWinWaveFormatChannelMask PaWin_DefaultChannelMask( int numChannels );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* PA_WIN_WAVEFORMAT_H */

1225
libkmaudio/portaudio.h Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

1209
libkmaudio/soundio.h Normal file

File diff suppressed because it is too large Load Diff

1
libs/aarch64/libad9361.so Symbolic link
View File

@ -0,0 +1 @@
libad9361.so.0

1
libs/aarch64/libad9361.so.0 Symbolic link
View File

@ -0,0 +1 @@
libad9361.so.0.1

Binary file not shown.

1
libs/aarch64/libiio.so Symbolic link
View File

@ -0,0 +1 @@
libiio.so.0

1
libs/aarch64/libiio.so.0 Symbolic link
View File

@ -0,0 +1 @@
libiio.so.0.21

BIN
libs/aarch64/libiio.so.0.16 Normal file

Binary file not shown.

BIN
libs/aarch64/libiio.so.0.21 Normal file

Binary file not shown.

BIN
libs/aarch64/libliquid.a Normal file

Binary file not shown.

BIN
libs/aarch64/libliquid.so Normal file

Binary file not shown.

BIN
libs/aarch64/libsoundio.a Normal file

Binary file not shown.

1
libs/aarch64/libsoundio.so Symbolic link
View File

@ -0,0 +1 @@
libsoundio.so.2

View File

@ -0,0 +1 @@
libsoundio.so.2.0.0

Binary file not shown.

1
libs/armhf/libad9361.so Symbolic link
View File

@ -0,0 +1 @@
libad9361.so.0

1
libs/armhf/libad9361.so.0 Symbolic link
View File

@ -0,0 +1 @@
libad9361.so.0.1

BIN
libs/armhf/libad9361.so.0.1 Normal file

Binary file not shown.

1
libs/armhf/libiio.so Symbolic link
View File

@ -0,0 +1 @@
libiio.so.0

1
libs/armhf/libiio.so.0 Symbolic link
View File

@ -0,0 +1 @@
libiio.so.0.21

BIN
libs/armhf/libiio.so.0.16 Normal file

Binary file not shown.

BIN
libs/armhf/libiio.so.0.21 Normal file

Binary file not shown.

BIN
libs/armhf/libliquid.a Normal file

Binary file not shown.

BIN
libs/armhf/libliquid.so Normal file

Binary file not shown.

BIN
libs/armhf/libsoundio.a Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More