├── .gitignore ├── LICENSE ├── README.md ├── android └── sample │ ├── .classpath │ ├── .cproject │ ├── .project │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── DCRejectionFilter.cpp │ ├── DCRejectionFilter.h │ ├── SonicGenerator.cpp │ ├── SonicListener.cpp │ ├── com_duowan_sonic_SonicGenerator.h │ └── com_duowan_sonic_SonicListener.h │ ├── proguard-project.txt │ ├── project.properties │ ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── layout │ │ └── activity_main.xml │ ├── menu │ │ └── main.xml │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── src │ └── com │ └── duowan │ └── sonic │ ├── MainActivity.java │ ├── SonicGenerator.java │ └── SonicListener.java ├── ios ├── SonicDemo │ ├── SonicDemo.xcodeproj │ │ └── project.pbxproj │ ├── SonicDemo │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── LaunchImage.launchimage │ │ │ │ └── Contents.json │ │ ├── MainViewController.h │ │ ├── MainViewController.mm │ │ ├── MainViewController.xib │ │ ├── SonicDemo-Info.plist │ │ ├── SonicDemo-Prefix.pch │ │ ├── WaveListener │ │ │ ├── WaveListener.h │ │ │ ├── WaveListener.mm │ │ │ ├── aurio_helper.cpp │ │ │ └── aurio_helper.h │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ ├── iPublicUtility │ │ │ ├── CABitOperations.h │ │ │ ├── CADebugMacros.cpp │ │ │ ├── CADebugMacros.h │ │ │ ├── CADebugPrintf.cpp │ │ │ ├── CADebugPrintf.h │ │ │ ├── CAMath.h │ │ │ ├── CAStreamBasicDescription.cpp │ │ │ ├── CAStreamBasicDescription.h │ │ │ ├── CAXException.cpp │ │ │ ├── CAXException.h │ │ │ ├── CFByteOrder.h │ │ │ └── CoreAudioTypes.h │ │ └── main.mm │ └── SonicDemoTests │ │ ├── SonicDemoTests-Info.plist │ │ ├── SonicDemoTests.m │ │ └── en.lproj │ │ └── InfoPlist.strings ├── SonicEngine │ ├── SonicEngine.xcodeproj │ │ └── project.pbxproj │ ├── SonicEngine │ │ ├── SonicEngine-Prefix.pch │ │ ├── SonicGenerator.h │ │ ├── SonicGenerator.mm │ │ ├── SonicListener.h │ │ └── SonicListener.mm │ └── SonicEngineTests │ │ ├── SonicEngineTests-Info.plist │ │ ├── SonicEngineTests.m │ │ └── en.lproj │ │ └── InfoPlist.strings └── sonic.xcworkspace │ └── contents.xcworkspacedata └── sdk ├── FFTBufferManager ├── FFTBufferManager.cpp └── FFTBufferManager.h ├── freq_util ├── bb_freq_util.cpp ├── bb_freq_util.h └── bb_header.h ├── generator_helper ├── generator_helper.cpp └── generator_helper.h ├── iPublicUtility ├── CABitOperations.h ├── CADebugMacros.cpp ├── CADebugMacros.h ├── CADebugPrintf.cpp ├── CADebugPrintf.h ├── CAMath.h ├── CAStreamBasicDescription.cpp ├── CAStreamBasicDescription.h ├── CAXException.cpp ├── CAXException.h ├── CFByteOrder.h ├── CoreAudioTypes.h ├── VectorMath.cpp ├── VectorMath.h └── libkern │ ├── OSAtomic.h │ ├── android │ ├── OSAtomic.c │ ├── OSSpinLock.c │ └── cutils │ │ ├── atomic-arm.h │ │ ├── atomic-inline.h │ │ ├── atomic-x86.h │ │ ├── atomic.c │ │ └── atomic.h │ └── windows │ └── OSAtomic.c ├── kiss_fft ├── _kiss_fft_guts.h ├── kiss_fastfir.c ├── kiss_fastfir.h ├── kiss_fft.c ├── kiss_fft.h ├── kiss_fftr.c └── kiss_fftr.h ├── listener_helper ├── listener_helper.cpp └── listener_helper.h ├── pcm_render ├── pcm_render.cpp └── pcm_render.h ├── queue ├── queue.cpp └── queue.h └── rscode ├── rscode.cpp └── rscode.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac OS X Finder and whatnot 2 | .DS_Store 3 | 4 | # XCode (and ancestors) per-user config (very noisy, and not relevant) 5 | *.mode1 6 | *.mode1v3 7 | *.mode2v3 8 | *.perspective 9 | *.perspectivev3 10 | *.pbxuser 11 | xcuserdata 12 | *.xcworkspace 13 | 14 | # Generated files 15 | VersionX-revision.h 16 | 17 | 18 | # build products 19 | build/ 20 | *.[oa] 21 | 22 | # Other source repository archive directories (protects when importing) 23 | .hg 24 | .svn 25 | CVS 26 | *.DS_Store 27 | 28 | aaa 29 | 30 | # for Android App 31 | 32 | # Built application files 33 | *.apk 34 | *.ap_ 35 | 36 | # Files for the Dalvik VM 37 | *.dex 38 | 39 | # Java class files 40 | *.class 41 | 42 | # Generated files 43 | bin/ 44 | gen/ 45 | obj/ 46 | libs/ 47 | 48 | # Gradle files 49 | .gradle/ 50 | build/ 51 | 52 | # Local configuration file (sdk path, etc) 53 | local.properties 54 | 55 | # Proguard folder generated by Eclipse 56 | proguard/ 57 | 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 linyehui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Sonic 2 | ===== 3 | ## 简介 4 | [Sonic](https://github.com/linyehui/sonic) 是一个跨平台的声波传输库(iOS & Android),技术上类似于[chirp](http://chirp.io/)和[蛐蛐儿](http://www.xququ.com/index_cn.html),但声波识别率上和他们还有很大的差距。 5 | 6 | 声波生成和识别的代码源自[WaveTrans](https://github.com/CloudSide/WaveTrans),linyehui 对源代码进行了精简,将声波编解码部分的代码进行了独立封装,并做了跨平台移植,从而得到了这个更简练的声波传输库:[Sonic](https://github.com/linyehui/sonic)。 7 | 8 | ## 关于声波识别率和存在的问题 9 | 目前的代码,降噪主要依赖于手机本身的物理降噪(类似双MIC降噪等),嘈杂环境下的声波识别率比较差; 10 | 如果你需要产品化这项技术,那么这份代码只能带你入门。 11 | 12 | ## 开发环境 13 | ```bash 14 | OS X 10.9.5 15 | Xcode 6.0.1 (准备开源的时候才做了Xcode6兼容,模拟器下iPhone 6还有问题) 16 | adt-bundle-mac-x86_64-20131030 17 | android-ndk-r9d 18 | ``` 19 | 20 | ``` 21 | 2016/01/07 更新 22 | 23 | 1、修复了iOS版本在Xcode 7.2下的编译问题,主要是64位编译器和32位编译器的兼容性问题,iOS 9.2 下可以运行了 24 | 2、生成语音没有问题了,模拟器和真机都可以正常运行 25 | 3、声音识别还有问题,目前还没找到原因,估计也和64位编译相关,有时间再继续排查下代码 26 | 27 | ``` 28 | 29 | ## 目录说明 30 | ```bash 31 | |---sonic 32 | | |--android # Android Demo 33 | | |--ios # iOS Demo 34 | | |--sdk # 跨平台的C++代码 35 | ``` 36 | 37 | ## 温馨提示 38 | iOS 和 Android Demo非常简陋,可以在两部设备上相互发送声波并识别,但交互上还有很多已知和未知的Bug :( 39 | 40 | ### 希望这份代码能给你带来些许帮助。 41 | 42 | ### Any questions, please feel free to send me an email: 43 | ```bash 44 | echo qwertyuwitotepasdwqifgs | tr qeryuoasdfgipwt lnyhudgmaco.@ie 45 | ``` -------------------------------------------------------------------------------- /android/sample/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /android/sample/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /android/sample/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sonic 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | ?children? 14 | ?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|?name?=entry\\\\\\\|\\\|\|| 15 | 16 | 17 | ?name? 18 | 19 | 20 | 21 | org.eclipse.cdt.make.core.append_environment 22 | true 23 | 24 | 25 | org.eclipse.cdt.make.core.buildArguments 26 | NDK_DEBUG=1 27 | 28 | 29 | org.eclipse.cdt.make.core.buildCommand 30 | ndk-build 31 | 32 | 33 | org.eclipse.cdt.make.core.cleanBuildTarget 34 | clean 35 | 36 | 37 | org.eclipse.cdt.make.core.contents 38 | org.eclipse.cdt.make.core.activeConfigSettings 39 | 40 | 41 | org.eclipse.cdt.make.core.enableAutoBuild 42 | false 43 | 44 | 45 | org.eclipse.cdt.make.core.enableCleanBuild 46 | true 47 | 48 | 49 | org.eclipse.cdt.make.core.enableFullBuild 50 | true 51 | 52 | 53 | org.eclipse.cdt.make.core.stopOnError 54 | true 55 | 56 | 57 | org.eclipse.cdt.make.core.useDefaultBuildCmd 58 | false 59 | 60 | 61 | 62 | 63 | com.android.ide.eclipse.adt.ResourceManagerBuilder 64 | 65 | 66 | 67 | 68 | com.android.ide.eclipse.adt.PreCompilerBuilder 69 | 70 | 71 | 72 | 73 | org.eclipse.jdt.core.javabuilder 74 | 75 | 76 | 77 | 78 | com.android.ide.eclipse.adt.ApkBuilder 79 | 80 | 81 | 82 | 83 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 84 | full,incremental, 85 | 86 | 87 | 88 | 89 | 90 | com.android.ide.eclipse.adt.AndroidNature 91 | org.eclipse.jdt.core.javanature 92 | org.eclipse.cdt.core.cnature 93 | org.eclipse.cdt.core.ccnature 94 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 95 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 96 | 97 | 98 | -------------------------------------------------------------------------------- /android/sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /android/sample/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linyehui/sonic/e1fcf22bf992ef78a913abd43ab85f10559d1b56/android/sample/ic_launcher-web.png -------------------------------------------------------------------------------- /android/sample/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Created by linyehui on 2014-04-10. 2 | # Copyright (c) 2014年 linyehui. All rights reserved. 3 | # 4 | 5 | LOCAL_PATH:= $(call my-dir) 6 | 7 | include $(CLEAR_VARS) 8 | 9 | LOCAL_C_INCLUDES := $(LOCAL_PATH) \ 10 | $(LOCAL_PATH)/../../../sdk/ \ 11 | $(LOCAL_PATH)/../../../sdk/FFTBufferManager/ \ 12 | $(LOCAL_PATH)/../../../sdk/freq_util/ \ 13 | $(LOCAL_PATH)/../../../sdk/iPublicUtility/ \ 14 | $(LOCAL_PATH)/../../../sdk/kiss_fft/ \ 15 | $(LOCAL_PATH)/../../../sdk/pcm_render/ \ 16 | $(LOCAL_PATH)/../../../sdk/queue/ \ 17 | $(LOCAL_PATH)/../../../sdk/rscode/ \ 18 | $(LOCAL_PATH)/../../../sdk/generator_helper/ \ 19 | $(LOCAL_PATH)/../../../sdk/listener_helper/ 20 | 21 | LOCAL_SRC_FILES := ../../../sdk/FFTBufferManager/FFTBufferManager.cpp \ 22 | ../../../sdk/freq_util/bb_freq_util.cpp \ 23 | ../../../sdk/iPublicUtility/VectorMath.cpp \ 24 | ../../../sdk/iPublicUtility/CADebugMacros.cpp \ 25 | ../../../sdk/iPublicUtility/CADebugPrintf.cpp \ 26 | ../../../sdk/iPublicUtility/CAStreamBasicDescription.cpp \ 27 | ../../../sdk/iPublicUtility/CAXException.cpp \ 28 | ../../../sdk/iPublicUtility/libkern/android/cutils/atomic.c \ 29 | ../../../sdk/iPublicUtility/libkern/android/OSAtomic.c \ 30 | ../../../sdk/kiss_fft/kiss_fft.c \ 31 | ../../../sdk/rscode/rscode.cpp \ 32 | ../../../sdk/queue/queue.cpp \ 33 | ../../../sdk/pcm_render/pcm_render.cpp \ 34 | ../../../sdk/generator_helper/generator_helper.cpp \ 35 | ../../../sdk/listener_helper/listener_helper.cpp \ 36 | SonicGenerator.cpp \ 37 | SonicListener.cpp \ 38 | DCRejectionFilter.cpp 39 | 40 | LOCAL_MODULE := sonicengine 41 | APP_OPTIM := debug 42 | 43 | LOCAL_CFLAGS += -g -Wno-multichar 44 | LOCAL_CFLAGS += -D SONIC_TARGET_OS_ANDROID 45 | LOCAL_CFLAGS += -D ANDROID_SMP=0 46 | 47 | # Include the static libraries pulled in via Android Maven plugin makefile (see include below) 48 | LOCAL_STATIC_LIBRARIES := $(ANDROID_MAVEN_PLUGIN_LOCAL_STATIC_LIBRARIES) 49 | 50 | LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog 51 | 52 | include $(BUILD_SHARED_LIBRARY) 53 | 54 | # Include the Android Maven plugin generated makefile 55 | # Important: Must be the last import in order for Android Maven Plugins paths to work 56 | include $(ANDROID_MAVEN_PLUGIN_MAKEFILE) -------------------------------------------------------------------------------- /android/sample/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi x86 -------------------------------------------------------------------------------- /android/sample/jni/DCRejectionFilter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // DCRejectionFilter.cpp 3 | // 4 | // 5 | // Created by linyehui on 2014-04-10. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #include "DCRejectionFilter.h" 10 | 11 | const float DCRejectionFilter::kDefaultPoleDist = 0.975f; 12 | 13 | ////////////////////////////////////////////////////////// 14 | 15 | DCRejectionFilter::DCRejectionFilter(float poleDist) 16 | { 17 | Reset(); 18 | } 19 | 20 | void DCRejectionFilter::Reset() 21 | { 22 | mY1 = mX1 = 0; 23 | } 24 | 25 | void DCRejectionFilter::InplaceFilter(float* ioData, unsigned long numFrames) 26 | { 27 | for (unsigned long i=0; i < numFrames; i++) 28 | { 29 | float xCurr = ioData[i]; 30 | ioData[i] = ioData[i] - mX1 + (kDefaultPoleDist * mY1); 31 | mX1 = xCurr; 32 | mY1 = ioData[i]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /android/sample/jni/DCRejectionFilter.h: -------------------------------------------------------------------------------- 1 | // 2 | // DCRejectionFilter.h 3 | // 4 | // 5 | // Created by linyehui on 2014-04-10. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #ifndef __DC_REJECTION_FILTER_H__ 10 | #define __DC_REJECTION_FILTER_H__ 11 | 12 | class DCRejectionFilter 13 | { 14 | public: 15 | DCRejectionFilter(float poleDist = DCRejectionFilter::kDefaultPoleDist); 16 | 17 | void InplaceFilter(float* ioData, unsigned long numFrames); 18 | void Reset(); 19 | 20 | protected: 21 | 22 | // State variables 23 | float mY1; 24 | float mX1; 25 | 26 | static const float kDefaultPoleDist; 27 | }; 28 | 29 | #endif // __DC_REJECTION_FILTER_H__ 30 | -------------------------------------------------------------------------------- /android/sample/jni/SonicGenerator.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // SonicGenerator.cpp 3 | // 4 | // 5 | // Created by linyehui on 2014-04-10. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | #include 9 | #include "com_duowan_sonic_SonicGenerator.h" 10 | 11 | #include "freq_util/bb_header.h" 12 | #include "queue/queue.h" 13 | #include "generator_helper/generator_helper.h" 14 | #include "pcm_render/pcm_render.h" 15 | 16 | #ifdef __cplusplus //最好有这个,否则被编译器改了函数名字找不到不要怪我 17 | extern "C" { 18 | #endif 19 | 20 | int getWaveLenByByte() 21 | { 22 | int len = SonicSDK::PCMRender::getChirpLengthByByte(RS_TOTAL_LEN) + SonicSDK::SONIC_HEADER_SIZE; 23 | return len; 24 | } 25 | 26 | int genWaveData(const char* hash_array, char* buffer, int buffer_len) 27 | { 28 | if (0 == hash_array || 0 == buffer) 29 | return -1; 30 | int hash_len = strlen(hash_array); 31 | if (hash_len != RS_DATA_LEN) 32 | return -1; 33 | 34 | if (buffer_len < getWaveLenByByte()) 35 | return -1; 36 | 37 | char result_with_rs[RS_TOTAL_LEN + 1]; 38 | if (!SonicSDK::GeneratorHelper::genRSCode(hash_array, result_with_rs, RS_TOTAL_LEN + 1)) 39 | { 40 | return 0; 41 | } 42 | 43 | long buffer_len_by_byte = SonicSDK::PCMRender::getChirpLengthByByte(RS_TOTAL_LEN); 44 | short* wave_buffer = (short*)malloc(buffer_len_by_byte); 45 | if (NULL == wave_buffer) 46 | return 0; 47 | 48 | unsigned char waveHeaderByteArray[SonicSDK::SONIC_HEADER_SIZE]; 49 | if (!SonicSDK::PCMRender::renderChirpData( 50 | result_with_rs, 51 | RS_TOTAL_LEN, 52 | waveHeaderByteArray, 53 | SonicSDK::SONIC_HEADER_SIZE, 54 | wave_buffer, 55 | buffer_len_by_byte)) 56 | { 57 | free(wave_buffer); 58 | return 0; 59 | } 60 | 61 | memcpy(buffer, waveHeaderByteArray, SonicSDK::SONIC_HEADER_SIZE); 62 | memcpy(buffer + SonicSDK::SONIC_HEADER_SIZE, wave_buffer, buffer_len_by_byte); 63 | //memcpy(pArray, wave_buffer, buffer_len_by_byte); 64 | 65 | if (0 != wave_buffer) 66 | { 67 | free(wave_buffer); 68 | } 69 | 70 | jint output_len = SonicSDK::SONIC_HEADER_SIZE + buffer_len_by_byte; 71 | return output_len; 72 | } 73 | 74 | /* 75 | * Class: com_duowan_sonic_SonicGenerator 76 | * Method: getWaveLenByByte 77 | * Signature: ()I 78 | */ 79 | JNIEXPORT jint JNICALL Java_com_duowan_sonic_SonicGenerator_getWaveLenByByte 80 | (JNIEnv *, jclass) 81 | { 82 | return getWaveLenByByte(); 83 | } 84 | 85 | /* 86 | * Class: com_duowan_sonic_SonicGenerator 87 | * Method: genWaveData 88 | * Signature: (Ljava/lang/String;[B)I 89 | */ 90 | JNIEXPORT jint JNICALL Java_com_duowan_sonic_SonicGenerator_genWaveData 91 | (JNIEnv* env, jclass, jstring hash_string, jbyteArray buffer) 92 | { 93 | const char* pHashString = (const char*)env->GetStringUTFChars(hash_string, JNI_FALSE); 94 | if (0 == pHashString) 95 | return -1; 96 | 97 | // env的调用好像不能嵌套,会crash,所以先把这个复制一份,然后先ReleaseStringUTFChars 98 | // linyehui 2014-04-22 99 | int len = strlen(pHashString); 100 | char* hash_buffer = new char[len+1]; 101 | if (0 == hash_buffer) 102 | { 103 | env->ReleaseStringUTFChars(hash_string, pHashString); 104 | return -1; 105 | } 106 | strcpy(hash_buffer, pHashString); 107 | env->ReleaseStringUTFChars(hash_string, pHashString); 108 | 109 | jboolean isCopy = false; 110 | jbyteArray pArray = (jbyteArray) env->GetPrimitiveArrayCritical(buffer, &isCopy); 111 | jsize size = env->GetArrayLength(buffer); 112 | 113 | jint output_len = genWaveData(hash_buffer, (char*)pArray, size); 114 | 115 | delete hash_buffer; 116 | env->ReleasePrimitiveArrayCritical(buffer, pArray, JNI_COMMIT); 117 | 118 | return output_len; 119 | } 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | -------------------------------------------------------------------------------- /android/sample/jni/SonicListener.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // SonicListener.cpp 3 | // 4 | // 5 | // Created by linyehui on 2014-04-10. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #include 10 | #include "com_duowan_sonic_SonicListener.h" 11 | #include "listener_helper.h" 12 | #include "DCRejectionFilter.h" 13 | 14 | #ifdef __cplusplus //最好有这个,否则被编译器改了函数名字找不到不要怪我 15 | extern "C" { 16 | #endif 17 | 18 | DCRejectionFilter g_dcFilter; 19 | 20 | /* 21 | * Class: com_duowan_sonic_SonicListener 22 | * Method: initFFTMgr 23 | * Signature: (J)I 24 | */ 25 | JNIEXPORT jint JNICALL Java_com_duowan_sonic_SonicListener_initFFTMgr 26 | (JNIEnv* env, jclass, jlong inNumberFrames) 27 | { 28 | SonicSDK::ListenerHelper::instance()->initFFTMgr(inNumberFrames); 29 | 30 | return 0; 31 | } 32 | 33 | /* 34 | * Class: com_duowan_sonic_SonicListener 35 | * Method: releaseFFTMgr 36 | * Signature: ()V 37 | */ 38 | JNIEXPORT void JNICALL Java_com_duowan_sonic_SonicListener_releaseFFTMgr 39 | (JNIEnv *, jclass) 40 | { 41 | SonicSDK::ListenerHelper::instance()->release(); 42 | } 43 | 44 | /* 45 | * Class: com_duowan_sonic_SonicListener 46 | * Method: grabAudioData 47 | * Signature: (JJJ[B)I 48 | */ 49 | JNIEXPORT jint JNICALL Java_com_duowan_sonic_SonicListener_grabAudioData 50 | (JNIEnv* env, 51 | jclass, 52 | jlong inNumberFrames, 53 | jlong numberChannels, 54 | jlong dataByteSize, 55 | jbyteArray buffer) 56 | { 57 | jboolean isCopy = false; 58 | jbyteArray pArray = (jbyteArray) env->GetPrimitiveArrayCritical(buffer, &isCopy); 59 | 60 | AudioBufferList ioDataFloat; 61 | ioDataFloat.mNumberBuffers = 1; 62 | 63 | unsigned short samples_num = dataByteSize / (sizeof(short) * numberChannels); 64 | 65 | ioDataFloat.mBuffers[0].mNumberChannels = numberChannels; 66 | ioDataFloat.mBuffers[0].mDataByteSize = dataByteSize*2; 67 | ioDataFloat.mBuffers[0].mData = malloc(ioDataFloat.mBuffers[0].mDataByteSize); 68 | 69 | //memcpy(ioDataFloat.mBuffers[0].mData, pArray, dataByteSize); 70 | float* tempFloat = (float*)ioDataFloat.mBuffers[0].mData; 71 | short* tempShort = (short*)pArray; 72 | for (int j = 0; j < samples_num; j++) 73 | { 74 | float f_value = (float) tempShort[j] / 32768.0; 75 | if( f_value > 1 ) f_value = 1; 76 | if( f_value < -1 ) f_value = -1; 77 | 78 | tempFloat[j] = f_value; 79 | } 80 | 81 | // Remove DC component 82 | g_dcFilter.InplaceFilter((float*)(ioDataFloat.mBuffers[0].mData), samples_num); 83 | 84 | SonicSDK::ListenerHelper::instance()->grabAudioData(&ioDataFloat); 85 | 86 | free(ioDataFloat.mBuffers[0].mData); 87 | 88 | env->ReleasePrimitiveArrayCritical(buffer, pArray, JNI_ABORT); 89 | 90 | return 0; 91 | } 92 | 93 | /* 94 | * Class: com_duowan_sonic_SonicListener 95 | * Method: computeWave 96 | * Signature: ([B)Z 97 | */ 98 | JNIEXPORT jboolean JNICALL Java_com_duowan_sonic_SonicListener_computeWave 99 | (JNIEnv *env, jclass, jbyteArray buffer) 100 | { 101 | jboolean ret = false; 102 | jboolean isCopy = false; 103 | jbyteArray pArray = (jbyteArray) env->GetPrimitiveArrayCritical(buffer, &isCopy); 104 | 105 | char result[10] = {0}; 106 | if (SonicSDK::ListenerHelper::instance()->computeWave(result, 10)) 107 | { 108 | memcpy(pArray, result, 10); 109 | ret = true; 110 | } 111 | 112 | Exit0: 113 | env->ReleasePrimitiveArrayCritical(buffer, pArray, 0); 114 | return ret; 115 | } 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | -------------------------------------------------------------------------------- /android/sample/jni/com_duowan_sonic_SonicGenerator.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_duowan_sonic_SonicGenerator */ 4 | 5 | #ifndef _Included_com_duowan_sonic_SonicGenerator 6 | #define _Included_com_duowan_sonic_SonicGenerator 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_duowan_sonic_SonicGenerator 12 | * Method: getWaveLenByByte 13 | * Signature: ()I 14 | */ 15 | JNIEXPORT jint JNICALL Java_com_duowan_sonic_SonicGenerator_getWaveLenByByte 16 | (JNIEnv *, jclass); 17 | 18 | /* 19 | * Class: com_duowan_sonic_SonicGenerator 20 | * Method: genWaveData 21 | * Signature: (Ljava/lang/String;[B)I 22 | */ 23 | JNIEXPORT jint JNICALL Java_com_duowan_sonic_SonicGenerator_genWaveData 24 | (JNIEnv *, jclass, jstring, jbyteArray); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /android/sample/jni/com_duowan_sonic_SonicListener.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_duowan_sonic_SonicListener */ 4 | 5 | #ifndef _Included_com_duowan_sonic_SonicListener 6 | #define _Included_com_duowan_sonic_SonicListener 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_duowan_sonic_SonicListener 12 | * Method: initFFTMgr 13 | * Signature: (J)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_com_duowan_sonic_SonicListener_initFFTMgr 16 | (JNIEnv *, jclass, jlong); 17 | 18 | /* 19 | * Class: com_duowan_sonic_SonicListener 20 | * Method: releaseFFTMgr 21 | * Signature: ()V 22 | */ 23 | JNIEXPORT void JNICALL Java_com_duowan_sonic_SonicListener_releaseFFTMgr 24 | (JNIEnv *, jclass); 25 | 26 | /* 27 | * Class: com_duowan_sonic_SonicListener 28 | * Method: grabAudioData 29 | * Signature: (JJJ[B)I 30 | */ 31 | JNIEXPORT jint JNICALL Java_com_duowan_sonic_SonicListener_grabAudioData 32 | (JNIEnv *, jclass, jlong, jlong, jlong, jbyteArray); 33 | 34 | /* 35 | * Class: com_duowan_sonic_SonicListener 36 | * Method: computeWave 37 | * Signature: ([B)Z 38 | */ 39 | JNIEXPORT jboolean JNICALL Java_com_duowan_sonic_SonicListener_computeWave 40 | (JNIEnv *, jclass, jbyteArray); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /android/sample/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /android/sample/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /android/sample/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linyehui/sonic/e1fcf22bf992ef78a913abd43ab85f10559d1b56/android/sample/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/sample/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linyehui/sonic/e1fcf22bf992ef78a913abd43ab85f10559d1b56/android/sample/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/sample/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linyehui/sonic/e1fcf22bf992ef78a913abd43ab85f10559d1b56/android/sample/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/sample/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linyehui/sonic/e1fcf22bf992ef78a913abd43ab85f10559d1b56/android/sample/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/sample/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 28 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/SonicDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/SonicDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_3_0 10 | #warning "This project uses features only available in iOS SDK 3.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/WaveListener/WaveListener.h: -------------------------------------------------------------------------------- 1 | // 2 | // WaveListener.h 3 | // 4 | // 5 | // Created by linyehui on 2014-04-10. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | #import 13 | #include 14 | #include 15 | 16 | #import "SonicEngine/SonicListener.h" 17 | #import "CAStreamBasicDescription.h" 18 | #import "aurio_helper.h" 19 | 20 | #define SPECTRUM_BAR_WIDTH 4 21 | 22 | #ifndef CLAMP 23 | #define CLAMP(min,x,max) (x < min ? min : (x > max ? max : x)) 24 | #endif 25 | 26 | 27 | @interface WaveListener : NSObject 28 | { 29 | SonicListener *listener_engine; 30 | 31 | AudioUnit rioUnit; 32 | BOOL unitIsRunning; 33 | BOOL unitHasBeenCreated; 34 | 35 | BOOL mute; 36 | BOOL interruption; 37 | 38 | DCRejectionFilter* dcFilter; 39 | CAStreamBasicDescription thruFormat; 40 | 41 | Float64 hwSampleRate; 42 | 43 | AudioConverterRef audioConverter; 44 | AURenderCallbackStruct inputProc; 45 | //SystemSoundID buttonPressSound; 46 | BOOL _isListening; 47 | } 48 | 49 | //@property (nonatomic, retain) EAGLView* view; 50 | @property (nonatomic, retain) SonicListener *listener_engine; 51 | 52 | @property (nonatomic, assign) AudioUnit rioUnit; 53 | @property (nonatomic, assign) BOOL unitIsRunning; 54 | @property (nonatomic, assign) BOOL unitHasBeenCreated; 55 | @property (nonatomic, assign) BOOL mute; 56 | @property (nonatomic, assign) AURenderCallbackStruct inputProc; 57 | @property (nonatomic, assign) BOOL interruption; 58 | 59 | + (WaveListener *)sharedWaveListener; 60 | 61 | - (void)setListening:(BOOL)state; 62 | - (void)startListening; 63 | - (void)computeWave; 64 | 65 | - (void)actionWhenApplicationDidBecomeActive; 66 | - (void)actionWhenApplicationWillResignActive; 67 | - (void)actionWhenApplicationDidEnterBackground; 68 | - (void)actionWhenApplicationWillEnterForeground; 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/WaveListener/aurio_helper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: aurio_helper.cpp 4 | Abstract: Helper class for manipulating the remote i/o audio unit 5 | Version: 1.0 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | #include 51 | #include 52 | #include 53 | 54 | #include "CAXException.h" 55 | #include "CAStreamBasicDescription.h" 56 | #include "aurio_helper.h" 57 | 58 | int SetupRemoteIO (AudioUnit& inRemoteIOUnit, AURenderCallbackStruct inRenderProc, CAStreamBasicDescription& outFormat) 59 | { 60 | try { 61 | // Open the output unit 62 | AudioComponentDescription desc; 63 | desc.componentType = kAudioUnitType_Output; 64 | desc.componentSubType = kAudioUnitSubType_RemoteIO; 65 | desc.componentManufacturer = kAudioUnitManufacturer_Apple; 66 | desc.componentFlags = 0; 67 | desc.componentFlagsMask = 0; 68 | 69 | AudioComponent comp = AudioComponentFindNext(NULL, &desc); 70 | 71 | XThrowIfError(AudioComponentInstanceNew(comp, &inRemoteIOUnit), "couldn't open the remote I/O unit"); 72 | 73 | UInt32 one = 1; 74 | XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof(one)), "couldn't enable input on the remote I/O unit"); 75 | 76 | XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inRenderProc, sizeof(inRenderProc)), "couldn't set remote i/o render callback"); 77 | 78 | // set our required format - LPCM non-interleaved 32 bit floating point 79 | //outFormat = CAStreamBasicDescription(44100, kAudioFormatLinearPCM, 4, 1, 4, 2, 32, kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsFloat | kAudioFormatFlagIsNonInterleaved); 80 | // set our required format - LPCM non-interleaved 16 bit 1 channels 81 | // linyehui 82 | outFormat = CAStreamBasicDescription(44100, kAudioFormatLinearPCM, 2, 1, 2, 1, 16, kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked); 83 | 84 | XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outFormat, sizeof(outFormat)), "couldn't set the remote I/O unit's output client format"); 85 | XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &outFormat, sizeof(outFormat)), "couldn't set the remote I/O unit's input client format"); 86 | 87 | XThrowIfError(AudioUnitInitialize(inRemoteIOUnit), "couldn't initialize the remote I/O unit"); 88 | } 89 | catch (CAXException &e) { 90 | char buf[256]; 91 | fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf)); 92 | return 1; 93 | } 94 | catch (...) { 95 | fprintf(stderr, "An unknown error occurred\n"); 96 | return 1; 97 | } 98 | 99 | return 0; 100 | } 101 | 102 | void SilenceData(AudioBufferList *inData) 103 | { 104 | for (UInt32 i=0; i < inData->mNumberBuffers; i++) 105 | memset(inData->mBuffers[i].mData, 0, inData->mBuffers[i].mDataByteSize); 106 | } 107 | 108 | 109 | const Float32 DCRejectionFilter::kDefaultPoleDist = 0.975f; 110 | 111 | DCRejectionFilter::DCRejectionFilter(Float32 poleDist) 112 | { 113 | Reset(); 114 | } 115 | 116 | void DCRejectionFilter::Reset() 117 | { 118 | mY1 = mX1 = 0; 119 | } 120 | 121 | void DCRejectionFilter::InplaceFilter(Float32* ioData, UInt32 numFrames) 122 | { 123 | for (UInt32 i=0; i < numFrames; i++) 124 | { 125 | Float32 xCurr = ioData[i]; 126 | ioData[i] = ioData[i] - mX1 + (kDefaultPoleDist * mY1); 127 | mX1 = xCurr; 128 | mY1 = ioData[i]; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/WaveListener/aurio_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: aurio_helper.h 4 | Abstract: Helper class for manipulating the remote i/o audio unit 5 | Version: 1.0 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | #if !defined(__rio_helper_h__) 51 | #define __rio_helper_h__ 52 | 53 | #include 54 | #include 55 | 56 | #include "CAStreamBasicDescription.h" 57 | 58 | #define kNumDrawBuffers 1 59 | #define kDefaultDrawSamples 1024 60 | #define kMinDrawSamples 64 61 | #define kMaxDrawSamples 4096 62 | 63 | int SetupRemoteIO (AudioUnit& inRemoteIOUnit, AURenderCallbackStruct inRenderProcm, CAStreamBasicDescription& outFormat); 64 | void SilenceData(AudioBufferList *inData); 65 | 66 | class DCRejectionFilter 67 | { 68 | public: 69 | DCRejectionFilter(Float32 poleDist = DCRejectionFilter::kDefaultPoleDist); 70 | 71 | void InplaceFilter(Float32* ioData, UInt32 numFrames); 72 | void Reset(); 73 | 74 | protected: 75 | 76 | // State variables 77 | Float32 mY1; 78 | Float32 mX1; 79 | 80 | static const Float32 kDefaultPoleDist; 81 | }; 82 | 83 | #endif -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/iPublicUtility/CABitOperations.h: -------------------------------------------------------------------------------- 1 | /* Copyright � 2007 Apple Inc. All Rights Reserved. 2 | 3 | Disclaimer: IMPORTANT: This Apple software is supplied to you by 4 | Apple Inc. ("Apple") in consideration of your agreement to the 5 | following terms, and your use, installation, modification or 6 | redistribution of this Apple software constitutes acceptance of these 7 | terms. If you do not agree with these terms, please do not use, 8 | install, modify or redistribute this Apple software. 9 | 10 | In consideration of your agreement to abide by the following terms, and 11 | subject to these terms, Apple grants you a personal, non-exclusive 12 | license, under Apple's copyrights in this original Apple software (the 13 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 14 | Software, with or without modifications, in source and/or binary forms; 15 | provided that if you redistribute the Apple Software in its entirety and 16 | without modifications, you must retain this notice and the following 17 | text and disclaimers in all such redistributions of the Apple Software. 18 | Neither the name, trademarks, service marks or logos of Apple Inc. 19 | may be used to endorse or promote products derived from the Apple 20 | Software without specific prior written permission from Apple. Except 21 | as expressly stated in this notice, no other rights or licenses, express 22 | or implied, are granted by Apple herein, including but not limited to 23 | any patent rights that may be infringed by your derivative works or by 24 | other works in which the Apple Software may be incorporated. 25 | 26 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 27 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 28 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 29 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 30 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 31 | 32 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 33 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 36 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 37 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 38 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 39 | POSSIBILITY OF SUCH DAMAGE. 40 | */ 41 | #ifndef _CABitOperations_h_ 42 | #define _CABitOperations_h_ 43 | 44 | //#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__) 45 | // #include 46 | //#else 47 | // #include "CFBase.h" 48 | //#endif 49 | //#include 50 | 51 | // return whether a number is a power of two 52 | inline UInt32 IsPowerOfTwo(UInt32 x) 53 | { 54 | return (x & (x-1)) == 0; 55 | } 56 | 57 | // count the leading zeros in a word 58 | // Metrowerks Codewarrior. powerpc native count leading zeros instruction: 59 | // I think it's safe to remove this ... 60 | //#define CountLeadingZeroes(x) ((int)__cntlzw((unsigned int)x)) 61 | 62 | inline UInt32 CountLeadingZeroes(UInt32 arg) 63 | { 64 | // GNUC / LLVM has a builtin 65 | #if defined(__GNUC__) 66 | // on llvm and clang the result is defined for 0 67 | #if (TARGET_CPU_X86 || TARGET_CPU_X86_64) && !defined(__llvm__) 68 | if (arg == 0) return 32; 69 | #endif // TARGET_CPU_X86 || TARGET_CPU_X86_64 70 | return __builtin_clz(arg); 71 | #elif TARGET_OS_WIN32 72 | UInt32 tmp; 73 | __asm{ 74 | bsr eax, arg 75 | mov ecx, 63 76 | cmovz eax, ecx 77 | xor eax, 31 78 | mov tmp, eax // this moves the result in tmp to return. 79 | } 80 | return tmp; 81 | #else 82 | #error "Unsupported architecture" 83 | #endif // defined(__GNUC__) 84 | } 85 | // Alias (with different spelling) 86 | #define CountLeadingZeros CountLeadingZeroes 87 | 88 | inline UInt32 CountLeadingZeroesLong(UInt64 arg) 89 | { 90 | // GNUC / LLVM has a builtin 91 | #if defined(__GNUC__) 92 | #if (TARGET_CPU_X86 || TARGET_CPU_X86_64) && !defined(__llvm__) 93 | if (arg == 0) return 64; 94 | #endif // TARGET_CPU_X86 || TARGET_CPU_X86_64 95 | return __builtin_clzll(arg); 96 | #elif TARGET_OS_WIN32 97 | UInt32 x = CountLeadingZeroes((UInt32)(arg >> 32)); 98 | if(x < 32) 99 | return x; 100 | else 101 | return 32+CountLeadingZeroes((UInt32)arg); 102 | #else 103 | #error "Unsupported architecture" 104 | #endif // defined(__GNUC__) 105 | } 106 | #define CountLeadingZerosLong CountLeadingZeroesLong 107 | 108 | // count trailing zeroes 109 | inline UInt32 CountTrailingZeroes(UInt32 x) 110 | { 111 | return 32 - CountLeadingZeroes(~x & (x-1)); 112 | } 113 | 114 | // count leading ones 115 | inline UInt32 CountLeadingOnes(UInt32 x) 116 | { 117 | return CountLeadingZeroes(~x); 118 | } 119 | 120 | // count trailing ones 121 | inline UInt32 CountTrailingOnes(UInt32 x) 122 | { 123 | return 32 - CountLeadingZeroes(x & (~x-1)); 124 | } 125 | 126 | // number of bits required to represent x. 127 | inline UInt32 NumBits(UInt32 x) 128 | { 129 | return 32 - CountLeadingZeroes(x); 130 | } 131 | 132 | // base 2 log of next power of two greater or equal to x 133 | inline UInt32 Log2Ceil(UInt32 x) 134 | { 135 | return 32 - CountLeadingZeroes(x - 1); 136 | } 137 | 138 | // base 2 log of next power of two less or equal to x 139 | inline UInt32 Log2Floor(UInt32 x) 140 | { 141 | return 32 - CountLeadingZeroes(x) - 1; 142 | } 143 | 144 | // next power of two greater or equal to x 145 | inline UInt32 NextPowerOfTwo(UInt32 x) 146 | { 147 | return 1 << Log2Ceil(x); 148 | } 149 | 150 | // counting the one bits in a word 151 | inline UInt32 CountOnes(UInt32 x) 152 | { 153 | // secret magic algorithm for counting bits in a word. 154 | UInt32 t; 155 | x = x - ((x >> 1) & 0x55555555); 156 | t = ((x >> 2) & 0x33333333); 157 | x = (x & 0x33333333) + t; 158 | x = (x + (x >> 4)) & 0x0F0F0F0F; 159 | x = x + (x << 8); 160 | x = x + (x << 16); 161 | return x >> 24; 162 | } 163 | 164 | // counting the zero bits in a word 165 | inline UInt32 CountZeroes(UInt32 x) 166 | { 167 | return CountOnes(~x); 168 | } 169 | 170 | // return the bit position (0..31) of the least significant bit 171 | inline UInt32 LSBitPos(UInt32 x) 172 | { 173 | return CountTrailingZeroes(x & -(SInt32)x); 174 | } 175 | 176 | // isolate the least significant bit 177 | inline UInt32 LSBit(UInt32 x) 178 | { 179 | return x & -(SInt32)x; 180 | } 181 | 182 | // return the bit position (0..31) of the most significant bit 183 | inline UInt32 MSBitPos(UInt32 x) 184 | { 185 | return 31 - CountLeadingZeroes(x); 186 | } 187 | 188 | // isolate the most significant bit 189 | inline UInt32 MSBit(UInt32 x) 190 | { 191 | return 1 << MSBitPos(x); 192 | } 193 | 194 | // Division optimized for power of 2 denominators 195 | inline UInt32 DivInt(UInt32 numerator, UInt32 denominator) 196 | { 197 | if(IsPowerOfTwo(denominator)) 198 | return numerator >> (31 - CountLeadingZeroes(denominator)); 199 | else 200 | return numerator/denominator; 201 | } 202 | 203 | #endif 204 | 205 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/iPublicUtility/CADebugMacros.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: CADebugMacros.cpp 4 | Abstract: Helper class for printing debug messages 5 | Version: 1.21 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | #include "CADebugMacros.h" 51 | #include 52 | #include 53 | #if TARGET_API_MAC_OSX 54 | #include 55 | #endif 56 | 57 | #if DEBUG 58 | #include 59 | 60 | void DebugPrint(const char *fmt, ...) 61 | { 62 | va_list args; 63 | va_start(args, fmt); 64 | vprintf(fmt, args); 65 | va_end(args); 66 | } 67 | #endif // DEBUG 68 | 69 | #if TARGET_API_MAC_OSX 70 | void LogError(const char *fmt, ...) 71 | { 72 | va_list args; 73 | va_start(args, fmt); 74 | #if DEBUG 75 | vprintf(fmt, args); 76 | #endif 77 | vsyslog(LOG_ERR, fmt, args); 78 | va_end(args); 79 | } 80 | 81 | void LogWarning(const char *fmt, ...) 82 | { 83 | va_list args; 84 | va_start(args, fmt); 85 | #if DEBUG 86 | vprintf(fmt, args); 87 | #endif 88 | vsyslog(LOG_WARNING, fmt, args); 89 | va_end(args); 90 | } 91 | #endif 92 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/iPublicUtility/CADebugPrintf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | File: CADebugPrintf.cpp 3 | Abstract: CADebugPrintf.h 4 | Version: 1.01 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2012 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | //================================================================================================== 48 | // Includes 49 | //================================================================================================== 50 | 51 | // Self Include 52 | #include "CADebugPrintf.h" 53 | 54 | #if DEBUG || CoreAudio_Debug 55 | 56 | #if TARGET_OS_WIN32 57 | #include 58 | #include 59 | #include 60 | extern "C" 61 | int CAWin32DebugPrintf(char* inFormat, ...) 62 | { 63 | char theMessage[1024]; 64 | va_list theArguments; 65 | va_start(theArguments, inFormat); 66 | _vsnprintf(theMessage, 1024, inFormat, theArguments); 67 | va_end(theArguments); 68 | OutputDebugString(theMessage); 69 | return 0; 70 | } 71 | #endif 72 | 73 | #if defined(CoreAudio_UseSideFile) 74 | #include 75 | FILE* sDebugPrintfSideFile = NULL; 76 | extern "C" 77 | void OpenDebugPrintfSideFile() 78 | { 79 | if(sDebugPrintfSideFile == NULL) 80 | { 81 | char theFileName[1024]; 82 | snprintf(theFileName, sizeof(theFileName), CoreAudio_UseSideFile, getpid()); 83 | sDebugPrintfSideFile = fopen(theFileName, "a+"); 84 | DebugPrintfRtn(DebugPrintfFileComma "\n------------------------------\n"); 85 | } 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/iPublicUtility/CADebugPrintf.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: CADebugPrintf.h 3 | Abstract: Part of CoreAudio Utility Classes 4 | Version: 1.01 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2012 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | #if !defined(__CADebugPrintf_h__) 48 | #define __CADebugPrintf_h__ 49 | 50 | //============================================================================= 51 | // Includes 52 | //============================================================================= 53 | 54 | #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__) 55 | #include 56 | #else 57 | #include "CoreAudioTypes.h" 58 | #endif 59 | 60 | //============================================================================= 61 | // Macros to redirect debugging output to various logging services 62 | //============================================================================= 63 | 64 | //#define CoreAudio_UseSysLog 1 65 | //#define CoreAudio_UseSideFile "/CoreAudio-%d.txt" 66 | 67 | #if DEBUG || CoreAudio_Debug 68 | 69 | #if TARGET_OS_WIN32 70 | #if defined(__cplusplus) 71 | extern "C" 72 | #endif 73 | extern int CAWin32DebugPrintf(char* inFormat, ...); 74 | #define DebugPrintfRtn CAWin32DebugPrintf 75 | #define DebugPrintfFile 76 | #define DebugPrintfLineEnding "\n" 77 | #define DebugPrintfFileComma 78 | #else 79 | #if CoreAudio_UseSysLog 80 | #include 81 | #define DebugPrintfRtn syslog 82 | #define DebugPrintfFile LOG_NOTICE 83 | #define DebugPrintfLineEnding "" 84 | #define DebugPrintfFileComma DebugPrintfFile, 85 | #elif defined(CoreAudio_UseSideFile) 86 | #include 87 | #if defined(__cplusplus) 88 | extern "C" 89 | #endif 90 | void OpenDebugPrintfSideFile(); 91 | extern FILE* sDebugPrintfSideFile; 92 | #define DebugPrintfRtn fprintf 93 | #define DebugPrintfFile ((sDebugPrintfSideFile != NULL) ? sDebugPrintfSideFile : stderr) 94 | #define DebugPrintfLineEnding "\n" 95 | #define DebugPrintfFileComma DebugPrintfFile, 96 | #else 97 | #include 98 | #define DebugPrintfRtn fprintf 99 | #define DebugPrintfFile stderr 100 | #define DebugPrintfLineEnding "\n" 101 | #define DebugPrintfFileComma DebugPrintfFile, 102 | #endif 103 | #endif 104 | 105 | #else 106 | #define DebugPrintfRtn 107 | #define DebugPrintfFile 108 | #define DebugPrintfLineEnding 109 | #define DebugPrintfFileComma 110 | #endif 111 | 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/iPublicUtility/CAMath.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: CAMath.h 4 | Abstract: Helper class for various math functions 5 | Version: 1.21 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | #ifndef __CAMath_h__ 51 | #define __CAMath_h__ 52 | 53 | #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__) 54 | #include 55 | #else 56 | #include "CoreAudioTypes.h" 57 | #endif 58 | 59 | inline bool fiszero(double f) { return (f == 0.); } 60 | inline bool fiszero(float f) { return (f == 0.f); } 61 | 62 | inline bool fnonzero(double f) { return !fiszero(f); } 63 | inline bool fnonzero(float f) { return !fiszero(f); } 64 | 65 | inline bool fequal(const double &a, const double &b) { return a == b; } 66 | inline bool fequal(const float &a, const float &b) { return a == b; } 67 | 68 | inline bool fnotequal(const double &a, const double &b) { return !fequal(a, b); } 69 | inline bool fnotequal(const float &a, const float &b) { return !fequal(a, b); } 70 | 71 | #endif // __CAMath_h__ 72 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/iPublicUtility/CAXException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: CAXException.cpp 4 | Abstract: Helper class for excpetion handling 5 | Version: 1.21 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | 51 | #include "CAXException.h" 52 | 53 | CAXException::WarningHandler CAXException::sWarningHandler = NULL; 54 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/iPublicUtility/CoreAudioTypes.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linyehui/sonic/e1fcf22bf992ef78a913abd43ab85f10559d1b56/ios/SonicDemo/SonicDemo/iPublicUtility/CoreAudioTypes.h -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemo/main.mm: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SonicDemo 4 | // 5 | // Created by linyehui on 14-2-20. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemoTests/SonicDemoTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemoTests/SonicDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SonicDemoTests.m 3 | // SonicDemoTests 4 | // 5 | // Created by linyehui on 14-2-20. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SonicDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SonicDemoTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /ios/SonicDemo/SonicDemoTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ios/SonicEngine/SonicEngine/SonicEngine-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /ios/SonicEngine/SonicEngine/SonicGenerator.h: -------------------------------------------------------------------------------- 1 | // 2 | // SonicGenerator.h 3 | // SonicEngine 4 | // 5 | // Created by linyehui on 14-3-6. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SonicGenerator : NSObject 12 | 13 | // 传入一个10char的字符串,生成8char的rscode之后一起返回 14 | // 返回18char的code+rscode的WAV格式Buffer 15 | - (NSData *) genWaveData: (NSString *)code; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /ios/SonicEngine/SonicEngine/SonicGenerator.mm: -------------------------------------------------------------------------------- 1 | // 2 | // SonicGenerator.m 3 | // SonicEngine 4 | // 5 | // Created by linyehui on 14-3-6. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #import "SonicGenerator.h" 10 | 11 | #import "bb_header.h" 12 | #import "queue.h" 13 | #import "pcm_render.h" 14 | #import "generator_helper.h" 15 | 16 | @implementation SonicGenerator 17 | 18 | - (NSData *) genWaveData: (NSString *)code 19 | { 20 | if (!code || ![code isKindOfClass:[NSString class]] || [code length] != RS_DATA_LEN) 21 | return nil; 22 | 23 | const char *src = [code UTF8String]; 24 | char result_with_rs[RS_TOTAL_LEN + 1]; 25 | if (!SonicSDK::GeneratorHelper::genRSCode(src, result_with_rs, RS_TOTAL_LEN + 1)) 26 | return nil; 27 | 28 | long buffer_len_by_byte = SonicSDK::PCMRender::getChirpLengthByByte(RS_TOTAL_LEN); 29 | short* wave_buffer = (short*)malloc(buffer_len_by_byte); 30 | if (NULL == wave_buffer) 31 | return nil; 32 | 33 | unsigned char waveHeaderByteArray[SonicSDK::SONIC_HEADER_SIZE]; 34 | if (!SonicSDK::PCMRender::renderChirpData( 35 | result_with_rs, 36 | RS_TOTAL_LEN, 37 | waveHeaderByteArray, 38 | SonicSDK::SONIC_HEADER_SIZE, 39 | wave_buffer, 40 | buffer_len_by_byte)) 41 | { 42 | free(wave_buffer); 43 | return nil; 44 | } 45 | 46 | 47 | NSMutableData *chirpData = [[NSMutableData alloc] initWithBytes:waveHeaderByteArray length:sizeof(waveHeaderByteArray)]; 48 | [chirpData appendBytes:wave_buffer length:(buffer_len_by_byte)]; 49 | 50 | free(wave_buffer); 51 | 52 | return chirpData; 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /ios/SonicEngine/SonicEngine/SonicListener.h: -------------------------------------------------------------------------------- 1 | // 2 | // SonicListener.h 3 | // 4 | // 5 | // Created by linyehui on 14-2-19. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #import 10 | #include "CAStreamBasicDescription.h" 11 | 12 | @interface SonicListener : NSObject 13 | { 14 | } 15 | 16 | - (void)initFFTMgr:(UInt32) inNumberFrames; 17 | - (void)grabAudioData: (AudioBufferList *) inBL; 18 | - (NSString*)computeWave; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /ios/SonicEngine/SonicEngine/SonicListener.mm: -------------------------------------------------------------------------------- 1 | // 2 | // SonicListener.mm 3 | // 4 | // 5 | // Created by linyehui on 14-2-19. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #import "SonicListener.h" 10 | #import "listener_helper.h" 11 | 12 | @implementation SonicListener 13 | 14 | -(void)dealloc 15 | { 16 | SonicSDK::ListenerHelper::instance()->release(); 17 | [super dealloc]; 18 | } 19 | 20 | - (void)initFFTMgr:(UInt32) inNumberFrames 21 | { 22 | SonicSDK::ListenerHelper::instance()->initFFTMgr(inNumberFrames); 23 | } 24 | 25 | - (void)grabAudioData: (AudioBufferList *) inBL 26 | { 27 | SonicSDK::ListenerHelper::instance()->grabAudioData(inBL); 28 | } 29 | 30 | - (NSString*)computeWave 31 | { 32 | char code[10] = {0}; 33 | if (SonicSDK::ListenerHelper::instance()->computeWave(code, 10)) 34 | { 35 | NSMutableString *string_code = [NSMutableString stringWithFormat:@""]; 36 | for (int i = 0; i < 10; i++) 37 | { 38 | [string_code appendFormat:@"%c", code[i]]; 39 | } 40 | 41 | return string_code; 42 | } 43 | else 44 | { 45 | return nil; 46 | } 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /ios/SonicEngine/SonicEngineTests/SonicEngineTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.linyehui.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /ios/SonicEngine/SonicEngineTests/SonicEngineTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SonicEngineTests.m 3 | // SonicEngineTests 4 | // 5 | // Created by linyehui on 14-2-19. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SonicEngineTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SonicEngineTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /ios/SonicEngine/SonicEngineTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ios/sonic.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sdk/FFTBufferManager/FFTBufferManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: FFTBufferManager.cpp 4 | Abstract: This class manages buffering and computation for FFT analysis on input audio data. The methods provided are used to grab the audio, buffer it, and perform the FFT when sufficient data is available 5 | Version: 1.0 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | #include 51 | #include "FFTBufferManager.h" 52 | #include "CABitOperations.h" 53 | #include "CAStreamBasicDescription.h" 54 | 55 | #include "../iPublicUtility/VectorMath.h" 56 | 57 | #define min(x,y) (x < y) ? x : y 58 | 59 | FFTBufferManager::FFTBufferManager(unsigned long inNumberFrames) : 60 | mNeedsAudioData(0), 61 | mHasAudioData(0), 62 | mFFTNormFactor(1.0/(2*inNumberFrames)), 63 | mAdjust0DB(1.5849e-13), 64 | m24BitFracScale(16777216.0f), 65 | mFFTLength(inNumberFrames/2), 66 | mLog2N(Log2Ceil(inNumberFrames)), 67 | mNumberFrames(inNumberFrames), 68 | mAudioBufferSize(inNumberFrames * sizeof(float)), 69 | mAudioBufferCurrentIndex(0) 70 | 71 | { 72 | mAudioBuffer = (float*) calloc(mNumberFrames,sizeof(float)); 73 | 74 | //mDspSplitComplex.realp = (float*) calloc(mFFTLength,sizeof(float)); 75 | //mDspSplitComplex.imagp = (float*) calloc(mFFTLength, sizeof(float)); 76 | mSplitComplexRe = (float*) calloc(mFFTLength,sizeof(float)); 77 | mSplitComplexIm = (float*) calloc(mFFTLength,sizeof(float)); 78 | 79 | //mSpectrumAnalysis = vDSP_create_fftsetup(mLog2N, kFFTRadix2); 80 | mKissFFTCfg = kiss_fft_alloc(mFFTLength, 0, NULL, NULL); 81 | OSAtomicIncrement32Barrier(&mNeedsAudioData); 82 | } 83 | 84 | FFTBufferManager::~FFTBufferManager() 85 | { 86 | //vDSP_destroy_fftsetup(mSpectrumAnalysis); 87 | kiss_fft_cleanup(); 88 | free(mAudioBuffer); 89 | //free (mDspSplitComplex.realp); 90 | //free (mDspSplitComplex.imagp); 91 | free (mSplitComplexRe); 92 | free (mSplitComplexIm); 93 | } 94 | 95 | void FFTBufferManager::GrabAudioData(AudioBufferList *inBL) 96 | { 97 | if (mAudioBufferSize < inBL->mBuffers[0].mDataByteSize) return; 98 | 99 | unsigned long bytesToCopy = min(inBL->mBuffers[0].mDataByteSize, mAudioBufferSize - mAudioBufferCurrentIndex); 100 | memcpy((char*)mAudioBuffer+mAudioBufferCurrentIndex, inBL->mBuffers[0].mData, bytesToCopy); 101 | 102 | mAudioBufferCurrentIndex += bytesToCopy / sizeof(float); 103 | if (mAudioBufferCurrentIndex >= mAudioBufferSize / sizeof(float)) 104 | { 105 | OSAtomicIncrement32Barrier(&mHasAudioData); 106 | OSAtomicDecrement32Barrier(&mNeedsAudioData); 107 | } 108 | } 109 | 110 | bool FFTBufferManager::ComputeFFT(int32_t *outFFTData) 111 | { 112 | if (HasNewAudioData()) 113 | { 114 | kiss_fft_stride(mKissFFTCfg, (const kiss_fft_cpx *)mAudioBuffer, (kiss_fft_cpx *)mAudioBuffer, 1); 115 | 116 | //Generate a split complex vector from the real data 117 | //vDSP_ctoz((COMPLEX *)mAudioBuffer, 2, &mDspSplitComplex, 1, mFFTLength); 118 | WebCore::VectorMath::ctoz((WebCore::VectorMath::Complex *)mAudioBuffer, 2, mSplitComplexRe, mSplitComplexIm, 1, mFFTLength); 119 | 120 | //Take the fft and scale appropriately 121 | //vDSP_fft_zrip(mSpectrumAnalysis, &mDspSplitComplex, 1, mLog2N, kFFTDirection_Forward); 122 | 123 | //vDSP_vsmul(mDspSplitComplex.realp, 1, &mFFTNormFactor, mDspSplitComplex.realp, 1, mFFTLength); 124 | WebCore::VectorMath::vsmul(mSplitComplexRe, 1, &mFFTNormFactor, mSplitComplexRe, 1, mFFTLength); 125 | 126 | //vDSP_vsmul(mDspSplitComplex.imagp, 1, &mFFTNormFactor, mDspSplitComplex.imagp, 1, mFFTLength); 127 | WebCore::VectorMath::vsmul(mSplitComplexIm, 1, &mFFTNormFactor, mSplitComplexIm, 1, mFFTLength); 128 | 129 | //Zero out the nyquist value 130 | mSplitComplexIm[0] = 0.0; 131 | 132 | //Convert the fft data to dB 133 | float tmpData[mFFTLength]; 134 | //vDSP_zvmags(&mDspSplitComplex, 1, tmpData, 1, mFFTLength); 135 | WebCore::VectorMath::zvmags(mSplitComplexRe, mSplitComplexIm, 1, tmpData, 1, mFFTLength); 136 | 137 | //In order to avoid taking log10 of zero, an adjusting factor is added in to make the minimum value equal -128dB 138 | //vDSP_vsadd(tmpData, 1, &mAdjust0DB, tmpData, 1, mFFTLength); 139 | WebCore::VectorMath::vsadd(tmpData, 1, &mAdjust0DB, tmpData, 1, mFFTLength); 140 | 141 | float one = 1; 142 | //vDSP_vdbcon(tmpData, 1, &one, tmpData, 1, mFFTLength, 0); 143 | WebCore::VectorMath::vdbcon(tmpData, 1, &one, tmpData, 1, mFFTLength, 0); 144 | 145 | //Convert floating point data to integer (Q7.24) 146 | //vDSP_vsmul(tmpData, 1, &m24BitFracScale, tmpData, 1, mFFTLength); 147 | WebCore::VectorMath::vsmul(tmpData, 1, &m24BitFracScale, tmpData, 1, mFFTLength); 148 | 149 | for(unsigned long i=0; i 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "queue.h" 22 | 23 | 24 | #define PI 3.1415926535897932384626433832795028841971 //定义圆周率值 25 | #define SAMPLE_RATE 44100 //采样频率 26 | 27 | #define BB_SEMITONE 1.05946311 28 | #define BB_BASEFREQUENCY 1760 29 | #define BB_BASEFREQUENCY_H 18032 30 | #define BB_BASEFREQUENCY_IS_H 1 31 | 32 | #define BB_CHARACTERS "0123456789abcdefghijklmnopqrstuv" 33 | 34 | #define BB_FREQUENCIES {1765,1856,1986,2130,2211,2363,2492,2643,2799,2964,3243,3316,3482,3751,3987,4192,4430,4794,5000,5449,5598,5900,6262,6627,7004,7450,7881,8174,8906,9423,9948,10536} 35 | 36 | #define BB_THRESHOLD 16 37 | 38 | #define BB_HEADER_0 17 39 | #define BB_HEADER_1 19 40 | 41 | typedef struct _bb_item_group bb_item_group; 42 | 43 | typedef float element; 44 | 45 | typedef struct { 46 | 47 | int num; 48 | int m; 49 | int r; 50 | int r_; 51 | int l; 52 | int l_; 53 | } struct_tmp; 54 | 55 | //void freq_init(); 56 | 57 | void switch_freq(int is_high); 58 | 59 | int freq_to_num(unsigned int f, int *n); 60 | 61 | int num_to_char(int n, char *c); 62 | 63 | int char_to_num(char c, unsigned int *n); 64 | 65 | int num_to_freq(int n, unsigned int *f); 66 | 67 | int char_to_freq(char c, unsigned int *f); 68 | 69 | int vote(int *src, int src_len, int *result); 70 | 71 | int multi_vote(int *src, int src_len, int *result, int res_len, int vote_res); 72 | 73 | int multi_vote_accurate(int *src, int src_len, int *result, int res_len, int vote_res); 74 | 75 | int statistics(int *src, int src_len, int *result, int res_len); 76 | 77 | int compose_statistics(int *src_vote, int *src_statics, int src_len, int *result, int res_len); 78 | 79 | ///////// 80 | int set_group(int *src, int src_len, bb_item_group *result, int res_len); 81 | 82 | int process_group(bb_item_group *src, int src_len); 83 | 84 | int get_group_data(bb_item_group *src, int src_len, int *result, int res_len); 85 | 86 | int post_process(bb_item_group *src, int src_len, bb_item_group *result, int res_len); 87 | 88 | ///////// 89 | int encode_sound(unsigned int freq, float buffer[], size_t buffer_length); 90 | 91 | int create_sending_code(unsigned char *src, unsigned char *result, int res_len); 92 | 93 | int decode_sound(short *src, int fft_number); 94 | 95 | int fft(void *src, int num); 96 | 97 | ///////// 98 | 99 | int statistics_2(int *src, int src_len, int *result, int res_len); 100 | int process_group_2(bb_item_group *src, int src_len); 101 | int post_process_2(bb_item_group *src, int src_len, bb_item_group *result, int res_len); 102 | 103 | void _medianfilter(const element* signal, element* result, int N); 104 | 105 | ////////// V2.0 106 | 107 | void generate_data(queue *que, int que_length, int *res, int *rrr, int res_length, float minValue, float maxValue); 108 | 109 | int array_search(int num, int a[], int array_length); 110 | 111 | int isset_struct(struct_tmp tmp_x); 112 | 113 | int isset_num(int num); 114 | 115 | void unset(struct_tmp *const tmp_x); 116 | 117 | int partions(float l[],int low,int high); 118 | 119 | void k_qsort(float l[],int low,int high); 120 | 121 | void quicksort(float l[],int n); 122 | 123 | #endif /* BBSDK_bb_freq_util_h */ 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /sdk/freq_util/bb_header.h: -------------------------------------------------------------------------------- 1 | // 2 | // bb_header.h 3 | // BBSDK 4 | // 5 | // Created by Littlebox on 13-5-15. 6 | // Copyright (c) 2013年 Littlebox. All rights reserved. 7 | // 8 | 9 | #ifndef BBSDK_bb_header_h 10 | #define BBSDK_bb_header_h 11 | 12 | #include "bb_freq_util.h" 13 | #include "rscode.h" 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /sdk/generator_helper/generator_helper.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // generator_helper.cpp 3 | // 4 | // 5 | // Created by linyehui on 2014-02-20. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #include "generator_helper.h" 10 | #include "rscode.h" 11 | #include "bb_freq_util.h" 12 | 13 | namespace SonicSDK 14 | { 15 | bool GeneratorHelper::genRSCode(const char *src, char* result_with_rs, unsigned int result_len) 16 | { 17 | if (NULL == src 18 | || NULL == result_with_rs 19 | || result_len != (RS_TOTAL_LEN + 1)) 20 | return false; 21 | if (strlen(src) != RS_DATA_LEN) 22 | return false; 23 | 24 | unsigned char data[RS_TOTAL_LEN]; 25 | 26 | for (int i=0; i> 32)); 91 | if(x < 32) 92 | return x; 93 | else 94 | return 32+CountLeadingZeroes((unsigned long)arg); 95 | #else 96 | #error "Unsupported architecture" 97 | #endif // defined(__GNUC__) 98 | } 99 | #define CountLeadingZerosLong CountLeadingZeroesLong 100 | 101 | // count trailing zeroes 102 | inline unsigned long CountTrailingZeroes(unsigned long x) 103 | { 104 | return 32 - CountLeadingZeroes(~x & (x-1)); 105 | } 106 | 107 | // count leading ones 108 | inline unsigned long CountLeadingOnes(unsigned long x) 109 | { 110 | return CountLeadingZeroes(~x); 111 | } 112 | 113 | // count trailing ones 114 | inline unsigned long CountTrailingOnes(unsigned long x) 115 | { 116 | return 32 - CountLeadingZeroes(x & (~x-1)); 117 | } 118 | 119 | // number of bits required to represent x. 120 | inline unsigned long NumBits(unsigned long x) 121 | { 122 | return 32 - CountLeadingZeroes(x); 123 | } 124 | 125 | // base 2 log of next power of two greater or equal to x 126 | inline unsigned long Log2Ceil(unsigned long x) 127 | { 128 | return 32 - CountLeadingZeroes(x - 1); 129 | } 130 | 131 | // base 2 log of next power of two less or equal to x 132 | inline unsigned long Log2Floor(unsigned long x) 133 | { 134 | return 32 - CountLeadingZeroes(x) - 1; 135 | } 136 | 137 | // next power of two greater or equal to x 138 | inline unsigned long NextPowerOfTwo(unsigned long x) 139 | { 140 | return 1 << Log2Ceil(x); 141 | } 142 | 143 | // counting the one bits in a word 144 | inline unsigned long CountOnes(unsigned long x) 145 | { 146 | // secret magic algorithm for counting bits in a word. 147 | unsigned long t; 148 | x = x - ((x >> 1) & 0x55555555); 149 | t = ((x >> 2) & 0x33333333); 150 | x = (x & 0x33333333) + t; 151 | x = (x + (x >> 4)) & 0x0F0F0F0F; 152 | x = x + (x << 8); 153 | x = x + (x << 16); 154 | return x >> 24; 155 | } 156 | 157 | // counting the zero bits in a word 158 | inline unsigned long CountZeroes(unsigned long x) 159 | { 160 | return CountOnes(~x); 161 | } 162 | 163 | // return the bit position (0..31) of the least significant bit 164 | inline unsigned long LSBitPos(unsigned long x) 165 | { 166 | return CountTrailingZeroes(x & -(signed long)x); 167 | } 168 | 169 | // isolate the least significant bit 170 | inline unsigned long LSBit(unsigned long x) 171 | { 172 | return x & -(signed long)x; 173 | } 174 | 175 | // return the bit position (0..31) of the most significant bit 176 | inline unsigned long MSBitPos(unsigned long x) 177 | { 178 | return 31 - CountLeadingZeroes(x); 179 | } 180 | 181 | // isolate the most significant bit 182 | inline unsigned long MSBit(unsigned long x) 183 | { 184 | return 1 << MSBitPos(x); 185 | } 186 | 187 | // Division optimized for power of 2 denominators 188 | inline unsigned long DivInt(unsigned long numerator, unsigned long denominator) 189 | { 190 | if(IsPowerOfTwo(denominator)) 191 | return numerator >> (31 - CountLeadingZeroes(denominator)); 192 | else 193 | return numerator/denominator; 194 | } 195 | 196 | #endif 197 | 198 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/CADebugMacros.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: CADebugMacros.cpp 4 | Abstract: Helper class for printing debug messages 5 | Version: 1.21 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | #include "CADebugMacros.h" 51 | #include 52 | #include 53 | #if TARGET_API_MAC_OSX 54 | #include 55 | #endif 56 | 57 | #if DEBUG 58 | #include 59 | 60 | void DebugPrint(const char *fmt, ...) 61 | { 62 | va_list args; 63 | va_start(args, fmt); 64 | vprintf(fmt, args); 65 | va_end(args); 66 | } 67 | #endif // DEBUG 68 | 69 | #if TARGET_API_MAC_OSX 70 | void LogError(const char *fmt, ...) 71 | { 72 | va_list args; 73 | va_start(args, fmt); 74 | #if DEBUG 75 | vprintf(fmt, args); 76 | #endif 77 | vsyslog(LOG_ERR, fmt, args); 78 | va_end(args); 79 | } 80 | 81 | void LogWarning(const char *fmt, ...) 82 | { 83 | va_list args; 84 | va_start(args, fmt); 85 | #if DEBUG 86 | vprintf(fmt, args); 87 | #endif 88 | vsyslog(LOG_WARNING, fmt, args); 89 | va_end(args); 90 | } 91 | #endif 92 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/CADebugPrintf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | File: CADebugPrintf.cpp 3 | Abstract: CADebugPrintf.h 4 | Version: 1.01 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2012 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | //================================================================================================== 48 | // Includes 49 | //================================================================================================== 50 | 51 | // Self Include 52 | #include "CADebugPrintf.h" 53 | 54 | #if DEBUG || CoreAudio_Debug 55 | 56 | #if TARGET_OS_WIN32 57 | #include 58 | #include 59 | #include 60 | extern "C" 61 | int CAWin32DebugPrintf(char* inFormat, ...) 62 | { 63 | char theMessage[1024]; 64 | va_list theArguments; 65 | va_start(theArguments, inFormat); 66 | _vsnprintf(theMessage, 1024, inFormat, theArguments); 67 | va_end(theArguments); 68 | OutputDebugString(theMessage); 69 | return 0; 70 | } 71 | #endif 72 | 73 | #if defined(CoreAudio_UseSideFile) 74 | #include 75 | FILE* sDebugPrintfSideFile = NULL; 76 | extern "C" 77 | void OpenDebugPrintfSideFile() 78 | { 79 | if(sDebugPrintfSideFile == NULL) 80 | { 81 | char theFileName[1024]; 82 | snprintf(theFileName, sizeof(theFileName), CoreAudio_UseSideFile, getpid()); 83 | sDebugPrintfSideFile = fopen(theFileName, "a+"); 84 | DebugPrintfRtn(DebugPrintfFileComma "\n------------------------------\n"); 85 | } 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/CADebugPrintf.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: CADebugPrintf.h 3 | Abstract: Part of CoreAudio Utility Classes 4 | Version: 1.01 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2012 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | #if !defined(__CADebugPrintf_h__) 48 | #define __CADebugPrintf_h__ 49 | 50 | //============================================================================= 51 | // Includes 52 | //============================================================================= 53 | 54 | #include "CoreAudioTypes.h" 55 | 56 | //============================================================================= 57 | // Macros to redirect debugging output to various logging services 58 | //============================================================================= 59 | 60 | //#define CoreAudio_UseSysLog 1 61 | //#define CoreAudio_UseSideFile "/CoreAudio-%d.txt" 62 | 63 | #if DEBUG || CoreAudio_Debug 64 | 65 | #if TARGET_OS_WIN32 66 | #if defined(__cplusplus) 67 | extern "C" 68 | #endif 69 | extern int CAWin32DebugPrintf(char* inFormat, ...); 70 | #define DebugPrintfRtn CAWin32DebugPrintf 71 | #define DebugPrintfFile 72 | #define DebugPrintfLineEnding "\n" 73 | #define DebugPrintfFileComma 74 | #else 75 | #if CoreAudio_UseSysLog 76 | #include 77 | #define DebugPrintfRtn syslog 78 | #define DebugPrintfFile LOG_NOTICE 79 | #define DebugPrintfLineEnding "" 80 | #define DebugPrintfFileComma DebugPrintfFile, 81 | #elif defined(CoreAudio_UseSideFile) 82 | #include 83 | #if defined(__cplusplus) 84 | extern "C" 85 | #endif 86 | void OpenDebugPrintfSideFile(); 87 | extern FILE* sDebugPrintfSideFile; 88 | #define DebugPrintfRtn fprintf 89 | #define DebugPrintfFile ((sDebugPrintfSideFile != NULL) ? sDebugPrintfSideFile : stderr) 90 | #define DebugPrintfLineEnding "\n" 91 | #define DebugPrintfFileComma DebugPrintfFile, 92 | #else 93 | #include 94 | #define DebugPrintfRtn fprintf 95 | #define DebugPrintfFile stderr 96 | #define DebugPrintfLineEnding "\n" 97 | #define DebugPrintfFileComma DebugPrintfFile, 98 | #endif 99 | #endif 100 | 101 | #else 102 | #define DebugPrintfRtn 103 | #define DebugPrintfFile 104 | #define DebugPrintfLineEnding 105 | #define DebugPrintfFileComma 106 | #endif 107 | 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/CAMath.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: CAMath.h 4 | Abstract: Helper class for various math functions 5 | Version: 1.21 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | #ifndef __CAMath_h__ 51 | #define __CAMath_h__ 52 | 53 | #include "CoreAudioTypes.h" 54 | 55 | inline bool fiszero(double f) { return (f == 0.); } 56 | inline bool fiszero(float f) { return (f == 0.f); } 57 | 58 | inline bool fnonzero(double f) { return !fiszero(f); } 59 | inline bool fnonzero(float f) { return !fiszero(f); } 60 | 61 | inline bool fequal(const double &a, const double &b) { return a == b; } 62 | inline bool fequal(const float &a, const float &b) { return a == b; } 63 | 64 | inline bool fnotequal(const double &a, const double &b) { return !fequal(a, b); } 65 | inline bool fnotequal(const float &a, const float &b) { return !fequal(a, b); } 66 | 67 | #endif // __CAMath_h__ 68 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/CAXException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: CAXException.cpp 4 | Abstract: Helper class for excpetion handling 5 | Version: 1.21 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | 51 | #include "CAXException.h" 52 | 53 | CAXException::WarningHandler CAXException::sWarningHandler = NULL; 54 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/CAXException.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: CAXException.h 4 | Abstract: Helper class for excpetion handling 5 | Version: 1.21 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 46 | 47 | 48 | */ 49 | 50 | 51 | #ifndef __CAXException_h__ 52 | #define __CAXException_h__ 53 | 54 | #include "CFByteOrder.h" 55 | #include "CADebugMacros.h" 56 | 57 | #include 58 | #include 59 | #include 60 | 61 | class CAX4CCString { 62 | public: 63 | CAX4CCString(signed long error) { 64 | // see if it appears to be a 4-char-code 65 | char *str = mStr; 66 | *(unsigned long *)(str + 1) = CFSwapInt32HostToBig(error); 67 | if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) { 68 | str[0] = str[5] = '\''; 69 | str[6] = '\0'; 70 | } else if (error > -200000 && error < 200000) 71 | // no, format it as an integer 72 | sprintf(str, "%d", (int)error); 73 | else 74 | sprintf(str, "0x%x", (int)error); 75 | } 76 | const char *get() const { return mStr; } 77 | operator const char *() const { return mStr; } 78 | private: 79 | char mStr[16]; 80 | }; 81 | 82 | // An extended exception class that includes the name of the failed operation 83 | class CAXException { 84 | public: 85 | CAXException(const char *operation, signed long err) : 86 | mError(err) 87 | { 88 | if (operation == NULL) 89 | mOperation[0] = '\0'; 90 | else if (strlen(operation) >= sizeof(mOperation)) { 91 | memcpy(mOperation, operation, sizeof(mOperation) - 1); 92 | mOperation[sizeof(mOperation) - 1] = '\0'; 93 | } else 94 | strcpy(mOperation, operation); 95 | } 96 | 97 | char *FormatError(char *str) const 98 | { 99 | return FormatError(str, mError); 100 | } 101 | 102 | char mOperation[256]; 103 | const signed long mError; 104 | 105 | // ------------------------------------------------- 106 | 107 | typedef void (*WarningHandler)(const char *msg, signed long err); 108 | 109 | static char *FormatError(char *str, signed long error) 110 | { 111 | strcpy(str, CAX4CCString(error)); 112 | return str; 113 | } 114 | 115 | static void Warning(const char *s, signed long error) 116 | { 117 | if (sWarningHandler) 118 | (*sWarningHandler)(s, error); 119 | } 120 | 121 | static void SetWarningHandler(WarningHandler f) { sWarningHandler = f; } 122 | private: 123 | static WarningHandler sWarningHandler; 124 | }; 125 | 126 | #if DEBUG || CoreAudio_Debug 127 | #define XThrowIfError(error, operation) \ 128 | do { \ 129 | signed long __err = error; \ 130 | if (__err) { \ 131 | DebugMessageN2("about to throw %s: %s", CAX4CCString(error).get(), operation);\ 132 | STOP; \ 133 | throw CAXException(operation, __err); \ 134 | } \ 135 | } while (0) 136 | 137 | #define XThrowIf(condition, error, operation) \ 138 | do { \ 139 | if (condition) { \ 140 | signed long __err = error; \ 141 | DebugMessageN2("about to throw %s: %s", CAX4CCString(error).get(), operation);\ 142 | STOP; \ 143 | throw CAXException(operation, __err); \ 144 | } \ 145 | } while (0) 146 | 147 | #define XRequireNoError(error, label) \ 148 | do { \ 149 | signed long __err = error; \ 150 | if (__err) { \ 151 | DebugMessageN2("about to throw %s: %s", CAX4CCString(error).get(), #error);\ 152 | STOP; \ 153 | goto label; \ 154 | } \ 155 | } while (0) 156 | 157 | #define XAssert(assertion) \ 158 | do { \ 159 | if (!(assertion)) { \ 160 | DebugMessageN1("error: failed assertion: %s", #assertion);\ 161 | STOP; \ 162 | } \ 163 | } while (0) 164 | 165 | #define XAssertNoError(error) \ 166 | do { \ 167 | signed long __err = error; \ 168 | if (__err) { \ 169 | DebugMessageN2("error %s: %s", CAX4CCString(error).get(), #error);\ 170 | STOP; \ 171 | } \ 172 | } while (0) 173 | 174 | #else 175 | #define XThrowIfError(error, operation) \ 176 | do { \ 177 | signed long __err = error; \ 178 | if (__err) { \ 179 | throw CAXException(operation, __err); \ 180 | } \ 181 | } while (0) 182 | 183 | #define XThrowIf(condition, error, operation) \ 184 | do { \ 185 | if (condition) { \ 186 | signed long __err = error; \ 187 | throw CAXException(operation, __err); \ 188 | } \ 189 | } while (0) 190 | 191 | #define XRequireNoError(error, label) \ 192 | do { \ 193 | signed long __err = error; \ 194 | if (__err) { \ 195 | goto label; \ 196 | } \ 197 | } while (0) 198 | 199 | #define XAssert(assertion) \ 200 | do { \ 201 | } while (0) 202 | 203 | #define XAssertNoError(error) \ 204 | do { \ 205 | /*signed long __err =*/ error; \ 206 | } while (0) 207 | #endif 208 | 209 | #define XThrow(error, operation) XThrowIf(true, error, operation) 210 | #define XThrowIfErr(error) XThrowIfError(error, #error) 211 | 212 | #endif // __CAXException_h__ 213 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/CoreAudioTypes.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linyehui/sonic/e1fcf22bf992ef78a913abd43ab85f10559d1b56/sdk/iPublicUtility/CoreAudioTypes.h -------------------------------------------------------------------------------- /sdk/iPublicUtility/VectorMath.h: -------------------------------------------------------------------------------- 1 | // 2 | // VectorMath.h 3 | // part of code in this file is from Webkit 4 | // 5 | // Created by linyehui on 2014-04-10. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | /* 10 | * Copyright (C) 2010, Google Inc. All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 22 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef VectorMath_h 34 | #define VectorMath_h 35 | 36 | #include 37 | 38 | // Defines the interface for several vector math functions whose implementation will ideally be optimized. 39 | 40 | namespace WebCore { 41 | 42 | namespace VectorMath { 43 | 44 | typedef struct Complex { 45 | float real; 46 | float imag; 47 | } Complex; 48 | 49 | // Vector scalar multiply and then add. 50 | void vsma(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess); 51 | 52 | void vsmul(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess); 53 | 54 | // add by linyehui 2014-03-28 11:30 55 | void ctoz (const Complex* sourceComplex, int sourceStride, float* destSplitComplexRe, float* destSplitComplexIm, int destStride, size_t framesToProcess); 56 | void vsadd(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess); 57 | void zvmags(const float* sourceRe, const float* sourceIm, int sourceStride, float* destP, int destStride, size_t framesToProcess); 58 | void vdbcon(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess, unsigned int flag); 59 | 60 | void vadd(const float* source1P, int sourceStride1, const float* source2P, int sourceStride2, float* destP, int destStride, size_t framesToProcess); 61 | 62 | // Finds the maximum magnitude of a float vector. 63 | void vmaxmgv(const float* sourceP, int sourceStride, float* maxP, size_t framesToProcess); 64 | 65 | // Sums the squares of a float vector's elements. 66 | void vsvesq(const float* sourceP, int sourceStride, float* sumP, size_t framesToProcess); 67 | 68 | // For an element-by-element multiply of two float vectors. 69 | void vmul(const float* source1P, int sourceStride1, const float* source2P, int sourceStride2, float* destP, int destStride, size_t framesToProcess); 70 | 71 | // Multiplies two complex vectors. 72 | void zvmul(const float* real1P, const float* imag1P, const float* real2P, const float* imag2P, float* realDestP, float* imagDestP, size_t framesToProcess); 73 | 74 | // Copies elements while clipping values to the threshold inputs. 75 | void vclip(const float* sourceP, int sourceStride, const float* lowThresholdP, const float* highThresholdP, float* destP, int destStride, size_t framesToProcess); 76 | 77 | } // namespace VectorMath 78 | 79 | } // namespace WebCore 80 | 81 | #endif // VectorMath_h 82 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/libkern/OSAtomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Dmitry Skiba 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _OSATOMIC_INCLUDED_ 18 | #define _OSATOMIC_INCLUDED_ 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* 27 | * Memory barrier 28 | */ 29 | 30 | void OSMemoryBarrier(void); 31 | 32 | 33 | /* 34 | * Arithmetic functions 35 | * 36 | * All functions return new value. 37 | */ 38 | 39 | int32_t OSAtomicAdd32(int32_t value,volatile int32_t* target); 40 | int32_t OSAtomicIncrement32(volatile int32_t* target); 41 | int32_t OSAtomicDecrement32(volatile int32_t* target); 42 | 43 | int32_t OSAtomicAdd32Barrier(int32_t value,volatile int32_t* target); 44 | int32_t OSAtomicIncrement32Barrier(volatile int32_t* target); 45 | int32_t OSAtomicDecrement32Barrier(volatile int32_t* target); 46 | 47 | /* 48 | int64_t OSAtomicAdd64(int64_t value,volatile int64_t* target); 49 | int64_t OSAtomicIncrement64(volatile int64_t* target); 50 | int64_t OSAtomicDecrement64(volatile int64_t* target); 51 | 52 | int64_t OSAtomicAdd64Barrier(int64_t value,volatile int64_t* target); 53 | int64_t OSAtomicIncrement64Barrier(volatile int64_t* target); 54 | int64_t OSAtomicDecrement64Barrier(volatile int64_t* target); 55 | */ 56 | 57 | /* 58 | * Bitwise functions 59 | * 60 | * 'Orig' functions return original value, others return new value. 61 | */ 62 | 63 | int32_t OSAtomicAnd32(uint32_t value,volatile uint32_t* target); 64 | int32_t OSAtomicOr32(uint32_t value,volatile uint32_t* target); 65 | int32_t OSAtomicXor32(uint32_t value,volatile uint32_t* target); 66 | 67 | int32_t OSAtomicAnd32Orig(uint32_t value,volatile uint32_t* target); 68 | int32_t OSAtomicOr32Orig(uint32_t value,volatile uint32_t* target); 69 | int32_t OSAtomicXor32Orig(uint32_t value,volatile uint32_t* target); 70 | 71 | int32_t OSAtomicAnd32Barrier(uint32_t value,volatile uint32_t* target); 72 | int32_t OSAtomicOr32Barrier(uint32_t value,volatile uint32_t* target); 73 | int32_t OSAtomicXor32Barrier(uint32_t value,volatile uint32_t* target); 74 | 75 | int32_t OSAtomicAnd32OrigBarrier(uint32_t value,volatile uint32_t* target); 76 | int32_t OSAtomicOr32OrigBarrier(uint32_t value,volatile uint32_t* target); 77 | int32_t OSAtomicXor32OrigBarrier(uint32_t value,volatile uint32_t* target); 78 | 79 | /* 80 | * Compare-and-swap functions 81 | * 82 | * Functions return 1 if swap occurred, 0 otherwise. 83 | */ 84 | 85 | int OSAtomicCompareAndSwapInt(int oldValue,int newValue,volatile int* target); 86 | int OSAtomicCompareAndSwapPtr(void* oldValue,void* newValue,void* volatile* target); 87 | int OSAtomicCompareAndSwapLong(long oldValue,long newValue,volatile long* target); 88 | int OSAtomicCompareAndSwap32(int32_t oldValue,int32_t newValue,volatile int32_t* target); 89 | 90 | int OSAtomicCompareAndSwapIntBarrier(int oldValue,int newValue,volatile int* target); 91 | int OSAtomicCompareAndSwapPtrBarrier(void* oldValue,void* newValue,void* volatile* target); 92 | int OSAtomicCompareAndSwapLongBarrier(long oldValue,long newValue,volatile long* target); 93 | int OSAtomicCompareAndSwap32Barrier(int32_t oldValue,int32_t newValue,volatile int32_t* target); 94 | 95 | /* 96 | int OSAtomicCompareAndSwap64(int64_t oldValue,int64_t newValue,volatile int64_t* target); 97 | int OSAtomicCompareAndSwap64Barrier(int64_t oldValue,int64_t newValue,volatile int64_t* target); 98 | */ 99 | 100 | /* 101 | * Bit functions 102 | * 103 | * Lowest bit has index of 1, 'bit/8' specifies byte in target. 104 | * Functions return original value of the bit (1 or 0). 105 | */ 106 | 107 | /* 108 | int OSAtomicTestAndSet(uint32_t bit,volatile void* target); 109 | int OSAtomicTestAndClear(uint32_t bit,volatile void* target); 110 | 111 | int OSAtomicTestAndSetBarrier(uint32_t bit,volatile void* target); 112 | int OSAtomicTestAndClearBarrier(uint32_t bit,volatile void* target); 113 | */ 114 | 115 | /* 116 | * Spinlock 117 | */ 118 | 119 | typedef int32_t OSSpinLock; 120 | 121 | #define OS_SPINLOCK_INIT 0 122 | 123 | /* OSSpinLockTry returns 1 on success, 0 otherwise. */ 124 | int OSSpinLockTry(volatile OSSpinLock* lock); 125 | 126 | void OSSpinLockLock(volatile OSSpinLock* lock); 127 | void OSSpinLockUnlock(volatile OSSpinLock* lock); 128 | 129 | /* 130 | * Atomic queue 131 | * 132 | * Not yet implemented. 133 | */ 134 | 135 | /* 136 | typedef struct { 137 | ??? 138 | } OSQueueHead; 139 | 140 | #define OS_ATOMIC_QUEUE_INIT {...} 141 | 142 | void OSAtomicEnqueue(OSQueueHead* list,void* item,size_t offset); 143 | void* OSAtomicDequeue(OSQueueHead* list,size_t offset); 144 | */ 145 | 146 | #ifdef __cplusplus 147 | } 148 | #endif 149 | 150 | #endif /* _OSATOMIC_INCLUDED_ */ 151 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/libkern/android/OSAtomic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Dmitry Skiba 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | //#include "android_atomic.h" 20 | #include "cutils/atomic.h" 21 | /* 22 | * Memory barrier 23 | */ 24 | 25 | void OSMemoryBarrier(void) { 26 | /*noop*/ 27 | } 28 | 29 | /* 30 | * Arithmetic functions 31 | */ 32 | 33 | int32_t OSAtomicAdd32(int32_t value,volatile int32_t* target) { 34 | return android_atomic_add(value,target) + value; 35 | } 36 | int32_t OSAtomicAdd32Barrier(int32_t value,volatile int32_t* target) { 37 | return OSAtomicAdd32(value,target); 38 | } 39 | 40 | /* 41 | int64_t OSAtomicAdd64(int64_t value,volatile int64_t* target); 42 | int64_t OSAtomicIncrement64(volatile int64_t* target); 43 | int64_t OSAtomicDecrement64(volatile int64_t* target); 44 | 45 | int64_t OSAtomicAdd64Barrier(int64_t value,volatile int64_t* target); 46 | int64_t OSAtomicIncrement64Barrier(volatile int64_t* target); 47 | int64_t OSAtomicDecrement64Barrier(volatile int64_t* target); 48 | */ 49 | 50 | /* inlines */ 51 | 52 | int32_t OSAtomicIncrement32(volatile int32_t* target) { 53 | return OSAtomicAdd32(1,target); 54 | } 55 | int32_t OSAtomicDecrement32(volatile int32_t* target) { 56 | return OSAtomicAdd32(-1,target); 57 | } 58 | int32_t OSAtomicIncrement32Barrier(volatile int32_t* target) { 59 | return OSAtomicAdd32Barrier(1,target); 60 | } 61 | int32_t OSAtomicDecrement32Barrier(volatile int32_t* target) { 62 | return OSAtomicAdd32Barrier(-1,target); 63 | } 64 | 65 | /* 66 | * Bitwise functions 67 | */ 68 | 69 | int32_t OSAtomicAnd32Orig(uint32_t value,volatile uint32_t* target) { 70 | return android_atomic_and(value,target); 71 | } 72 | int32_t OSAtomicAnd32OrigBarrier(uint32_t value,volatile uint32_t* target) { 73 | return OSAtomicAnd32Orig(value,target); 74 | } 75 | 76 | int32_t OSAtomicOr32Orig(uint32_t value,volatile uint32_t* target) { 77 | return android_atomic_or(value,target); 78 | } 79 | int32_t OSAtomicOr32OrigBarrier(uint32_t value,volatile uint32_t* target) { 80 | return OSAtomicOr32Orig(value,target); 81 | } 82 | 83 | //int32_t OSAtomicXor32Orig(uint32_t value,volatile uint32_t* target) { 84 | // return android_atomic_xor(value,target); 85 | //} 86 | //int32_t OSAtomicXor32OrigBarrier(uint32_t value,volatile uint32_t* target) { 87 | // return OSAtomicXor32Orig(value,target); 88 | //} 89 | 90 | /* inlines */ 91 | 92 | int32_t OSAtomicAnd32(uint32_t value,volatile uint32_t* target) { 93 | return OSAtomicAnd32Orig(value,target) & value; 94 | } 95 | int32_t OSAtomicOr32(uint32_t value,volatile uint32_t* target) { 96 | return OSAtomicOr32Orig(value,target) | value; 97 | } 98 | //int32_t OSAtomicXor32(uint32_t value,volatile uint32_t* target) { 99 | // return OSAtomicXor32Orig(value,target) ^ value; 100 | //} 101 | 102 | int32_t OSAtomicAnd32Barrier(uint32_t value,volatile uint32_t* target) { 103 | return OSAtomicAnd32OrigBarrier(value,target) & value; 104 | } 105 | int32_t OSAtomicOr32Barrier(uint32_t value,volatile uint32_t* target) { 106 | return OSAtomicOr32OrigBarrier(value,target) | value; 107 | } 108 | //int32_t OSAtomicXor32Barrier(uint32_t value,volatile uint32_t* target) { 109 | // return OSAtomicXor32OrigBarrier(value,target) ^ value; 110 | //} 111 | 112 | /* 113 | * Compare-and-swap functions 114 | */ 115 | 116 | int OSAtomicCompareAndSwapInt(int oldValue,int newValue,volatile int* target) { 117 | return !android_atomic_cmpxchg(oldValue,newValue,target); 118 | } 119 | int OSAtomicCompareAndSwapIntBarrier(int oldValue,int newValue,volatile int* target) { 120 | return OSAtomicCompareAndSwapInt(oldValue,newValue,target); 121 | } 122 | 123 | /* 124 | int OSAtomicCompareAndSwap64(int64_t oldValue,int64_t newValue,volatile int64_t* target); 125 | int OSAtomicCompareAndSwap64Barrier(int64_t oldValue,int64_t newValue,volatile int64_t* target); 126 | */ 127 | 128 | /* inlines */ 129 | 130 | int OSAtomicCompareAndSwapPtr(void* oldValue,void* newValue,void* volatile* target) { 131 | return OSAtomicCompareAndSwapInt((int)oldValue,(int)newValue,(volatile int*)target); 132 | } 133 | int OSAtomicCompareAndSwapLong(long oldValue,long newValue,volatile long* target) { 134 | return OSAtomicCompareAndSwapInt((int)oldValue,(int)newValue,(volatile int*)target); 135 | } 136 | int OSAtomicCompareAndSwap32(int32_t oldValue,int32_t newValue,volatile int32_t* target) { 137 | return OSAtomicCompareAndSwapInt((int)oldValue,(int)newValue,(volatile int*)target); 138 | } 139 | 140 | int OSAtomicCompareAndSwapPtrBarrier(void* oldValue,void* newValue,void* volatile* target) { 141 | return OSAtomicCompareAndSwapIntBarrier((int)oldValue,(int)newValue,(volatile int*)target); 142 | } 143 | int OSAtomicCompareAndSwapLongBarrier(long oldValue,long newValue,volatile long* target) { 144 | return OSAtomicCompareAndSwapIntBarrier((int)oldValue,(int)newValue,(volatile int*)target); 145 | } 146 | int OSAtomicCompareAndSwap32Barrier(int32_t oldValue,int32_t newValue,volatile int32_t* target) { 147 | return OSAtomicCompareAndSwapIntBarrier((int)oldValue,(int)newValue,(volatile int*)target); 148 | } 149 | 150 | /* 151 | * Bit functions 152 | */ 153 | 154 | /* 155 | int OSAtomicTestAndSet(uint32_t bit,volatile void* target); 156 | int OSAtomicTestAndSetBarrier(uint32_t bit,volatile void* target); 157 | int OSAtomicTestAndClear(uint32_t bit,volatile void* target); 158 | int OSAtomicTestAndClearBarrier(uint32_t bit,volatile void* target); 159 | */ 160 | 161 | /* 162 | * Atomic queue 163 | */ 164 | 165 | /* 166 | void OSAtomicEnqueue(OSQueueHead* list,void* item,size_t offset); 167 | void* OSAtomicDequeue(OSQueueHead* list,size_t offset); 168 | */ 169 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/libkern/android/OSSpinLock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Dmitry Skiba 3 | * Copyright (C) The Android Open Source Project 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | /* 22 | * Lock a non-recursive mutex. 23 | * 24 | * There are three states: 25 | * 0 (unlocked, no contention) 26 | * 1 (locked, no contention) 27 | * 2 (locked, contention) 28 | * 29 | * Non-recursive mutexes don't use the thread-id or counter fields, and the 30 | * "type" value is zero, so the only bits that will be set are the ones in 31 | * the lock state field. 32 | */ 33 | void OSSpinLockLock(volatile OSSpinLock* lock) { 34 | /* 35 | * The common case is an unlocked mutex, so we begin by trying to 36 | * change the lock's state from 0 to 1. __atomic_cmpxchg() returns 0 37 | * if it made the swap successfully. If the result is nonzero, this 38 | * lock is already held by another thread. 39 | */ 40 | if (__atomic_cmpxchg(0, 1, lock ) != 0) { 41 | /* 42 | * We want to go to sleep until the mutex is available, which 43 | * requires promoting it to state 2. We need to swap in the new 44 | * state value and then wait until somebody wakes us up. 45 | * 46 | * __atomic_swap() returns the previous value. We swap 2 in and 47 | * see if we got zero back; if so, we have acquired the lock. If 48 | * not, another thread still holds the lock and we wait again. 49 | * 50 | * The second argument to the __futex_wait() call is compared 51 | * against the current value. If it doesn't match, __futex_wait() 52 | * returns immediately (otherwise, it sleeps for a time specified 53 | * by the third argument; 0 means sleep forever). This ensures 54 | * that the mutex is in state 2 when we go to sleep on it, which 55 | * guarantees a wake-up call. 56 | */ 57 | while (__atomic_swap(2, lock ) != 0) 58 | __futex_wait(lock, 2, 0); 59 | } 60 | } 61 | 62 | int OSSpinLockTry(volatile OSSpinLock* lock) { 63 | return __atomic_cmpxchg(0, 1, lock ) == 0; 64 | } 65 | 66 | /* 67 | * Release a non-recursive mutex. The caller is responsible for determining 68 | * that we are in fact the owner of this lock. 69 | */ 70 | void OSSpinLockUnlock(volatile OSSpinLock* lock) { 71 | /* 72 | * The mutex value will be 1 or (rarely) 2. We use an atomic decrement 73 | * to release the lock. __atomic_dec() returns the previous value; 74 | * if it wasn't 1 we have to do some additional work. 75 | */ 76 | if (__atomic_dec(lock) != 1) { 77 | /* 78 | * Start by releasing the lock. The decrement changed it from 79 | * "contended lock" to "uncontended lock", which means we still 80 | * hold it, and anybody who tries to sneak in will push it back 81 | * to state 2. 82 | * 83 | * Once we set it to zero the lock is up for grabs. We follow 84 | * this with a __futex_wake() to ensure that one of the waiting 85 | * threads has a chance to grab it. 86 | * 87 | * This doesn't cause a race with the swap/wait pair in 88 | * _normal_lock(), because the __futex_wait() call there will 89 | * return immediately if the mutex value isn't 2. 90 | */ 91 | *lock = 0; 92 | 93 | /* 94 | * Wake up one waiting thread. We don't know which thread will be 95 | * woken or when it'll start executing -- futexes make no guarantees 96 | * here. There may not even be a thread waiting. 97 | * 98 | * The newly-woken thread will replace the 0 we just set above 99 | * with 2, which means that when it eventually releases the mutex 100 | * it will also call FUTEX_WAKE. This results in one extra wake 101 | * call whenever a lock is contended, but lets us avoid forgetting 102 | * anyone without requiring us to track the number of sleepers. 103 | * 104 | * It's possible for another thread to sneak in and grab the lock 105 | * between the zero assignment above and the wake call below. If 106 | * the new thread is "slow" and holds the lock for a while, we'll 107 | * wake up a sleeper, which will swap in a 2 and then go back to 108 | * sleep since the lock is still held. If the new thread is "fast", 109 | * running to completion before we call wake, the thread we 110 | * eventually wake will find an unlocked mutex and will execute. 111 | * Either way we have correct behavior and nobody is orphaned on 112 | * the wait queue. 113 | */ 114 | __futex_wake(lock, 1); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/libkern/android/cutils/atomic-inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_ATOMIC_INLINE_H 18 | #define ANDROID_CUTILS_ATOMIC_INLINE_H 19 | 20 | /* 21 | * Inline declarations and macros for some special-purpose atomic 22 | * operations. These are intended for rare circumstances where a 23 | * memory barrier needs to be issued inline rather than as a function 24 | * call. 25 | * 26 | * Most code should not use these. 27 | * 28 | * Anything that does include this file must set ANDROID_SMP to either 29 | * 0 or 1, indicating compilation for UP or SMP, respectively. 30 | * 31 | * Macros defined in this header: 32 | * 33 | * void ANDROID_MEMBAR_FULL(void) 34 | * Full memory barrier. Provides a compiler reordering barrier, and 35 | * on SMP systems emits an appropriate instruction. 36 | */ 37 | 38 | #if !defined(ANDROID_SMP) 39 | # error "Must define ANDROID_SMP before including atomic-inline.h" 40 | #endif 41 | 42 | #if defined(__arm__) 43 | #include "./atomic-arm.h" 44 | #elif defined(__i386__) || defined(__x86_64__) 45 | #include "./atomic-x86.h" 46 | #elif defined(__sh__) 47 | /* implementation is in atomic-android-sh.c */ 48 | #else 49 | #error atomic operations are unsupported 50 | #endif 51 | 52 | #if ANDROID_SMP == 0 53 | #define ANDROID_MEMBAR_FULL android_compiler_barrier 54 | #else 55 | #define ANDROID_MEMBAR_FULL android_memory_barrier 56 | #endif 57 | 58 | #endif /* ANDROID_CUTILS_ATOMIC_INLINE_H */ 59 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/libkern/android/cutils/atomic-x86.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_ATOMIC_X86_H 18 | #define ANDROID_CUTILS_ATOMIC_X86_H 19 | 20 | #include 21 | 22 | extern inline void android_compiler_barrier(void) 23 | { 24 | __asm__ __volatile__ ("" : : : "memory"); 25 | } 26 | 27 | #if ANDROID_SMP == 0 28 | extern inline void android_memory_barrier(void) 29 | { 30 | android_compiler_barrier(); 31 | } 32 | #else 33 | extern inline void android_memory_barrier(void) 34 | { 35 | __asm__ __volatile__ ("mfence" : : : "memory"); 36 | } 37 | #endif 38 | 39 | extern inline int32_t android_atomic_acquire_load(volatile int32_t *ptr) { 40 | int32_t value = *ptr; 41 | android_compiler_barrier(); 42 | return value; 43 | } 44 | 45 | extern inline int32_t android_atomic_release_load(volatile int32_t *ptr) { 46 | android_memory_barrier(); 47 | return *ptr; 48 | } 49 | 50 | extern inline void android_atomic_acquire_store(int32_t value, 51 | volatile int32_t *ptr) { 52 | *ptr = value; 53 | android_memory_barrier(); 54 | } 55 | 56 | extern inline void android_atomic_release_store(int32_t value, 57 | volatile int32_t *ptr) { 58 | android_compiler_barrier(); 59 | *ptr = value; 60 | } 61 | 62 | extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, 63 | volatile int32_t *ptr) 64 | { 65 | int32_t prev; 66 | __asm__ __volatile__ ("lock; cmpxchgl %1, %2" 67 | : "=a" (prev) 68 | : "q" (new_value), "m" (*ptr), "0" (old_value) 69 | : "memory"); 70 | return prev != old_value; 71 | } 72 | 73 | extern inline int android_atomic_acquire_cas(int32_t old_value, 74 | int32_t new_value, 75 | volatile int32_t *ptr) 76 | { 77 | /* Loads are not reordered with other loads. */ 78 | return android_atomic_cas(old_value, new_value, ptr); 79 | } 80 | 81 | extern inline int android_atomic_release_cas(int32_t old_value, 82 | int32_t new_value, 83 | volatile int32_t *ptr) 84 | { 85 | /* Stores are not reordered with other stores. */ 86 | return android_atomic_cas(old_value, new_value, ptr); 87 | } 88 | 89 | extern inline int32_t android_atomic_swap(int32_t new_value, 90 | volatile int32_t *ptr) 91 | { 92 | __asm__ __volatile__ ("xchgl %1, %0" 93 | : "=r" (new_value) 94 | : "m" (*ptr), "0" (new_value) 95 | : "memory"); 96 | /* new_value now holds the old value of *ptr */ 97 | return new_value; 98 | } 99 | 100 | extern inline int32_t android_atomic_add(int32_t increment, 101 | volatile int32_t *ptr) 102 | { 103 | __asm__ __volatile__ ("lock; xaddl %0, %1" 104 | : "+r" (increment), "+m" (*ptr) 105 | : : "memory"); 106 | /* increment now holds the old value of *ptr */ 107 | return increment; 108 | } 109 | 110 | extern inline int32_t android_atomic_inc(volatile int32_t *addr) { 111 | return android_atomic_add(1, addr); 112 | } 113 | 114 | extern inline int32_t android_atomic_dec(volatile int32_t *addr) { 115 | return android_atomic_add(-1, addr); 116 | } 117 | 118 | extern inline int32_t android_atomic_and(int32_t value, 119 | volatile int32_t *ptr) 120 | { 121 | int32_t prev, status; 122 | do { 123 | prev = *ptr; 124 | status = android_atomic_cas(prev, prev & value, ptr); 125 | } while (__builtin_expect(status != 0, 0)); 126 | return prev; 127 | } 128 | 129 | extern inline int32_t android_atomic_or(int32_t value, volatile int32_t *ptr) 130 | { 131 | int32_t prev, status; 132 | do { 133 | prev = *ptr; 134 | status = android_atomic_cas(prev, prev | value, ptr); 135 | } while (__builtin_expect(status != 0, 0)); 136 | return prev; 137 | } 138 | 139 | #endif /* ANDROID_CUTILS_ATOMIC_X86_H */ 140 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/libkern/android/cutils/atomic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define inline 18 | 19 | #include "./atomic-inline.h" 20 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/libkern/android/cutils/atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_ATOMIC_H 18 | #define ANDROID_CUTILS_ATOMIC_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* 28 | * A handful of basic atomic operations. The appropriate pthread 29 | * functions should be used instead of these whenever possible. 30 | * 31 | * The "acquire" and "release" terms can be defined intuitively in terms 32 | * of the placement of memory barriers in a simple lock implementation: 33 | * - wait until compare-and-swap(lock-is-free --> lock-is-held) succeeds 34 | * - barrier 35 | * - [do work] 36 | * - barrier 37 | * - store(lock-is-free) 38 | * In very crude terms, the initial (acquire) barrier prevents any of the 39 | * "work" from happening before the lock is held, and the later (release) 40 | * barrier ensures that all of the work happens before the lock is released. 41 | * (Think of cached writes, cache read-ahead, and instruction reordering 42 | * around the CAS and store instructions.) 43 | * 44 | * The barriers must apply to both the compiler and the CPU. Note it is 45 | * legal for instructions that occur before an "acquire" barrier to be 46 | * moved down below it, and for instructions that occur after a "release" 47 | * barrier to be moved up above it. 48 | * 49 | * The ARM-driven implementation we use here is short on subtlety, 50 | * and actually requests a full barrier from the compiler and the CPU. 51 | * The only difference between acquire and release is in whether they 52 | * are issued before or after the atomic operation with which they 53 | * are associated. To ease the transition to C/C++ atomic intrinsics, 54 | * you should not rely on this, and instead assume that only the minimal 55 | * acquire/release protection is provided. 56 | * 57 | * NOTE: all int32_t* values are expected to be aligned on 32-bit boundaries. 58 | * If they are not, atomicity is not guaranteed. 59 | */ 60 | 61 | /* 62 | * Basic arithmetic and bitwise operations. These all provide a 63 | * barrier with "release" ordering, and return the previous value. 64 | * 65 | * These have the same characteristics (e.g. what happens on overflow) 66 | * as the equivalent non-atomic C operations. 67 | */ 68 | int32_t android_atomic_inc(volatile int32_t* addr); 69 | int32_t android_atomic_dec(volatile int32_t* addr); 70 | int32_t android_atomic_add(int32_t value, volatile int32_t* addr); 71 | int32_t android_atomic_and(int32_t value, volatile int32_t* addr); 72 | int32_t android_atomic_or(int32_t value, volatile int32_t* addr); 73 | 74 | /* 75 | * Perform an atomic load with "acquire" or "release" ordering. 76 | * 77 | * This is only necessary if you need the memory barrier. A 32-bit read 78 | * from a 32-bit aligned address is atomic on all supported platforms. 79 | */ 80 | int32_t android_atomic_acquire_load(volatile int32_t* addr); 81 | int32_t android_atomic_release_load(volatile int32_t* addr); 82 | 83 | /* 84 | * Perform an atomic store with "acquire" or "release" ordering. 85 | * 86 | * This is only necessary if you need the memory barrier. A 32-bit write 87 | * to a 32-bit aligned address is atomic on all supported platforms. 88 | */ 89 | void android_atomic_acquire_store(int32_t value, volatile int32_t* addr); 90 | void android_atomic_release_store(int32_t value, volatile int32_t* addr); 91 | 92 | /* 93 | * Unconditional swap operation with release ordering. 94 | * 95 | * Stores the new value at *addr, and returns the previous value. 96 | */ 97 | int32_t android_atomic_swap(int32_t value, volatile int32_t* addr); 98 | 99 | /* 100 | * Compare-and-set operation with "acquire" or "release" ordering. 101 | * 102 | * This returns zero if the new value was successfully stored, which will 103 | * only happen when *addr == oldvalue. 104 | * 105 | * (The return value is inverted from implementations on other platforms, 106 | * but matches the ARM ldrex/strex result.) 107 | * 108 | * Implementations that use the release CAS in a loop may be less efficient 109 | * than possible, because we re-issue the memory barrier on each iteration. 110 | */ 111 | int android_atomic_acquire_cas(int32_t oldvalue, int32_t newvalue, 112 | volatile int32_t* addr); 113 | int android_atomic_release_cas(int32_t oldvalue, int32_t newvalue, 114 | volatile int32_t* addr); 115 | 116 | /* 117 | * Aliases for code using an older version of this header. These are now 118 | * deprecated and should not be used. The definitions will be removed 119 | * in a future release. 120 | */ 121 | #define android_atomic_write android_atomic_release_store 122 | #define android_atomic_cmpxchg android_atomic_release_cas 123 | 124 | #ifdef __cplusplus 125 | } // extern "C" 126 | #endif 127 | 128 | #endif // ANDROID_CUTILS_ATOMIC_H 129 | -------------------------------------------------------------------------------- /sdk/iPublicUtility/libkern/windows/OSAtomic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Dmitry Skiba 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | /* 21 | * Memory barrier 22 | */ 23 | 24 | void OSMemoryBarrier(void) { 25 | MemoryBarrier(); 26 | } 27 | 28 | /* 29 | * Arithmetic functions 30 | */ 31 | 32 | int32_t OSAtomicAdd32Barrier(int32_t value,volatile int32_t* target) { 33 | return value+InterlockedExchangeAdd(target,value); 34 | } 35 | 36 | int32_t OSAtomicIncrement32Barrier(volatile int32_t* target) { 37 | return InterlockedIncrement(target); 38 | } 39 | 40 | int32_t OSAtomicDecrement32Barrier(volatile int32_t* target) { 41 | return InterlockedDecrement(target); 42 | } 43 | 44 | /* 45 | int64_t OSAtomicAdd64(int64_t value,volatile int64_t* target); 46 | int64_t OSAtomicIncrement64(volatile int64_t* target); 47 | int64_t OSAtomicDecrement64(volatile int64_t* target); 48 | 49 | int64_t OSAtomicAdd64Barrier(int64_t value,volatile int64_t* target); 50 | int64_t OSAtomicIncrement64Barrier(volatile int64_t* target); 51 | int64_t OSAtomicDecrement64Barrier(volatile int64_t* target); 52 | */ 53 | 54 | /* inlines */ 55 | 56 | int32_t OSAtomicAdd32(int32_t value,volatile int32_t* target) { 57 | return OSAtomicAdd32Barrier(value,target); 58 | } 59 | 60 | int32_t OSAtomicIncrement32(volatile int32_t* target) { 61 | return OSAtomicIncrement32Barrier(target); 62 | } 63 | int32_t OSAtomicDecrement32(volatile int32_t* target) { 64 | return OSAtomicDecrement32Barrier(target); 65 | } 66 | 67 | /* 68 | * Bitwise functions 69 | */ 70 | 71 | #define IMPLEMENT_BITWISE_ORIG(Name,Operator) \ 72 | int32_t Name(uint32_t value,volatile uint32_t* target) { \ 73 | while (1) { \ 74 | uint32_t targetValue=*target; \ 75 | if (targetValue==InterlockedCompareExchange( \ 76 | target,(targetValue Operator value),targetValue)) \ 77 | { \ 78 | return targetValue; \ 79 | } \ 80 | } \ 81 | } 82 | 83 | IMPLEMENT_BITWISE_ORIG(OSAtomicAnd32OrigBarrier,&); 84 | IMPLEMENT_BITWISE_ORIG(OSAtomicOr32OrigBarrier,|); 85 | IMPLEMENT_BITWISE_ORIG(OSAtomicXor32OrigBarrier,^); 86 | 87 | #undef IMPLEMENT_BITWISE_ORIG 88 | 89 | /* inlines */ 90 | 91 | int32_t OSAtomicAnd32Orig(uint32_t value,volatile uint32_t* target) { 92 | return OSAtomicAnd32OrigBarrier(value,target); 93 | } 94 | int32_t OSAtomicOr32Orig(uint32_t value,volatile uint32_t* target) { 95 | return OSAtomicOr32OrigBarrier(value,target); 96 | } 97 | int32_t OSAtomicXor32Orig(uint32_t value,volatile uint32_t* target) { 98 | return OSAtomicXor32OrigBarrier(value,target); 99 | } 100 | 101 | int32_t OSAtomicAnd32(uint32_t value,volatile uint32_t* target) { 102 | return OSAtomicAnd32Orig(value,target) & value; 103 | } 104 | int32_t OSAtomicOr32(uint32_t value,volatile uint32_t* target) { 105 | return OSAtomicOr32Orig(value,target) | value; 106 | } 107 | int32_t OSAtomicXor32(uint32_t value,volatile uint32_t* target) { 108 | return OSAtomicXor32Orig(value,target) ^ value; 109 | } 110 | 111 | int32_t OSAtomicAnd32Barrier(uint32_t value,volatile uint32_t* target) { 112 | return OSAtomicAnd32OrigBarrier(value,target) & value; 113 | } 114 | int32_t OSAtomicOr32Barrier(uint32_t value,volatile uint32_t* target) { 115 | return OSAtomicOr32OrigBarrier(value,target) | value; 116 | } 117 | int32_t OSAtomicXor32Barrier(uint32_t value,volatile uint32_t* target) { 118 | return OSAtomicXor32OrigBarrier(value,target) ^ value; 119 | } 120 | 121 | /* 122 | * Compare-and-swap functions 123 | */ 124 | 125 | int OSAtomicCompareAndSwapIntBarrier(int oldValue,int newValue,volatile int* target) { 126 | return InterlockedCompareExchange(target,newValue,oldValue)==oldValue; 127 | } 128 | 129 | int OSAtomicCompareAndSwapPtrBarrier(void* oldValue,void* newValue,void* volatile* target) { 130 | return InterlockedCompareExchangePointer(target,newValue,oldValue)==oldValue; 131 | } 132 | 133 | int OSAtomicCompareAndSwapLongBarrier(long oldValue,long newValue,volatile long* target) { 134 | return OSAtomicCompareAndSwapIntBarrier(oldValue,newValue,target); 135 | } 136 | 137 | int OSAtomicCompareAndSwap32Barrier(int32_t oldValue,int32_t newValue,volatile int32_t* target) { 138 | return OSAtomicCompareAndSwapIntBarrier(oldValue,newValue,target); 139 | } 140 | 141 | /* 142 | int OSAtomicCompareAndSwap64(int64_t oldValue,int64_t newValue,volatile int64_t* target); 143 | int OSAtomicCompareAndSwap64Barrier(int64_t oldValue,int64_t newValue,volatile int64_t* target); 144 | */ 145 | 146 | /* inlines */ 147 | 148 | int OSAtomicCompareAndSwapInt(int oldValue,int newValue,volatile int* target) { 149 | return OSAtomicCompareAndSwapIntBarrier(oldValue,newValue,target); 150 | } 151 | int OSAtomicCompareAndSwapPtr(void* oldValue,void* newValue,void* volatile* target) { 152 | return OSAtomicCompareAndSwapPtrBarrier(oldValue,newValue,target); 153 | } 154 | int OSAtomicCompareAndSwapLong(long oldValue,long newValue,volatile long* target) { 155 | return OSAtomicCompareAndSwapInt((int)oldValue,(int)newValue,(volatile int*)target); 156 | } 157 | int OSAtomicCompareAndSwap32(int32_t oldValue,int32_t newValue,volatile int32_t* target) { 158 | return OSAtomicCompareAndSwapInt((int)oldValue,(int)newValue,(volatile int*)target); 159 | } 160 | 161 | /* 162 | * Bit functions 163 | */ 164 | 165 | /* 166 | int OSAtomicTestAndSet(uint32_t bit,volatile void* target); 167 | int OSAtomicTestAndSetBarrier(uint32_t bit,volatile void* target); 168 | int OSAtomicTestAndClear(uint32_t bit,volatile void* target); 169 | int OSAtomicTestAndClearBarrier(uint32_t bit,volatile void* target); 170 | */ 171 | 172 | /* 173 | * Spinlock 174 | */ 175 | 176 | void OSSpinLockLock(volatile OSSpinLock* lock) { 177 | while (!OSSpinLockTry(lock)) { 178 | Sleep(1); 179 | } 180 | } 181 | 182 | void OSSpinLockUnlock(volatile OSSpinLock* lock) { 183 | InterlockedExchange(lock,0); 184 | } 185 | 186 | int OSSpinLockTry(volatile OSSpinLock* lock) { 187 | return InterlockedCompareExchange(lock,1,0)==0; 188 | } 189 | 190 | /* 191 | * Atomic queue 192 | */ 193 | 194 | /* 195 | void OSAtomicEnqueue(OSQueueHead* list,void* item,size_t offset); 196 | void* OSAtomicDequeue(OSQueueHead* list,size_t offset); 197 | */ 198 | -------------------------------------------------------------------------------- /sdk/kiss_fft/_kiss_fft_guts.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2003-2010, Mark Borgerding 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | */ 14 | 15 | /* kiss_fft.h 16 | defines kiss_fft_scalar as either short or a float type 17 | and defines 18 | typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ 19 | #include "kiss_fft.h" 20 | #include 21 | 22 | #define MAXFACTORS 32 23 | /* e.g. an fft of length 128 has 4 factors 24 | as far as kissfft is concerned 25 | 4*4*4*2 26 | */ 27 | 28 | #define BB_MAX_FFT_SIZE 4096 29 | 30 | struct kiss_fft_state{ 31 | int nfft; 32 | int inverse; 33 | int factors[2*MAXFACTORS]; 34 | kiss_fft_cpx twiddles[1]; 35 | }; 36 | 37 | /* 38 | Explanation of macros dealing with complex math: 39 | 40 | C_MUL(m,a,b) : m = a*b 41 | C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise 42 | C_SUB( res, a,b) : res = a - b 43 | C_SUBFROM( res , a) : res -= a 44 | C_ADDTO( res , a) : res += a 45 | * */ 46 | #ifdef FIXED_POINT 47 | #if (FIXED_POINT==32) 48 | # define FRACBITS 31 49 | # define SAMPPROD int64_t 50 | #define SAMP_MAX 2147483647 51 | #else 52 | # define FRACBITS 15 53 | # define SAMPPROD int32_t 54 | #define SAMP_MAX 32767 55 | #endif 56 | 57 | #define SAMP_MIN -SAMP_MAX 58 | 59 | #if defined(CHECK_OVERFLOW) 60 | # define CHECK_OVERFLOW_OP(a,op,b) \ 61 | if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \ 62 | fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) ); } 63 | #endif 64 | 65 | 66 | # define smul(a,b) ( (SAMPPROD)(a)*(b) ) 67 | # define sround( x ) (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS ) 68 | 69 | # define S_MUL(a,b) sround( smul(a,b) ) 70 | 71 | # define C_MUL(m,a,b) \ 72 | do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \ 73 | (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0) 74 | 75 | # define DIVSCALAR(x,k) \ 76 | (x) = sround( smul( x, SAMP_MAX/k ) ) 77 | 78 | # define C_FIXDIV(c,div) \ 79 | do { DIVSCALAR( (c).r , div); \ 80 | DIVSCALAR( (c).i , div); }while (0) 81 | 82 | # define C_MULBYSCALAR( c, s ) \ 83 | do{ (c).r = sround( smul( (c).r , s ) ) ;\ 84 | (c).i = sround( smul( (c).i , s ) ) ; }while(0) 85 | 86 | #else /* not FIXED_POINT*/ 87 | 88 | # define S_MUL(a,b) ( (a)*(b) ) 89 | #define C_MUL(m,a,b) \ 90 | do{ (m).r = (a).r*(b).r - (a).i*(b).i;\ 91 | (m).i = (a).r*(b).i + (a).i*(b).r; }while(0) 92 | # define C_FIXDIV(c,div) /* NOOP */ 93 | # define C_MULBYSCALAR( c, s ) \ 94 | do{ (c).r *= (s);\ 95 | (c).i *= (s); }while(0) 96 | #endif 97 | 98 | #ifndef CHECK_OVERFLOW_OP 99 | # define CHECK_OVERFLOW_OP(a,op,b) /* noop */ 100 | #endif 101 | 102 | #define C_ADD( res, a,b)\ 103 | do { \ 104 | CHECK_OVERFLOW_OP((a).r,+,(b).r)\ 105 | CHECK_OVERFLOW_OP((a).i,+,(b).i)\ 106 | (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \ 107 | }while(0) 108 | #define C_SUB( res, a,b)\ 109 | do { \ 110 | CHECK_OVERFLOW_OP((a).r,-,(b).r)\ 111 | CHECK_OVERFLOW_OP((a).i,-,(b).i)\ 112 | (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \ 113 | }while(0) 114 | #define C_ADDTO( res , a)\ 115 | do { \ 116 | CHECK_OVERFLOW_OP((res).r,+,(a).r)\ 117 | CHECK_OVERFLOW_OP((res).i,+,(a).i)\ 118 | (res).r += (a).r; (res).i += (a).i;\ 119 | }while(0) 120 | 121 | #define C_SUBFROM( res , a)\ 122 | do {\ 123 | CHECK_OVERFLOW_OP((res).r,-,(a).r)\ 124 | CHECK_OVERFLOW_OP((res).i,-,(a).i)\ 125 | (res).r -= (a).r; (res).i -= (a).i; \ 126 | }while(0) 127 | 128 | 129 | #ifdef FIXED_POINT 130 | # define KISS_FFT_COS(phase) floor(.5+SAMP_MAX * cos (phase)) 131 | # define KISS_FFT_SIN(phase) floor(.5+SAMP_MAX * sin (phase)) 132 | # define HALF_OF(x) ((x)>>1) 133 | #elif defined(USE_SIMD) 134 | # define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) ) 135 | # define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) ) 136 | # define HALF_OF(x) ((x)*_mm_set1_ps(.5)) 137 | #else 138 | # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) 139 | # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) 140 | # define HALF_OF(x) ((x)*.5) 141 | #endif 142 | 143 | #define kf_cexp(x,phase) \ 144 | do{ \ 145 | (x)->r = KISS_FFT_COS(phase);\ 146 | (x)->i = KISS_FFT_SIN(phase);\ 147 | }while(0) 148 | 149 | 150 | /* a debugging function */ 151 | #define pcpx(c)\ 152 | fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) ) 153 | 154 | 155 | #ifdef KISS_FFT_USE_ALLOCA 156 | // define this to allow use of alloca instead of malloc for temporary buffers 157 | // Temporary buffers are used in two case: 158 | // 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5 159 | // 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform. 160 | #include 161 | #define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes) 162 | #define KISS_FFT_TMP_FREE(ptr) 163 | #else 164 | #define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) 165 | #define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) 166 | #endif 167 | -------------------------------------------------------------------------------- /sdk/kiss_fft/kiss_fastfir.h: -------------------------------------------------------------------------------- 1 | // 2 | // kiss_fastfir.h 3 | // BBSDK 4 | // 5 | // Created by Bruce on 13-5-22. 6 | // Copyright (c) 2013年 Littlebox. All rights reserved. 7 | // 8 | 9 | #ifndef BBSDK_kiss_fastfir_h 10 | #define BBSDK_kiss_fastfir_h 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | /* 25 | Some definitions that allow real or complex filtering 26 | */ 27 | #ifdef REAL_FASTFIR 28 | #define MIN_FFT_LEN 2048 29 | #include "kiss_fftr.h" 30 | 31 | typedef kiss_fft_scalar kffsamp_t; 32 | typedef kiss_fftr_cfg kfcfg_t; 33 | #define FFT_ALLOC kiss_fftr_alloc 34 | #define FFTFWD kiss_fftr 35 | #define FFTINV kiss_fftri 36 | #else 37 | #define MIN_FFT_LEN 1024 38 | typedef kiss_fft_cpx kffsamp_t; 39 | typedef kiss_fft_cfg kfcfg_t; 40 | #define FFT_ALLOC kiss_fft_alloc 41 | #define FFTFWD kiss_fft 42 | #define FFTINV kiss_fft 43 | #endif 44 | 45 | typedef struct kiss_fastfir_state *kiss_fastfir_cfg; 46 | 47 | 48 | 49 | kiss_fastfir_cfg kiss_fastfir_alloc(const kffsamp_t * imp_resp,size_t n_imp_resp, 50 | size_t * nfft,void * mem,size_t*lenmem); 51 | 52 | /* see do_file_filter for usage */ 53 | size_t kiss_fastfir( kiss_fastfir_cfg cfg, kffsamp_t * inbuf, kffsamp_t * outbuf, size_t n, size_t *offset); 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /sdk/kiss_fft/kiss_fft.h: -------------------------------------------------------------------------------- 1 | #ifndef KISS_FFT_H 2 | #define KISS_FFT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* 14 | ATTENTION! 15 | If you would like a : 16 | -- a utility that will handle the caching of fft objects 17 | -- real-only (no imaginary time component ) FFT 18 | -- a multi-dimensional FFT 19 | -- a command-line utility to perform ffts 20 | -- a command-line utility to perform fast-convolution filtering 21 | 22 | Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c 23 | in the tools/ directory. 24 | */ 25 | 26 | #ifdef USE_SIMD 27 | # include 28 | # define kiss_fft_scalar __m128 29 | #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) 30 | #define KISS_FFT_FREE _mm_free 31 | #else 32 | #define KISS_FFT_MALLOC malloc 33 | #define KISS_FFT_FREE free 34 | #endif 35 | 36 | 37 | #ifdef FIXED_POINT 38 | #include 39 | # if (FIXED_POINT == 32) 40 | # define kiss_fft_scalar int32_t 41 | # else 42 | # define kiss_fft_scalar int16_t 43 | # endif 44 | #else 45 | # ifndef kiss_fft_scalar 46 | /* default is float */ 47 | # define kiss_fft_scalar float 48 | # endif 49 | #endif 50 | 51 | typedef struct { 52 | kiss_fft_scalar r; 53 | kiss_fft_scalar i; 54 | }kiss_fft_cpx; 55 | 56 | typedef struct kiss_fft_state* kiss_fft_cfg; 57 | 58 | /* 59 | * kiss_fft_alloc 60 | * 61 | * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 62 | * 63 | * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); 64 | * 65 | * The return value from fft_alloc is a cfg buffer used internally 66 | * by the fft routine or NULL. 67 | * 68 | * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. 69 | * The returned value should be free()d when done to avoid memory leaks. 70 | * 71 | * The state can be placed in a user supplied buffer 'mem': 72 | * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 73 | * then the function places the cfg in mem and the size used in *lenmem 74 | * and returns mem. 75 | * 76 | * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 77 | * then the function returns NULL and places the minimum cfg 78 | * buffer size in *lenmem. 79 | * */ 80 | 81 | kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 82 | 83 | /* 84 | * kiss_fft(cfg,in_out_buf) 85 | * 86 | * Perform an FFT on a complex input buffer. 87 | * for a forward FFT, 88 | * fin should be f[0] , f[1] , ... ,f[nfft-1] 89 | * fout will be F[0] , F[1] , ... ,F[nfft-1] 90 | * Note that each element is complex and can be accessed like 91 | f[k].r and f[k].i 92 | * */ 93 | void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); 94 | 95 | /* 96 | A more generic version of the above function. It reads its input from every Nth sample. 97 | * */ 98 | void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); 99 | 100 | /* If kiss_fft_alloc allocated a buffer, it is one contiguous 101 | buffer and can be simply free()d when no longer needed*/ 102 | #define kiss_fft_free free 103 | 104 | /* 105 | Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 106 | your compiler output to call this before you exit. 107 | */ 108 | void kiss_fft_cleanup(void); 109 | 110 | 111 | /* 112 | * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) 113 | */ 114 | int kiss_fft_next_fast_size(int n); 115 | 116 | /* for real ffts, we need an even size */ 117 | #define kiss_fftr_next_fast_size_real(n) \ 118 | (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /sdk/kiss_fft/kiss_fftr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2003-2004, Mark Borgerding 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | */ 14 | 15 | #include "kiss_fftr.h" 16 | #include "_kiss_fft_guts.h" 17 | 18 | struct kiss_fftr_state{ 19 | kiss_fft_cfg substate; 20 | kiss_fft_cpx * tmpbuf; 21 | kiss_fft_cpx * super_twiddles; 22 | #ifdef USE_SIMD 23 | void * pad; 24 | #endif 25 | }; 26 | 27 | kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem) 28 | { 29 | int i; 30 | kiss_fftr_cfg st = NULL; 31 | size_t subsize, memneeded; 32 | 33 | if (nfft & 1) { 34 | fprintf(stderr,"Real FFT optimization must be even.\n"); 35 | return NULL; 36 | } 37 | nfft >>= 1; 38 | 39 | kiss_fft_alloc (nfft, inverse_fft, NULL, &subsize); 40 | memneeded = sizeof(struct kiss_fftr_state) + subsize + sizeof(kiss_fft_cpx) * ( nfft * 3 / 2); 41 | 42 | if (lenmem == NULL) { 43 | st = (kiss_fftr_cfg) KISS_FFT_MALLOC (memneeded); 44 | } else { 45 | if (*lenmem >= memneeded) 46 | st = (kiss_fftr_cfg) mem; 47 | *lenmem = memneeded; 48 | } 49 | if (!st) 50 | return NULL; 51 | 52 | st->substate = (kiss_fft_cfg) (st + 1); /*just beyond kiss_fftr_state struct */ 53 | st->tmpbuf = (kiss_fft_cpx *) (((char *) st->substate) + subsize); 54 | st->super_twiddles = st->tmpbuf + nfft; 55 | kiss_fft_alloc(nfft, inverse_fft, st->substate, &subsize); 56 | 57 | for (i = 0; i < nfft/2; ++i) { 58 | double phase = 59 | -3.14159265358979323846264338327 * ((double) (i+1) / nfft + .5); 60 | if (inverse_fft) 61 | phase *= -1; 62 | kf_cexp (st->super_twiddles+i,phase); 63 | } 64 | return st; 65 | } 66 | 67 | void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata) 68 | { 69 | /* input buffer timedata is stored row-wise */ 70 | int k,ncfft; 71 | kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc; 72 | 73 | if ( st->substate->inverse) { 74 | fprintf(stderr,"kiss fft usage error: improper alloc\n"); 75 | exit(1); 76 | } 77 | 78 | ncfft = st->substate->nfft; 79 | 80 | /*perform the parallel fft of two real signals packed in real,imag*/ 81 | kiss_fft( st->substate , (const kiss_fft_cpx*)timedata, st->tmpbuf ); 82 | /* The real part of the DC element of the frequency spectrum in st->tmpbuf 83 | * contains the sum of the even-numbered elements of the input time sequence 84 | * The imag part is the sum of the odd-numbered elements 85 | * 86 | * The sum of tdc.r and tdc.i is the sum of the input time sequence. 87 | * yielding DC of input time sequence 88 | * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... 89 | * yielding Nyquist bin of input time sequence 90 | */ 91 | 92 | tdc.r = st->tmpbuf[0].r; 93 | tdc.i = st->tmpbuf[0].i; 94 | C_FIXDIV(tdc,2); 95 | CHECK_OVERFLOW_OP(tdc.r ,+, tdc.i); 96 | CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i); 97 | freqdata[0].r = tdc.r + tdc.i; 98 | freqdata[ncfft].r = tdc.r - tdc.i; 99 | #ifdef USE_SIMD 100 | freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0); 101 | #else 102 | freqdata[ncfft].i = freqdata[0].i = 0; 103 | #endif 104 | 105 | for ( k=1;k <= ncfft/2 ; ++k ) { 106 | fpk = st->tmpbuf[k]; 107 | fpnk.r = st->tmpbuf[ncfft-k].r; 108 | fpnk.i = - st->tmpbuf[ncfft-k].i; 109 | C_FIXDIV(fpk,2); 110 | C_FIXDIV(fpnk,2); 111 | 112 | C_ADD( f1k, fpk , fpnk ); 113 | C_SUB( f2k, fpk , fpnk ); 114 | C_MUL( tw , f2k , st->super_twiddles[k-1]); 115 | 116 | freqdata[k].r = HALF_OF(f1k.r + tw.r); 117 | freqdata[k].i = HALF_OF(f1k.i + tw.i); 118 | freqdata[ncfft-k].r = HALF_OF(f1k.r - tw.r); 119 | freqdata[ncfft-k].i = HALF_OF(tw.i - f1k.i); 120 | } 121 | } 122 | 123 | void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata) 124 | { 125 | /* input buffer timedata is stored row-wise */ 126 | int k, ncfft; 127 | 128 | if (st->substate->inverse == 0) { 129 | fprintf (stderr, "kiss fft usage error: improper alloc\n"); 130 | exit (1); 131 | } 132 | 133 | ncfft = st->substate->nfft; 134 | 135 | st->tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r; 136 | st->tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r; 137 | C_FIXDIV(st->tmpbuf[0],2); 138 | 139 | for (k = 1; k <= ncfft / 2; ++k) { 140 | kiss_fft_cpx fk, fnkc, fek, fok, tmp; 141 | fk = freqdata[k]; 142 | fnkc.r = freqdata[ncfft - k].r; 143 | fnkc.i = -freqdata[ncfft - k].i; 144 | C_FIXDIV( fk , 2 ); 145 | C_FIXDIV( fnkc , 2 ); 146 | 147 | C_ADD (fek, fk, fnkc); 148 | C_SUB (tmp, fk, fnkc); 149 | C_MUL (fok, tmp, st->super_twiddles[k-1]); 150 | C_ADD (st->tmpbuf[k], fek, fok); 151 | C_SUB (st->tmpbuf[ncfft - k], fek, fok); 152 | #ifdef USE_SIMD 153 | st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0); 154 | #else 155 | st->tmpbuf[ncfft - k].i *= -1; 156 | #endif 157 | } 158 | kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata); 159 | } 160 | -------------------------------------------------------------------------------- /sdk/kiss_fft/kiss_fftr.h: -------------------------------------------------------------------------------- 1 | #ifndef KISS_FTR_H 2 | #define KISS_FTR_H 3 | 4 | #include "kiss_fft.h" 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | 10 | /* 11 | 12 | Real optimized version can save about 45% cpu time vs. complex fft of a real seq. 13 | 14 | 15 | 16 | */ 17 | 18 | typedef struct kiss_fftr_state *kiss_fftr_cfg; 19 | 20 | 21 | kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem); 22 | /* 23 | nfft must be even 24 | 25 | If you don't care to allocate space, use mem = lenmem = NULL 26 | */ 27 | 28 | 29 | void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata); 30 | /* 31 | input timedata has nfft scalar points 32 | output freqdata has nfft/2+1 complex points 33 | */ 34 | 35 | void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata); 36 | /* 37 | input freqdata has nfft/2+1 complex points 38 | output timedata has nfft scalar points 39 | */ 40 | 41 | #define kiss_fftr_free free 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | #endif 47 | -------------------------------------------------------------------------------- /sdk/listener_helper/listener_helper.h: -------------------------------------------------------------------------------- 1 | // 2 | // listener_helper.h 3 | // 4 | // 5 | // Created by linyehui on 2014-04-10. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #ifndef __LISTENER_HELPER_H__ 10 | #define __LISTENER_HELPER_H__ 11 | 12 | #include "FFTBufferManager.h" 13 | #include "CAStreamBasicDescription.h" 14 | 15 | ////////////////////////////////////////////////////////////////// 16 | 17 | namespace SonicSDK 18 | { 19 | class ListenerHelper 20 | { 21 | protected: 22 | ListenerHelper(); 23 | virtual ~ListenerHelper(); 24 | public: 25 | static ListenerHelper* instance(); 26 | static void release(); 27 | 28 | void initFFTMgr(long inNumberFrames); 29 | void grabAudioData(AudioBufferList* inBL); 30 | void setFFTData(int32_t* FFTDATA, long LENGTH); 31 | bool computeWave(char* code_buffer, long buffer_len); 32 | 33 | protected: 34 | void helper(double fftIdx_i, float interpVal, int length); 35 | bool helperResultWithTimeSlice(int length, char* code_buffer, long buffer_len); 36 | 37 | private: 38 | static ListenerHelper* ms_instance; 39 | 40 | FFTBufferManager* fftBufferManager; 41 | int32_t* l_fftData; 42 | 43 | int32_t* fftData; 44 | long fftLength; 45 | bool hasNewFFTData; 46 | 47 | CAStreamBasicDescription drawFormat; 48 | bool isFreqHigh; 49 | 50 | }; 51 | 52 | } // namespace SonicSDK 53 | 54 | #endif // __LISTENER_HELPER_H__ 55 | -------------------------------------------------------------------------------- /sdk/pcm_render/pcm_render.h: -------------------------------------------------------------------------------- 1 | // 2 | // pcm_render.h 3 | // 4 | // 5 | // Created by linyehui on 2014-03-06. 6 | // Copyright (c) 2014年 linyehui. All rights reserved. 7 | // 8 | 9 | #ifndef __PCM_RENDER_H__ 10 | #define __PCM_RENDER_H__ 11 | 12 | namespace SonicSDK 13 | { 14 | const unsigned int SONIC_HEADER_SIZE = 44; 15 | 16 | class PCMRender 17 | { 18 | public: 19 | static int getChirpLengthByByte(unsigned int data_len); 20 | 21 | static bool renderChirpData( 22 | const char* code_with_rs, 23 | unsigned int data_len, 24 | unsigned char* header, 25 | unsigned int header_len, 26 | short* wave_buffer, 27 | long buffer_len_by_byte); 28 | }; 29 | 30 | } 31 | 32 | #endif // SonicSDK 33 | 34 | -------------------------------------------------------------------------------- /sdk/queue/queue.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // queue.cpp 3 | // aurioTouch2 4 | // 5 | // Created by Bruce on 13-11-6. 6 | // 7 | // 8 | 9 | #include "queue.h" 10 | #include 11 | #include 12 | 13 | void init_queue(queue *q, int length) 14 | { 15 | if (length >= QUEUESIZE) 16 | printf("Warning: queue overflow enqueue x=%d\n", length); 17 | 18 | q->first = 0; 19 | q->last = length-1; 20 | q->count = 0; 21 | q->length = length; 22 | } 23 | 24 | void enqueue_adv(queue *q, queue_item x) 25 | { 26 | queue_item xx = x; 27 | 28 | if (!queue_is_empty(q)) { 29 | 30 | xx = x * 0.5 + q->q[q->last] * 0.5; 31 | 32 | if (xx <= x) { 33 | 34 | xx = x; 35 | } 36 | 37 | if (xx < 0.05) { 38 | 39 | xx = (queue_item)0.0; 40 | } 41 | 42 | /* 43 | 44 | if (q->q[q->last] >= xx) { 45 | 46 | xx = (queue_item)0.0; 47 | 48 | } else { 49 | 50 | q->q[q->last] = (queue_item)0.0; 51 | } 52 | 53 | if (xx < 0.05) { 54 | 55 | xx = (queue_item)0.0; 56 | } 57 | */ 58 | } 59 | 60 | enqueue(q, xx); 61 | } 62 | 63 | void enqueue(queue *q, queue_item x) 64 | { 65 | if (q->count >= q->length) 66 | dequeue(q); 67 | //else 68 | { 69 | q->last = (q->last+1) % q->length; 70 | q->q[ q->last ] = x; 71 | q->count = q->count + 1; 72 | } 73 | } 74 | 75 | queue_item dequeue(queue *q) 76 | { 77 | queue_item x = 0.0; 78 | 79 | if (q->count <= 0) printf("Warning: empty queue dequeue.\n"); 80 | else { 81 | x = q->q[ q->first ]; 82 | q->first = (q->first+1) % q->length; 83 | q->count = q->count - 1; 84 | } 85 | 86 | return(x); 87 | } 88 | 89 | int queue_is_empty(queue *q) 90 | { 91 | if (q->count <= 0) return (true); 92 | else return (false); 93 | } 94 | 95 | queue_item queue_item_at_index(queue *q, int index) 96 | { 97 | int i = q->first; 98 | 99 | if (index > 0) { 100 | 101 | i = (i + index) % q->length; 102 | } 103 | 104 | return q->q[i]; 105 | } 106 | 107 | void print_queue(queue *q) 108 | { 109 | int i; 110 | 111 | i = q->first; 112 | 113 | while (i != q->last) { 114 | 115 | printf("%f ",q->q[i]); 116 | i = (i+1) % q->length; 117 | } 118 | 119 | printf("%f ",q->q[i]); 120 | printf("\n"); 121 | } -------------------------------------------------------------------------------- /sdk/queue/queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // queue.h 3 | // aurioTouch2 4 | // 5 | // Created by Bruce on 13-11-6. 6 | // 7 | // 8 | 9 | #ifndef aurioTouch2_queue_h 10 | #define aurioTouch2_queue_h 11 | 12 | #define QUEUESIZE 128 13 | 14 | typedef float queue_item; 15 | 16 | typedef struct { 17 | queue_item q[QUEUESIZE+1];// = {0}; /* body of queue */ 18 | int first; /* position of first element */ 19 | int last; /* position of last element */ 20 | int count; /* number of queue elements */ 21 | int length; 22 | 23 | } queue; 24 | 25 | void init_queue(queue *q, int length); 26 | void enqueue(queue *q, queue_item x); 27 | void enqueue_adv(queue *q, queue_item x); 28 | queue_item dequeue(queue *q); 29 | int queue_is_empty(queue *q); 30 | void print_queue(queue *q); 31 | queue_item queue_item_at_index(queue *q, int index); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /sdk/rscode/rscode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Reed solomon encoder. This code is taken from Phil Karn's libfec then 5 | * editted and packed into a pair of .c and .h files. 6 | * 7 | * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q 8 | * (libfec is released under the GNU Lesser General Public License.) 9 | * 10 | * Copyright (C) 2006-2011 Kentaro Fukuchi 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef __RSCODE_H__ 28 | #define __RSCODE_H__ 29 | 30 | #define RS_SYMSIZE 5 31 | #define RS_GFPOLY 0x25 32 | #define RS_FCR 1 33 | #define RS_PRIM 1 34 | #define RS_NROOTS 8 35 | #define RS_DATA_LEN 10 36 | #define RS_TOTAL_LEN (RS_DATA_LEN + RS_NROOTS) 37 | #define RS_PAD ((1<