如何追踪颤振库audo_recorder和立体声之间的干扰

时间:2018-06-04 19:02:38

标签: flutter flutter-dependencies

我正在使用Flutter构建一个应用程序,允许我录制音频,然后再播放。我正在使用包audio_recorder 0.4.0来录制音频,使用包stereo 1.0.0来播放音频。

当我使用iOS模拟器录制时,一切正常。但是当我在物理设备(iPhone 6 Plus)上运行时,我总是在录制会话结束时得到一个28字节的文件 - 基本上只是m4a文件的标题。

我已将此跟踪到两个库之间的某种干扰。如果我使用audio_recorder 0.4.0附带的示例应用程序,我可以在物理设备上录制。但我要做的就是将行stereo: 1.0.0添加到同一个示例项目的pubspec.yml中的依赖项中,然后突然我开始在记录会话结束时在物理设备上获取28字节文件而不是正常大小的m4a文件。

我有一个由两部分组成的问题:

  1. stereo库可能会导致audio_recorder库中出现这种类型的故障?我怀疑是频道干扰,但是我试图隔离它并没有产生任何影响。

  2. 如何追踪导致此问题的原因?

  3. 我检查了两个会话的控制台输出。当它失败时,我在尝试开始录制后立即在控制台输出中看到几行(8):

    mediaserverd    1111: AudioConverterNew returned -50
    

    其他人建议在没有可用的麦克风时发生此错误。

    我也看到了输出之间的这种可疑差异。 录音被打破时:

    default 11:36:57.098825 -0700   mediaserverd    4414: { "action":"set_play_state", "session":{"ID":"0x3315820","PID":14591,"name":"Runner"}, "details":"entry" }
    default 11:36:57.100484 -0700   mediaserverd    -CMSessionMgr- cmsSetIsPlaying: CMSession: 'sid:0x3315820, Runner(14591), 'prim'' with [MediaPlayback/Default] [NonMixable] [System Audio] starting playing.
    default 11:36:57.104699 -0700   mediaserverd    CAReportingClient.mm:328:-[CAReportingClient sendMessage:category:type:reporters:]: message {
        Volume = "0.75";
        VolumeCategory = "Audio/Video";
        VolumeOperationProcess = "com.monkela.audioRecordSample";
        VolumeOperationTime = 576708;
        VolumePlayingState = 1;
    }: (
        857014545
    )
    default 11:36:57.105879 -0700   mediaserverd    -CMVAEndptMgr- vaemSetDeviceVolume: CMSession: Setting cmsvolume = 0.750 for device ID: VirtualAudioDevice_Default
    default 11:36:57.107295 -0700   mediaserverd    VirtualAudio_Device.cpp:2046:SetPropertyData: [volm/outp/0] on device [ type: vdef; id: 354; addr: 0x1014e1ba0; hidden: 0; VA strms: { o/883/0x106fc5980 }; agg dev: [ id: 872; addr: 0x106f1a460; uid: "VAD [vdef] AggDev 52"; virt strms: {  }; phys devs: { [ id: 292; addr: 0x104b0fdb0; uid: "Speaker"; streams: { i/294/0x104b11cd0, o/293/0x104b12790 } ] } ] ]: 0.750000.
    default 11:36:57.108123 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:662:CommitVolume: Setting Volume = -14.500000 dB, Final HW Volume = 0.000000 dB, Final SW Volume = -14.500000 dB, External Volume Handler: No
    default 11:36:57.109008 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:663:CommitVolume:     PhysicalDevice UID = "Speaker"
    default 11:36:57.109721 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:664:CommitVolume:     Scope = 1869968496 ("outp")
    default 11:36:57.110704 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:665:CommitVolume:     Element = 0 ("0")
    default 11:36:57.112062 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:698:CommitVolume:     SW Volume: 0.750000 scalar
    default 11:36:57.114393 -0700   mediaserverd    VirtualAudio_Device.cpp:2066:SetPropertyData: Client request to set nominal sample rate to 44100.000000 on VAD 354.
    default 11:36:57.116038 -0700   assertiond  [Runner:14591] Attempting to acquire assertion for Runner:14591: <BKProcessAssertion: 0x101349110; "CMSession.14591."com.monkela.audioRecordSample"."MediaPlayback".isPlayingProcessAssertion" (audio:inf); id:…C74721DE1F95>
    default 11:36:57.116572 -0700   assertiond  [Runner:14591] Add assertion: <BKProcessAssertion: 0x101349110; id: 13077-914DDDE2-35CE-4420-85ED-C74721DE1F95; name: CMSession.14591."com.monkela.audioRecordSample"."MediaPlayback".isPlayingProcessAssertion; state: active; reason: audio; duration: infs> {
        owner = <BSProcessHandle: 0x101009be0; mediaserverd:13077; valid: YES>;
        flags = preventSuspend, preventThrottleDownCPU, preventIdleSleep, preventSuspendOnSleep;
    }
    

    录制工作时:

    default 11:39:19.865022 -0700   mediaserverd    2863: { "action":"activate", "session":{"ID":"0x3315826","PID":14609,"name":"Runner"}, "details":"entry" }
    default 11:39:19.880637 -0700   mediaserverd    CAReportingClient.mm:328:-[CAReportingClient sendMessage:category:type:reporters:]: message {
        "active devices" = "[ { vdef, [  ], [ pspk ( 0 ) ] }, { vspd, [ pmbi ( 0 ) ], [  ] }, { vcal, [ pdln ( 0 ) ], [ puln ( 0 ) ] } ]";
        category = csav;
        "going_active" = 1;
        mode = imdf;
        "staying_active" = 0;
    }: (
        857014546
    )
    

    录制时的输出被破坏表明我开始录制的尝试实际上开始播放(即调用错误的库)。

1 个答案:

答案 0 :(得分:3)

我跟踪了这​​一点,并通过修改stereo包找出了如何使库协同工作。事实证明,stereo包正在application didFinishLaunchingWithOptions中激活播放音频会话。基本上这些行:

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:&error];
[session setActive:YES error:&error];

我分叉stereo包并更改代码以仅在实际需要时激活回放会话。可悲的是我的录音功能开始起作用了。

我不确定为什么它在模拟器中有效。不知何故,模拟器必须能够同时进行回放和录制会话。

更新:stereo包的作者接受了我的拉取请求,只要你有1.0.1版本的包,就应该能够避免这种干扰问题。