简体   繁体   English

如何使用音频文件服务获取音频文件的原始数据?

[英]How to use Audio File Services to get the raw data of an audio file?

I'm trying to use the Audio File Services from the AudioToolBox framework to get the raw data from a wav file. 我正在尝试使用AudioToolBox框架中的音频文件服务从wav文件中获取原始数据。 Specifically, I'm using AudioFileReadBytes() call to get the bytes. 具体来说,我正在使用AudioFileReadBytes()调用来获取字节。 Here is the relevant code I have: 这是我的相关代码:

NSString *audioFilePath = [[NSString stringWithCString:argv[1]
                                              encoding:NSUTF8StringEncoding]
                           stringByExpandingTildeInPath];          
NSURL *audioURL = [NSURL fileURLWithPath:audioFilePath];               

AudioFileID audioFile;                                               
OSStatus theErr = noErr;
UInt64 fileDataSize = 0;
AudioStreamBasicDescription theFileFormat;
UInt32 thePropertySize = sizeof(theFileFormat);
theErr = AudioFileOpenURL((CFURLRef)audioURL, kAudioFileReadPermission, 0, &audioFile); 

thePropertySize = sizeof(fileDataSize);
theErr = AudioFileGetProperty(audioFile, kAudioFilePropertyAudioDataByteCount, &thePropertySize, &fileDataSize);

//Read data into buffer
UInt32 dataSize = fileDataSize;
void* theData = malloc(dataSize);
if (theData) {
    AudioFileReadBytes(audioFile, false, 0, &dataSize, theData);
            // create an NSData object to hold the buffer data
    NSData* nsdata = [NSData dataWithBytesNoCopy:theData length:dataSize]; //?
}

Now the question is: after I create the NSData object (nsdata), how do I get the numbered values from it (like if I do 'wavread' in Matlab it will give me an array of floats) so that I can manipulate the values(eg to pass through some filter)? 现在问题是:在我创建NSData对象(nsdata)之后,如何从中获取编号值(就像我在Matlab中'wavread'它会给我一个浮点数组),这样我就可以操作这些值(例如,通过一些过滤器)?

Any input is greatly appreciated! 任何输入都非常感谢!

I'm not sure why you need the NSData object at all. 我不确定你为什么需要NSData对象。

Using AudioFileGetProperty with kAudioFilePropertyDataFormat, you should be able to determine the type of audio data (eg array of floats) etc, and therefore how to interpret "theData". 将AudioFileGetProperty与kAudioFilePropertyDataFormat一起使用,您应该能够确定音频数据的类型(例如浮点数组)等,以及如何解释“theData”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM