first commit
This commit is contained in:
@@ -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/>.
|
||||
@@ -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
|
||||
|
||||
@@ -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.
@@ -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
|
||||
Binary file not shown.
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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;
|
||||
}
|
||||
@@ -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.
@@ -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.
Binary file not shown.
+8823
File diff suppressed because it is too large
Load Diff
@@ -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 */
|
||||
@@ -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 */
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user