Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

auto import from //depot/cupcake/@135843

  • Loading branch information...
commit 4a68b3365c8c50aa93505e99ead2565ab73dcdb0 1 parent e6733b7
The Android Open Source Project authored
Showing with 174,143 additions and 0 deletions.
  1. +14 −0 Android.mk
  2. 0  MODULE_LICENSE_APACHE2
  3. +205 −0 NOTICE
  4. +1 −0  audio/Android.mk
  5. +1 −0  audio/AudioIn/Android.mk
  6. +1 −0  audio/AudioIn/UNIX/Android.mk
  7. +262 −0 audio/AudioIn/UNIX/include/audioin.h
  8. +128 −0 audio/AudioIn/UNIX/include/audioinerr.h
  9. +43 −0 audio/AudioIn/UNIX/include/audioinwrapper.h
  10. +61 −0 audio/AudioIn/UNIX/include/filter.h
  11. +26 −0 audio/AudioIn/UNIX/src/Android.mk
  12. +1,442 −0 audio/AudioIn/UNIX/src/audioin.c
  13. +214 −0 audio/AudioIn/UNIX/src/audioinwrapper.cpp
  14. +376 −0 audio/AudioIn/UNIX/src/filter.c
  15. +1 −0  audio/test/Android.mk
  16. +32 −0 audio/test/AudioHardwareRecord/Android.mk
  17. +99 −0 audio/test/AudioHardwareRecord/src/AudioHardwareRecord.c
  18. +32 −0 audio/test/AudioHardwareRecordLoop/Android.mk
  19. +140 −0 audio/test/AudioHardwareRecordLoop/src/AudioHardwareRecordLoop.c
  20. +32 −0 audio/test/AudioInRecord/Android.mk
  21. +147 −0 audio/test/AudioInRecord/src/AudioInRecord.c
  22. +1 −0  config/Android.mk
  23. +108 −0 config/en.us/Android.mk
  24. +12 −0 config/en.us/adb_pull_system_usr_srec_bothtags5.sh
  25. +15 −0 config/en.us/adb_pull_system_usr_srec_bothtags5_from_saved.sh
  26. +6 −0 config/en.us/adb_pull_system_usr_srec_change_sample_rate2.sh
  27. +5 −0 config/en.us/adb_pull_system_usr_srec_liveaudio.sh
  28. +6 −0 config/en.us/adb_pull_system_usr_srec_set_get_param.sh
  29. BIN  config/en.us/audio/m252/m252a10e.nwv
  30. BIN  config/en.us/audio/m252/m252a11e.nwv
  31. BIN  config/en.us/audio/m252/m252a12e.nwv
  32. BIN  config/en.us/audio/m252/m252a21e.nwv
  33. BIN  config/en.us/audio/m252/m252a22e.nwv
  34. BIN  config/en.us/audio/m252/m252a24e.nwv
  35. BIN  config/en.us/audio/m252/m252a3fe.nwv
  36. +53 −0 config/en.us/audio/v139/v139_007.nwv
  37. +53 −0 config/en.us/audio/v139/v139_021.nwv
  38. +39 −0 config/en.us/audio/v139/v139_024.nwv
  39. +74 −0 config/en.us/audio/v139/v139_040.nwv
  40. +97 −0 config/en.us/audio/v139/v139_067.nwv
  41. +119 −0 config/en.us/audio/v139/v139_077.nwv
  42. BIN  config/en.us/audio/v139/v139_103.nwv
  43. +72 −0 config/en.us/audio/v139/v139_107.nwv
  44. BIN  config/en.us/audio/v139/v139_113.nwv
  45. BIN  config/en.us/audio/v139/v139_127.nwv
  46. BIN  config/en.us/audio/v139/v139_189.nwv
  47. BIN  config/en.us/audio/v139/v139_202.nwv
  48. BIN  config/en.us/audio/v139/v139_206.nwv
  49. +45 −0 config/en.us/audio/v139/v139_248.nwv
  50. BIN  config/en.us/audio/v139/v139_254.nwv
  51. +116 −0 config/en.us/baseline.par
  52. +123 −0 config/en.us/baseline11k.par
  53. +125 −0 config/en.us/baseline8k.par
  54. +31 −0 config/en.us/dictionary/basic.ok
  55. +127,118 −0 config/en.us/dictionary/c0.6
  56. +186 −0 config/en.us/dictionary/cmu2nuance.cpp
  57. BIN  config/en.us/dictionary/cmu6plus.ok.zip
  58. +53 −0 config/en.us/dictionary/enroll.ok
  59. +202 −0 config/en.us/dictionary/fixit.ok
  60. +32,918 −0 config/en.us/dictionary/large.ok
  61. +39 −0 config/en.us/dictionary/numbers.ok
  62. BIN  config/en.us/g2p/en-US-ttp.data
  63. +163 −0 config/en.us/grammars/VoiceDialer.grxml
  64. +31 −0 config/en.us/grammars/boolean.grxml
  65. +128 −0 config/en.us/grammars/bothtags5.grxml
  66. +76 −0 config/en.us/grammars/digits.grxml
  67. +28 −0 config/en.us/grammars/dynamic-test.grxml
  68. +75 −0 config/en.us/grammars/enroll.grxml
  69. +131 −0 config/en.us/grammars/homonym_test1.grxml
  70. +135 −0 config/en.us/grammars/homonym_test2.grxml
  71. +134 −0 config/en.us/grammars/homonym_test3.grxml
  72. +136 −0 config/en.us/grammars/homonym_test4.grxml
  73. +179 −0 config/en.us/grammars/ipaq_commands.grxml
  74. +163 −0 config/en.us/grammars/lookup.grxml
  75. +18 −0 config/en.us/grammars/rootslot.grxml
  76. +16 −0 config/en.us/grammars/run_clean_grammars.sh
  77. +58 −0 config/en.us/grammars/run_compile_grammars.sh
  78. +52 −0 config/en.us/grammars/slot_test1.grxml
  79. +36 −0 config/en.us/grammars/slot_test2.grxml
  80. BIN  config/en.us/models/generic.C
  81. BIN  config/en.us/models/generic.lda
  82. +83 −0 config/en.us/models/generic.pht
  83. BIN  config/en.us/models/generic.swiarb
  84. BIN  config/en.us/models/generic11.lda
  85. BIN  config/en.us/models/generic11_f.swimdl
  86. BIN  config/en.us/models/generic11_m.swimdl
  87. BIN  config/en.us/models/generic8.lda
  88. BIN  config/en.us/models/generic8_f.swimdl
  89. BIN  config/en.us/models/generic8_m.swimdl
  90. BIN  config/en.us/models/generic_f.swimdl
  91. BIN  config/en.us/models/generic_m.swimdl
  92. +780 −0 config/en.us/models/models128x.map
  93. +128 −0 config/en.us/models/phones.map
  94. +17 −0 config/en.us/run-bothtags5-from-saved.sh
  95. +17 −0 config/en.us/run-bothtags5.sh
  96. +7 −0 config/en.us/run-change-sample-rate2.sh
  97. +5 −0 config/en.us/run-chmod.sh
  98. +7 −0 config/en.us/run-liveaudio.sh
  99. +7 −0 config/en.us/run-set-get-param.sh
  100. +104 −0 config/en.us/tcp/bothtags5.tcp
  101. +93 −0 config/en.us/tcp/bothtags5_from_saved.tcp
  102. +78 −0 config/en.us/tcp/change_sample_rate2.tcp
  103. +14 −0 config/en.us/tcp/recognize_10_live.tcp
  104. +5 −0 config/en.us/tcp/recognize_1_live.tcp
  105. +15 −0 config/en.us/tcp/set_get_param.tcp
  106. BIN  config/en.us/wave/dallas-8kHz/0301/S078.nwf
  107. BIN  config/en.us/wave/dallas-8kHz/0301/S079.nwf
  108. BIN  config/en.us/wave/dallas-8kHz/0301/S080.nwf
  109. BIN  config/en.us/wave/dallas-8kHz/0301/S082.nwf
  110. BIN  config/en.us/wave/dallas-8kHz/0301/S083.nwf
  111. BIN  config/en.us/wave/dallas-8kHz/0301/S089.nwf
  112. BIN  config/en.us/wave/dallas-8kHz/0302/S051.nwf
  113. BIN  config/en.us/wave/dallas-8kHz/0302/S052.nwf
  114. BIN  config/en.us/wave/dallas-8kHz/0302/S053.nwf
  115. BIN  config/en.us/wave/dallas-8kHz/0302/S054.nwf
  116. BIN  config/en.us/wave/dallas-8kHz/0302/S065.nwf
  117. BIN  config/en.us/wave/dallas-8kHz/0302/S070.nwf
  118. BIN  config/en.us/wave/dallas-8kHz/0302/S071.nwf
  119. BIN  config/en.us/wave/dallas/0000/S072.nwf
  120. BIN  config/en.us/wave/dallas/0000/S074.nwf
  121. BIN  config/en.us/wave/dallas/0000/S075.nwf
  122. BIN  config/en.us/wave/dallas/0000/S076.nwf
  123. BIN  config/en.us/wave/dallas/0000/S077.nwf
  124. BIN  config/en.us/wave/dallas/0000/S079.nwf
  125. BIN  config/en.us/wave/dallas/0000/S080.nwf
  126. BIN  config/en.us/wave/dallas/0000/S083.nwf
  127. BIN  config/en.us/wave/dallas/0000/S086.nwf
  128. BIN  config/en.us/wave/dallas/0000/S088.nwf
  129. BIN  config/en.us/wave/dallas/0300/S052.nwf
  130. BIN  config/en.us/wave/dallas/0300/S053.nwf
  131. BIN  config/en.us/wave/dallas/0300/S057.nwf
  132. BIN  config/en.us/wave/dallas/0300/S063.nwf
  133. BIN  config/en.us/wave/dallas/0300/S065.nwf
  134. BIN  config/en.us/wave/dallas/0303/S080.nwf
  135. BIN  config/en.us/wave/dallas/0303/S083.nwf
  136. BIN  config/en.us/wave/dallas/0303/S084.nwf
  137. BIN  config/en.us/wave/dallas/0303/S087.nwf
  138. BIN  config/en.us/wave/dallas/0303/S088.nwf
  139. BIN  config/en.us/wave/dallas/0303/S089.nwf
  140. BIN  config/en.us/wave/dallas/0303/S090.nwf
  141. BIN  config/en.us/wave/dallas/0304/S052.nwf
  142. BIN  config/en.us/wave/dallas/0304/S054.nwf
  143. BIN  config/en.us/wave/dallas/0304/S055.nwf
  144. BIN  config/en.us/wave/dallas/0304/S074.nwf
  145. BIN  config/en.us/wave/dallas/0304/S075.nwf
  146. BIN  config/en.us/wave/dallas/0304/S076.nwf
  147. BIN  config/en.us/wave/dallas/0304/S077.nwf
  148. BIN  doc/Recognizer_status.pdf
  149. BIN  doc/SREC_Architecture.pdf
  150. BIN  doc/SREC_User_Guide.pdf
  151. BIN  doc/SREC_and_UAPI_Release_Notes.pdf
  152. BIN  doc/SREC_eScript_Specification.pdf
  153. BIN  doc/UAPI_Design.pdf
  154. BIN  doc/UAPI_User_Guide.pdf
  155. BIN  doc/doxygen.tar.gz
  156. BIN  doc/logs/srec/bothtags5_saved.g2g
  157. BIN  doc/logs/srec/linux_ship_a1__VCE_Pete_Gonzalez.raw
  158. BIN  doc/logs/srec/linux_ship_a1__VCE_Pete_Gonzalez_from_saved.raw
  159. BIN  doc/logs/srec/linux_ship_a2__VCE_Andrew_Evans.raw
  160. BIN  doc/logs/srec/linux_ship_a2__VCE_Andrew_Evans_from_saved.raw
  161. BIN  doc/logs/srec/linux_ship_a3__VCE_Peter_Wilson.raw
  162. BIN  doc/logs/srec/linux_ship_a3__VCE_Peter_Wilson_from_saved.raw
  163. BIN  doc/logs/srec/linux_ship_a4__VCE_Edgar_Young.raw
  164. BIN  doc/logs/srec/linux_ship_a4__VCE_Edgar_Young_from_saved.raw
  165. BIN  doc/logs/srec/linux_ship_a5__VCE_John_Martinez.raw
  166. BIN  doc/logs/srec/linux_ship_a5__VCE_John_Martinez_from_saved.raw
  167. +606 −0 doc/logs/srec/out_SHIP_bothtags5.txt
  168. +607 −0 doc/logs/srec/out_SHIP_bothtags5_from_saved.txt
  169. +2,534 −0 doc/logs/srec/out_SHIP_change_sample_rate2.txt
  170. +22 −0 doc/logs/srec/out_SHIP_set_get_param.txt
  171. +44 −0 doc/logs/srec/recog4_SHIP_bothtags5.res
  172. +44 −0 doc/logs/srec/recog4_SHIP_bothtags5_from_saved.res
  173. +84 −0 doc/logs/srec/recog4_SHIP_change_sample_rate2.res
  174. +20 −0 doc/logs/srec/recog4_SHIP_liveaudio.res
  175. 0  doc/logs/srec/recog4_SHIP_set_get_param.res
  176. +24 −0 doc/logs/uapi/run_ERT.log
  177. +39 −0 doc/logs/uapi/run_contacts.log
  178. +35 −0 doc/logs/uapi/run_parameters.log
  179. +971 −0 doc/logs/uapi/run_robustness1.log
  180. +1,321 −0 doc/logs/uapi/run_robustness2.log
Sorry, we could not display the entire diff because too many files (641) changed.
View
14 Android.mk
@@ -0,0 +1,14 @@
+###############################################################################
+# FILE: Makefile
+#
+# Top-level Makefile for ASR
+###############################################################################
+
+# remember root of ASR source tree
+export ASR_ROOT_DIR := $(call my-dir)
+export ASR_MAKE_DIR := $(ASR_ROOT_DIR)/make/asr
+
+# perform sub-makes
+ifneq ($(TARGET_SIMULATOR),true) # not 64 bit clean
+include $(call all-subdir-makefiles)
+endif
View
0  MODULE_LICENSE_APACHE2
No changes.
View
205 NOTICE
@@ -0,0 +1,205 @@
+These files are Copyright 2007, 2008 Nuance Communications, but released under
+the Apache2 License.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
View
1  audio/Android.mk
@@ -0,0 +1 @@
+include $(call all-subdir-makefiles)
View
1  audio/AudioIn/Android.mk
@@ -0,0 +1 @@
+include $(call all-subdir-makefiles)
View
1  audio/AudioIn/UNIX/Android.mk
@@ -0,0 +1 @@
+include $(call all-subdir-makefiles)
View
262 audio/AudioIn/UNIX/include/audioin.h
@@ -0,0 +1,262 @@
+/*---------------------------------------------------------------------------*
+ * audioin.h *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+#ifndef __AUDIOIN_H__
+#define __AUDIOIN_H__
+/* -------------------------------------------------------------------------+
+ | ScanSoft Inc. |
+ + -------------------------------------------------------------------------*/
+
+
+
+/* -------------------------------------------------------------------------+
+ | Project : ScanSoft AudioIn component
+ | Module : AUDIOIN
+ | File name : audioin.h
+ | Description : Interface definition for AUDIOIN
+ | Reference(s) : wavein, audioin.chm, audioin.doc, audioin.hlp
+ | SltGl00001_audioin_gl1.doc
+ | Status : Version 1.2
+ + -------------------------------------------------------------------------*/
+/* Oct/8/2002: Fixes for Windows 2000, and memory leaks. Version 1.1 */
+/* PVP Jan/8/2004: Default audio format changed to 16kHz. Version 2.0 */
+/*--------------------------------------------------------------------------*/
+
+/* @doc AUDIOININTERFACE */
+
+
+#include "audioinerr.h"
+
+#if defined( __cplusplus )
+extern "C"
+{
+#endif
+
+/* -------------------------------------------------------------------------+
+ | MACROS |
+ + -------------------------------------------------------------------------*/
+
+/* none */
+
+/* -------------------------------------------------------------------------+
+ | TYPE DEFINITIONS |
+ + -------------------------------------------------------------------------*/
+
+typedef short audioinSample;
+
+
+/* Type Definitions for SCANSOFT-TYPES (re-definition)*/
+
+/* @type AUDIOIN_H | Handle to an audio-in component.
+ * @comm Type is declared as a void *. The actual implementation is
+ * done by the implementation engineer. */
+typedef void * AUDIOIN_H;
+#define WAVE_MAPPER 0
+/* @enum AUDIOIN_STATUSINFO | Enumerator for the Status Information of the AudioIn component.
+ * @comm The information contained in this definition concerns not only to the status of
+ * the FIFO but also the general status of the audio component.
+ *
+ * @xref <f lh_audioinGetSamples>(), AudioIn Diagram State */
+typedef enum _AUDIOIN_STATUSINFO {
+ AUDIOIN_NORMAL, /* @emem Normal state of the audio buffer. No problems detected while retrieving
+ samples.*/
+ AUDIOIN_TIMEOUT, /* @emem The audio-in component timed out after no audio was received from the
+ audio device. The MMSystem is not providing any more samples, or the
+ lh_audioinGetSamples function may be called much faster than the actual
+ thread filling the buffer (Probable issue with the audio device). This could
+ be fixed by decreasing the number of samples that you want to retrieve or by
+ waiting till samples are available. A time out period is set internally on
+ the audioin implementation. Default of:
+ <nlpar>const DWORD GETSAMPLESTIMEOUT_PERIOD = 10000; (time in milliseconds)*/
+ AUDIOIN_HIGHWATERMARK,/* @emem The buffer has been filled out with 75% or more. A high watermark on
+ the audio buffer has been detected and the buffer could be close to an OVERRUN
+ state.*/
+ AUDIOIN_FIFOOVERRUN, /* @emem The buffer has been overfilled with audio samples. You can still retrieve
+ samples from the FIFO with the lhs_audioinGetSamples function, but the audio-in
+ component will not buffer any new audio into the FIFO. AudioinStop must be
+ called to reset the audio-in component.*/
+ AUDIOIN_FLUSHED, /* @emem The buffer has been overfilled with audio samples. You can no longer retrieve
+ samples from the FIFO, since you already emptied it with lhs_audioinGetSamples.
+ The audio-in component will not buffer any new audio into the FIFO.
+ lhs_audioinStop must be called in the audio-in component since
+ lhs_audioinGetSamples will not longer work.*/
+ AUDIOIN_HWOVERRUN, /* @emem The buffer has been overfilled with audio samples inside the device component
+ (audio device). lhs_audioinStop should be called to reset the contents of the
+ FIFO and the codec. This state is caused by an error in the MMSystem. It is
+ recommended to initialize the audio-in component before retrieving samples
+ again.*/
+} AUDIOIN_STATUSINFO;
+
+
+/* @struct AUDIOIN_INFO | Structure for the AudioIn Information
+ * @comm The AUDIOIN_INFO contains information about several parts of the audio-in component.
+ * It gives information about the FIFO buffering audio and at the same time about the audio
+ * component.
+ *
+ * @xref <f lh_audioinGetSamples>(), AudioIn Diagram State */
+typedef struct _AUDIOIN_INFO{
+ AUDIOIN_STATUSINFO eStatusInfo; /* @field The state in which the audio Buffer of the audio-in component
+ is. This is detailed in AUDIOIN_STATUSINFO. */
+ unsigned long u32SamplesAvailable; /* @field The number of Samples still available in the audio Buffer after
+ lhs_audioinGetSamples is called. This value can help you to
+ detect over-runs in the audio buffer.*/
+} AUDIOIN_INFO;
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+typedef enum _AUDIOIN_MSG {
+ AUDIOIN_MSG_OPEN, // audio device was opened
+ AUDIOIN_MSG_START, // start audio acquisition
+ AUDIOIN_MSG_DATA, // audio samples are available
+ AUDIOIN_MSG_STOP, // stop audio acquisition
+ AUDIOIN_MSG_CLOSE, // audio device was closed
+ AUDIOIN_MSG_INVALID, // bogus
+} AUDIOIN_MSG;
+
+/* callback function for "samples ready" notification */
+typedef void (*pCallbackFunc)(AUDIOIN_H hAudioIn, AUDIOIN_MSG uMsg, void* dwInstance, void* dwParam1, void* dwParam2);
+
+/* data structure passed to callback function; loosely based on Windows' WAVEHDR */
+typedef struct {
+ void *pData;
+ unsigned long nBufferLength;
+ unsigned long nBytesRecorded;
+ AUDIOIN_STATUSINFO status;
+} AUDIOIN_WAVEHDR;
+#endif
+
+/* -------------------------------------------------------------------------+
+| EXTERNAL DATA (+ meaning) |
++ -------------------------------------------------------------------------*/
+
+/* none */
+
+/* -------------------------------------------------------------------------+
+| GLOBAL FUNCTION PROTOTYPES |
++ -------------------------------------------------------------------------*/
+#if 0
+ LHS_AUDIOIN_ERROR lhs_audioinOpenEx (
+ unsigned long u32AudioInID, /*@parm [in] Audio-in device ID (ranges from 0 to a number of available
+ devices on the system). You can also use the following flag
+ instead of a device identifier.
+ <nl><nl><bold WAVE_MAPPER> = The function selects a
+ waveform-audio input device capable of recording in the
+ specified format. <bold Header:> Declared in Mmsystem.h from
+ the Windows Multimedia: Platform SDK.*/
+ unsigned long u32Frequency, /*@parm [in] Frequency of the recognition engine in Hz. */
+ unsigned long u32NbrOfFrames, /*@parm [in] (not used) Number of frames buffered internally */
+ unsigned long u32SamplesPerFrame, /*@parm [in] Size, in samples, of each individual frame. */
+ AUDIOIN_H * phAudioIn /*@parm [out] Handle to the audio-in device */
+ );
+#endif
+
+LHS_AUDIOIN_ERROR lhs_audioinOpen(
+ unsigned long u32AudioInID, /* [in] audio-in device ID (ranges from 0 to a number of available devices on the
+ system). You can also use the following flag instead of a device identifier.
+ <nl><nl><bold WAVE_MAPPER> = The function selects a waveform-audio input
+ device capable of recording in the specified format. <bold Header:>
+ Declared in Mmsystem.h from the Windows Multimedia: Platform SDK.*/
+ unsigned long u32Frequency, /* [in] Frequency of the recognition engine in Hz. */
+ AUDIOIN_H * phAudioIn /* [out] Handle to the audio-in device */
+);
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+LHS_AUDIOIN_ERROR lhs_audioinOpenCallback(
+ unsigned long u32AudioInID, /* [in] audio-in device ID (ranges from 0 to a number of available devices on the
+ system). You can also use the following flag instead of a device identifier.
+ <nl><nl><bold WAVE_MAPPER> = The function selects a waveform-audio input
+ device capable of recording in the specified format. <bold Header:>
+ Declared in Mmsystem.h from the Windows Multimedia: Platform SDK.*/
+ unsigned long u32Frequency, /* [in] Frequency of the recognition engine in Hz. */
+ unsigned long u32NbrOfSamples, /*[in] <nl><bold Input:> Number of samples requested per callback */
+
+ pCallbackFunc pCallback, /* [in] callback function */
+ void *pCallbackInstance, /* [in] callback instance */
+ AUDIOIN_H * phAudioIn /* [out] Handle to the audio-in device */
+);
+#endif
+
+LHS_AUDIOIN_ERROR lhs_audioinClose(
+ AUDIOIN_H * phAudioIn /*[in] Pointer to the handle of the audio-in device to be closed.*/
+);
+
+LHS_AUDIOIN_ERROR lhs_audioinStart(
+ AUDIOIN_H hAudioIn /*[in] Handle of the audio-in device */
+);
+
+LHS_AUDIOIN_ERROR lhs_audioinStop(
+ AUDIOIN_H hAudioIn /*[in] Handle of the audio-in device*/
+);
+
+LHS_AUDIOIN_ERROR lhs_audioinGetSamples (
+ AUDIOIN_H hAudioIn, /*[in] Handle of the audio-in device */
+ unsigned long * u32NbrOfSamples, /*[in/out] <nl><bold Input:> The requested number of samples to be filled in
+ the pAudioBuffer. Note that the memory used for pBuffer should be large enough
+ to contain the requested number of samples, also note how the u32NbrOfSamples
+ is different than the Buffer size, since each frame has an specific size depending
+ on the audio format.
+ <nl><bold Output:> The actual number of recorded audio samples written in pBuffer.
+ If you pass 0 to this parameter then you may still retrieve the AUDIOIN_STATUSINFO
+ on the audio component. */
+ void * pAudioBuffer, /*[out] Buffer that contains the recorded samples. The memory used for this
+ buffer is allocated by the client. So, it is the responsibility of the client to
+ make sure that this memory can contain the requested number of samples. The memory
+ for this buffer needs also to be freed by the client. */
+ AUDIOIN_INFO * pAudioInInfo /*[out] Information about the audio internal buffer described in
+ AUDIOIN_INFO.*/
+);
+
+
+LHS_AUDIOIN_ERROR lhs_audioinGetVersion(
+ unsigned long * pu32Version /*[out] The version number of the API implementation. */
+);
+
+
+LHS_AUDIOIN_ERROR lhs_audioinGetVolume(
+ AUDIOIN_H hAudioIn, /*[in] Handle of the audio-in device.*/
+ unsigned long * pu32Volume /*[out] Pointer to a variable that will be filled with the current volume
+ (normally range of 0 - 65535). Depending on the platform the volume
+ value may be set to in sizes of 16, 32 or other size, the range also
+ depends on the platform (Implementations of this interface may
+ change because of the compatibility of the internal function).*/
+);
+
+LHS_AUDIOIN_ERROR lhs_audioinSetVolume(
+ AUDIOIN_H hAudioIn, /*[in] Handle of the audio-in device.*/
+ unsigned long u32Volume /*[in] The volume to be set (normal range 0-65535). Depending on the
+ platform the volume value may be set to in sizes of 16, 32 or other size,
+ the range also depends on the platform. (Implementations of this interface
+ may change because of the compatibility of the internal function)*/
+);
+
+
+const TCHAR * lhs_audioinErrorGetString(
+ const LHS_AUDIOIN_ERROR Error /*[in] The Error code.*/
+);
+
+
+/* -------------------------------------------------------------------------+
+ | END |
+ + -------------------------------------------------------------------------*/
+
+#if defined( __cplusplus )
+}
+#endif
+
+
+#endif /* #ifndef __AUDIOIN_H__ */
View
128 audio/AudioIn/UNIX/include/audioinerr.h
@@ -0,0 +1,128 @@
+/*---------------------------------------------------------------------------*
+ * audioinerr.h *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+#ifndef _AUDIOINERRAPI_H
+#define _AUDIOINERRAPI_H
+
+/* -------------------------------------------------------------------------+
+ | ScanSoft Inc. |
+ + -------------------------------------------------------------------------*/
+
+
+
+/* -------------------------------------------------------------------------+
+ | Project : ScanSoft AudioIn component
+ | Module : AUDIOINERROR
+ | File name : audioinerr.h
+ | Description : Definition file for the error handling of the AUDIOIN
+ | Reference(s) : wavein, audioin.chm, audioin.doc, audioin.hlp
+ | SltGl00001_audioin_gl1.doc
+ | Status : Version 1.0
+ + -------------------------------------------------------------------------*/
+
+/* @doc AUDIOININTERFACE */
+
+
+
+
+#if defined( __cplusplus )
+extern "C"
+{
+#endif
+
+/* -------------------------------------------------------------------------+
+ | MACROS |
+ + -------------------------------------------------------------------------*/
+
+ /* none */
+
+/* -------------------------------------------------------------------------+
+ | TYPE DEFINITIONS |
+ + -------------------------------------------------------------------------*/
+
+#define TCHAR char
+
+/* @type LHS_AUDIOIN_ERROR | LONG value for Error Code. (i386 win32 wince specific)
+ * @comm Type is declared as a LONG.
+ * @xref LHS_U32, LHS_U16, LHS_BOOL */
+typedef long LHS_AUDIOIN_ERROR;
+
+ /* ERROR CODES */
+
+ /* general errors */
+#define LHS_AUDIOIN_OK 0
+#define LHS_E_AUDIOIN_BASE 1000
+ /* AUDIOIN general errors */
+#define LHS_E_AUDIOIN_NOTIMPLEMENTED (LHS_E_AUDIOIN_BASE+0)
+#define LHS_E_AUDIOIN_NULLPOINTER (LHS_E_AUDIOIN_BASE+1)
+#define LHS_E_AUDIOIN_OUTOFMEMORY (LHS_E_AUDIOIN_BASE+2)
+#define LHS_E_AUDIOIN_INVALIDARG (LHS_E_AUDIOIN_BASE+3)
+ /* AUDIOIN specific errors */
+#define LHS_E_AUDIOIN_INVALIDDEVICEID (LHS_E_AUDIOIN_BASE+4)
+#define LHS_E_AUDIOIN_NOAUDIODRIVER (LHS_E_AUDIOIN_BASE+5)
+#define LHS_E_AUDIOIN_COULDNOTOPENDEVICE (LHS_E_AUDIOIN_BASE+6)
+#define LHS_E_AUDIOIN_BADFORMAT (LHS_E_AUDIOIN_BASE+7)
+#define LHS_E_AUDIOIN_WRONGSTATE (LHS_E_AUDIOIN_BASE+8)
+#define LHS_E_AUDIOIN_OVERRUN (LHS_E_AUDIOIN_BASE+9)
+#define LHS_E_AUDIOIN_NOSAMPLES (LHS_E_AUDIOIN_BASE+10)
+#define LHS_E_AUDIOIN_GETSETVOLUME (LHS_E_AUDIOIN_BASE+11)
+#define LHS_E_AUDIOIN_AUDIOINOPENTIMEDOUT (LHS_E_AUDIOIN_BASE+12)
+#define LHS_E_AUDIOIN_AUDIOINBUSY (LHS_E_AUDIOIN_BASE+13)
+#define LHS_E_AUDIOIN_CREATEEVENTERROR (LHS_E_AUDIOIN_BASE+14)
+#define LHS_E_AUDIOIN_CANNOTRESETAUDIODEV (LHS_E_AUDIOIN_BASE+15)
+#define LHS_E_AUDIOIN_CANNOTCLOSEAUDIODEV (LHS_E_AUDIOIN_BASE+16)
+#define LHS_E_AUDIOIN_CANNOTSTARTAUDIODEV (LHS_E_AUDIOIN_BASE+17)
+#define LHS_E_AUDIOIN_CANNOTSTOPAUDIODEV (LHS_E_AUDIOIN_BASE+18)
+
+// ******************* Error Type Definitions *********************
+typedef struct _AUDIOIN_ERRORINFO
+{
+ long u32ErrorCode;
+
+ const TCHAR *szExplanation;
+
+
+}AUDIOIN_ERRORINFO;
+
+
+/* -------------------------------------------------------------------------+
+| EXTERNAL DATA (+ meaning) |
++ -------------------------------------------------------------------------*/
+
+ /* none */
+
+/* -------------------------------------------------------------------------+
+ | GLOBAL FUNCTION PROTOTYPES |
+ + -------------------------------------------------------------------------*/
+
+#if ( !defined(_MSC_VER) && !defined(WINAPI) )
+#define WINAPI
+#endif
+
+/* -------------------------------------------------------------------------+
+ | END |
+ + -------------------------------------------------------------------------*/
+
+
+#if defined( __cplusplus )
+}
+#endif
+
+#endif /* _AUDIOINERRAPI_H*/
+
View
43 audio/AudioIn/UNIX/include/audioinwrapper.h
@@ -0,0 +1,43 @@
+/*---------------------------------------------------------------------------*
+ * audioinwrapper.h *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+#ifndef __AUDIOINWRAPPER_H__
+#define __AUDIOINWRAPPER_H__
+
+#if defined( __cplusplus )
+extern "C"
+{
+#endif
+
+/* -------------------------------------------------------------------------+
+ | C++ FUNCTION WRAPPER |
+ + -------------------------------------------------------------------------*/
+
+int AudioOpen(void);
+int AudioClose(void);
+int AudioSetInputFormat(int sample_rate, int channel_count);
+int AudioRead(short *buffer, int frame_count);
+int AudioSetVolume(int stream_type, int volume);
+int AudioGetVolume(int stream_type);
+
+#if defined( __cplusplus )
+}
+#endif
+
+#endif
View
61 audio/AudioIn/UNIX/include/filter.h
@@ -0,0 +1,61 @@
+/*---------------------------------------------------------------------------*
+ * filter.h *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+#ifndef __FILTER_H__
+#define __FILTER_H__
+
+// Define new data types
+
+typedef short typeSample; // for input and output samples
+typedef short typeCoeff; // FIR filter coefficients
+typedef long typeAccum; // FIR filter accumulator
+
+#define FACTOR_UP 1 // upsampling factor
+#define FACTOR_DOWN 4 // downsampling factor
+
+#define u16ScaleFilterCoeff_up1_down4 15
+
+typedef struct fir_struct
+{
+ int state; // state of FIR delay line (index of next slot to fill)
+ typeSample *z; // pointer to delay line
+
+ unsigned int factor_up;
+ unsigned int factor_down;
+
+ unsigned int nTaps; // length of FIR filter
+ unsigned int scale; // fixed-point filter scale factor
+ const typeCoeff *h; // pointer to FIR filter coefficients
+ typeAccum round; // used for roundoff
+} FIR_struct;
+
+extern const typeCoeff ps16FilterCoeff_up1_down4[];
+
+extern unsigned int filter_length;
+
+extern void FIR_downsample(unsigned int nInput, typeSample *pInput,
+ typeSample *pOutput, FIR_struct *pFIR);
+
+extern FIR_struct* FIR_construct(unsigned int nTaps, const typeCoeff *pCoeffs, int scale, int factor_up, int factor_down);
+
+extern int FIR_deconstruct(FIR_struct *pFIR);
+
+extern void FIR_reset(FIR_struct *pFIR);
+
+#endif
View
26 audio/AudioIn/UNIX/src/Android.mk
@@ -0,0 +1,26 @@
+# Copyright 2006 The Android Open Source Project
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# common settings for all ASR builds, exports some variables for sub-makes
+include $(ASR_MAKE_DIR)/Makefile.defs
+
+LOCAL_SRC_FILES:= \
+ audioin.c \
+ audioinwrapper.cpp \
+ filter.c \
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/../include \
+ $(LOCAL_PATH)/../../../../portable/include \
+
+LOCAL_CFLAGS := \
+
+LOCAL_CFLAGS += \
+ $(ASR_GLOBAL_DEFINES) \
+ $(ASR_GLOBAL_CPPFLAGS) \
+
+LOCAL_MODULE:= libSR_AudioIn
+
+include $(BUILD_STATIC_LIBRARY)
View
1,442 audio/AudioIn/UNIX/src/audioin.c
@@ -0,0 +1,1442 @@
+/*---------------------------------------------------------------------------*
+ * audioin.c *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+/* -------------------------------------------------------------------------+
+ | ScanSoft Inc. |
+ + -------------------------------------------------------------------------*/
+
+
+
+/* -------------------------------------------------------------------------+
+ | Project : ScanSoft AudioIn
+ | Module : audioin
+ | File name : audioin.c
+ | Description : This module contains the main implementation for the audioIn
+ | component.
+ | Reference(s) : wavein, audioout, audioin.chm, audioin.doc, audioin.hlp,
+ | SltGl00001_audioin_gl1.doc
+ | Status : Version 1.2
+ + -------------------------------------------------------------------------*/
+/* Feb/25/2002: First QNX/SH4 "draft" version. Version 1.1 */
+/* Nov/25/2004: clean up and minor changes like choice of the codec */
+/* frame size which is now automatically selected */
+/*--------------------------------------------------------------------------*/
+
+#if !defined(ANDROID) || defined(__ARM_ARCH_5__)
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <pthread.h>
+#include <sched.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/select.h>
+#include "plog.h"
+#include "audioin.h"
+
+#if defined(ANDROID)
+#include "audioinwrapper.h"
+#else
+#include <alsa/asoundlib.h>
+#endif
+
+// #define SAVE_RAW_AUDIO 1
+
+#ifdef SAVE_RAW_AUDIO
+#include <sys/time.h>
+#include <stdio.h>
+
+static FILE *audio_data;
+static struct timeval buffer_save_audio;
+#endif
+
+/*#define FILTER_ON*/
+
+#ifdef FILTER_ON
+#include "filter.h"
+#endif
+
+/* -------------------------------------------------------------------------+
+ | EXTERNAL DATA (+ meaning) |
+ + -------------------------------------------------------------------------*/
+
+/* none */
+
+/* -------------------------------------------------------------------------+
+ | MACROS |
+ + -------------------------------------------------------------------------*/
+
+#define NR_OF_CHANNELS 1
+
+#if defined(ANDROID)
+/* size in samples */
+/* We really no longer use this for ANDROID but more changes are needed to remove it. SteveR */
+#define SAMPLES_BUFFER_SIZE (8*1024)
+#define SAMPLES_BUFFER_HIGH_WATERMARK (6*1024)
+#else
+#define SAMPLES_BUFFER_SIZE (50*4410)
+#define SAMPLES_BUFFER_HIGH_WATERMARK (40*4410)
+#endif
+
+/* IMPORTANT NOTE:
+ Here a "frame" is an ALSA term. A frame is comprised of 1 sample if mono,
+ and 2 samples if stereo. This should be distinguished from what the
+ ASR engine and lhs_audioin*() API functions refer to as a frame which is
+ a set of consecutive samples.
+ (see http://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html) */
+#if defined(ANDROID)
+#define CODEC_FRAGMENT_SIZE_IN_FRAMES 1024
+#else
+//read the equivalent of 100 ms per buffer. Note: we are recording at 44 kHz
+#define CODEC_FRAGMENT_SIZE_IN_FRAMES 4410
+#endif
+
+/* -------------------------------------------------------------------------+
+ | TYPE DEFINITIONS |
+ + -------------------------------------------------------------------------*/
+
+/* -------------------------------------------------------------------------+
+ | GLOBAL CONSTANTS |
+ + -------------------------------------------------------------------------*/
+
+
+/* -------------------------------------------------------------------------+
+ | GLOBAL VARIABLES |
+ + -------------------------------------------------------------------------*/
+
+#if !defined(ANDROID)
+static snd_pcm_t *ghPCM; /* handle to the PCM recording device */
+#endif
+
+static int gCodecFragmentSizeInFrames = CODEC_FRAGMENT_SIZE_IN_FRAMES; /* fragment size used by the codec driver */
+static audioinSample gSamplesBufferCircularFifo[SAMPLES_BUFFER_SIZE]; /* circular buffer that buffers the incoming samples */
+
+static int gWriteIndexPointer = 0; /* write pointer in the circular FIFO samples buffer */
+static int gReadIndexPointer = 0; /* read pointer in the circular FIFO samples buffer */
+static AUDIOIN_INFO gAudioInInfo; /* to store the info about the acquisition */
+static pthread_mutex_t gAudioMutex; /* to prevent using the read/write pointers at the same time in both threads */
+
+static pthread_cond_t gThreadRunning; /* synchronize when the AcquisitionThreadID is running*/
+static int gThreadRunningSignaled = 0;
+
+static pthread_cond_t gOpenExCalled; /* synchronize when the lhs_audioinOpenEx is called*/
+static int gOpenExCalledSignaled = 0;
+
+static pthread_cond_t gCloseCalled; /* synchronize when the lhs_audioinClose is called*/
+static int gCloseCalledSignaled = 0;
+
+static pthread_t AcquisitionThreadID; /* acquisition thread id */
+
+static int gInitialized = 0; /* did we initialize some of the variables*/
+static int gTerminateThread = 0;
+static struct timeval timer; /* timer used by select to relinquish cpu times */
+
+static int gRecordingVolume = -1; /* recording volume ; number between 0 and 15 */
+static int bRecord = 0; /* recording state is off */
+static int bClose = 1; /* audio pipe is closed */
+
+#ifdef FILTER_ON
+static FIR_struct *pFIR = NULL; /* pointer to FIR structure */
+#endif
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+static pCallbackFunc gpCallback = NULL;
+static void *gpCallbackInstance = NULL;
+static unsigned long gnCallbackSamples = 0;
+#endif
+
+/* -------------------------------------------------------------------------+
+ | LOCAL FUNCTION PROTOTYPES |
+ + -------------------------------------------------------------------------*/
+
+static void *AcquisitionThread(void *data); /* Entry function for the acquisition thread */
+static int OpenAndPrepareSound(unsigned long ulFrequency);
+
+/**
+ * returns 0 if success
+ */
+static int Initialize(AUDIOIN_H * phAudioIn)
+{
+ int doneWaiting = 0;
+
+ if( gInitialized == 1 )
+ return 0;
+
+ /* creates the mutex that will be used to lock/unlock access to some variables/code */
+ if (pthread_mutex_init(&gAudioMutex, NULL) != 0)
+ {
+ return 1;
+ }
+
+ if(pthread_cond_init(&gThreadRunning, 0) != 0 )
+ {
+ return 1;
+ }
+
+ if(pthread_cond_init(&gOpenExCalled, 0) != 0 )
+ {
+ return 1;
+ }
+
+ if(pthread_cond_init(&gCloseCalled, 0) != 0 )
+ {
+ return 1;
+ }
+
+ pthread_mutex_lock(&gAudioMutex);
+
+ /* create a thread with very high priority that will do the acquisition */
+ if (pthread_create(&AcquisitionThreadID, NULL, AcquisitionThread, phAudioIn) != 0)
+ {
+ return 1;
+ }
+
+ //wait for the thread to run
+ while (!doneWaiting)
+ {
+ int rc = pthread_cond_wait(&gThreadRunning, &gAudioMutex);
+ switch (rc)
+ {
+ case 0:
+ if (!gThreadRunningSignaled)
+ {
+ // Avoid spurious wakeups
+ continue;
+ }
+ else
+ {
+ gThreadRunningSignaled = 0;
+ doneWaiting = 1;
+ break;
+ }
+ break;
+ default:
+ pthread_mutex_unlock(&gAudioMutex);
+ return 1;
+ }
+ }
+
+ pthread_mutex_unlock(&gAudioMutex);
+
+
+ //thread is now running.
+
+ gInitialized = 1;
+
+ return 0;
+}
+
+#if 0
+/* disable this unused function for now until we decide what to do with this */
+
+/**
+ * returns 0 if success
+ */
+static int UnInitialize()
+{
+ //signal the thread that it has to stop running.
+ pthread_mutex_lock ( &gAudioMutex );
+ gTerminateThread = 1;
+
+ //signal to tell that our thread is now running.
+ if ( pthread_cond_signal ( &gOpenExCalled ) != 0 )
+ {
+ pthread_mutex_unlock ( &gAudioMutex );
+ PLogError ( "Audio In Error pthread_cond_signal\n" );
+ return 1;
+ }
+ gOpenExCalledSignaled = 1;
+ pthread_mutex_unlock ( &gAudioMutex );
+
+ /* wait until thread exits */
+ if (pthread_join(AcquisitionThreadID, NULL) != 0)
+ {
+ return 1;
+ }
+
+ /* destroy the mutex */
+ if (pthread_mutex_destroy(&gAudioMutex) !=0 )
+ {
+ return 1;
+ }
+ if( pthread_cond_destroy(&gThreadRunning) != 0 )
+ {
+ return 1;
+ }
+ if( pthread_cond_destroy(&gOpenExCalled) != 0 )
+ {
+ return 1;
+ }
+ if( pthread_cond_destroy(&gCloseCalled) != 0 )
+ {
+ return 1;
+ }
+ gInitialized = 0;
+ return 0;
+}
+#endif
+
+/* -------------------------------------------------------------------------+
+ | LOCAL FUNCTION (should be static) |
+ + -------------------------------------------------------------------------*/
+
+static void setRecordOn(void)
+{
+ bRecord = 1;
+}
+
+static void setRecordOff(void)
+{
+ bRecord = 0;
+}
+
+static int getRecord(void)
+{
+ return bRecord;
+}
+
+static void setCloseOn(void)
+{
+ bClose = 1;
+}
+
+static void setCloseOff(void)
+{
+ bClose = 0;
+}
+
+static int getClose(void)
+{
+ return bClose;
+}
+
+
+/**************************************************************
+ * AcquisitionThread *
+ * *
+ * This function is the entry function of a thread created by *
+ * lhs_audioinOpen and which is responsible of getting the *
+ * samples from the codec and store them in a big circular *
+ * FIFO buffer. *
+ * The priority of this thread has been set to high in order *
+ * to prevent codec buffer overrun. Since the FIFO is limited *
+ * in size (5 sec default ; see SAMPLES_BUFFER_SIZE *
+ * parameter), the application must still be fast enough to *
+ * prevent FIFO overflow/overrun *
+ **************************************************************/
+#if defined(ANDROID)
+
+void *AcquisitionThread ( void *data )
+{
+ int doneWaiting = 0;
+ audioinSample *CodecBuffer;
+ long x;
+ long y;
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+ AUDIOIN_H *phAudioIn = (AUDIOIN_H *)data;
+ AUDIOIN_WAVEHDR *pwhdr;
+#endif
+
+
+ pthread_mutex_lock ( &gAudioMutex );
+
+ //signal to tell that our thread is now running.
+ if ( pthread_cond_signal ( &gThreadRunning ) != 0 )
+ {
+ pthread_mutex_unlock ( &gAudioMutex );
+ PLogError ( "Audio In Error pthread_cond_signal\n" );
+ exit ( 1 );
+ }
+ gThreadRunningSignaled = 1;
+
+ while( 1 )
+ {
+
+ while (!doneWaiting)
+ {
+ int rc = pthread_cond_wait(&gOpenExCalled, &gAudioMutex);
+ switch (rc)
+ {
+ case 0:
+ if (!gOpenExCalledSignaled)
+ {
+ // Avoid spurious wakeups
+ continue;
+ }
+ else
+ {
+ gOpenExCalledSignaled = 0;
+ doneWaiting = 1;
+ break;
+ }
+ break;
+ default:
+ PLogError ( "Audio In Error pthread_cond_signal\n" );
+ pthread_mutex_unlock(&gAudioMutex);
+ return ( (void *)NULL );
+ }
+ }
+ doneWaiting = 0;
+ pthread_mutex_unlock(&gAudioMutex);
+
+ if( gTerminateThread == 1 )
+ break;
+
+
+
+ /* buffer of 16 bits samples */
+ CodecBuffer = (audioinSample *)malloc ( gCodecFragmentSizeInFrames * sizeof ( audioinSample ) );
+
+ if ( CodecBuffer == NULL )
+ {
+ PLogError ( "Audio In Error malloc\n" );
+ exit ( 1 );
+ }
+ pwhdr = malloc ( sizeof ( AUDIOIN_WAVEHDR ) );
+
+ if ( pwhdr == NULL )
+ {
+ PLogError ( "Audio In Error malloc\n" );
+ exit ( 1 );
+ }
+
+ while ( !getClose ( ) )
+ {
+
+ int iReadFrames = 0; /* number of frames acquired by the codec */
+ /* NOTE: here a frame is comprised of 1 sample if mono, 2 samples if stereo, etc */
+ int iReadSamples = 0; /* number of samples acquired by the codec */
+ int frames_to_read; /* Actual number to read */
+ int frames_read; /* Frames read on one read */
+
+ iReadFrames = 0;
+
+ do
+ {
+ frames_to_read = gCodecFragmentSizeInFrames - iReadFrames;
+ /* AudioRead() - output: number of frames (mono: 1 sample, stereo: 2 samples)*/
+ frames_read = AudioRead ( CodecBuffer + iReadFrames, frames_to_read );
+
+ if ( frames_read > 0 )
+ iReadFrames += frames_read;
+ }
+ while ( ( iReadFrames < gCodecFragmentSizeInFrames ) && ( frames_read > 0 ) );
+ iReadSamples = iReadFrames;
+
+ if ( getRecord ( ) ) /* else continue to read from driver but discard samples */
+ {
+ if ( iReadSamples < 0 )
+ {
+ iReadSamples = 0;
+ gAudioInInfo.eStatusInfo = AUDIOIN_HWOVERRUN;
+ }
+ else
+ {
+#ifdef FILTER_ON
+ /* x: index for start of input samples; y: index for output sample */
+ for ( x = 0, y = 0; x < iReadSamples; x += pFIR->factor_down )
+ {
+ FIR_downsample ( pFIR->factor_down, &( CodecBuffer[x] ), &( CodecBuffer[y++] ), pFIR );
+ }
+ /* update the number samples */
+ iReadSamples = y;
+#endif
+ pthread_mutex_lock ( &gAudioMutex );
+
+ if ( gAudioInInfo.u32SamplesAvailable + iReadSamples > SAMPLES_BUFFER_SIZE )
+ {
+ gAudioInInfo.u32SamplesAvailable = SAMPLES_BUFFER_SIZE;
+ gAudioInInfo.eStatusInfo = AUDIOIN_FIFOOVERRUN;
+ }
+ else
+ {
+ if ( gAudioInInfo.u32SamplesAvailable + iReadSamples > SAMPLES_BUFFER_HIGH_WATERMARK )
+ {
+ gAudioInInfo.eStatusInfo = AUDIOIN_HIGHWATERMARK;
+ }
+ else if ( gAudioInInfo.eStatusInfo != AUDIOIN_FIFOOVERRUN )
+ {
+ gAudioInInfo.eStatusInfo = AUDIOIN_NORMAL;
+ }
+ gAudioInInfo.u32SamplesAvailable += iReadSamples;
+ }
+ if ( gWriteIndexPointer + iReadSamples <= SAMPLES_BUFFER_SIZE )
+ {
+ memcpy ( &( gSamplesBufferCircularFifo[gWriteIndexPointer] ), CodecBuffer,
+ iReadSamples * sizeof ( audioinSample ) );
+ gWriteIndexPointer += iReadSamples;
+
+ if ( gWriteIndexPointer >= SAMPLES_BUFFER_SIZE )
+ gWriteIndexPointer = 0;
+ }
+ else
+ {
+ int NbToCopy;
+
+ NbToCopy = SAMPLES_BUFFER_SIZE - gWriteIndexPointer;
+ memcpy ( &( gSamplesBufferCircularFifo [gWriteIndexPointer] ), CodecBuffer,
+ NbToCopy * sizeof ( audioinSample ) );
+ gWriteIndexPointer = 0;
+ memcpy ( gSamplesBufferCircularFifo, &( CodecBuffer [NbToCopy] ),
+ ( iReadSamples-NbToCopy ) * sizeof ( audioinSample ) );
+ gWriteIndexPointer = iReadSamples - NbToCopy;
+ }
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+ /* Callback notification. Ideally this audio acquisition thread should be very lean.
+ It should simply read from the low level driver, store the filtered samples in
+ the FIFO, then go back to reading from the driver. The additional data copy
+ for the callback function is ok despite the overhead incurred, but only because
+ there's some buffering done by the low level driver. This design should be
+ revisited to make it more general purpose.
+ */
+ if ( gpCallback != NULL )
+ {
+ pwhdr->nBufferLength = iReadSamples * sizeof ( audioinSample );
+ pwhdr->nBytesRecorded = pwhdr->nBufferLength;
+ pwhdr->status = AUDIOIN_NORMAL;
+ pwhdr->pData = CodecBuffer;
+ /* pass samples to callback function who should deallocate the buffer and structure */
+ gpCallback ( *phAudioIn, AUDIOIN_MSG_DATA, gpCallbackInstance, pwhdr, NULL );
+ }
+#endif
+ /* samples are available to read */
+ pthread_mutex_unlock ( &gAudioMutex );
+ timer.tv_sec = 0;
+ timer.tv_usec = 200;
+ select ( 0, NULL, NULL, NULL, &timer );
+ }
+ } /* if (getRecord()) */
+
+ } /* while (!getClose()) */
+ if ( AudioClose ( ) !=0 )
+ {
+ PLogError ( "Audio In Error Closing Hardware\n" );
+ }
+ free ( CodecBuffer );
+
+ pthread_mutex_lock ( &gAudioMutex );
+ //signal to tell that our thread is now running.
+ if ( pthread_cond_signal ( &gCloseCalled ) != 0 )
+ {
+ pthread_mutex_unlock ( &gAudioMutex );
+ PLogError ( "Audio In Error pthread_cond_signal\n" );
+ exit ( 1 );
+ }
+ gCloseCalledSignaled = 1;
+ }
+
+ pthread_exit ( (void *)NULL );
+ return ( (void *)NULL );
+}
+
+#else
+/* non-ANDROID version */
+
+void *AcquisitionThread ( void *data )
+{
+ int doneWaiting = 0;
+ audioinSample *CodecBuffer;
+#ifdef FILTER_ON
+ long x;
+ long y;
+#endif
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+ AUDIOIN_H *phAudioIn = (AUDIOIN_H *)data;
+#endif
+
+ pthread_mutex_lock ( &gAudioMutex );
+
+ //signal to tell that our thread is now running.
+ if ( pthread_cond_signal ( &gThreadRunning ) != 0 )
+ {
+ pthread_mutex_unlock ( &gAudioMutex );
+ PLogError ( "Audio In Error pthread_cond_signal\n" );
+ exit ( 1 );
+ }
+ gThreadRunningSignaled = 1;
+
+ while( 1 )
+ {
+ while (!doneWaiting)
+ {
+ int rc = pthread_cond_wait(&gOpenExCalled, &gAudioMutex);
+ switch (rc)
+ {
+ case 0:
+ if (!gOpenExCalledSignaled)
+ {
+ // Avoid spurious wakeups
+ continue;
+ }
+ else
+ {
+ gOpenExCalledSignaled = 0;
+ doneWaiting = 1;
+ break;
+ }
+ break;
+ default:
+ PLogError ( "Audio In Error pthread_cond_wait\n" );
+ pthread_mutex_unlock(&gAudioMutex);
+ return ( (void *)NULL );
+ }
+ }
+ doneWaiting = 0;
+ pthread_mutex_unlock(&gAudioMutex);
+
+ if( gTerminateThread == 1 )
+ break;
+
+ /* buffer of 16 bits samples */
+ CodecBuffer = (audioinSample *)malloc ( gCodecFragmentSizeInFrames * sizeof ( audioinSample ) );
+
+ if ( CodecBuffer == NULL )
+ {
+ PLogError ( "Audio In Error pthread_cond_signal\n" );
+ exit ( 1 );
+ }
+
+ while ( !getClose ( ) )
+ {
+ int iReadFrames = 0; /* number of frames acquired by the codec */
+ /* NOTE: here a frame is comprised of 1 sample if mono, 2 samples if stereo, etc */
+ int iReadSamples = 0; /* number of samples acquired by the codec */
+ if ( ( iReadFrames = snd_pcm_readi ( ghPCM, (void *)CodecBuffer, gCodecFragmentSizeInFrames ) ) < 0 )
+ {
+ if ( iReadFrames == -EBADFD )
+ {
+ PLogError ( "Audio In Error PCM Not In The Right State\n" );
+ }
+ else if ( iReadFrames == -EPIPE )
+ {
+ snd_pcm_prepare(ghPCM);
+ PLogError ( "Audio In Error Overrun\n" );
+ }
+ else if ( iReadFrames == -ESTRPIPE )
+ {
+ PLogError ( "Audio In Error Stream Suspended\n" );
+ }
+ }
+ iReadSamples = iReadFrames;
+
+ if ( getRecord ( ) ) /* else continue to read from driver but discard samples */
+ {
+ if ( iReadSamples < 0 )
+ {
+ iReadSamples = 0;
+ gAudioInInfo.eStatusInfo = AUDIOIN_HWOVERRUN;
+ }
+ else
+ {
+#ifdef FILTER_ON
+ /* x: index for start of input samples; y: index for output sample */
+ for ( x = 0, y = 0; x < iReadSamples; x += pFIR->factor_down )
+ {
+ FIR_downsample ( pFIR->factor_down, &( CodecBuffer[x] ), &( CodecBuffer[y++] ), pFIR );
+ }
+ /* update the number samples */
+ iReadSamples = y;
+#endif
+#ifdef SAVE_RAW_AUDIO
+ if ( iReadSamples > 0 )
+ fwrite ( CodecBuffer, 2, iReadSamples, audio_data );
+#endif
+
+ pthread_mutex_lock ( &gAudioMutex );
+
+ if ( gAudioInInfo.u32SamplesAvailable + iReadSamples > SAMPLES_BUFFER_SIZE )
+ {
+ gAudioInInfo.u32SamplesAvailable = SAMPLES_BUFFER_SIZE;
+ gAudioInInfo.eStatusInfo = AUDIOIN_FIFOOVERRUN;
+ }
+ else
+ {
+ if ( gAudioInInfo.u32SamplesAvailable + iReadSamples > SAMPLES_BUFFER_HIGH_WATERMARK )
+ {
+ gAudioInInfo.eStatusInfo = AUDIOIN_HIGHWATERMARK;
+ }
+ else if ( gAudioInInfo.eStatusInfo != AUDIOIN_FIFOOVERRUN )
+ {
+ gAudioInInfo.eStatusInfo = AUDIOIN_NORMAL;
+ }
+ gAudioInInfo.u32SamplesAvailable += iReadSamples;
+ }
+ if ( gWriteIndexPointer + iReadSamples <= SAMPLES_BUFFER_SIZE )
+ {
+ memcpy ( &( gSamplesBufferCircularFifo[gWriteIndexPointer] ), CodecBuffer,
+ iReadSamples * sizeof ( audioinSample ) );
+ gWriteIndexPointer += iReadSamples;
+
+ if ( gWriteIndexPointer >= SAMPLES_BUFFER_SIZE )
+ gWriteIndexPointer = 0;
+ }
+ else
+ {
+ int NbToCopy;
+
+ NbToCopy = SAMPLES_BUFFER_SIZE - gWriteIndexPointer;
+ memcpy ( &( gSamplesBufferCircularFifo [gWriteIndexPointer] ), CodecBuffer,
+ NbToCopy * sizeof ( audioinSample ) );
+ gWriteIndexPointer = 0;
+ memcpy ( gSamplesBufferCircularFifo, &( CodecBuffer [NbToCopy] ),
+ ( iReadSamples-NbToCopy ) * sizeof ( audioinSample ) );
+ gWriteIndexPointer = iReadSamples - NbToCopy;
+ }
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+ /* Callback notification. Ideally this audio acquisition thread should be very lean.
+ It should simply read from the low level driver, store the filtered samples in
+ the FIFO, then go back to reading from the driver. The additional data copy
+ for the callback function is ok despite the overhead incurred, but only because
+ there's some buffering done by the low level driver. This design should be
+ revisited to make it more general purpose.
+ */
+ while ( ( gpCallback != NULL ) && ( gAudioInInfo.u32SamplesAvailable >= gnCallbackSamples ) )
+ {
+ AUDIOIN_WAVEHDR *pwhdr;
+
+ pwhdr = malloc ( sizeof ( AUDIOIN_WAVEHDR ) );
+
+ if ( pwhdr != NULL )
+ {
+ pwhdr->nBufferLength = gnCallbackSamples * sizeof ( audioinSample );
+ pwhdr->nBytesRecorded = pwhdr->nBufferLength;
+ pwhdr->status = gAudioInInfo.eStatusInfo;
+ pwhdr->pData = malloc ( pwhdr->nBufferLength );
+
+ if ( pwhdr->pData != NULL )
+ {
+ if ( gReadIndexPointer + gnCallbackSamples <= SAMPLES_BUFFER_SIZE )
+ {
+ memcpy ( pwhdr->pData, &( gSamplesBufferCircularFifo [gReadIndexPointer] ),
+ pwhdr->nBufferLength );
+ gReadIndexPointer += gnCallbackSamples;
+
+ if ( gReadIndexPointer >= SAMPLES_BUFFER_SIZE )
+ gReadIndexPointer = 0;
+ }
+ else
+ {
+ size_t nSamplesPart1 = SAMPLES_BUFFER_SIZE - gReadIndexPointer;
+ size_t nSamplesPart2 = gnCallbackSamples - nSamplesPart1;
+
+ memcpy ( pwhdr->pData, &( gSamplesBufferCircularFifo [gReadIndexPointer] ),
+ nSamplesPart1*sizeof ( audioinSample ) );
+ gReadIndexPointer = 0;
+ memcpy ( pwhdr->pData + nSamplesPart1 * sizeof (audioinSample ),
+ gSamplesBufferCircularFifo, nSamplesPart2 * sizeof ( audioinSample ) );
+ gReadIndexPointer = nSamplesPart2;
+ }
+ gAudioInInfo.u32SamplesAvailable -= gnCallbackSamples;
+ /* pass samples to callback function who should deallocate the buffer and structure */
+ gpCallback ( *phAudioIn, AUDIOIN_MSG_DATA, gpCallbackInstance, pwhdr, NULL );
+ }
+ else
+ {
+ // error
+ }
+ }
+ else
+ {
+ // error
+ }
+ }
+#endif
+ /* samples are available to read */
+ pthread_mutex_unlock ( &gAudioMutex );
+ timer.tv_sec = 0;
+ timer.tv_usec = 200;
+ select ( 0, NULL, NULL, NULL, &timer );
+ }
+ } /* if (getRecord()) */
+
+ } /* while (!getClose()) */
+
+ if ( snd_pcm_close ( ghPCM ) !=0 )
+ {
+ PLogError ( "Audio In Error Closing Hardware\n" );
+ }
+
+ free ( CodecBuffer );
+
+ pthread_mutex_lock ( &gAudioMutex );
+ //signal to tell that our thread is now running.
+ if ( pthread_cond_signal ( &gCloseCalled ) != 0 )
+ {
+ pthread_mutex_unlock ( &gAudioMutex );
+ PLogError ( "Audio In Error pthread_cond_signal\n" );
+ exit ( 1 );
+ }
+ gCloseCalledSignaled = 1;
+ }
+ pthread_exit ( (void *)NULL );
+ return ( (void *)NULL );
+}
+#endif
+
+/**************************************************************
+ * OpenAndPrepareSound *
+ *************************************************************/
+
+
+static int OpenAndPrepareSound(unsigned long ulFrequency)
+{
+#if defined(ANDROID)
+
+ /* Only support certain frequencies. Modify this to check frequency
+ against a structure of valid frequencies */
+#ifdef FILTER_ON
+ if ( ulFrequency == 11025 )
+ {
+ if ( AudioSetInputFormat ( 44100, NR_OF_CHANNELS ) != 0 ) /* sample at 44100 then downsample */
+ {
+ PLogError ( "Audio In Error OpenAndPrepareSound - AudioSetInputFormat failed!\n");
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+ }
+ else
+ {
+ PLogError ( "Audio In Error OpenAndPrepareSound - invalid frequency!");
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+#else
+ if ( ( ulFrequency == 11025 ) || ( ulFrequency == 8000 ) )
+ {
+ if ( AudioSetInputFormat ( ulFrequency, NR_OF_CHANNELS ) != 0 )
+ {
+ PLogError ( "Audio In Error OpenAndPrepareSound - AudioSetInputFormat failed!");
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+ }
+ else
+ {
+ PLogError ( "Audio In Error OpenAndPrepareSound - invalid frequency!");
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+#endif
+
+ /* set some variables */
+ gAudioInInfo.u32SamplesAvailable = 0;
+
+ /* Open Audio driver */
+ if (AudioOpen() < 0)
+ {
+ PLogError ( "Audio In Error OpenAndPrepareSound - AudioOpen failed!");
+ return ~LHS_AUDIOIN_OK;
+ }
+
+#else
+
+ snd_pcm_hw_params_t *hwparams;
+ unsigned int exact_rate;
+ int dir;
+ int rc;
+
+ /* step 1 : open the sound device */
+ /* ------------------------------ */
+ if ((rc = snd_pcm_open(&ghPCM, "default", SND_PCM_STREAM_CAPTURE, 0)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_open() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+ if ((rc = snd_pcm_hw_params_malloc(&hwparams)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_hw_params_malloc() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+ /* step 2 : configuring the audio channel */
+ /* -------------------------------------- */
+
+ if ((rc = snd_pcm_hw_params_any(ghPCM, hwparams)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_hw_params_any() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+ if ((rc = snd_pcm_hw_params_set_access(ghPCM, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_hw_params_set_access() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+ if ((rc = snd_pcm_hw_params_set_format(ghPCM, hwparams, SND_PCM_FORMAT_S16_LE)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_hw_params_set_format() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+#ifdef FILTER_ON
+ if (ulFrequency == 11025)
+ {
+ exact_rate = 44100;
+ }
+ else
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+#else
+ exact_rate = ulFrequency;
+#endif
+
+ dir = 0;
+
+#if 0
+ /* This version seems to have problems when the code is compiled into a shared library.
+ The subsequent call to snd_pcm_hw_params() fails. */
+ if ((rc = snd_pcm_hw_params_set_rate_near(ghPCM, hwparams, &exact_rate, &dir)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_hw_params_set_rate_near() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+#else
+ /* This version works better and in fact makes more sense. */
+ if ((rc = snd_pcm_hw_params_set_rate(ghPCM, hwparams, exact_rate, dir)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_hw_params_set_rate() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+#endif
+
+
+ if ((rc = snd_pcm_hw_params_set_channels(ghPCM, hwparams, NR_OF_CHANNELS)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_hw_params_set_channels() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+ if ((rc = snd_pcm_hw_params(ghPCM, hwparams)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_hw_params() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+ /* step 3 : preparing for read */
+ /* --------------------------- */
+
+ /*prepare the channel */
+
+ if ((rc = snd_pcm_prepare(ghPCM)) < 0)
+ {
+ PLogError ( "Audio In Error snd_pcm_prepare() (rc = %d: %s)\n", rc, snd_strerror(rc));
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+ /* set some variables */
+ gAudioInInfo.u32SamplesAvailable = 0;
+
+
+#endif
+
+ /* prepare to read samples */
+ setCloseOff();
+
+ return 0;
+}
+
+
+/* -------------------------------------------------------------------------+
+ | GLOBAL FUNCTIONS (prototypes in header file) |
+ + -------------------------------------------------------------------------*/
+
+/**************************************************************
+ * lhs_audioinOpenEx *
+ * *
+ * notes : *
+ * -the input parameters are in fact not used but present *
+ * to ensure compatibility with Win32 implementations *
+ **************************************************************/
+LHS_AUDIOIN_ERROR lhs_audioinOpenEx (
+ unsigned long u32AudioInID, /*@parm [in] Audio-in device ID (ranges from 0 to a number of available
+ devices on the system). You can also use the following flag
+ instead of a device identifier.
+ <nl><nl><bold WAVE_MAPPER> = The function selects a
+ waveform-audio input device capable of recording in the
+ specified format. <bold Header:> Declared in Mmsystem.h from
+ the Windows Multimedia: Platform SDK.*/
+ unsigned long u32Frequency, /*@parm [in] Frequency of the recognition engine in Hz. */
+ unsigned long u32NbrOfFrames, /*@parm [in] Number of frames buffered internally. */
+ unsigned long u32SamplesPerFrame, /*@parm [in] Size, in samples, of each individual frame. */
+ AUDIOIN_H * phAudioIn /*@parm [out] Handle to the audio-in device */
+ )
+{
+ //initialize some of the static variables.
+ if( Initialize(phAudioIn) )
+ return ~LHS_AUDIOIN_OK;
+
+
+ /* prepare sound */
+ if (OpenAndPrepareSound(u32Frequency) != 0)
+ {
+ return LHS_E_AUDIOIN_COULDNOTOPENDEVICE;
+ }
+
+ //signal the thread that it has to stop running.
+ pthread_mutex_lock ( &gAudioMutex );
+ //signal to tell that our thread is now running.
+ if ( pthread_cond_signal ( &gOpenExCalled ) != 0 )
+ {
+ pthread_mutex_unlock ( &gAudioMutex );
+ PLogError ( "Audio In Error pthread_cond_signal\n" );
+ exit ( 1 );
+ }
+ gOpenExCalledSignaled = 1;
+ pthread_mutex_unlock ( &gAudioMutex );
+
+#ifdef FILTER_ON
+ /* need to make this more generic to support different filters */
+ pFIR = FIR_construct(filter_length, ps16FilterCoeff_up1_down4, u16ScaleFilterCoeff_up1_down4, FACTOR_UP, FACTOR_DOWN);
+ if (pFIR == NULL)
+ {
+ // TO DO: HANDLE THIS (or modify for static allocation)
+ }
+#endif
+
+ /* set the status to normal */
+ gAudioInInfo.eStatusInfo = AUDIOIN_NORMAL;
+
+ /* do not care, but some applications are checking a NULL handle */
+ *phAudioIn = (void *)10;
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+ gpCallback = NULL;
+ gpCallbackInstance = NULL;
+ gnCallbackSamples = 0;
+#endif
+
+ return LHS_AUDIOIN_OK;
+}
+
+/**************************************************************
+ * lhs_audioinOpen *
+ * *
+ * notes : *
+ * -the input parameters are in fact not used but present *
+ * to ensure compatibility with Win32 implementation *
+ **************************************************************/
+LHS_AUDIOIN_ERROR lhs_audioinOpen (
+ unsigned long u32AudioInID, /*@parm [in] Audio-in device ID (ranges from 0 to a number of available
+ devices on the system). You can also use the following flag
+ instead of a device identifier.
+ <nl><nl><bold WAVE_MAPPER> = The function selects a
+ waveform-audio input device capable of recording in the
+ specified format. <bold Header:> Declared in Mmsystem.h from
+ the Windows Multimedia: Platform SDK.*/
+ unsigned long u32Frequency, /*@parm [in] Frequency of the recognition engine in Hz. */
+ AUDIOIN_H * phAudioIn /*@parm [out] Handle to the audio-in device */
+ )
+{
+ return lhs_audioinOpenEx(u32AudioInID, u32Frequency, 0, 0, phAudioIn);
+} /* lhs_audioinOpen */
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+/**************************************************************
+ * lhs_audioinOpenCallback *
+ * *
+ * notes : *
+ * -the input parameters are in fact not used but present *
+ * to ensure compatibility with Win32 implementation *
+ **************************************************************/
+LHS_AUDIOIN_ERROR lhs_audioinOpenCallback (
+ unsigned long u32AudioInID, /*@parm [in] Audio-in device ID (ranges from 0 to a number of available
+ devices on the system). You can also use the following flag
+ instead of a device identifier.
+ <nl><nl><bold WAVE_MAPPER> = The function selects a
+ waveform-audio input device capable of recording in the
+ specified format. <bold Header:> Declared in Mmsystem.h from
+ the Windows Multimedia: Platform SDK.*/
+ unsigned long u32Frequency, /*@parm [in] Frequency of the recognition engine in Hz. */
+ unsigned long u32NbrOfSamples, /*@parm [in] <nl><bold Input:> Number of samples requested per callback */
+ pCallbackFunc pCallback, /*@parm [in] callback function */
+ void *pCallbackInstance, /*@parm [in] callback instance */
+ AUDIOIN_H * phAudioIn /*@parm [out] Handle to the audio-in device */
+ )
+{
+ LHS_AUDIOIN_ERROR lhsErr;
+
+#ifdef FILTER_ON
+ gCodecFragmentSizeInFrames = u32NbrOfSamples * 4;
+#else
+ gCodecFragmentSizeInFrames = u32NbrOfSamples;
+#endif
+
+ if ((pCallback == NULL) || (u32NbrOfSamples == 0))
+ {
+ return LHS_E_AUDIOIN_INVALIDARG;
+ }
+ lhsErr = lhs_audioinOpenEx(u32AudioInID, u32Frequency, 0, 0, phAudioIn);
+ if (lhsErr != LHS_AUDIOIN_OK)
+ {
+ return lhsErr;
+ }
+
+ /* install callback */
+ gpCallback = pCallback;
+ gpCallbackInstance = pCallbackInstance;
+ gnCallbackSamples = u32NbrOfSamples;
+
+ /* callback notification */
+ gpCallback(*phAudioIn, AUDIOIN_MSG_OPEN, gpCallbackInstance, NULL, NULL);
+
+ return LHS_AUDIOIN_OK;
+
+} /* lhs_audioinOpenCallback */
+#endif
+
+/**************************************************************
+ * lhs_audioinClose *
+ * *
+ * notes : *
+ * -the input parameters are in fact not used but present *
+ * to ensure compatibility with Win32 implementations *
+ **************************************************************/
+
+LHS_AUDIOIN_ERROR lhs_audioinClose(AUDIOIN_H *phAudioIn)
+{
+ int doneWaiting = 0;
+
+ /* Validate the handle */
+ if ((phAudioIn == NULL) || (*phAudioIn == NULL))
+ {
+ return LHS_E_AUDIOIN_NULLPOINTER;
+ }
+
+ /* stop recording audio samples */
+ setRecordOff();
+
+ /* stop reading audio samples */
+ setCloseOn();
+
+ //wait for the thread to stop reading samples.
+ pthread_mutex_lock ( &gAudioMutex );
+
+ while (!doneWaiting)
+ {
+ int rc = pthread_cond_wait(&gCloseCalled, &gAudioMutex);
+ switch (rc)
+ {
+ case 0:
+ if (!gCloseCalledSignaled)
+ {
+ // Avoid spurious wakeups
+ continue;
+ }
+ else
+ {
+ gCloseCalledSignaled = 0;
+ doneWaiting = 1;
+ break;
+ }
+ break;
+ default:
+ PLogError ( "Audio In Error pthread_cond_wait\n" );
+ pthread_mutex_unlock(&gAudioMutex);
+ return ~LHS_AUDIOIN_OK;
+ }
+ }
+ pthread_mutex_unlock(&gAudioMutex);
+
+#ifdef FILTER_ON
+ FIR_deconstruct(pFIR);
+#endif
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+ /* callback notification */
+ if (gpCallback != NULL) gpCallback(*phAudioIn, AUDIOIN_MSG_CLOSE, gpCallbackInstance, NULL, NULL);
+#endif
+
+ return LHS_AUDIOIN_OK;
+}
+
+/**************************************************************
+ * lhs_audioinStart *
+ * *
+ * notes : *
+ * -the input parameters are in fact not used but present *
+ * to ensure compatibility with Win32 implementations *
+ * -in fact the recording is never stopped or started, when *
+ * non in 'start' status, the samples are just ignored *
+ **************************************************************/
+
+LHS_AUDIOIN_ERROR lhs_audioinStart(AUDIOIN_H hAudioIn)
+{
+#ifdef SAVE_RAW_AUDIO
+ char file_name [256];
+
+ gettimeofday ( &buffer_save_audio, NULL );
+ sprintf ( file_name, "data_%ld_%ld.raw", buffer_save_audio.tv_sec, buffer_save_audio.tv_usec );
+ audio_data = fopen ( file_name, "w" );
+#endif
+ if (hAudioIn == NULL)
+ {
+ return LHS_E_AUDIOIN_NULLPOINTER;
+ }
+
+ pthread_mutex_lock ( &gAudioMutex );
+
+#ifdef FILTER_ON
+ FIR_reset(pFIR);
+#endif
+
+ gWriteIndexPointer = 0;
+ gReadIndexPointer = 0;
+ gAudioInInfo.u32SamplesAvailable = 0;
+
+ /* start recording */
+ setRecordOn();
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+ /* callback notification */
+ if (gpCallback != NULL) gpCallback(hAudioIn, AUDIOIN_MSG_START, gpCallbackInstance, NULL, NULL);
+#endif
+ pthread_mutex_unlock ( &gAudioMutex );
+
+ return LHS_AUDIOIN_OK;
+}
+
+/**************************************************************
+ * lhs_audioinStop *
+ * *
+ * notes : *
+ * -the input parameters are in fact not used but present *
+ * to ensure compatibility with Win32 implementations *
+ * -in fact the recording is never stopped or started, when *
+ * non in 'start' status, the samples are just ignored *
+ **************************************************************/
+
+LHS_AUDIOIN_ERROR lhs_audioinStop(AUDIOIN_H hAudioIn)
+{
+#ifdef SAVE_RAW_AUDIO
+ fclose ( audio_data );
+#endif
+ if (hAudioIn == NULL)
+ {
+ return LHS_E_AUDIOIN_NULLPOINTER;
+ }
+ pthread_mutex_lock ( &gAudioMutex );
+
+ /* stop recording (discard samples) */
+ setRecordOff();
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+ /* callback notification */
+ if (gpCallback != NULL) gpCallback(hAudioIn, AUDIOIN_MSG_STOP, gpCallbackInstance, NULL, NULL);
+#endif
+ pthread_mutex_unlock ( &gAudioMutex );
+
+ return LHS_AUDIOIN_OK;
+}
+
+/**************************************************************
+ * lhs_audioinGetSamples *
+ * *
+ * notes : *
+ **************************************************************/
+
+LHS_AUDIOIN_ERROR lhs_audioinGetSamples(AUDIOIN_H hAudioIn, unsigned long * u32NbrOfSamples, void * pAudioBuffer, AUDIOIN_INFO * pgAudioInInfo)
+{
+ unsigned long cSamples;
+ //unsigned long nToCopy;
+
+ /* Check if the handle is valid */
+ if (hAudioIn == NULL)
+ {
+ return LHS_E_AUDIOIN_NULLPOINTER;
+ }
+
+ cSamples = 0;
+
+ while (1)
+ {
+ /* wait until we have enough samples */
+ if (*u32NbrOfSamples <= gAudioInInfo.u32SamplesAvailable)
+ {
+ /* lock the code to prevent dual access to some variables */
+ pthread_mutex_lock(&gAudioMutex);
+
+ /* TO DO: consider copying in chunks (like in AquisitionThread)
+ rather than 1 sample at a time. */
+
+ /* copy all samples into the input buffer */
+ while ((cSamples < *u32NbrOfSamples))
+ {
+ ((audioinSample *)pAudioBuffer)[cSamples++] = gSamplesBufferCircularFifo[gReadIndexPointer++];
+
+ /* adapt the parameters */
+ gAudioInInfo.u32SamplesAvailable -= 1;
+
+ /* adapt circular buffer */
+ if (gReadIndexPointer >= SAMPLES_BUFFER_SIZE)
+ {
+ gReadIndexPointer = 0;
+ }
+
+ /* enough samples */
+ if (cSamples == *u32NbrOfSamples)
+ {
+ /* return the audioin info structure */
+ memcpy(pgAudioInInfo, &gAudioInInfo, sizeof(AUDIOIN_INFO));
+ pthread_mutex_unlock(&gAudioMutex);
+ return LHS_AUDIOIN_OK;
+ }
+ }
+ }
+ else
+ {
+ /* relinquish CPU. select() is more reliable than usleep(). */
+ timer.tv_sec = 0;
+ timer.tv_usec = 10000;
+ select(0, NULL, NULL, NULL, &timer);
+ }
+ } /* while (1) */
+}
+
+/**************************************************************
+ * lhs_audioinGetVersion *
+ * *
+ * notes : not implemented *
+ **************************************************************/
+
+LHS_AUDIOIN_ERROR lhs_audioinGetVersion(unsigned long *pu32Version)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+
+/**************************************************************
+ * lhs_audioinGetVolume/lhs_audioinSetVolume *
+ * *
+ * notes : not implemented *
+ **************************************************************/
+
+LHS_AUDIOIN_ERROR lhs_audioinGetVolume(AUDIOIN_H hAudioIn, unsigned long *pu32Volume)
+{
+ *pu32Volume = gRecordingVolume;
+ return LHS_AUDIOIN_OK;
+}
+
+LHS_AUDIOIN_ERROR lhs_audioinSetVolume(AUDIOIN_H hAudioIn, unsigned long u32Volume)
+{
+ gRecordingVolume = u32Volume;
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+/**************************************************************
+ * lhs_audioinErrorGetString *
+ * *
+ * notes : not implemented *
+ **************************************************************/
+
+const char *lhs_audioinErrorGetString(const LHS_AUDIOIN_ERROR Error)
+{
+ return ("unknown error");
+}
+
+
+#else
+/******************************************************************************/
+/* STUB FUNCTIONS FOR SIMULATOR BUILD (DOES NOT SUPPORT THREADS) */
+/* This code is enabled if both ANDROID and __ARM_ARCH_5__ are defined. */
+/******************************************************************************/
+
+#include "audioin.h"
+
+LHS_AUDIOIN_ERROR lhs_audioinOpenEx (
+ unsigned long u32AudioInID, /*@parm [in] Audio-in device ID (ranges from 0 to a number of available
+ devices on the system). You can also use the following flag
+ instead of a device identifier.
+ <nl><nl><bold WAVE_MAPPER> = The function selects a
+ waveform-audio input device capable of recording in the
+ specified format. <bold Header:> Declared in Mmsystem.h from
+ the Windows Multimedia: Platform SDK.*/
+ unsigned long u32Frequency, /*@parm [in] Frequency of the recognition engine in Hz. */
+ unsigned long u32NbrOfFrames, /*@parm [in] Number of frames buffered internally. */
+ unsigned long u32SamplesPerFrame, /*@parm [in] Size, in samples, of each individual frame. */
+ AUDIOIN_H * phAudioIn /*@parm [out] Handle to the audio-in device */
+ )
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+LHS_AUDIOIN_ERROR lhs_audioinOpen (
+ unsigned long u32AudioInID, /*@parm [in] Audio-in device ID (ranges from 0 to a number of available
+ devices on the system). You can also use the following flag
+ instead of a device identifier.
+ <nl><nl><bold WAVE_MAPPER> = The function selects a
+ waveform-audio input device capable of recording in the
+ specified format. <bold Header:> Declared in Mmsystem.h from
+ the Windows Multimedia: Platform SDK.*/
+ unsigned long u32Frequency, /*@parm [in] Frequency of the recognition engine in Hz. */
+ AUDIOIN_H * phAudioIn /*@parm [out] Handle to the audio-in device */
+ )
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+#ifdef AUDIOIN_SUPPORT_CALLBACK
+LHS_AUDIOIN_ERROR lhs_audioinOpenCallback(unsigned long u32AudioInID, unsigned long u32Frequency, unsigned long u32NbrOfSamples, pCallbackFunc pCallback, void* pCallbackInstance, AUDIOIN_H * phAudioIn)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+#endif
+
+LHS_AUDIOIN_ERROR lhs_audioinClose(AUDIOIN_H *phAudioIn)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+LHS_AUDIOIN_ERROR lhs_audioinStart(AUDIOIN_H hAudioIn)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+LHS_AUDIOIN_ERROR lhs_audioinStop(AUDIOIN_H hAudioIn)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+LHS_AUDIOIN_ERROR lhs_audioinGetSamples(AUDIOIN_H hAudioIn, unsigned long * u32NbrOfSamples, void * pAudioBuffer, AUDIOIN_INFO * pgAudioInInfo)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+LHS_AUDIOIN_ERROR lhs_audioinGetVersion(unsigned long *pu32Version)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+LHS_AUDIOIN_ERROR lhs_audioinGetVolume(AUDIOIN_H hAudioIn, unsigned long *pu32Volume)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+LHS_AUDIOIN_ERROR lhs_audioinSetVolume(AUDIOIN_H hAudioIn, unsigned long u32Volume)
+{
+ return LHS_E_AUDIOIN_NOTIMPLEMENTED;
+}
+
+const char *lhs_audioinErrorGetString(const LHS_AUDIOIN_ERROR Error)
+{
+ return "LHS_E_AUDIOIN_NOTIMPLEMENTED";
+}
+
+#endif
View
214 audio/AudioIn/UNIX/src/audioinwrapper.cpp
@@ -0,0 +1,214 @@
+/*---------------------------------------------------------------------------*
+ * audioinwrapper.cpp *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+
+#if defined(ANDROID) && defined(__ARM_ARCH_5__)
+
+//#define USE_DEV_EAC_FILE 1
+
+#if defined(USE_DEV_EAC_FILE)
+#include <fcntl.h>
+#define N_CHANNELS 1
+#else
+#include <media/AudioRecord.h>
+#include <media/AudioSystem.h>
+using namespace android;
+#endif
+
+#endif // defined(ANDROID) && defined(__ARM_ARCH_5__)
+
+#include "plog.h"
+
+// #define SAVE_RAW_AUDIO 1
+
+#ifdef SAVE_RAW_AUDIO
+#include <sys/time.h>
+#include <stdio.h>
+
+
+static FILE *audio_data;
+static struct timeval buffer_save_audio;
+#endif