1.

AQRecorder

    mRecordFormat.mFormatID = inFormatID;
if (inFormatID == kAudioFormatLinearPCM)
{
// if we want pcm, default to signed 16-bit little-endian
mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
mRecordFormat.mBitsPerChannel = ;
mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame = (mRecordFormat.mBitsPerChannel / ) * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mFramesPerPacket = ;
} // else {
//
// mRecordFormat.mSampleRate = 44100;//8000.0;//44100.0;
//
// mRecordFormat.mFormatID = kAudioFormatMPEG4AAC; // kAudioFormatMPEG4AAC_HE does not work. Can't find `AudioClassDescription`. `mFormatFlags` is set to 0.
// mRecordFormat.mFormatFlags = kMPEG4Object_AAC_LC; // Format-specific flags to specify details of the format. Set to 0 to indicate no format flags. See “Audio Data Format Identifiers” for the flags that apply to each format.
// mRecordFormat.mBytesPerPacket = 0; // The number of bytes in a packet of audio data. To indicate variable packet size, set this field to 0. For a format that uses variable packet size, specify the size of each packet using an AudioStreamPacketDescription structure.
// mRecordFormat.mFramesPerPacket = 0; // The number of frames in a packet of audio data. For uncompressed audio, the value is 1. For variable bit-rate formats, the value is a larger fixed number, such as 1024 for AAC. For formats with a variable number of frames per packet, such as Ogg Vorbis, set this field to 0.
// mRecordFormat.mBytesPerFrame = 0; // The number of bytes from the start of one frame to the start of the next frame in an audio buffer. Set this field to 0 for compressed formats. ...
// mRecordFormat.mChannelsPerFrame = 1; // The number of channels in each frame of audio data. This value must be nonzero.
// mRecordFormat.mBitsPerChannel = 0; // ... Set this field to 0 for compressed formats.
// mRecordFormat.mReserved = 0; // Pads the structure out to force an even 8-byte alignment. Must be set to 0.
// }
        url = CFURLCreateWithString(kCFAllocatorDefault, (CFStringRef)inRecordFile, NULL);

        // create the audio file
OSStatus status = AudioFileCreateWithURL(url, kAudioFileCAFType, &mRecordFormat, kAudioFileFlags_EraseFile, &mRecordFile);
CFRelease(url);
// ____________________________________________________________________________________
// AudioQueue callback function, called when an input buffers has been filled.
void AQRecorder::MyInputBufferHandler( void * inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp * inStartTime,
UInt32 inNumPackets,
const AudioStreamPacketDescription* inPacketDesc)
{
AQRecorder *aqr = (AQRecorder *)inUserData;
try {
if (inNumPackets > ) {
// write packets to file
XThrowIfError(AudioFileWritePackets(aqr->mRecordFile, FALSE, inBuffer->mAudioDataByteSize,
inPacketDesc, aqr->mRecordPacket, &inNumPackets, inBuffer->mAudioData),
"AudioFileWritePackets failed");
aqr->mRecordPacket += inNumPackets;
} // if we're not stopping, re-enqueue the buffe so that it gets filled again
if (aqr->IsRunning())
XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, , NULL), "AudioQueueEnqueueBuffer failed");
} catch (CAXException e) {
char buf[];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}
}

AQPlayer

void AQPlayer::SetupNewQueue()
{
XThrowIfError(AudioQueueNewOutput(&mDataFormat, AQPlayer::AQBufferCallback, this,
CFRunLoopGetCurrent(), kCFRunLoopCommonModes, , &mQueue), "AudioQueueNew failed"); ... void AQPlayer::AQBufferCallback(void * inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inCompleteAQBuffer)
{
AQPlayer *THIS = (AQPlayer *)inUserData; if (THIS->mIsDone) return; UInt32 numBytes;
UInt32 nPackets = THIS->GetNumPacketsToRead();
OSStatus result = AudioFileReadPackets(THIS->GetAudioFileID(), false, &numBytes, inCompleteAQBuffer->mPacketDescriptions, THIS->GetCurrentPacket(), &nPackets,
inCompleteAQBuffer->mAudioData);
if (result)
printf("AudioFileReadPackets failed: %d", (int)result);
if (nPackets > ) {
inCompleteAQBuffer->mAudioDataByteSize = numBytes;
inCompleteAQBuffer->mPacketDescriptionCount = nPackets;
AudioQueueEnqueueBuffer(inAQ, inCompleteAQBuffer, , NULL);
THIS->mCurrentPacket = (THIS->GetCurrentPacket() + nPackets);
}

2.levelmeter

- (void)updateLevelMeter:(id)sender {
/*
if (self.delegate) {
UInt32 dataSize = sizeof(AudioQueueLevelMeterState);
AudioQueueGetProperty([self.decapsulator Queue], kAudioQueueProperty_CurrentLevelMeter, levelMeterStates, &dataSize);
if ([self.delegate respondsToSelector:@selector(levelMeterChanged:)]) {
[self.delegate levelMeterChanged:levelMeterStates[0].mPeakPower];
} }*/
}
    //self.timerLevelMeter = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(updateLevelMeter:) userInfo:nil repeats:YES];
__weak __typeof(self)weakSelf = self;
MLAudioMeterObserver *meterObserver = [[MLAudioMeterObserver alloc]init];
meterObserver.actionBlock = ^(NSArray *levelMeterStates,MLAudioMeterObserver *meterObserver){
NSLog(@"volume:%f",[MLAudioMeterObserver volumeForLevelMeterStates:levelMeterStates]); if ([weakSelf.delegate respondsToSelector:@selector(levelMeterChanged:)]) {
[weakSelf.delegate levelMeterChanged:[MLAudioMeterObserver volumeForLevelMeterStates:levelMeterStates]];
}
};
meterObserver.errorBlock = ^(NSError *error,MLAudioMeterObserver *meterObserver){
//[[[UIAlertView alloc]initWithTitle:@"错误" message:error.userInfo[NSLocalizedDescriptionKey] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"知道了", nil]show];
};
self.meterObserver = meterObserver;
self.meterObserver.audioQueue = player->Queue();

3.

linesview

- (void)levelMeterChanged:(float)levelMeter {
dispatch_async(dispatch_get_main_queue(), ^{
//self.levelMeter.progress = levelMeter;
NSLog(@"%.2f",levelMeter*); [self.levelMeterLineView1 addMeter:levelMeter*];
[self.levelMeterLineView2 addMeter:levelMeter*];
}); }
-(void)addMeter:(float)meter
{
if (high) {
meter = meter*0.6 + 0.4;
} else {
meter = meter*0.6 + 0.35;
}
high = !high; [_meters addObject:@(meter)]; if (_meters.count > ) {
[_meters removeObjectAtIndex:];
}
[self setNeedsDisplay];
}

DXRecordView

- (void)levelMeterChanged:(float)levelMeter {
dispatch_async(dispatch_get_main_queue(), ^{
//self.levelMeter.progress = levelMeter;
NSLog(@"%.2f",levelMeter*); float showMeter = levelMeter*0.6 + 0.35; [_recordView setVoiceImageWithLowPassResults:showMeter]; }); }
-(void)setVoiceImageWithLowPassResults:(double)lowPassResults
{
CGRect frame = _meterImageView.frame;
frame.size.height = *lowPassResults;
frame.origin.y = +5.5+*(-lowPassResults);
_meterImageView.frame = frame;

4.recordButton 按住说话

    //录制
self.recordButton = [[UIButton alloc] initWithFrame:CGRectMake(, kVerticalPadding, CGRectGetWidth(self.bounds)-( * ), kInputTextViewMinHeight)];
self.recordButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
[self.recordButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
[self.recordButton setBackgroundImage:[UIImage imageNamed:@"btn_long_round"] forState:UIControlStateNormal];
[self.recordButton setBackgroundImage:[UIImage imageNamed:@"btn_long_round_hl"] forState:UIControlStateHighlighted];
[self.recordButton setTitle:LOCALIZATION(@"按住说话") forState:UIControlStateNormal];
[self.recordButton setTitle:LOCALIZATION(@"松开结束") forState:UIControlStateHighlighted];
[self.recordButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//self.recordButton.hidden = YES;
[self.recordButton addTarget:self action:@selector(recordButtonTouchDown) forControlEvents:UIControlEventTouchDown];
[self.recordButton addTarget:self action:@selector(recordButtonTouchUpOutside) forControlEvents:UIControlEventTouchUpOutside];
[self.recordButton addTarget:self action:@selector(recordButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
[self.recordButton addTarget:self action:@selector(recordDragOutside) forControlEvents:UIControlEventTouchDragExit];
[self.recordButton addTarget:self action:@selector(recordDragInside) forControlEvents:UIControlEventTouchDragEnter];

5.EMChatAudioBubbleView

- (void)setModel:(MessageModel *)model
{
[super setModel:model]; _timeLabel.text = [NSString stringWithFormat:@"%d'",self.model.time]; if (self.model.isSender) {
[_isReadView setHidden:YES];
_animationImageView.image = [UIImage imageNamed:SENDER_ANIMATION_IMAGEVIEW_IMAGE_DEFAULT];
_animationImageView.animationImages = _senderAnimationImages;
}
else{
if (model.isPlayed) {
[_isReadView setHidden:YES];
}else{
[_isReadView setHidden:NO];
} _animationImageView.image = [UIImage imageNamed:RECEIVER_ANIMATION_IMAGEVIEW_IMAGE_DEFAULT];
_animationImageView.animationImages = _recevierAnimationImages;
} if (self.model.isPlaying)
{
[self startAudioAnimation];
}else {
[self stopAudioAnimation];
}
}
@interface MiniCourseViewTableViewCell : UITableViewCell<UITableViewDataSource,UITableViewDelegate,CommentVoiceDelegate>

@property(nonatomic, strong) NSString * MiniContent;
@property(nonatomic, strong) UILabel *contentLabel,*numberLabel,* nameLabel,* timeLabel;
@property(nonatomic, strong) NSMutableArray * commentModelArray;
@property(nonatomic, strong) UIImageView * headImageView;
@property(nonatomic, strong) UIButton * laudButton; @property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, strong) PlayVoiceButton *playVoiceButton;
@property (nonatomic, strong)id <ReplyVoiceDelegate> delegate; @property(nonatomic, strong) CourseReplay * replyModel; + (float)getHeightWithString:(NSString *)string fontSize:(int)size contenViewWidth:(CGFloat)width; @end
 
@interface FollowTalkThingCommentTableViewCell : UITableViewCell

@property (nonatomic, strong) UIImageView *userImageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIButton *zanButton; @property (strong, nonatomic) UILabel *answerLabel,*replyLabel;
@property (nonatomic, strong) PlayVoiceButton *voiceButton;
@property (strong, nonatomic) UIView *answerView; @property (strong, nonatomic) UILabel *scoreLabel; @property (nonatomic, strong)id <playVoiceButton> delegate; +(CGSize)cellBubbleSizeWithContent:(NSString *)content; @property (strong, nonatomic) id model; @end

第九天 iOS音频技术的更多相关文章

  1. iOS 开发技术体系

    iOS 开发技术体系图: - 层级 | 主要框架 - ---------------------|--------------------------------------------------- ...

  2. iOS音频AAC视频H264编码 推流最佳方案

    iOS音频AAC视频H264编码 推流最佳方案 项目都是个人的调研与实验,可能很多不好或者不对的地方请多包涵. 1    功能概况 *  实现音视频的数据的采集 *  实现音视频数据的编码,视频编码成 ...

  3. IOS 音频开发文件大小计算

    音频基础知识 音频文件计算大小 音频转码 标签(空格分隔): 调查 IOS音频 https://developer.apple.com/library/ios/documentation/MusicA ...

  4. iOS音频处理

    ios音频处理 1. iOS底层音频处理技术(带源代码) http://www.cocoachina.com/ios/20111122/3563.html 2.ios 音频入门 http://blog ...

  5. 了解iOS消息推送一文就够:史上最全iOS Push技术详解

    本文作者:陈裕发, 腾讯系统测试工程师,由腾讯WeTest整理发表. 1.引言 开发iOS系统中的Push推送,通常有以下3种情况: 1)在线Push:比如QQ.微信等IM界面处于前台时,聊天消息和指 ...

  6. IOS音频1:之采用四种方式播放音频文件(一)AudioToolbox AVFoundation OpenAL AUDIO QUEUE

    本文转载至 http://blog.csdn.net/u014011807/article/details/40187737 在本卷你可以学到什么? 采用四种方法设计应用于各种场合的音频播放器: 基于 ...

  7. 内行看门道:看似“佛系”的《QQ炫舞手游》,背后的音频技术一点都不简单

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯游戏云发表于云+社区专栏 3月14日,腾讯旗下知名手游<QQ炫舞>正式上线各大应用商店,并迅速登上App Store免 ...

  8. 转: HTTP Live Streaming直播(iOS直播)技术分析与实现

    http://www.cnblogs.com/haibindev/archive/2013/01/30/2880764.html HTTP Live Streaming直播(iOS直播)技术分析与实现 ...

  9. iOS 音频开发

      音频基础知识 组成 音频文件的组成:文件格式(或者音频容器) + 数据格式(或者音频编码). 文件格式(或音频容器)是用于形容文件本身的格式. 我们可以通过多种不同的方法为真正的音频数据编码.例如 ...

随机推荐

  1. POJ 1236 Network of Schools(强连通分量/Tarjan缩点)

    传送门 Description A number of schools are connected to a computer network. Agreements have been develo ...

  2. [JavaEE] NIO与IO的区别

    nio是new io的简称,从jdk1.4就被引入了.现在的jdk已经到了1.6了,可以说不是什么新东西了.但其中的一些思想值得我来研究.这两天,我研究了下其中的套接字部分,有一些心得,在此分享. 首 ...

  3. wpf arcgis engine 当前没有或未启用Spatial Analyst许可解决办法

    用wpf 在做叠加分析时 遇到了一个错误:“ERROR 010096:当前没有或未启用Spatial Analyst许可”:在环境中把这个Spatial Analyst扩展功能给勾了也不能解决,现在把 ...

  4. php格式化金额函数分享

    /**  * 格式化金额 *  * @param int $money  * @param int $len  * @param string $sign  * @return string  */ ...

  5. php 数据访问(以mysql数据库为例)

    //建一个连接,造一个连接对象$db = new MySQLi("localhost","root","123","mydb&qu ...

  6. tomcat7.0配置CORS(跨域资源共享)

    平时我们做前台页面时可能会遇到浏览器以下提示(浏览器控制台): 已阻止跨源请求:同源策略禁止读取位于 http://xxx.xxx.com 的远程资源.(原因:CORS 头缺少 'Access-Con ...

  7. Win7、Ubuntu双系统正确卸载Ubuntu系统

    正确的删除ubuntu方法如下: 第1步,修复MBR 1.进入win7,下载个软件MbrFix,放在C:windowssystem32文件夹中 2.点击开始>所有程序>附件>命令提示 ...

  8. IO多路复用及ThreadingTCPServer源码阅读

    IO多路复用 socket模块是阻塞的,通过socket建立的服务端可以接收多个请求,但只能同时处理一个请求,其他请求都被阻塞.可以通过IO多路复用解决这个问题,socketserver内部使用的就是 ...

  9. 20145212《Java程序设计》实验报告一:Java开发环境的熟悉(Windows+IDE)

    20145212<Java程序设计>实验报告一:Java开发环境的熟悉(Windows+IDE) 实验内容及步骤 1.命令行下的JAVA程序开发 建立并进入实验目录: 撰写简单的Hello ...

  10. 删除ibus之后导致系统设置进不了

    sudo apt-get instal ubuntu-desktop 快捷键调出sogou拼音,默认为"ctrl+,"