Tag: pcm

IOS Swift读取PCM缓冲区

我有一个Android项目,通过麦克风缓冲区中的PCM数据读取一个short[]arrays进行实时分析。 我需要将此function转换为iOS Swift。 在Android中,它非常简单,看起来像这样.. import android.media.AudioFormat; import android.media.AudioRecord; … AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, someSampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(…)); recorder.startRecording(); 后来我读了缓冲区 recorder.read(data, offset, length); //data is short[] (这就是我要找的) 文档: https : //developer.android.com/reference/android/media/AudioRecord.html 我对Swift和iOS非常陌生。 我已经阅读了大量有关AudioToolkit,Core和其他文档的文档。 我find的只是C ++ / Obj-C和Bridging Swift Header解决scheme。 这对我来说已经提前和过时了。 现在我可以读取PCM数据到AVFoundation的CAF文件 settings = [ AVLinearPCMBitDepthKey: 16 as NSNumber, AVFormatIDKey: Int(kAudioFormatLinearPCM), AVLinearPCMIsBigEndianKey: 0 as NSNumber, AVLinearPCMIsFloatKey: […]

从AVPlayer获取HLS的PCM数据

这个问题似乎在过去几年中被问及几次,但没有人回答这个问题。 我正在尝试处理来自HLS的PCM数据,我必须使用AVPlayer。 这篇文章点击本地文件https://chritto.wordpress.com/2013/01/07/processing-avplayers-audio-with-mtaudioprocessingtap/ 而这个点击工作与远程文件,但不与.m3u8 hls文件。 http://venodesigns.net/2014/01/08/recording-live-audio-streams-on-ios/ 我可以播放播放列表中的前两个曲目,但它不启动所需的callback获得pcm,当文件是本地或远程(不stream)我仍然可以得到pcm,但它是hls不工作,我需要HLS工作 这是我的代码 //avplayer tap try – (void)viewDidLoad { [super viewDidLoad]; NSURL*testUrl= [NSURL URLWithString:@"http://playlists.ihrhls.com/c5/1469/playlist.m3u8"]; AVPlayerItem *item = [AVPlayerItem playerItemWithURL:testUrl]; self.player = [AVPlayer playerWithPlayerItem:item]; // Watch the status property – when this is good to go, we can access the // underlying AVAssetTrack we need. [item addObserver:self forKeyPath:@"status" options:0 context:nil]; } […]

播放来自NSStream的原始pcmaudio数据

我想从NSInputStream播放pcm数据。 任何人都可以提供正确的方法或代码来做到这一点。 我用下面的代码得到了StreamHasData事件中的audio。 uint8_t bytes[self.audioStreamReadMaxLength]; UInt32 length = [audioStream readData:bytes maxLength:self.audioStreamReadMaxLength]; 现在我怎么能在iPhone中播放字节audio数据?

如何在iOS上使用AVAssetReader正确读取已解码的PCM样本 – 目前解码不正确

我目前正在从事计算机科学学士学位的申请工作。 该应用程序将关联来自iPhone硬件(加速度计,GPS)和正在播放的音乐的数据。 这个项目还处于起步阶段,只有2个月的时间。 我现在正需要帮助的时刻,是从iTunes库中的歌曲中读取PCM样本,并使用audio单元进行播放。 目前我想工作的实现如下:从iTunes中随机select一首歌曲,并在需要时从中读取样本,并存储在缓冲区中,让我们称之为sampleBuffer。 稍后在消费者模型中,audio单元(具有混音器和remoteIO输出)具有callback,我只需将sampleBuffer中所需的样本数复制到callback中指定的缓冲区中。 然后我通过扬声器听到的是不是我所期望的; 我可以认识到,它正在播放歌曲,但它似乎是不正确的解码,它有很多的噪音! 我附加了一个图像,显示了第一〜半秒(24576样本@ 44.1kHz),这不像一个正常的输出。 在我进入清单之前,我已经检查过这个文件没有被破坏,类似的,我写了缓冲区的testing用例(所以我知道缓冲区不会改变这个样本),尽pipe这可能不是最好的方法(有些人会主张走audio队列路线),我想对样本进行各种操作,并在完成之前更改歌曲,重新排列播放什么歌曲等。此外,audio中可能存在一些不正确的设置单位,但是,显示样本(显示样本解码不正确)的graphics是从缓冲区中直接获取的,因此我现在只是在寻找解决为什么从磁盘读取和解码不能正常工作的原因。 现在我只想通过工作来玩游戏。 不能张贴图像,因为新的到stackoverflow所以inheritance人的形象的链接: 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]; 现在下面的代码清单是一个接收NSString和歌曲的persistant_id的方法: -(BOOL)setNextSongID:(NSString*)persistand_id { […]

确定核心audioAudioBuffer中的帧数

我正在尝试访问iPhone / iPad上的audio文件的原始数据。 我有下面的代码,这是我需要的path基本开始。 但是,我有一个AudioBuffer后,我很难做什么。 AVAssetReader *assetReader = [AVAssetReader assetReaderWithAsset:urlAsset error:nil]; AVAssetReaderTrackOutput *assetReaderOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:[[urlAsset tracks] objectAtIndex:0] outputSettings:nil]; [assetReader addOutput:assetReaderOutput]; [assetReader startReading]; CMSampleBufferRef ref; NSArray *outputs = assetReader.outputs; AVAssetReaderOutput *output = [outputs objectAtIndex:0]; int y = 0; while (ref = [output copyNextSampleBuffer]) { AudioBufferList audioBufferList; CMBlockBufferRef blockBuffer; CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(ref, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, […]