我在目标C App上遇到了问题。
我正在从一个发送PCM编码声音的服务器(Socket c#)读取一个字节数组,我正在寻找一个示例代码,为我解码这个字节数组(NSData),并播放它。
有谁知道解决方案?或者我怎样才能阅读u-Law音频?
非常感谢! :d
答案 0 :(得分:2)
此链接包含有关mu-law编码和解码的信息:
http://dystopiancode.blogspot.com.es/2012/02/pcm-law-and-u-law-companding-algorithms.html
#define MULAW_BIAS 33
/*
* Description:
* Decodes an 8-bit unsigned integer using the mu-Law.
* Parameters:
* number - the number who will be decoded
* Returns:
* The decoded number
*/
int16_t MuLaw_Decode(int8_t number)
{
uint8_t sign = 0, position = 0;
int16_t decoded = 0;
number=~number;
if(number&0x80)
{
number&=~(1<<7);
sign = -1;
}
position = ((number & 0xF0) >>4) + 5;
decoded = ((1<<position)|((number&0x0F)<<(position-4))|(1<<(position-5)))
- MULAW_BIAS;
return (sign==0)?(decoded):(-(decoded));
}
当您拥有未压缩的音频时,您应该能够使用音频队列API播放它。
祝你好运!