在我的问题here发布之后,LAME
对gdb
的进一步调查显示,在任何给定时间,只有576个样本从输入pcm
文件中读取。但是,这些样本用于填充2304 1D或2 * 1152 2D阵列。这是我无法理解的转换。我在这里发布相关代码并请求解释。我已经解释了代码的一部分,并将问题插入代码???
。
samples_read = read_samples_pcm(global.musicin, insamp, num_channels * samples_to_read);
/* global.musicin = FILE pointer to input pcm file.
* insamp is a 1D int array of [2*1152] size.
* num_channels = 1. samples_to_read = 576. */
if (samples_read < 0) {
return samples_read;
}
p = insamp + samples_read;
samples_read /= num_channels; /*samples_read = 576 after this step. prior to this it is optimized out.*/
if (buffer != NULL) { /* output to int buffer */
if (num_channels == 2) {
for (i = samples_read; --i >= 0;) {
buffer[1][i] = *--p;
buffer[0][i] = *--p;
}
}
else if (num_channels == 1) {
memset(buffer[1], 0, samples_read * sizeof(int));
for (i = samples_read; --i >= 0;) {
buffer[0][i] = *--p;
/*??? Is this line a fancy way of copying first 576 samples of insamp into buffer[0]?*/
}
}
else
assert(0);
}
函数read_samples_pcm
定义如下:
static int
read_samples_pcm(FILE * const musicin, int sample_buffer[2304], int samples_to_read)
{
int samples_read;
samples_read = sf_read_int((SNDFILE *) musicin, sample_buffer, samples_to_read);
#if 0
switch (global.pcmbitwidth) {
case 8:
for (i = 0; i < samples_read; i++)
sample_buffer[i] <<= (8 * sizeof(int) - 8);
break;
case 16: /*input pcm is 16 bit say.*/
for (i = 0; i < samples_read; i++)
sample_buffer[i] <<= (8 * sizeof(int) - 16); /*??? what is going on? */
break;
case 24:
for (i = 0; i < samples_read; i++)
sample_buffer[i] <<= (8 * sizeof(int) - 24);
break;
case 32:
break;
default:
if (silent < 10) {
error_printf("Only 8, 16, 24 and 32 bit input files supported \n");
}
exit(1);
}
#endif
return samples_read;
}
答案 0 :(得分:1)
/ ???这条线是复制第一批576个insamp样本的奇特方式吗? 进入缓冲区[0]? /
基本上,是的。它只是复制数据结束 - >开始而不是通常的开始 - >结束顺序。我不确定,但我认为有些人更喜欢这种内存缓存性能原因。
/ * ???到底是怎么回事? * /
它将16位输入缩放为32位数。让我们来看看它:
sample_buffer[i] <<= (8 * sizeof(int) - 16);
如果sizeof(int)是4个字节,则8 * 4 - 16 = 16.因此,将16位数字左移16,以便将其缩放为32位数字。如果sizeof(int)是8个字节,则8 * 8 - 16 = 48.如果int是64位,则需要左移48位。
我不确定我是否在这里回答了你所有的问题。随意跟进。