首页 > 解决方案 > 如何将 portaudio 录制的样本写入不同的文件?

问题描述

我正在使用peax_record.c示例从麦克风录制音频。一切都很好,但我想将录制的原始音频写入单独的文件。每一个都应该是 1 秒。1.raw 0-1 秒 2.raw 1-2 秒 ...

所以我对 WRITE_TO_FILE 做了一些修改

   #if WRITE_TO_FILE
        {
          FILE  *fid;
          SAMPLE *tempRecord = (SAMPLE *) malloc( totalFrames/NUM_SECONDS );
          fid = fopen("test.raw", "wb");    
          if( fid == NULL )
          {
           printf("Could not open file.");
          }
          for(int i=0; i <totalFrames/NUM_SECONDS ; i++) {
              tempRecord[i] = data.recordedSamples[i];    
              }
          int x = fwrite( tempRecord, NUM_CHANNELS * sizeof(SAMPLE), totalFrames/NUM_SECONDS, fid );
        }
    #endif

实际上,我知道,这不是我想要的,但作为第一步,我想写第一秒,如果成功,我可以写其他秒。但是使用这段代码,我遇到了分段错误。

如何解析 data.recordedSamples ?

标签: cportaudio

解决方案


推荐阅读