我正在对IOS音频队列服务进行一些测试和学习
当我尝试创建一个新的InputAudioQueue时,我得到了-50 osstatus ,我做错了什么?
我读了几次苹果AudioQueue服务参考,并阅读了函数文档,但我还不知道这个问题是什么
由于
#import "AudioSenderVC.h"
#import <AudioToolbox/AudioToolbox.h>
#import <Foundation/Foundation.h>
@interface AudioSenderVC ()
@property (weak, nonatomic) IBOutlet UITextField *ipTextField;
@end
@implementation AudioSenderVC
static void MyAudioQueueInputCallback (
void *inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp *inStartTime,
UInt32 inNumberPacketDescriptions,
const AudioStreamPacketDescription *inPacketDescs
)
{
NSLog(@"hey I just got audio data from the mic!");
}
void createAudioQueue(AudioStreamBasicDescription* mDataFormat)
{
AudioQueueRef* inAQ = NULL;
OSStatus err=AudioQueueNewInput(mDataFormat, MyAudioQueueInputCallback ,NULL,CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, inAQ);
if(inAQ!=NULL)
NSLog(@"YAY!, InputQueue was Created");
if(err)
NSLog(@"Error:%i",(int)err);
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)setupAudioFormat:(AudioStreamBasicDescription*)format
{
format->mSampleRate = 8000.0;
format->mFormatID = kAudioFormatLinearPCM;
format->mFramesPerPacket = 1;
format->mChannelsPerFrame = 1;
format->mBytesPerFrame = 2;
format->mBytesPerPacket = 2;
format->mBitsPerChannel = 16;
format->mReserved = 0;
format->mFormatFlags = kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsSignedInteger |
kLinearPCMFormatFlagIsPacked;
}
- (IBAction)sendAudio:(id)sender {
AudioStreamBasicDescription* mDataFormat=malloc(sizeof(AudioStreamBasicDescription));
[self setupAudioFormat:mDataFormat];
createAudioQueue(mDataFormat);
}
@end
答案 0 :(得分:0)
您为结果队列传递NULL,而应该传递AudioQueueRef
的地址,如下所示:
AudioQueueRef inAQ;
OSStatus err=AudioQueueNewInput(mDataFormat, MyAudioQueueInputCallback, NULL, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &inAQ);