0%

iOS使用openAL控制声音的输出设备

项目中播放ios录音的时候使用的是AVAudio相关库, 播放音效又是用的openAL.
如果同时或交替播放这两类声音, 会造成声音一会从听筒发声,一会从扬声器发声.
千辛万苦找到解决方案:

1
2
3
4
5
6
7
8
9
10
Interesting enough, it can be done!

Basically you add a property listener to get route change events:
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback,0);

Then in the callback, determine if its a headphone being plugged-in and override the audio route:
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);

Too simple...

iOS AVAudioSession 监听静音开关

录音使用AVAudioSession播放的时候, 无法识别Iphone手机的物理静音开关,需要修改下模式

1
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

修改成

1
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:nil];//监听静音

vector deque

在使用 vector、deque遍历删除元素时,也可以通过erase的返回值来获取下一个元素的位置:

1
2
3
4
5
6
7
8
9
10
11
std::vector<int> Vec;
std::vector<int>::iterator itVec;
for( itVec = Vec.begin(); itVec != Vec.end(); )
{
if( WillDelete( *itVec) )
{
itVec = Vec.erase( itVec);
}
else
itList++;
}
阅读全文 »

问题提出:有一个模板函数,函数在处理int型和double型时需要进行特殊的处理,那么怎么在编译期知道传入的参数的数据类型是int型还是double型呢?
如:

1
2
3
4
5
6
7
#include <iostream>
template <typename TYPE>
void typeCheck(TYPE data)
{
//do something check data type
//std::cout<< out put the type
}

这里就需要用到C++11的type_traits头文件了,type_traits头文件定义了很多类型检查相关的方法,上面的例子具体用到了其中两个结构:

阅读全文 »

1. git 基础

1.1 git的基础操作

  1. 命令git add 把文件添加到仓库

  2. 命令git commit 把文件提交到仓库

  3. 命令git pull 把远程仓库拉取文件

  4. 命令git push 把文件提交到远程仓库

  5. 命令git log 查看git提交日志

  6. 如果嫌输出信息太多, 可以加上–pretty=oneline参数. 另外也可以花式log输出, git lg查看下

    1
    git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
  7. 命令git diff 查看版本之间文件修改变化

    1
    git diff 87b91b6 f9b3075 [--name-only]加上可以只看文件名字
阅读全文 »

首先找到Xcode中的自带的配置文件

1
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

这个文件里配置了一些可以设置快捷键的操作, 使用常用的编辑器打开它(需要root权限)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<key>GDI Commands</key>
<dict>
<key>GDI Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>GDI Delete Current Line</key>
<string>deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToBeginningOfLine:</string>
<key>GDI Move Current Line Up</key>
<string>selectLine:, cut:, moveUp:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
<key>GDI Move Current Line Down</key>
<string>selectLine:, cut:, moveDown:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
<key>GDI Insert Line Above</key>
<string>moveUp:, moveToEndOfLine:, insertNewline:</string>
<key>GDI Insert Line Below</key>
<string>moveToEndOfLine:, insertNewline:</string>
</dict>
阅读全文 »

Xcode 主题

1
https://github.com/tursunovic/xcode-themes

elfDark

1
2
3
https://code.google.com/archive/p/elf-ios-resource/downloads

cd /Users/liuwei/Library/Developer/Xcode/UserData/FontAndColorThemes 放进去
阅读全文 »

1. 安装hexo

1
2
3
4
5
apt install npm
npm install -g hexo-cli
mkdir hexo
hexo init hexo
cd hexo
阅读全文 »

公司需要把所有代码放到一个文件内,加上版权信息. 于是用shell简单的处理了下

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
#!/bin/sh

NAME="a.txt"
if [ -f $NAME ]; then
`rm $NAME`
fi

DIR=""
FILE=""
for file in `ls -R`
do
if [ -f $file ]; then
if [ $file = "a.sh" ];then
continue
fi
# echo "===================== $file begin =====================" >> $NAME
# `cat $file >> $NAME`
# echo "===================== $file end =====================" >> $NAME
echo $file
else
if [ ${file:0:1} = "." ];then
DIR=${file/://}
else
if [ "$DIR" != "" ] && [ ${DIR:0:6} = "./base" ];then
continue #此处可以过滤不想要的文件夹
fi
FILE=$DIR$file
if [ -f $FILE ]; then
# echo "===================== $file begin =====================" >> $NAME
# `cat $FILE >> $NAME`
# echo "===================== $file end =====================" >> $NAME
echo $FILE
fi
fi
fi
done

工作需要把 Mud makes my mom mad. 这句话带有m的加上颜色,或者把某些单词加上颜色
临时写了个脚本处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import re
import sys


# replace letter
#find = "m"
#str = "Mud makes my mom mad."

#replace key words
#find = "Mud|makes|mad"
#str = "Mud makes my mom mad."

# how to use
# python b.py "m" "Mud makes my mom mad."
# python b.py "mud|mess|mop|make|the|help" "Mud makes my mom mad."


find = sys.argv[1]
str = sys.argv[2]


result = re.sub(r'('+find+')', r'<color:#ff0000>\1</color>', str, 0, re.IGNORECASE)
print result