代码拉取完成,页面将自动刷新
同步操作将从 lmc/G711 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "g711_table.h"
void print_usage(char *program_name)
{
printf("Usage: %s input_file CONVERSION output_file\n", program_name);
printf("Supported CONVERSIONs: pcm_alaw, pcm_ulaw, alaw_pcm, ulaw_pcm\n");
}
long get_file_size(FILE *f)
{
long file_size;
/* Go to end of file */
fseek(f, 0L, SEEK_END);
/* Get the number of bytes */
file_size = ftell(f);
/* reset the file position indicator to
the beginning of the file */
fseek(f, 0L, SEEK_SET);
return file_size;
}
char * allocate_buffer(long buffer_size)
{
char *buffer;
/* grab sufficient memory for the
buffer to hold the audio */
buffer = (char*)calloc(buffer_size, sizeof(char));
/* memory error */
if(buffer == NULL)
{
perror("Error while allocating memory for write buffer.\n");
exit(EXIT_FAILURE);
}
return buffer;
}
int main(int argc, char *argv[])
{
FILE *fRead, *fWrite;
char *bufferRead, *bufferWrite;
long bufferReadSize, bufferWriteSize;
size_t readed;
if(argc != 4)
{
printf("Incorrect parameter length.\n");
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
/* open an existing file for reading */
fRead = fopen(argv[1],"rb");
/* quit if the file does not exist */
if( fRead == NULL )
{
perror("Error while opening read file.\n");
exit(EXIT_FAILURE);
}
/* Get file size */
bufferReadSize = get_file_size(fRead);
/* grab sufficient memory for the
buffer to hold the audio */
bufferRead = allocate_buffer(bufferReadSize);
/* copy all the text into the buffer */
readed = fread(bufferRead, sizeof(char), bufferReadSize, fRead);
if (readed != bufferReadSize)
{
perror("Incorrect bytes readed\n");
exit(EXIT_FAILURE);
}
fclose(fRead);
/* Conversions */
if (strcmp(argv[2], "alaw_pcm") == 0)
{
alaw_pcm16_tableinit();
bufferWriteSize = bufferReadSize * 2;
bufferWrite = allocate_buffer(bufferWriteSize);
alaw_to_pcm16(bufferReadSize, bufferRead, bufferWrite);
}
else if (strcmp(argv[2], "ulaw_pcm") == 0)
{
ulaw_pcm16_tableinit();
bufferWriteSize = bufferReadSize * 2;
bufferWrite = allocate_buffer(bufferWriteSize);
ulaw_to_pcm16(bufferReadSize, bufferRead, bufferWrite);
}
else if (strcmp(argv[2], "pcm_alaw") == 0)
{
pcm16_alaw_tableinit();
bufferWriteSize = bufferReadSize / 2;
bufferWrite = allocate_buffer(bufferWriteSize);
pcm16_to_alaw(bufferReadSize, bufferRead, bufferWrite);
}
else if (strcmp(argv[2], "pcm_ulaw") == 0)
{
pcm16_ulaw_tableinit();
bufferWriteSize = bufferReadSize / 2;
bufferWrite = allocate_buffer(bufferWriteSize);
pcm16_to_ulaw(bufferReadSize, bufferRead, bufferWrite);
}
else
{
perror("Incorrect parameter.\n");
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
printf("Bytes read: %ld, Buffer Write: %ld\n", bufferReadSize, bufferWriteSize);
/* open a file for writing */
fWrite = fopen(argv[3], "wb");
/* quit if the file can not be opened */
if( fWrite == NULL )
{
perror("Error while opening the write file.\n");
exit(EXIT_FAILURE);
}
/* copy all the buffer into the file */
fwrite (bufferWrite , sizeof(char), bufferWriteSize, fWrite);
fclose (fWrite);
/* free the memory we used for the buffer */
free(bufferWrite);
free(bufferRead);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。