├── .gitignore
├── LICENSE
├── Makefile
├── README.md
└── rtlmic.c
/.gitignore:
--------------------------------------------------------------------------------
1 | rtlmic
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | PREFIX ?= /usr
2 | CFLAGS ?= -O3
3 |
4 | all: rtlmic
5 |
6 | rtlmic: rtlmic.c
7 | gcc -Wall $(CFLAGS) -o $@ $< -lrtlsdr -lvolk -lm -ljack
8 |
9 | install: rtlmic
10 | install rtlmic $(PREFIX)/bin/rtlmic
11 |
12 | clean:
13 | rm -f rtlmic
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rtlmic: Wireless microphone receiver for RTL-SDR
2 |
3 | rtlmic is a multichannel FM microphone receiver/demodulator for RTL-SDR cards.
4 | It outputs realtime audio to JACK.
5 |
6 | ## Installation
7 |
8 | Dependencies:
9 |
10 | * libjack
11 | * libvolk
12 | * librtlsdr
13 |
14 | To build and install, just use `make && sudo make install`.
15 |
16 | ## Usage
17 |
18 | Basic usage is simply:
19 |
20 | ```shell
21 | $ rtlmic [channel 1 frequency] [channel 2 frequency]...
22 | ```
23 |
24 | You can capture as many channels as your CPU can handle, as long as they all
25 | fit within the capture bandwidth of the RTL-SDR.
26 |
27 | Use `rtlmic --help` to see all available options.
28 |
29 | In order to get back correct audio, you should know certain parameters about
30 | your microphones: the companding ratio (`-e`), the companding tau (`-E`), the
31 | deemphasis tau (`-M`), and the FM deviation (`-w`).
32 |
33 | Most microphones use 2:1 companding (the default ratio). The companding
34 | tau is usually determined by an R-C filter in the microphone, connected to the
35 | compressor chip. In my case, the component values are 10kΩ and 1µF, which gives
36 | 10kΩ * 1µF = 10ms tau. The deemphasis tau just affects the frequency response:
37 | the higher the tau, the less high-end the microphone will have. If you do not
38 | know the exact values for your microphone, you can just try and see what sounds
39 | best.
40 |
41 | By default, the RTL-SDR will be tuned to the frequency in between the highest
42 | and lowest channel specified. However, if you have a channel near that point
43 | (e.g. if you are only capturing one channel, or an odd number of evenly spaced
44 | channels) then you may experience additional noise, as the RTL-SDR does not
45 | perform well near DC. You can work around this by choosing a different center
46 | frequency with `-f`.
47 |
48 | You may want to play around with other parameters, e.g. adjusting the tuner gain
49 | (`-g`) and squelch threshold (`-s`), as well as the audio gain (`-a`). If your
50 | channels are spaced closely together, lower the transition width (`-t`) and use
51 | a tight deviation (`-w`). Note that lowering the transition width increases CPU
52 | usage significantly.
53 |
54 | If you have persistent buffer over/underrun problems, you should try changing
55 | the buffering settings `-b` and `-B`, as well as the JACK period size in the
56 | JACK server. A few under/overruns on startup are normal, as it takes some time
57 | for rtlmic to lock onto the exact ratio between the true SDR and JACK
58 | frequencies.
59 |
--------------------------------------------------------------------------------
/rtlmic.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2017 Hector Martin "marcan"
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, version 3.
7 |
8 | This program is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU General Public License for more details.
12 |
13 | You should have received a copy of the GNU General Public License
14 | along with this program. If not, see .
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | struct onepole {
32 | float acc;
33 | float alpha;
34 | };
35 |
36 | struct channel {
37 | int f;
38 | int df;
39 |
40 | int ntaps;
41 | float complex **taps;
42 |
43 | float complex phase;
44 | float complex phi;
45 | float complex *sample;
46 | float complex last;
47 |
48 | struct onepole squelch_lpf;
49 | float squelch_ctr;
50 | struct onepole dc_lpf;
51 | struct onepole env_lpf;
52 | struct onepole emph_lpf;
53 |
54 | float acc;
55 | int cnt;
56 | float *audio_buf1;
57 | float *p1;
58 |
59 | jack_ringbuffer_t *rb;
60 | int running;
61 | jack_port_t *port;
62 | float history[3];
63 | float mu;
64 | };
65 |
66 | struct state {
67 | int verbose;
68 |
69 | // Sampling
70 | int tuner_gain; // Tuner gain in .1dB increments
71 | rtlsdr_dev_t *dev;
72 | int fs; // Sampling frequency
73 | int fc; // Center tuning frequency
74 |
75 | // Buffering
76 | int blockcnt; // Number of outstanding USB transactions
77 | int blocksz; // Buffer size in samples (raw bytes / 2)
78 | int bufpad; // Number of history samples to keep
79 | int bufsz; // Total buffer size
80 | float complex *buffer;
81 | int p; // Current buffer pointer
82 |
83 | // Filtering
84 | struct onepole dc_lpf_i;
85 | struct onepole dc_lpf_q;
86 | int width; // Filter half-width (deviation)
87 | int twidth; // Transition band width
88 | int decimation; // Decimation after filtering
89 | float fi; // Intermediate frequency (fs / decimation)
90 | int ntaps; // Number of filter taps
91 | int align; // Required platform alignment for buffers in bytes
92 | int nalign; // Alignment in complex samples
93 |
94 | // Audio processing
95 | float fa; // Audio sampling frequency
96 | int adecimation; // Decimation before audio processing
97 | float squelch_thr; // Squelch threshold
98 | float squelch_tau; // Squelch LPF tau
99 | float dc_tau; // DC removal LPF tau
100 | float exp_tau; // Expander tau
101 | float exp_ratio; // Expander ratio
102 | float emph_tau; // De-emphasis tau
103 | float audio_gain; // Audio gain factor
104 |
105 | // Audio buffering/resampling
106 | int fjack; // JACK sample rate
107 | int rb_size; // JACK ringbuffer size
108 | int iblock; // Input (SDR) block size at AF frequency;
109 | int pblock; // Output (JACK) block size at AF frequency;
110 | int oblock; // Output (JACK) block size
111 | int low_thresh; // Ring buffer low threshold
112 | int high_thresh; // Ring buffer high threshold
113 | float dmu; // Downsampling factor
114 | struct onepole buf_lpf; // Resampling loop lpf
115 |
116 | // Channels
117 | int nch;
118 | struct channel *ch;
119 |
120 | jack_client_t *client;
121 | int jack_alive;
122 | };
123 |
124 | struct state st;
125 |
126 | static int compute_ntaps(int transition_width, int sample_rate)
127 | {
128 | float delta_f = transition_width / (float)sample_rate;
129 | return (((int)(3.3f / delta_f + 0.5f)) & ~1) + 1;
130 | }
131 |
132 | static void generate_lpf(float complex *taps, int ntaps, int fs, int width)
133 | {
134 | int M = ntaps / 2;
135 | double fwT0 = 2 * M_PI * width / (double)fs;
136 |
137 | // Sinc function with Hamming window
138 | // Taps are real here but stored as complex for rotation later
139 | taps[M] = fwT0;
140 | float gain = taps[M];
141 | for (int i = 1; i <= M; i++) {
142 | float c = sin(i * fwT0) / i * (0.54 + 0.46 * cos(M_PI * i / (double)M));
143 | gain += 2 * c;
144 | taps[M-i] = taps[M+i] = c;
145 | }
146 |
147 | // Normalize
148 | gain = 1.f / gain;
149 | for(int i = 0; i < ntaps; i++)
150 | taps[i] *= gain;
151 | }
152 |
153 | static void init_onepole(struct onepole *filt, float fs, float tau)
154 | {
155 | if (tau == 0)
156 | filt->alpha = 1.0;
157 | else
158 | filt->alpha = 1.0 - expf(-(1.0 / fs) / tau);
159 | filt->acc = 0;
160 | }
161 |
162 | static inline float filter_onepole(struct onepole *filt, float v)
163 | {
164 | filt->acc = filt->acc * (1.f - filt->alpha) + v * filt->alpha;
165 | return filt->acc;
166 | }
167 |
168 | static inline float cubic(float *y, float mu)
169 | {
170 | float a0,a1,a2,mu2;
171 |
172 | mu2 = mu * mu;
173 | a0 = y[3] - y[2] - y[0] + y[1];
174 | a1 = y[0] - y[1] - a0;
175 | a2 = y[2] - y[0];
176 |
177 | return a0 * mu * mu2 + a1 * mu2 + a2 * mu + y[1];
178 | }
179 |
180 | static void init_channel(int c)
181 | {
182 | struct channel *ch = &st.ch[c];
183 |
184 | ch->df = st.fc - ch->f;
185 | ch->ntaps = st.ntaps;
186 |
187 | ch->taps = malloc(st.nalign * sizeof(float complex *));
188 | for (int i = 0; i < st.nalign; i++) {
189 | ch->taps[i] = volk_malloc(
190 | sizeof(float complex) * (ch->ntaps + st.nalign), st.align);
191 | memset(ch->taps[i], 0, sizeof(float complex) * ch->ntaps);
192 | }
193 |
194 | generate_lpf(ch->taps[0], st.ntaps, st.fs, st.width);
195 |
196 | // Shift LPF into BPF
197 | double fwT0 = 2 * M_PI * ch->df / (double)st.fs;
198 | for (int i = 0; i < st.ntaps; i++) {
199 | ch->taps[0][i] = ch->taps[0][i] * cexpf(lv_cmake(0, i * fwT0));
200 | }
201 | // Frequency shifter
202 | ch->phase = lv_cmake(1.f, 0.f);
203 | ch->phi = cexp(lv_cmake(0, fwT0 * st.decimation));
204 |
205 | // Build offset tap vectors, padded with zeros, for SIMD alignment
206 | for (int i = 1; i < st.nalign; i++)
207 | memcpy(&ch->taps[i][i], ch->taps[0], st.ntaps * sizeof(float complex));
208 |
209 | // Make sure output sample buffer is aligned too
210 | ch->sample = volk_malloc(sizeof(float complex), st.align);
211 |
212 | init_onepole(&ch->squelch_lpf, st.fi, st.squelch_tau);
213 | init_onepole(&ch->dc_lpf, st.fa, st.dc_tau);
214 | init_onepole(&ch->env_lpf, st.fa, st.exp_tau);
215 | init_onepole(&ch->emph_lpf, st.fa, st.emph_tau);
216 |
217 | ch->audio_buf1 = malloc(st.iblock * sizeof(float));
218 | ch->p1 = ch->audio_buf1;
219 |
220 | ch->rb = jack_ringbuffer_create(st.rb_size * sizeof(float));
221 |
222 | char name[16];
223 | sprintf(name, "channel_%d", c + 1);
224 | ch->port = jack_port_register(st.client, name, JACK_DEFAULT_AUDIO_TYPE,
225 | JackPortIsOutput, 0);
226 | }
227 |
228 | static void process_channel_sample(int c, float complex *buf)
229 | {
230 | struct channel *ch = &st.ch[c];
231 |
232 | uintptr_t pad = (((uintptr_t)buf) & (st.align - 1)) / sizeof(float complex);
233 |
234 | // Bandpass filter
235 | volk_32fc_x2_dot_prod_32fc_a(ch->sample, buf - pad, ch->taps[pad],
236 | st.ntaps + pad);
237 | // Shift frequency
238 | float complex ss = *ch->sample * ch->phase;
239 | ch->phase *= ch->phi;
240 | // Demodulate FM
241 | float s = cargf(lv_conj(ch->last) * ss);
242 | // Squelch
243 | if (filter_onepole(&ch->squelch_lpf, cabsf(ss)) < st.squelch_thr) {
244 | s = 0;
245 | ch->squelch_ctr = 0;
246 | } else if (ch->squelch_ctr < 1.0) {
247 | s *= ch->squelch_ctr;
248 | ch->squelch_ctr += 0.00005;
249 | }
250 | // Simple boxcar filter for audio decimation
251 | ch->acc += s;
252 | if (++ch->cnt >= st.adecimation) {
253 | *(ch->p1++) = ch->acc / st.adecimation;
254 | ch->cnt = 0;
255 | ch->acc = 0;
256 | }
257 |
258 | ch->last = ss;
259 | }
260 |
261 | static void process_channel_audio(int c)
262 | {
263 | struct channel *ch = &st.ch[c];
264 |
265 | jack_ringbuffer_data_t wdata[2];
266 |
267 | jack_ringbuffer_get_write_vector(ch->rb, wdata);
268 |
269 | float *dp = (void*)wdata[0].buf;
270 | int wcnt = wdata[0].len / sizeof(float);
271 | int put = 0;
272 |
273 | float *p = ch->audio_buf1;
274 | while (p != ch->p1) {
275 | if (!wcnt) {
276 | if (wdata[1].len) {
277 | dp = (void*)wdata[1].buf;
278 | wcnt = wdata[1].len / sizeof(float);
279 | wdata[1].len = 0;
280 | } else {
281 | if (c == 0)
282 | fprintf(stderr, "Ring buffer overrun! Left=%d \n",
283 | (int)(ch->p1 - p));
284 | break;
285 | }
286 | }
287 |
288 | float s = *p++;
289 | // Remove DC
290 | s -= filter_onepole(&ch->dc_lpf, s);
291 | // Expander
292 | s *= powf(filter_onepole(&ch->env_lpf, fabsf(s)), st.exp_ratio - 1.f);
293 | // De-emphasis
294 | s = filter_onepole(&ch->emph_lpf, s);
295 | // Gain
296 | s *= st.audio_gain;
297 | *dp++ = s;
298 | wcnt--;
299 | put++;
300 | }
301 | jack_ringbuffer_write_advance(ch->rb, put * sizeof(float));
302 | ch->p1 = ch->audio_buf1;
303 |
304 | // Normalize phase to make sure it doesn't go wacky
305 | ch->phase /= cabsf(ch->phase);
306 | }
307 |
308 |
309 | void got_samples(unsigned char *buf, uint32_t len, void *ctx)
310 | {
311 | if (!st.jack_alive)
312 | return;
313 |
314 | if (len != st.blocksz * 2) {
315 | printf("Got %d bytes, expected %d!\n", len, st.blocksz);
316 | exit(1);
317 | }
318 |
319 | memcpy(st.buffer, &st.buffer[st.blocksz],
320 | st.bufpad * sizeof(float complex));
321 |
322 | float complex *dst = &st.buffer[st.ntaps];
323 | len /= 2;
324 |
325 | while (len--) {
326 | float i = (buf[0] - 127) / 127.f;
327 | float q = (buf[1] - 127) / 127.f;
328 | i -= filter_onepole(&st.dc_lpf_i, i);
329 | q -= filter_onepole(&st.dc_lpf_q, q);
330 | *dst++ = lv_cmake(i, q);
331 | buf += 2;
332 | }
333 |
334 | int p = st.p;
335 | int max = st.blocksz + st.decimation;
336 | float complex *pbuf = &st.buffer[p];
337 | for (; p < max; p += st.decimation)
338 | {
339 | for (int i = 0; i < st.nch; i++)
340 | process_channel_sample(i, pbuf);
341 | pbuf += st.decimation;
342 | }
343 | st.p = p - st.blocksz;
344 |
345 | for (int i = 0; i < st.nch; i++) {
346 | process_channel_audio(i);
347 | }
348 |
349 | float fullness = jack_ringbuffer_read_space(st.ch[0].rb) /
350 | sizeof(float) / (float)st.rb_size;
351 |
352 | float f2 = filter_onepole(&st.buf_lpf, fullness);
353 |
354 | st.dmu = st.fa / st.fjack * (1.0 + 0.2 * (f2 - 0.5));
355 |
356 | if (st.verbose >= 2)
357 | fprintf(stderr, "RB fullness: %.02f (%.02f) AF=%.01f \r",
358 | 100.0f * fullness, 100.0f * f2, st.dmu * st.fjack);
359 |
360 | }
361 |
362 | void jack_shutdown (void *arg)
363 | {
364 | exit (1);
365 | }
366 |
367 | int jack_process (jack_nframes_t nframes, void *arg)
368 | {
369 | st.jack_alive = 1;
370 | for (int c = 0; c < st.nch; c++) {
371 | struct channel *ch = &st.ch[c];
372 | float *o = (float *)jack_port_get_buffer(ch->port, nframes);
373 | jack_ringbuffer_data_t rvec[2];
374 | jack_ringbuffer_get_read_vector(ch->rb, rvec);
375 | int avail = (rvec[0].len + rvec[1].len) / sizeof(float);
376 | int left = nframes;
377 | int read = 0;
378 |
379 | if (!ch->running && avail < (st.rb_size / 2)) {
380 | memset(o, 0, nframes * sizeof(float));
381 | continue;
382 | }
383 |
384 | avail = rvec[0].len / sizeof(float);
385 | float *r = (void *)rvec[0].buf;
386 | ch->running = 1;
387 |
388 | float y[4], mu=ch->mu, dmu=st.dmu;
389 | memcpy(y, ch->history, sizeof(float) * 4);
390 |
391 | while (left--) {
392 | *o++ = cubic(y, ch->mu);
393 | mu += dmu;
394 | while (mu >= 1.f) {
395 | y[0] = y[1];
396 | y[1] = y[2];
397 | y[2] = y[3];
398 | if (!avail) {
399 | if (rvec[1].len) {
400 | avail = rvec[1].len / sizeof(float);
401 | rvec[1].len = 0;
402 | r = (void *)rvec[1].buf;
403 | } else {
404 | if (c == 0)
405 | fprintf(stderr,
406 | "Ring buffer underrun! left=%d \n",
407 | left);
408 | memset(o, 0, sizeof(float) * left);
409 | y[3] = 0;
410 | while (mu >= 1.f)
411 | mu -= 1.f;
412 | ch->running = 0;
413 | goto next_channel;
414 | }
415 | }
416 | y[3] = *r++;
417 | mu -= 1.f;
418 | read++;
419 | avail--;
420 | }
421 | }
422 | next_channel:
423 | jack_ringbuffer_read_advance(ch->rb, read * sizeof(float));
424 | ch->mu = mu;
425 | memcpy(ch->history, y, sizeof(float) * 4);
426 | }
427 |
428 | return 0;
429 | }
430 |
431 | static struct option long_options[] =
432 | {
433 | {"verbose", no_argument, 0, 'v'},
434 | {"client-name", required_argument, 0, 'c'},
435 | {"fc", required_argument, 0, 'f'},
436 | {"rate", required_argument, 0, 'r'},
437 | {"tuner-gain", required_argument, 0, 'g'},
438 | {"blocksize", required_argument, 0, 'b'},
439 | {"blocks", required_argument, 0, 'n'},
440 | {"width", required_argument, 0, 'w'},
441 | {"transition-width", required_argument, 0, 't'},
442 | {"squelch", required_argument, 0, 's'},
443 | {"squelch-tau", required_argument, 0, 'S'},
444 | {"dc-tau", required_argument, 0, 'D'},
445 | {"expander-ratio", required_argument, 0, 'e'},
446 | {"expander-tau", required_argument, 0, 'E'},
447 | {"deemph-tau", required_argument, 0, 'M'},
448 | {0, 0, 0, 0}
449 | };
450 |
451 | void usage(void)
452 | {
453 | fprintf(stderr, "Usage: rtlmic [OPTION]... [FREQUENCY]...\n");
454 | fprintf(stderr, "rtlmic - Demodulate FM microphones using an RTL-SDR\n");
455 | fprintf(stderr, "\n");
456 | fprintf(stderr, " -h, --help this help\n");
457 | fprintf(stderr, " -v, --verbose be verbose\n");
458 | fprintf(stderr, " -c, --client-name=NAME JACK client name (default: rtlmic)\n");
459 | fprintf(stderr, " -f, --fc=HZ center frequency to tune to\n");
460 | fprintf(stderr, " (default: auto)\n");
461 | fprintf(stderr, " -r, --rate=HZ capture sample rate\n");
462 | fprintf(stderr, " (default: auto)\n");
463 | fprintf(stderr, " -g, --tuner-gain=DB tuner gain in dB\n");
464 | fprintf(stderr, " (default: 10 dB)\n");
465 | fprintf(stderr, " -b, --blocksize=SIZE capture block size in samples\n");
466 | fprintf(stderr, " must be a multiple of 256\n");
467 | fprintf(stderr, " (default: 8192)\n");
468 | fprintf(stderr, " -n, --blocks=NUMBER number of outstanding transfers\n");
469 | fprintf(stderr, " (default: 4)\n");
470 | fprintf(stderr, " -w, --width=HZ filter half-width (FM deviation)\n");
471 | fprintf(stderr, " (default: 100000 Hz)\n");
472 | fprintf(stderr, " -t, --transition-width=HZ\n");
473 | fprintf(stderr, " filter transition bandwidth\n");
474 | fprintf(stderr, " (default: 50000 Hz)\n");
475 | fprintf(stderr, " -s, --squelch=DB squelch level in dB\n");
476 | fprintf(stderr, " (default: -50 dB)\n");
477 | fprintf(stderr, " -S, --squelch-tau=MS squelch time constant in msec\n");
478 | fprintf(stderr, " (default: 0.1 ms)\n");
479 | fprintf(stderr, " -D, --dc-tau=S DC removal time constant in sec\n");
480 | fprintf(stderr, " (default: 2 s)\n");
481 | fprintf(stderr, " -e, --expander-ratio=N expander ratio. 1=1:1, 2=2:1, etc.\n");
482 | fprintf(stderr, " (default: 2 (2:1))\n");
483 | fprintf(stderr, " -E, --expander-tau=MS expander time constant in msec\n");
484 | fprintf(stderr, " (default: 10 ms)\n");
485 | fprintf(stderr, " -M, --deemph-tau=US de-emphasis time constant in usec\n");
486 | fprintf(stderr, " (default: 75 us)\n");
487 | fprintf(stderr, " -a, --audio-gain=DB audio gain in dB (default: 0 dB)\n");
488 | }
489 |
490 | // "Nice" sample rates for RTL-SDR
491 | int sample_rates[] = {
492 | 240000, 300000, 960000, 1152000, 1200000, 1440000,
493 | 1600000, 1800000, 1920000, 2400000, 2880000, 3200000,
494 | 0
495 | };
496 |
497 | int main(int argc, char **argv)
498 | {
499 | memset(&st, 0, sizeof(st));
500 |
501 | char *client_name = "rtlmic";
502 |
503 | int fmin = INT_MAX;
504 | int fmax = 0;
505 |
506 | st.tuner_gain = 100;
507 | st.blocksz = 8192;
508 | st.blockcnt = 4;
509 | st.width = 100000;
510 | st.twidth = 50000;
511 | st.squelch_thr = powf(10.f, -50 / 20.f);
512 | st.squelch_tau = 0.0001f;
513 | st.dc_tau = 2.f;
514 | st.exp_tau = 0.01f;
515 | st.exp_ratio = 2.f;
516 | st.emph_tau = 75e-6;
517 | st.audio_gain = 1.f;
518 |
519 | while (1) {
520 | int c = getopt_long(argc, argv, "vc:f:r:g:b:n:w:t:s:S:D:e:E:M:a:",
521 | long_options, NULL);
522 | if (c == -1)
523 | break;
524 |
525 | switch (c)
526 | {
527 | case 'v':
528 | st.verbose++;
529 | break;
530 | case 'c':
531 | client_name = optarg;
532 | break;
533 | case 'f':
534 | st.fc = atoi(optarg);
535 | break;
536 | case 'r':
537 | st.fs = atoi(optarg);
538 | break;
539 | case 'g':
540 | st.tuner_gain = atoi(optarg) * 10;
541 | break;
542 | case 'b':
543 | st.blocksz = atoi(optarg);
544 | break;
545 | case 'n':
546 | st.blockcnt = atoi(optarg);
547 | break;
548 | case 'w':
549 | st.width = atoi(optarg);
550 | break;
551 | case 't':
552 | st.twidth = atoi(optarg);
553 | break;
554 | case 's':
555 | st.squelch_thr = powf(10.f, atoi(optarg) / 20.f);
556 | break;
557 | case 'S':
558 | st.squelch_tau = atof(optarg) / 1000.f;
559 | break;
560 | case 'D':
561 | st.dc_tau = atof(optarg);
562 | break;
563 | case 'e':
564 | st.exp_ratio = atof(optarg);
565 | break;
566 | case 'E':
567 | st.exp_tau = atof(optarg) / 1000.0;
568 | break;
569 | case 'M':
570 | st.emph_tau = atof(optarg) / 1000000.0;
571 | break;
572 | case 'a':
573 | st.audio_gain = powf(10.f, atoi(optarg) / 20.f);
574 | break;
575 | case 'h':
576 | usage();
577 | return 1;
578 | default:
579 | usage();
580 | return 1;
581 | }
582 | }
583 |
584 | if (optind == argc)
585 | {
586 | fprintf(stderr, "No frequencies specified.\n");
587 | usage();
588 | return 1;
589 | }
590 |
591 | st.ch = malloc((argc - optind) * sizeof(struct channel));
592 | memset(st.ch, 0, (argc - optind) * sizeof(struct channel));
593 |
594 | while (optind < argc)
595 | {
596 | int f = atoi(argv[optind++]);
597 | st.ch[st.nch].f = f;
598 | if (f < fmin)
599 | fmin = f;
600 | if (f > fmax)
601 | fmax = f;
602 | if (st.verbose)
603 | fprintf(stderr, "Channel %d: %d Hz\n", st.nch, f);
604 | st.nch++;
605 | }
606 | //st.nch = 1;
607 |
608 | st.align = volk_get_alignment();
609 | st.nalign = st.align / sizeof(float complex);
610 | if (st.verbose)
611 | fprintf(stderr, "Platform alignment: %d (%d samples)\n",
612 | st.align, st.nalign);
613 |
614 | if (st.fc == 0) {
615 | st.fc = (fmin + fmax) / 2;
616 | }
617 | if (st.verbose)
618 | fprintf(stderr, "Center frequency: %d Hz\n", st.fc);
619 |
620 | if (st.fs == 0) {
621 | // Give us one extra filter-width worth of padding
622 | int need_rate = (fmax - fmin) + 3 * st.width;
623 | for (int i = 0; st.fs < need_rate; i++) {
624 | if (!sample_rates[i]) {
625 | fprintf(stderr, "Channels are too far apart! "
626 | "Total bandwidth needed is %d Hz\n", need_rate);
627 | return 1;
628 | }
629 | st.fs = sample_rates[i];
630 | }
631 | }
632 | if (st.verbose) {
633 | fprintf(stderr, "RTL-SDR sample rate: %d Hz\n", st.fs);
634 | fprintf(stderr, "RTL-SDR block size: %d\n", st.blocksz);
635 | }
636 |
637 | jack_status_t jack_status;
638 |
639 | st.client = jack_client_open(client_name, JackNullOption, &jack_status);
640 | if (!st.client) {
641 | fprintf (stderr, "jack server not running?\n");
642 | return 1;
643 | }
644 | st.fjack = jack_get_sample_rate(st.client);
645 | st.oblock = jack_get_buffer_size(st.client);
646 | if (st.verbose) {
647 | fprintf(stderr, "JACK sample rate: %d Hz\n", st.fjack);
648 | }
649 |
650 | st.decimation = st.fs / (st.width * 2);
651 | st.fi = (float)st.fs / st.decimation;
652 | st.adecimation = (int)st.fi / st.fjack;
653 | st.fa = st.fi / st.adecimation;
654 |
655 | st.ntaps = compute_ntaps(st.twidth, st.fs);
656 |
657 | st.bufpad = st.ntaps + st.decimation;
658 | st.bufsz = st.blocksz + st.bufpad;
659 | st.buffer = volk_malloc(sizeof(float complex) * st.bufsz, st.align);
660 | st.p = st.decimation;
661 | memset(st.buffer, 0, sizeof(float complex) * st.bufsz);
662 |
663 | st.iblock = (st.blocksz / st.decimation + 1) / st.adecimation + 1;
664 | st.pblock = (int)((float)st.oblock / st.fjack * st.fa + 5);
665 |
666 | st.low_thresh = st.iblock;
667 | if (st.pblock < st.iblock)
668 | st.low_thresh = st.pblock;
669 |
670 | st.low_thresh += st.low_thresh / 3;
671 |
672 | st.rb_size = 128;
673 | if (st.rb_size < 3 * st.iblock)
674 | st.rb_size = 3 * st.iblock;
675 | if (st.rb_size < 3 * st.oblock)
676 | st.rb_size = 3 * st.oblock;
677 |
678 | st.high_thresh = st.rb_size - st.low_thresh;
679 |
680 | st.dmu = st.fa / st.fjack;
681 |
682 | if (st.verbose) {
683 | fprintf(stderr, "Decimation: %d\n", st.decimation);
684 | fprintf(stderr, "IF: %.2f Hz\n", st.fi);
685 | fprintf(stderr, "Audio decimation: %d\n", st.adecimation);
686 | fprintf(stderr, "AF: %.2f Hz\n", st.fa);
687 | fprintf(stderr, "Filter taps: %d\n", st.ntaps);
688 | fprintf(stderr, "Buffer sizes: %d/%d/%d -> %d\n",
689 | st.iblock, st.pblock, st.oblock, st.rb_size);
690 | fprintf(stderr, "Buffer low threshold: %d\n", st.low_thresh);
691 | }
692 |
693 | init_onepole(&st.dc_lpf_i, st.fs, 1.);
694 | init_onepole(&st.dc_lpf_q, st.fs, 1.);
695 |
696 | init_onepole(&st.buf_lpf, 1., 200.);
697 | st.buf_lpf.acc = 0.5;
698 |
699 | for (int i = 0; i < st.nch; i++)
700 | init_channel(i);
701 |
702 | int r = rtlsdr_open(&st.dev, 0);
703 | if (r < 0) {
704 | fprintf(stderr, "Failed to open rtlsdr device: error %d.\n", r);
705 | return 1;
706 | }
707 |
708 | rtlsdr_set_offset_tuning(st.dev, 1);
709 | rtlsdr_set_tuner_gain(st.dev, st.tuner_gain);
710 | rtlsdr_set_agc_mode(st.dev, 0);
711 | rtlsdr_reset_buffer(st.dev);
712 | rtlsdr_set_center_freq(st.dev, st.fc);
713 | rtlsdr_set_sample_rate(st.dev, st.fs);
714 |
715 | jack_set_process_callback(st.client, jack_process, NULL);
716 | jack_on_shutdown(st.client, jack_shutdown, NULL);
717 | if (jack_activate(st.client)) {
718 | fprintf(stderr, "cannot activate client");
719 | return 1;
720 | }
721 |
722 | rtlsdr_read_async(st.dev, got_samples, NULL, st.blockcnt, st.blocksz * 2);
723 | jack_client_close(st.client);
724 | }
725 |
--------------------------------------------------------------------------------