Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 播放时如何在iPod库中获取音乐的音频样本?_Ios_Audio - Fatal编程技术网

Ios 播放时如何在iPod库中获取音乐的音频样本?

Ios 播放时如何在iPod库中获取音乐的音频样本?,ios,audio,Ios,Audio,我需要获取实时播放的iPod音乐的音频样本 应用程序EQu(http://itunes.apple.com/us/app/equ-the-quality-equalizer/id403704212?mt=8)我认为,它已经实现了这一点,或者它无法应用其过滤器 我试过一些方法,但都没有用 我所能做的就是使用Avassetrader和Writer来保存iPod音乐的本地转换文件,并使用AudioUnit等低级技术进行播放?我想这个本地文件可能非常大 谢谢大家。几个步骤: I.创建本地缓冲区,如下面的

我需要获取实时播放的iPod音乐的音频样本

应用程序EQu(http://itunes.apple.com/us/app/equ-the-quality-equalizer/id403704212?mt=8)我认为,它已经实现了这一点,或者它无法应用其过滤器

我试过一些方法,但都没有用

我所能做的就是使用Avassetrader和Writer来保存iPod音乐的本地转换文件,并使用AudioUnit等低级技术进行播放?我想这个本地文件可能非常大

谢谢大家。

几个步骤:

I.创建本地缓冲区,如下面的示例所示,您必须确保
答:写入缓冲区时有足够的空间
b:当您从缓冲区读取数据时,有足够的数据
通过查看读/写idx

typedef struct
{
    //suppose non-interleaved LEI16 LPCM format
    SInt16 data[MUSIC_RING_BUFFER_NUM_CHANNEL][MUSIC_RING_BUFFER_SIZE];
    UInt16 readIdx;
    UInt16 writeIdx;
} MyRingBuffer;
CMSampleBufferRef nextBuffer = [self.trackOutput copyNextSampleBuffer];
CMBlockBufferRef buffer = CMSampleBufferGetDataBuffer( nextBuffer );

size_t lengthAtOffset;
size_t totalLength;
char* data;

if( CMBlockBufferGetDataPointer( buffer, 0, &lengthAtOffset, &totalLength, &data ) != noErr )
{
    NSLog( @"error!" );
    return;
}

//raw audio sample data now in (char*) data
[self performSelectorOnMainThread:@selector(fillMusicBuffer:) withObject:Nil waitUntilDone:NO];

二,。每次从AvassettTrackouput获取一些原始数据,如

typedef struct
{
    //suppose non-interleaved LEI16 LPCM format
    SInt16 data[MUSIC_RING_BUFFER_NUM_CHANNEL][MUSIC_RING_BUFFER_SIZE];
    UInt16 readIdx;
    UInt16 writeIdx;
} MyRingBuffer;
CMSampleBufferRef nextBuffer = [self.trackOutput copyNextSampleBuffer];
CMBlockBufferRef buffer = CMSampleBufferGetDataBuffer( nextBuffer );

size_t lengthAtOffset;
size_t totalLength;
char* data;

if( CMBlockBufferGetDataPointer( buffer, 0, &lengthAtOffset, &totalLength, &data ) != noErr )
{
    NSLog( @"error!" );
    return;
}

//raw audio sample data now in (char*) data
[self performSelectorOnMainThread:@selector(fillMusicBuffer:) withObject:Nil waitUntilDone:NO];

三、 然后将数据复制到本地缓冲区

非交织16位LPCM的原始数据如下

[2 bytes data x N, from left channel][2 bytes data x N from right channel] 顺便说一句,始终检查音频格式设置是否相同。从CMSampleBufferRef获取ASBD信息,并与AudioUnit输入设置进行比较