如何使用AVAudioPlayer或AVPlayer播放PCM数据/缓冲区?我知道,我可以使用AudioUnit/AudioQueue播放PCM数据/缓冲区,方法是将数据输入播放回调方法.但是不想这样做.
我在谷歌上搜索了很多,但找不到任何有用的答案或任何示例代码来执行此操作.任何帮助将受到高度赞赏.
如何在运行时/现场使用音频单元对音频(PCM数据)重新采样?
我有一个音频单元设置,如下所示。
- (void) setUpAudioUnit {
OSStatus status;
AudioComponentInstance audioUnit;
AudioComponent inputComponent;
AudioComponentDescription audioComponentDescription;
AudioStreamBasicDescription audioStreamBasicDescription;
// Describe audio component
audioComponentDescription.componentType = kAudioUnitType_Output;
audioComponentDescription.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
audioComponentDescription.componentFlags = 0;
audioComponentDescription.componentFlagsMask = 0;
audioComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
// Get component
inputComponent = AudioComponentFindNext(NULL, &audioComponentDescription);
// Get audio units
status = AudioComponentInstanceNew(inputComponent, &audioUnit);
checkStatus(status);
// Enable IO for recording
UInt32 flag = 1;
status = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
kInputBus,
&flag,
sizeof(flag));
checkStatus(status);
// Enable IO for playback
status = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
kOutputBus, …Run Code Online (Sandbox Code Playgroud) 我在 macOS 10.12.3 上。通过 Homebrew 安装并运行 MySQL。每当我尝试在终端上使用brew services start mysql或sudo mysql.server start命令启动 MySQL 时,它都会启动。以下是我的my.cnf文件驻留在/etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/Cellar/mysql/5.7.17
datadir=/usr/local/var/mysql
port=3306
server_id=1
socket=/tmp/mysql.sock
[client]
user=mysql
basedir=/usr/local/Cellar/mysql/5.7.17
datadir=/usr/local/var/mysql
port=3306
server_id=1
socket=/tmp/mysql.sock
Run Code Online (Sandbox Code Playgroud)
然后我尝试按照那里的说明使用Perfect-MySQL连接到 MySQL 。但未能找到并连接到套接字文件。得到以下错误,
[ERR] MySQL connection error: Can't connect to local MySQL server through socket '' (2)
[ERR] Error msg: error("MySQL server has gone away")
Run Code Online (Sandbox Code Playgroud)
显然它未能识别应该是/tmp/mysql.sock. 但是在运行 mysql 服务器后,我在mysql.sock.lock.lock文件/tmp/夹中找到了文件,没有mysql.sock文件。然后我将 my.cnf 文件更改为socket=/tmp/mysql.sock.lock.lock. 但同样的结果。
我没有安装其他 …
我试图在原始PCM数据之上添加一个wav标题,以使其可以通过AVAudioPlayer播放.但我在iOS上使用Objective-C/Swift找不到任何解决方案或源代码.虽然我发现了这个,但它没有正确的答案.
但是我在这里发现了一段代码,它在C中并且还包含一些问题.wav文件无法正常播放,该文件是从该代码生成的.
到目前为止,我已经给出了我编码的代码.
int NumChannels = AUDIO_CHANNELS_PER_FRAME;
short BitsPerSample = AUDIO_BITS_PER_CHANNEL;
int SamplingRate = AUDIO_SAMPLE_RATE;
int numOfSamples = [[NSData dataWithContentsOfFile:filePath] length];
int ByteRate = NumChannels*BitsPerSample*SamplingRate/8;
short BlockAlign = NumChannels*BitsPerSample/8;
int DataSize = NumChannels*numOfSamples*BitsPerSample/8;
int chunkSize = 16;
int totalSize = 36 + DataSize;
short audioFormat = 1;
if((fout = fopen([wavFilePath cStringUsingEncoding:1], "w")) == NULL)
{
printf("Error opening out file ");
}
fwrite("RIFF", sizeof(char), 4,fout);
fwrite(&totalSize, sizeof(int), 1, fout);
fwrite("WAVE", sizeof(char), 4, fout);
fwrite("fmt ", …Run Code Online (Sandbox Code Playgroud) ios ×3
objective-c ×3
audiounit ×2
c++ ×2
audio ×1
c ×1
core-audio ×1
homebrew ×1
ios7 ×1
mysql ×1
mysql.sock ×1
perfect ×1
resampling ×1
sockets ×1