我正在开发一个应用程序,我需要通过输出音频插孔同时通过音频捕获记录和保存视频.
我已经研究了aurio touch apple示例代码并实现了音频直通.
我也通过实施视频录制AVCaptureSession.以上两个功能单独完成并且完美地工作.
但是当我合并功能音频通过不工作因为音频会话AVCapturesession.
我还试图通过AVCaptureSession委托方法传递音频数据.以下是我的代码:
OSStatus err = noErr;
AudioBufferList audioBufferList;
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
CMItemCount numberOfFrames = CMSampleBufferGetNumSamples(sampleBuffer); // corresponds to the number of CoreAudio audio frames
currentSampleTime += (double)numberOfFrames;
AudioTimeStamp timeStamp;
memset(&timeStamp, 0, sizeof(AudioTimeStamp));
timeStamp.mSampleTime = currentSampleTime;
timeStamp.mFlags |= kAudioTimeStampSampleTimeValid;
AudioUnitRenderActionFlags flags = 0;
aurioTouchAppDelegate *THIS = (aurioTouchAppDelegate *)[[UIApplication sharedApplication]delegate];
err = AudioUnitRender(self.rioUnit, &flags, &timeStamp, 1, numberOfFrames, &audioBufferList);
if (err) { printf("PerformThru: error %d\n", …Run Code Online (Sandbox Code Playgroud) 我最近碰到了一个我在互联网上找不到的问题 - 我正在初始化AVAudioPlayer播放音频文件,并收到以下错误:
Error Domain=NSOSStatusErrorDomain Code=-50 "Operation could not be completed. (OSStatus error -50.)
Run Code Online (Sandbox Code Playgroud)
事实证明,我在创建NSURL发送到音频播放器init方法时犯了一个错误,导致NSURL对象为空.愚蠢的错误,调试时很容易找到,但我想我会在这里列出它以防万一其他人做同样的事情.
我想录制一些音频AVAudioEngine和用户麦克风.我已经有了一个工作样本,但是无法弄清楚如何指定我想要的输出格式...
我的要求是,我需要AVAudioPCMBuffer我现在说的话......
我是否需要添加一个可以进行转码的单独节点?我找不到关于那个问题的文档/样本......
在Audio-Stuff方面,我也是一个菜鸟.我知道我想要NSData包含PCM-16bit,最大采样率为16000(8000会更好)
这是我的工作样本:
private var audioEngine = AVAudioEngine()
func startRecording() {
let format = audioEngine.inputNode!.inputFormatForBus(bus)
audioEngine.inputNode!.installTapOnBus(bus, bufferSize: 1024, format: format) { (buffer: AVAudioPCMBuffer, time:AVAudioTime) -> Void in
let audioFormat = PCMBuffer.format
print("\(audioFormat)")
}
audioEngine.prepare()
do {
try audioEngine.start()
} catch { /* Imagine some super awesome error handling here */ }
}
Run Code Online (Sandbox Code Playgroud)
如果我改变格式让'说'
let format = AVAudioFormat(commonFormat: AVAudioCommonFormat.PCMFormatInt16, sampleRate: 8000.0, channels: 1, interleaved: false)
Run Code Online (Sandbox Code Playgroud)
然后如果会产生一个错误,说样本速率需要与hwInput相同...
很感谢任何形式的帮助!!!
编辑:我刚刚发现,AVAudioConverter但我需要兼容iOS8 ...
我编写了以下AVAudioEngine代码,用于初始化我的一个自定义AUAudioUnit子类并将其连接到引擎的主混音器节点.
class AudioEngine {
let engine = AVAudioEngine()
init() {
let sess = AVAudioSession.sharedInstance()
try! sess.setCategory(AVAudioSessionCategoryPlayback)
try! sess.setActive(true)
let desc = AudioComponentDescription(componentType: kAudioUnitType_Generator, componentSubType: 0x00000001, componentManufacturer: 0x00000002, componentFlags: 0, componentFlagsMask: 0)
AUAudioUnit.registerSubclass(MyAudioUnit.self, as: desc, name: "MyAudioUnit", version: 2)
let format = engine.outputNode.outputFormat(forBus: 0)
engine.connect(engine.mainMixerNode, to: engine.outputNode, format: format)
AVAudioUnit.instantiate(with: desc, options: []) { (audiounit, error) in
guard let au = audiounit else { return }
self.engine.attach(au)
let stereoFormat = AVAudioFormat(standardFormatWithSampleRate: format.sampleRate, channels: 2)
// CRASHES HERE
self.engine.connect(au, to: …Run Code Online (Sandbox Code Playgroud) 使用3个AudioBuffers初始化(分配内存)和释放(释放)AudioBufferList的正确方法是什么?(我知道可能有多种方法可以做到这一点.)
我想使用这3个缓冲区来读取音频文件的连续部分并使用音频单元播放它们.
开发使用CoreAudio框架的iOS应用程序,我正在处理SDL reg的IMHO废话行为.播放音频.SDL循环播放音频,只有如何触发播放的方式是调用SDL_PauseAudio(0),而如何停止它的唯一方法(没有其他副作用,这里我不会谈到)是调用SDL_PauseAudio(1).我所知道的.
SDL在这里有什么问题?简单 - 下一次调用SDL_PauseAudio(1)实际上恢复播放,导致框架在要求新的声音数据*之前播放一些混乱*.这是因为SDL_CoreAudio.c实现回放循环的方式.
这意味着,SDL不实现STOP,它只实现PAUSE/RESUME并错误地管理音频处理.这意味着,如果您播放sampleA,并希望稍后播放sampleB,您将听到sampleA的片段,同时期望只听到sampleB的播放.
如果我错了,请纠正我.
如果不是,这是我的差异,是我用来实现也将停止行为:只要我完成播放sampleA,我打电话SDL_PauseAudio(2)让循环播放退出并SDL_PauseAudio下一个电话(0)打再次启动,这一次没搞成从sampleA,但正确播放来自smapleB的数据.
Index: src/audio/coreaudio/SDL_coreaudio.c
===================================================================
--- src/audio/coreaudio/SDL_coreaudio.c
+++ src/audio/coreaudio/SDL_coreaudio.c
@@ -250,6 +250,12 @@
abuf = &ioData->mBuffers[i];
SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
}
+ if (2 == this->paused)
+ {
+ // this changes 'pause' behavior to 'stop' behavior - next
+ // plyaing starts from beginning, i.e. it won't resume
+ this->hidden->bufferOffset = this->hidden->bufferSize;
+ }
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我感到很惭愧,我编辑了SDL代码,但我与作者没有关系,也没有找到任何帮助.嗯,对我来说很奇怪,在SDL中似乎没有人需要STOP行为?
这是我的代码:我使用此代码通过使用音频单元记录iPhone输出音频,然后将输出保存在output.caf中,但output.caf文件为空,任何人都知道我该怎么办?输出音频文件为空
这是音频单元的初始化
-(void) initializaeOutputUnit
{
OSStatus status;
// Describe audio component
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
// Get component
AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc);
// Get audio units
status = AudioComponentInstanceNew(inputComponent, &audioUnit);
// Enable IO for recording
UInt32 flag = 1;
status = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
kInputBus,
&flag,
sizeof(flag));
// Enable IO for playback
status = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
kOutputBus,
&flag,
sizeof(flag));
// Describe format
AudioStreamBasicDescription audioFormat={0};
audioFormat.mSampleRate …Run Code Online (Sandbox Code Playgroud) RemoteIO设备有没有办法在iPhone 5上拿回麦克风?我可以配置AVAudioSession在前置麦克风或底部麦克风之间进行选择,但我找不到选择后置麦克风的方法.
在AVFoundation framework确定了使用视频录制的背部麦克风使用后置摄像头的时候,但我希望的方式来选择使用相同的CoreAudio的.那可能吗 ?
我读过这些问题:
iOS FFT Accerelate.framework在播放期间绘制频谱
它们都描述了如何使用加速框架设置fft.在他们的帮助下,我能够设置fft并获得一个基本的频谱分析仪.现在,我正在显示我从fft获得的所有值.但是,我只想显示10-15或一个可变数量的条形图来确定某些频率.就像iTunes或WinAmp Level Meter一样.1.我是否需要从一系列频率中平均幅度值?或者他们只是向您展示特定频率条的幅度?2.此外,我是否需要将我的幅度值转换为db?3.如何将数据映射到特定范围.我是否映射了我的声音bitdepth的最大db范围?获取bin的最大值将导致跳转最大映射值.
我的RenderCallback:
static OSStatus PlaybackCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData)
{
UInt32 maxSamples = kAudioBufferNumFrames;
UInt32 log2n = log2f(maxSamples); //bins
UInt32 n = 1 << log2n;
UInt32 stride = 1;
UInt32 nOver2 = n/2;
COMPLEX_SPLIT A;
float *originalReal, *obtainedReal, *frequencyArray, *window, *in_real;
in_real = (float *) malloc(maxSamples * sizeof(float));
A.realp = (float *) malloc(nOver2 * sizeof(float));
A.imagp = (float *) malloc(nOver2 * sizeof(float));
memset(A.imagp, …Run Code Online (Sandbox Code Playgroud) core-audio ×10
ios ×5
audiounit ×4
iphone ×4
avfoundation ×3
c ×1
cocoa-touch ×1
fft ×1
ios5 ×1
objective-c ×1
playback ×1
remoteio ×1
sdl ×1
spectrum ×1
vdsp ×1