# iOS耳机红外线遥控器

### 前言

（网上找的，侵删)

http://www.icpcw.com/Smartphone/Android/Skill/3234/323495_all.htm

### 红外波形码的获得

[8985,4481,578,555,578,555,578,555,578,555,578,555,578,555,578,555,578,555,578,1688,578,1688,578,1688,578,1688,578,1688,578,1688,578,555,578,1688,578,1688,578,555,578,1688,578,1688,578,555,578,555,578,556,578,555,578,555,578,1688,578,555,578,555,578,1688,578,1688,578,1688,578,1688,578,40734,8985,2242,578,96165]

### 软件实现

#define kNum 0.0441  //1微妙采样的点数
#define KAmplitude 32767
#define kFrequency 19000
#define KSampleRate 44100 //采样率

y=Asin(ωx+φ)+k

double dVal = 0.3+(double)(0.3*sin(2*M_PI*((double)kFrequency)*((double)j/44100)));
short val = (short)(dVal*KAmplitude);

NSMutableData *pcmData = [[NSMutableData alloc] init];

for(int i=0; i<num;i++){
if (i%2 == 0) {//如果是偶数，产生正弦波
int allNum = plus[i]*kNum;
for (int j=0; j<allNum; j++) {
double dVal = 0.5+(double)(0.5*sin(2*M_PI*((double)kFrequency)*((double)j/44100)));
short val = (short)(dVal*KAmplitude);
NSData *data = [NSData dataWithBytes:&val length:sizeof(short)];
[pcmData appendData:data];
short valMin = (short)(-val);
NSData *data1 = [NSData dataWithBytes:&valMin length:sizeof(short)];
[pcmData appendData:data1];

}
}else{//如果是奇数，填0
int allNum = plus[i]*kNum;
for (int j=0; j<allNum; j++) {
double dVal = 0.0;
short shortData = (short)(dVal);
NSData *data = [NSData dataWithBytes:&shortData length:sizeof(short)];
[pcmData appendData:data];
short shortData1 = (short)(-dVal);
NSData *data1 = [NSData dataWithBytes:&shortData1 length:sizeof(short)];
[pcmData appendData:data1];
}

}
}

//给音频数据添加wav头
NSMutableData *wavData = [[NSMutableData alloc] init];
[wavData appendData:pcmData];

//播放音频数据
NSError *error;
_audioPlayer = [[AVAudioPlayer alloc] initWithData:wavData error:&error];
if (error) {
NSLog(@"error log is %@",error.localizedDescription);
}else{
[_audioPlayer play];
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120