0
我有一個NSDATA是一個音頻緩衝區(BIG_ENDIAN),我試圖獲取緩衝區的每2個字節,並將其轉換爲int_16格式以在這些結果中應用編解碼器。我正在嘗試以下操作:如何將字節從NSDATA轉換爲BigInt16?
-(NSData*)encodeSample:(NSData*)buffer
{
NSMutableData *backValue = [[NSMutableData alloc] init];
for (int i = 0; i < [buffer length]; i+=4)
{
if (i+4 > [buffer length])
{
break;
}
else
{
NSRange range = {i,2};
int16_t temp1 = OSReadBigInt16([buffer subdataWithRange:range], 0);
int result1 = [self encode:temp1] & 0x0F; //codec call
NSRange range2 = {i+2,2};
int temp2 = OSReadBigInt16([buffer subdataWithRange:range2], 0);
int result2 = [self encode:temp2] & 0x0F;
Byte finalValue = (Byte) ((result1 << 4) | result2);
[backValue appendBytes:&valorFinal length:sizeof(valorFinal)];
}
我正在閱讀函數OSReadBigInt16的蘋果文檔,我認爲它不適用於NSDATA,我不知道該怎麼做才能獲得正確的值。
有人有關於如何從nsdata獲取字節並將其轉換爲int_16的想法嗎?