I need to stream audio from the mic to a http server.
These recording settings are what I need:
NSDictionary *audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatULaw],AVFormatIDKey,
[NSNumber numberWithFloat:8000.0],AVSampleRateKey,//was 44100.0
[NSData dataWithBytes: &acl length: sizeof( AudioChannelLayout ) ], AVChannelLayoutKey,
[NSNumber numberWithInt:1],AVNumberOfChannelsKey,
[NSNumber numberWithInt:64000],AVEncoderBitRateKey,
nil];
Run Code Online (Sandbox Code Playgroud)
API im coding to states:
Send a continuous stream of audio to the currently viewed camera. Audio needs to be encoded at G711 mu-law at 64 kbit/s for transfer to the Axis camera at the bedside. …
我目前正在申请作为我的计算机科学学士学位的一部分.该应用程序将关联来自iPhone硬件(加速度计,gps)和正在播放的音乐的数据.
该项目仍处于起步阶段,仅用了2个月.
我现在的那一刻,以及我需要帮助的地方,是从itunes库中的歌曲中读取PCM样本,然后使用音频单元播放它们.目前我想要实现的实现如下:从iTunes中选择一首随机歌曲,并在需要时从中读取样本,并将其存储在缓冲区中,我们称之为sampleBuffer.稍后在消费者模型中,音频单元(具有混音器和remoteIO输出)具有回调,我只需将sampleBuffer中所需数量的样本复制到回调中指定的缓冲区中.我通过扬声器听到的东西并不是我所期待的; 我可以认识到它正在播放这首歌,但似乎它被错误地解码并且它有很多噪音!我附上了一个显示前半秒钟(24576个样本@ 44.1kHz)的图像,这不像一个看起来很小的输出.在我进入列表之前,我已经检查过文件没有损坏,类似地我已经为缓冲区编写了测试用例(所以我知道缓冲区不会改变样本),虽然这可能不是最好的方法(有些人会主张去音频队列路线),我想对样本进行各种操作,以及在完成之前更改歌曲,重新排列播放的歌曲等等.此外,音频中可能有一些不正确的设置但是,显示样本的图形(显示样本被错误地解码)直接从缓冲区获取,因此我现在只想解决为什么从磁盘读取和解码不能正常工作.现在我只想通过工作获得一个游戏.无法发布图片,因为新的stackoverflow因此是图像的链接:http://i.stack.imgur.com/RHjlv.jpg
清单:
这是我设置audioReadSettigns的地方,它将用于AVAssetReaderAudioMixOutput
// Set the read settings
audioReadSettings = [[NSMutableDictionary alloc] init];
[audioReadSettings setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM]
forKey:AVFormatIDKey];
[audioReadSettings setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[audioReadSettings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[audioReadSettings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
[audioReadSettings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsNonInterleaved];
[audioReadSettings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
Run Code Online (Sandbox Code Playgroud)
现在,下面的代码清单是一个接收带有歌曲的persistant_id的NSString的方法:
-(BOOL)setNextSongID:(NSString*)persistand_id {
assert(persistand_id != nil);
MPMediaItem *song = [self getMediaItemForPersistantID:persistand_id];
NSURL *assetUrl = [song valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetUrl
options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey]];
NSError *assetError = nil;
assetReader = [[AVAssetReader assetReaderWithAsset:songAsset error:&assetError] retain];
if …Run Code Online (Sandbox Code Playgroud) 我有这个代码,我试图用来捕获音频数据.然而,编译器抱怨CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
AudioBufferList audioBufferList;
NSMutableData *data= [[NSMutableData alloc] init];
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
for (int y = 0; y < audioBufferList.mNumberBuffers; y++) {
AudioBuffer audioBuffer = audioBufferList.mBuffers[y];
Float32 *frame = (Float32*)audioBuffer.mData;
[data appendBytes:frame length:audioBuffer.mDataByteSize];
}
CFRelease(blockBuffer);
blockBuffer=NULL;
[data release];
}
Run Code Online (Sandbox Code Playgroud)
错误:
架构armv7的未定义符号:
"_CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer",引用自: - MicCommunicator.o中的[MicCommunicator captureOutput:didOutputSampleBuffer:fromConnection:] ld:未找到架构armv7 clang的符号:错误:链接器命令失败,退出代码为1(使用-v查看调用)
我正在做类似的事情,如从iPod库中流式传输音频,通过网络或蓝牙发送数据,以及使用音频队列播放.
感谢您提出这个问题和代码.帮助我很多.
我有两个问题.
我应该从一台设备发送到另一台设备?CMSampleBufferRef?AudioBuffer?MDATA?AudioQueueBuffer?包?我不知道.
当应用程序完成播放时,它崩溃了,我收到错误(-12733).我只是想知道如何处理错误而不是让它崩溃.(检查OSState?发生错误时,停止吗?)
错误:无法读取样本数据(-12733)