美文网首页
iOS/Mac pcm dump

iOS/Mac pcm dump

作者: Youzhicha | 来源:发表于2021-05-25 10:04 被阅读0次
    
     // 全局 file path:
    char debug_recording_path_[256];
    
      // locate file path on ios in debug mode
      NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSString* pcmPath = [NSString stringWithFormat: @"%@/testL.pcm", documentsDirectory];
      strcpy(debug_recording_path_, [pcmPath UTF8String]);
      RTC_LOG(LS_INFO) << "debug_recording_path_:"  << debug_recording_path_;
    
    
    =========== c++ 文件  ==============
    //pcm debug
    FILE *fp = nullptr;
    
    // file path
    extern char debug_recording_path_[256];
    
    
    // open file
    if(fp == NULL){
        fp = fopen(debug_recording_path_, "wb");
    }
    
    //write
     if(fp) {
           fwrite(reinterpret_cast<const int8_t*>(audio_frame->data()), 1, audio_frame->samples_per_channel_ * audio_frame->num_channels_ * 2, fp);
          }
    
    
    或者
    
    int8_t* datas = reinterpret_cast<int8_t*>(const_cast<int16_t*>(audio_frame->data()));
      if(fp && datas != NULL) {
        fwrite(datas, 1, audio_frame->samples_per_channel_*audio_frame->num_channels_*2, fp);
      }
    
    //close
    if(fp) fclose(fp);
    
    

    if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)

    extern char global_debug_recording_path_[256];

    endif

    if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)

    // open file
    if(fp == NULL){
    fp = fopen(global_debug_recording_path_, "wb");
    }

    swift 获取文件路径

     let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
     var pcmFilePath = documentsPath + "/tl.pcm"
      print("pcmFilePath:", pcmFilePath)
    
    

    相关文章

      网友评论

          本文标题:iOS/Mac pcm dump

          本文链接:https://www.haomeiwen.com/subject/tmeqsltx.html