c - 读取 AU 文件的 header - C

标签 c audio

我正在尝试读取 C 语言中的 .au 文件的 header ,并且我将所有值存储在 struct 中,但在转换时遇到问题它们为 Little Endian 格式。

我偶然发现了一种方法,ntohl,它应该获取字节并将它们转换为主机格式,但在编译程序时我不断收到错误。

对“ntohl”的 undefined reference

#include <stdio.h>

struct header
{
    char magic[5];
    int offset;
    int size;
    int encoding;
    int rate;
    int channels;
};

int main()
{
    FILE *fin, *fout;
    struct header au;
    char path[10];

    printf("Enter name of file to be processed: ");
    scanf("%s", path);

    fin = fopen(path, "r");
    fout = fopen("out.au","w");

    fscanf(fin, "%s %d %d %d %d %d", &au.magic, &au.offset, &au.size, &au.encoding, &au.rate, &au.channels);
    printf("%s\n%d\n%d\n%d\n%d\n%d\n", au.magic, ntohl(au.offset), ntohl(au.size), ntohl(au.encoding), ntohl(au.rate), ntohl(au.channels));
}

我正确读取标题值吗?

最佳答案

关于Linux OS ntohlarpa/inet.h(或 netinet/in.h)头文件中声明。上Windows它是Winsock2.h

至于读取标题的正确性,是不正确的。您正在执行 fscanf(fin, "%s %d %d %d %d %d... ,这是尝试读取文本表示中的数字,用空格分隔,这完全不是AU file 是如何表示的。此文件类型是二进制文件,应该使用 fread 作为二进制文件进行读取。

关于c - 读取 AU 文件的 header - C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29479220/

相关文章:

c - 在 C 中一次从文件中读入 X 个字符

c - 在 C 中确定文件是否正在 Windows 上被删除

audio - 在Drupal的同一页面上播放和下载音频文件

javascript - 浏览器中的自定义渐进式音频流

android - 我如何将 byte[] 缓冲区转换为振幅电平

c - 进程间信号量有时无法按预期工作

c++ - 从 32 位和 64 位二进制文​​件读取

c - Notetaker 漏洞利用问题

shell - 无法使用 ffmpeg 将评论元数据提供给 MP3 文件

android - 如何从声音文件(mp3)获取音频源?