Tag: audio

iOS – 从后台程序访问输出audio

情景:我的应用程序正在后台运行。 iPhone / iPad用户在其设备上启动iPod应用程序(或潘多拉或其他播放audio的程序)并开始播放音乐。 我的应用程序检测到音乐正在播放,并以某种方式logging或以某种方式处理当前正在播放的audio(如stream式传输到服务器),同时仍在后台运行。 这可能吗? 任何人都可以指出我在正确的方向在SDK中如何做到这一点?

如何转换audio,以便可以跨设备进行stream式传输

编辑2: 我已经创build了一个模拟这个问题的项目。 它所做的只是录制audio,将其转换为数据,将其转换回AVAudioPCMBuffer并播放audio。 这里是链接: https : //github.com/Lkember/IntercomTest 使用具有2个通道的设备时出现故障,但是我已经修复了这个问题。 我一直在寻找这个问题的答案大约一个月,所以任何帮助表示赞赏! 我正在使用AVAudioEngine来录制audio。 这个audio是用一个水龙头logging的: localInput?.installTap(onBus: 0, bufferSize: 4096, format: localInputFormat) { logging下来inputAVAudioPCMBuffer。 它需要转换为types[UInt8] 我这样做的方法: func audioBufferToBytes(audioBuffer: AVAudioPCMBuffer) -> [UInt8] { let srcLeft = audioBuffer.floatChannelData![0] let bytesPerFrame = audioBuffer.format.streamDescription.pointee.mBytesPerFrame let numBytes = Int(bytesPerFrame * audioBuffer.frameLength) // initialize bytes by 0 var audioByteArray = [UInt8](repeating: 0, count: numBytes) srcLeft.withMemoryRebound(to: UInt8.self, […]

为什么我不能在AU多声道调音台的input范围内更改元素/总线的数量?

更新:我正在更改我的代码,以更简化的方式说明问题。 另外我还有一个小问题,虽然没有阻止问题,却增加了一些困惑。 我在iOS(kAudioUnitSubType_MultiChannelMixer)中实例化一个多通道混音器AU,并执行以下操作: OSStatus status = noErr; // Set component type: AudioComponentDescription cd = {0}; cd.componentType = kAudioUnitType_Mixer; cd.componentSubType = kAudioUnitSubType_MultiChannelMixer; cd.componentManufacturer = kAudioUnitManufacturer_Apple; // Alloc unit: AudioComponent defaultOutput = AudioComponentFindNext(NULL, &cd); AudioUnit mixer; status = AudioComponentInstanceNew(defaultOutput, &mixer); NSLog(@"AU init status: %li", status); // You can try initializing the unit before or after the attempt […]

iOS – 使用AVFoundation录制声音后的iPhone声音级别较低

我有一个应用程序,我正在其中的一个function是通过iPhone microphone录制声音,并能够播放给我。 问题:我logging后让我说,我说话,播放水平是非常低的。 现在我没有从AudioToolbox切换到AVFoundation ,这发生在切换后。 我是否需要在AVFoundation的音量参数中进行AVFoundation ? 我没有看到documentation任何documentation 。 我感谢任何帮助。

iOS:使用AudioUnitRender的模拟器中的错误

我又打了另一个iOS模拟器的错误。 我的问题是,是否有一些解决方法? 错误是这样的: 加载苹果的AurioTouch示例项目。 并简单地输出渲染callback接收的帧数(在aurioTouchAppDelegate.mm中) static OSStatus PerformThru( void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) { printf( "%u, ", (unsigned int)inNumberFrames ); 我得到以下输出: 471, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, … 但是,如果您在下一行注释掉对AudioUnitRender的调用: { printf( "%u, ", (unsigned int)inNumberFrames ); aurioTouchAppDelegate […]

Objective-c,AVPlayer花费太多时间恢复播放来自URL的audio

我已经实现了AVPlayer。 它工作正常。 但是在播放来自URL的audio的过程中,很多时候会自动停止/暂停,需要很长时间来恢复/重播。 另一方面,如果我手动暂停并播放它,则表示不需要太多时间来重新播放。 只要准备就绪,我想恢复/重播。 任何build议将是伟大的。 预先感谢 !!!!!!!! 我的代码: – (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (!songFinished) { if (object == playerItem && [keyPath isEqualToString:@"playbackBufferEmpty"]) { if (playerItem.playbackBufferEmpty) { printf("\n\n\t****player item playback buffer is empty****\n\n"); //[s activityIndicator] startAnimating]; [player pause]; } } else if (object == playerItem && [keyPath isEqualToString:@"playbackLikelyToKeepUp"]) { if […]

从Core Audio Callback更新UI的最佳做法是什么?

我目前正在围绕Core Audio进行包装,并且遇到了如何更新GUI AudioQueueInputCallback的问题。 首先,我想用麦克风的电平表读数来更新标签。 在我的代码中,我将当前的电平表值存储在每个callback的结构中。 func MyAudioQueueInputCallback(inUserData: UnsafeMutablePointer<Void>, inAQ: AudioQueueRef, inBuffer: AudioQueueBufferRef, inStartTime: UnsafePointer<AudioTimeStamp>, var inNumberPacketDesc: UInt32, inPacketDesc: UnsafePointer<AudioStreamPacketDescription>){ var error: OSStatus if (inNumberPacketDesc > 0){ error = AudioFileWritePackets(MyRecorder.recordFile, false, inBuffer.memory.mAudioDataByteSize, inPacketDesc, MyRecorder.recordPacket, &inNumberPacketDesc, inBuffer.memory.mAudioData) checkError(error, operation: "AudioFileWritePackets Failed ") // Increment the packet index MyRecorder.recordPacket += Int64(inNumberPacketDesc) if (MyRecorder.running){ error = AudioQueueEnqueueBuffer(inAQ, inBuffer, inNumberPacketDesc, […]

在iPhone上的耳机和扬声器之间切换

我正在尝试设置iPhone应用程序输出的audio路由。 我正在使用路由更改侦听器来检测何时audio路由已更改。 聆听者检测到这些变化,例如耳机插入和拔出的时间。 默认情况下,扬声器播放audio,然后插入耳机,并通过耳机传输audio。 从那里,即使路由更改侦听器正在检测它们,也不会发生任何更改。 任何帮助将非常感激。 NSError *sessionError = nil; [[AVAudioSession sharedInstance] setDelegate:self]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError]; UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord; AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory); AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(sessionCategory), &sessionCategory); AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, RouteChangeListener, (__bridge void *)(self)); AudioSessionSetActive(YES); callback监听器: void RouteChangeListener( void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue) { if (inPropertyID == kAudioSessionProperty_AudioRouteChange) { CFStringRef newRoute; UInt32 size […]

从麦克风获取audio并将其写入iOS上的套接字

这是我想要做的: 从麦克风获取audio 将其编码为AAC,G.711或G.726 将编码的帧写入套接字。 我发现了很多例子,但都是写入文件。 你能链接我的任何教程/文档/示例/库有一个输出缓冲区或callback,而不是?

我可以将peakPowerForChannel转换为dB吗?

我发现有些应用程序可以显示audio级别的分贝(dB)值。 我一直在尝试一段时间,但一直没有find功率和dB之间的关系。 有人可以告诉我该怎么做吗?