【问题标题】:Change in the audio samples when reading directly from the file using RandomAcessFile?使用 RandomAcessFile 直接从文件中读取时音频样本的变化?
【发布时间】:2013-03-25 08:36:40
【问题描述】:

我正在尝试绘制声音文件的图表。我这样做的方式是使用 Fileinputstream 获取声音文件的字节并将其更改为短裤并获取声音样本并根据该注释绘制图形:前 45 个字节是标题所以我跳过这些字节。我成功地做到了。

File-->skip header(44)-->Bytes-->to shorts-->seek to point-->take samples in Shorts-->DRAW THE GRAPH

但问题是,我无法将大型音频文件 (2GB) 的字节存储到内存中。发生内存崩溃。

因此尝试使用 RandomAcessfile 直接从文件中读取短裤。但是当我这样做时,我没有得到正确的图表。我希望正在阅读的样本有一些变化。

File-->skip header(44)-->seek to point-->take samples in Shorts-->DRAW THE GRAPH

我的疑问是,当我们直接从文件中读取时,音频数据的短样本会发生任何变化吗?RandomAcessFile 是一个好方法吗?有什么方法可以在不改变样本的情况下获取 2GB 音频文件的样本。

注意:我跳过了标题的前 44 个字节。

【问题讨论】:

    标签: android audio sampling


    【解决方案1】:
                        double mPerwidth = (double) iPixel / 960;
                        int SampletoDraw;
                        long totalLen = mRfs.length() - 44;
                        SampletoDraw = (int) (totalLen * mPerwidth) * 2;
                        System.out.println(iPixel);
    
                        // val=mRfs.readShort()/2;
                        mRfs.seek(SampletoDraw);
                        bData[0] = mRfs.readByte();
                        mRfs.seek(SampletoDraw + 1);
                        bData[1] = mRfs.readByte();
    
                        val = (short) ((bData[1] & 0xff) << 8 | (bData
    
                                        [0] & 0xff));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      相关资源
      最近更新 更多