在我在此处LAME
发布的问题之后,对with 的进一步调查gdb
显示,在任何给定时间,仅从输入pcm
文件中读取 576 个样本。但是,这些样本用于填充 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;
}