
我正在看Hollance的声音银行播放器.它会吸收大约15个左右的钢琴音符,通过计算出最接近哪个样本来播放任何音符,然后调整适当数量的音高.这是执行此 *** 作的代码:
- (voID) noteOn: (int) mIDiNoteNumber gain: (float) gain{ if (!initialized) { NSLog(@"SoundBankPlayer is not initialized yet"); return; } int sourceIndex = [self findAvailableSource]; if (sourceIndex != -1) { alGetError(); // clear any errors Note* note = notes + mIDiNoteNumber; if (note->bufferIndex != -1) { Buffer* buffer = buffers + note->bufferIndex; Source* source = sources + sourceIndex; source->noteIndex = mIDiNoteNumber; alSourcef(source->sourceID,AL_PITCH,note->pitch / buffer->pitch); alSourcei(source->sourceID,AL_LOOPing,AL_FALSE); alSourcef(source->sourceID,AL_REFERENCE_disTANCE,100.0f); alSourcef(source->sourceID,AL_GAIN,gain); float sourcePos[] = { note->panning,0.0f,0.0f }; alSourcefv(source->sourceID,AL_position,sourcePos); alSourcei(source->sourceID,AL_BUFFER,AL_NONE); alSourcei(source->sourceID,buffer->bufferID); ALenum error; if ((error = alGetError()) != AL_NO_ERROR) { NSLog(@"Error attaching buffer to source: %x",error); return; } alSourcePlay(source->sourceID); if ((error = alGetError()) != AL_NO_ERROR) { NSLog(@"Error starting source: %x",error); return; } } }} 你可以看到这条线做了音高变换:
alSourcef(source->sourceID,note->pitch / buffer->pitch);
不幸的是,这对于同时播放一堆音符并不好,因为它需要太多的cpu.它是动态的音高变换.
我想要的是为每个钢琴音符创建一个缓冲区,并使用这种音高变换技术填充这些缓冲区.但我无法看到如何让openAL将声音播放到缓冲区而不是通过扬声器播放.
有没有办法管道输出
alSourcePlay(源 – >的SourceID);
进入缓冲区?
如果我不能这样做,我的选择是什么?我已经尝试过使用DSPDimension文章中的smbPitchShift,但它没有提供良好的保真度:钢琴音符的攻击阶段确实丢失了.我想我可以使用Dirac3的免费版本…(我目前没有完整版本的钱,但我认为免费版本允许Mono处理,所以我可以破解它).还有其他选择吗?
编辑:我已经测试过Dirac3,它也有同样的问题.它似乎包围了攻击.似乎OpenAL的音高变换器以某种方式做了Dirac3没有的东西.
解决方法 alSourcePlayv允许你同时播放多个源 – 最大数量的源是平台相关的,但在iOS上是32(在苹果核心 – 音频列表上回答,这里为完整性) @H_301_2@ 总结以上是内存溢出为你收集整理的iOS:将OpenAL的Pitch Shifting和Piping输出转换为缓冲区全部内容,希望文章能够帮你解决iOS:将OpenAL的Pitch Shifting和Piping输出转换为缓冲区所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)