amr解码C语言程序
时间: 2023-12-16 10:04:20 浏览: 32
以下是一个简单的 AMR 解码的 C 语言程序:
```c
#include <stdio.h>
#include <stdlib.h>
#include "amrnb_decoder.h"
int main(int argc, char **argv) {
FILE *input_file;
FILE *output_file;
void *decoder_state;
unsigned char input_buffer[32];
short output_buffer[160];
int frame_size;
int read_size;
if (argc < 3) {
printf("Usage: %s input.amr output.pcm\n", argv[0]);
return 1;
}
input_file = fopen(argv[1], "rb");
if (!input_file) {
printf("Error: cannot open input file.\n");
return 1;
}
output_file = fopen(argv[2], "wb");
if (!output_file) {
printf("Error: cannot open output file.\n");
fclose(input_file);
return 1;
}
decoder_state = Decoder_Interface_init();
while (!feof(input_file)) {
read_size = fread(input_buffer, 1, 32, input_file);
if (read_size != 32) {
break;
}
frame_size = Decoder_Interface_Decode(decoder_state, input_buffer, output_buffer, 0);
fwrite(output_buffer, 1, frame_size * sizeof(short), output_file);
}
Decoder_Interface_exit(decoder_state);
fclose(input_file);
fclose(output_file);
return 0;
}
```
该程序使用了开源的 AMR-NB 编解码库,需要下载并编译该库之后才能使用。在编译时需要链接 amrnb 库和 pthread 库。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)