如何在iOS上没有失真的情况下增加MIDI合成器音量增益?

如何在iOS上没有失真的情况下增加MIDI合成器音量增益?,第1张

概述我在 this library年使用MIKMIDIS合成器在iPhone上播放MIDI文件.不幸的是,即使将iPhone的系统音量一直提升,音量也非常低.为了进一步增加它,我试过这些东西: >将所有MIDI Note On事件的速度属性修改为最大值127.这略微但不足以提高音量. >如here所述,将混音器节点添加到AUGraph.这足以提高音量,但会立即扭曲信号,使质量太差. >使用像Polyp 我在 this library年使用MIKMIdis合成器在iPhone上播放MIDI文件.不幸的是,即使将iPhone的系统音量一直提升,音量也非常低.为了进一步增加它,我试过这些东西:

>将所有MIDI Note On事件的速度属性修改为最大值127.这略微但不足以提高音量.
>如here所述,将混音器节点添加到AUGraph.这足以提高音量,但会立即扭曲信号,使质量太差.
>使用像polyphone这样的声音编辑器提高soundFont样本的音量.这没有可察觉的效果.

现在我的选项已经用完了.是否有任何额外的参数或级别(如AVAudioSession或CoreMIDI,可能),我错过了并提供调整音量/增益的可能性?或者MIDI命令也这样做?

代码片段

1.使用混音器节点

这是我修改的MIKMIdisynthesizer的一部分,以便用混音器节点控制音量.

- (BOol)setupAUGraph{    AUGraph graph;    Osstatus err = 0;    // 1. Create new AUGraph    if ((err = NewAUGraph(&graph))) {        NSLog(@"Unable to create AU graph: %@",@(err));        return NO;    }    // 2. Create output node    AudioComponentDescription outputcd = {0};    outputcd.componentType = kAudioUnitType_Output;    outputcd.componentSubType = kAudioUnitSubType_RemoteIO;    outputcd.componentManufacturer = kAudioUnitManufacturer_Apple;    AUNode outputNode;    if ((err = AUGraphAddNode(graph,&outputcd,&outputNode))) {        NSLog(@"Unable to add ouptput node to graph: %@",@(err));        return NO;    }    // 3. Create the instrument node    AudioComponentDescription instrumentcd = self.componentDescription;    AUNode instrumentNode;    if ((err = AUGraphAddNode(graph,&instrumentcd,&instrumentNode))) {        NSLog(@"Unable to add instrument node to AU graph: %@",@(err));        return NO;    }    if ((err = AUGraphOpen(graph))) {        NSLog(@"Unable to open AU graph: %@",@(err));        return NO;    }    AudioUnit instrumentUnit;    if ((err = AUGraphNodeInfo(graph,instrumentNode,NulL,&instrumentUnit))) {        NSLog(@"Unable to get instrument AU unit: %@",@(err));        return NO;    }    // 4. Create the mixer node    AUNode mixerNode;    AudioComponentDescription cd = {};    cd.componentManufacturer = kAudioUnitManufacturer_Apple;    cd.componentType = kAudioUnitType_mixer;    cd.componentSubType = kAudioUnitSubType_MultiChannelmixer;    if ((err = AUGraphAddNode(graph,&cd,&mixerNode))) {        NSLog(@"Unable to add mixer node to AU graph: %@",@(err));        return NO;    }    if ((err = AUGraphNodeInfo(graph,mixerNode,&_mixerUnit))) {        NSLog(@"Unable to fetch mixer node reference from AU graph: %@",@(err));        return NO;    }    UInt32 busCount = 2;    err = AudioUnitSetProperty(_mixerUnit,kAudioUnitProperty_ElementCount,kAudioUnitScope_input,&busCount,sizeof (busCount)                               );    if (err) {        NSLog(@"Unable to set mixer unit propertIEs");        return NO;    }    // 5.1 Connect the instrument node as the mixer node's input    if ((err = AUGraphConnectNodeinput(graph,0))) {        NSLog(@"Unable to connect input node and mixer node: %@",@(err));        return NO;    }    // 5.2 Connect the mixer node as the output node's input    if ((err = AUGraphConnectNodeinput(graph,outputNode,@(err));        return NO;    }    if ((err = AUGraphInitialize(graph))) {        NSLog(@"Unable to initialize AU graph: %@",@(err));        return NO;    }    // 6. Finally,start the graph    if ((err = AUGraphStart(graph))) {        NSLog(@"Unable to start AU graph: %@",@(err));        return NO;    }    self.graph = graph;    self.instrumentUnit = instrumentUnit;    return YES;}

设置混音器节点后,我可以像这样更改音量(引入剪辑!):

-(voID) setVolume: (float) volume {    AudioUnitSetParameter(_mixerUnit,kMultiChannelmixerParam_Volume,kAudioUnitScope_Output,volume,0);}

2.更改MIDI事件

第二种方法将每个Node On事件的veLocity属性设置为最大值127.它增加音量而没有任何噪声,但仅增加到一定水平.代码驻留在MIKMIDINoteEvent中:

+ (MIKMIDINoteOnCommand *)noteOnCommandFromNoteEvent:(MIKMIDINoteEvent *)noteEvent clock:(MIKMIDIClock *)clock{    MIKMutableMIDINoteOnCommand *noteOn = [MIKMutableMIDINoteOnCommand commandForCommandType:MIKMIDICommandTypeNoteOn];    noteOn.mIDiTimestamp = [clock mIDiTimeStampForMusicTimeStamp:noteEvent.timeStamp];    noteOn.channel = noteEvent.channel;    noteOn.note = noteEvent.note;    noteOn.veLocity = 127; // <------- Here's the magic    return [noteOn copy];}
解决方法 对于MIDI合成器使用的某些类型的采样波形,可能会发生这种情况.采样波形的峰值体积可能已包含格式附近或最大可能的样本(例如,对于16位样本为-32767,对于浮点样本为-1.0),即使平均体积(能量总和)太低.因此,音量的任何简单线性增加都会产生剪切噪声,这听起来非常糟糕.

各种压缩器技术或滤波器可能能够在不削波的情况下增加平均音量,但是这可以增加其自身的质量降低(但是比削波更不烦人).

补充:使用另一个mIDi采样器,声音字体或具有接近恒定音量的声音(较低的PAPR,峰值平均功率比)是另一种可能性.

总结

以上是内存溢出为你收集整理的如何在iOS上没有失真的情况下增加MIDI合成器音量/增益?全部内容,希望文章能够帮你解决如何在iOS上没有失真的情况下增加MIDI合成器音量/增益?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1059293.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存