8位转换器源代码

8位转换器源代码

本文介绍了简单的WAV 16位/8位转换器源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我提供一个简单的WAV 16位到8位(如果可能的话,还可以返回)转换器的源代码(最好是C/C ++)的链接吗?我具有C ++的基本知识,并且需要有一个资源来理解wav编写和转换新项目的值.目前,我有一个关于RIFF块结构的讲座.

could someone provide me a link to source code (preferably C/C++) of a simple WAV 16-bit to 8-bit (and back if possible) converter? I have basic knowledge of C++ and I need to have a resource to understand wav writing and converting values for my new project. At this moment I have a lecture about RIFF chunks structure.

任何在不同位深度之间转换值的公式(也是这些非标准的)都值得赞赏...

Also any formulas for converting values between different bit depths (also these un standard) appreciated...

我希望它是简单易用的命令行,因此我可以使用记事本对其进行编辑并轻松进行编译.

I'll prefer it to be simple and command line so I can edit it with notepad and easily compile.

提前谢谢!

推荐答案

对于读写WAV文件,请查看规范:
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

For reading and writing WAV files have a look at the specification:
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

要在8位和16位之间转换,您只需将其除以256.
例如(将C中的16位转换为8位):

For converting between 8 and 16 bit you just need to divide or multiply by 256.
For example (converting from 16 to 8 bit in C):

  • 使用fopen()打开16位文件和(尚不存在)8位文件.
  • 根据规范,您读取了16位文件的开头,并写入了8位文件的开头.
  • 然后对每个样本执行以下操作:
  • You open the 16 bit file and the (not yet existent) 8 bit file using fopen().
  • You read the beginning of the 16 bit file and write the beginning of the 8 bit file according to the specification.
  • Then you do the following for each sample:
    int sample = 0;
    // read 2 bytes (= 16 bits) from the 16 bit file into sample:
    fread (&sample, 2, 1, wav_file_16bit);
    sample /= 256; // divide sample by 256
    // write 1 byte (= 8 bits) to the 8 bit file:
    fwrite (&sample, 1, 1, wav_file_8bit);

  • 别忘了关闭文件.
  • 如果您需要更多具体信息,请询问.

    If you need more specific information please ask.

    这篇关于简单的WAV 16位/8位转换器源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:12