如何找到正确的RAW格式 [英] How to find the right RAW format

查看:144
本文介绍了如何找到正确的RAW格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码

SNDFILE *sf;
SF_INFO info;
int num_channels;
int num, num_items;
int *buf;
int f,sr,c;
int i,j;
FILE *out;

/* Open the WAV file. */
info.format     = (SF_FORMAT_RAW | SF_FORMAT_PCM_16);  
info.samplerate = 44100;
info.channels = 2;  

sf = sf_open("test.raw",SFM_READ,&info);

if (sf == NULL)
    {
    printf("Failed to open the file. ( %d )\n",sf_perror(sf));
    exit(-1);
    }
/* Print some of the info, and figure out how much data to read. */
f = info.frames;
sr = info.samplerate;
c = info.channels;
num_items = f*c;
/* Allocate space for the data to be read, then read it. */
buf = (int *) malloc(num_items*sizeof(int));
num = sf_read_int(sf,buf,num_items);
sf_close(sf);
printf("Read %d items\n",num);
/* Write the data to filedata.out. */
out = fopen("test.txt","w");  
int links;
int rechts;
for (i = 0; i < num; i += c)
{
  for (j = 0; j < c; ++j)
      fprintf(out,"%d ",buf[i+j]);
  fprintf(out,"\n");
}  
fclose(out);

其目的是读取"test.raw",将其转换为数组并将其写入"test.txt". "test.raw"是由

It's purpose is to read "test.raw", convert it to an array and write this into "test.txt". "test.raw" is a raw pcm created by

...    
static const pa_sample_spec ss = 
{
    .format = PA_SAMPLE_S16LE,
    .rate = 44100,
    .channels = 2
};
pa_simple *s = NULL;
int ret = 1;
int error;
s = pa_simple_new(NULL, 
        "rec", 
        PA_STREAM_RECORD, 
        "bluez_source.00_00_00_00_00_00", 
        "rec", 
        &ss, 
        NULL, 
        NULL, 
        &error)  
...     

来自pulseaudio录音示例(下载).

from the pulseaudio audio recording sample(download).

事实是,我得到了类似的东西

Thing is, I get something like

219676672 -131072 
219676672 327680 
219611136 655360 
219217920 327680 
218955776 -131072 
219152384 -393216 
218693632 -720896 

在test.txt中.我添加了标题,以获得

in test.txt. I added headers, to get

SAMPLES:    365568
BITSPERSAMPLE:  16
CHANNELS:   2
SAMPLERATE: 44100
NORMALIZED: FALSE
219676672 -131072 
219676672 327680 
219611136 655360 
219217920 327680 
218955776 -131072 
219152384 -393216 
218693632 -720896 

并作为ascii文件导入到Adobe Audition中.我在那里使用44100、16位和立体声以及英特尔(也尝试过摩托罗拉).

and imported into adobe audition as ascii file. I use 44100, 16 bit and stereo there aswell as the intel(also tried the motorola).

每次,我只会得到条",即音量恒定的时间段.在试听中读取"test.raw"时,我看到的数据应该使用intel属性.

Each time I only get "bars" ie periods of constant volume. When reading "test.raw" in audition i see the data as it should be using the intel property.

我需要进行哪些调整才能使其正常工作?

What do I need to tweak for this to work?

推荐答案

通过查看数据,您似乎在16位和32位带符号整数数据之间感到困惑.您的.raw数据是16位的,可能还可以,但是您的.txt数据具有类似219676672, -131072的数字​​,显然不在16位数据范围内(最小值为-32768,最大值为32767).

By looking at your data, it seems that you have a confusion between 16-bit and 32-bit signed integer data. Your .raw data is 16-bit and is probably okay, but your .txt data has numbers like 219676672, -131072 which is clearly out of 16-bit data range (minimum is -32768, maximum is 32767).

您所描述的每次我只得到条",即恒定体积的时间段,这称为饱和度:您试图显示超出限制的数字,以便将数值替换为限制. Audition检测到您的数据是32位的,因此它将正确显示.

What you are describing as Each time I only get "bars" i.e. periods of constant volume, is called saturation: You are trying to display numbers above the limits so the values are replaced by the limit. Audition detects your data is 32-bit so it will display it correctly.

我认为您的int是32位,因此您不应该将读取的数据存储到int,而是存储到short或16位等效项.

I think your int is 32-bit, so you should not store read data to an int, but a short or the 16-bit equivalent.

short *buf;

. . .

/* Allocate space for the data to be read, then read it. */
buf = (short *) malloc(num_items*sizeof(short));
num = sf_read_short(sf,buf,num_items);

这篇关于如何找到正确的RAW格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆