Logo Search packages:      
Sourcecode: aften version File versions  Download package

int pcm_init ( PcmContext *  pc,
int  num_files,
FILE **  fp_list,
enum PcmSampleFormat  read_format,
int  file_format 
)

Initializes PcmContext structure using the given input file pointers. Examines the header (if present) to get audio information and has the file pointer aligned at start of data when it exits.

Parameters:
pc The PcmContext to initialize
num_files Number of source files
fp_list Array of file pointers to source files
read_format Sample format to convert to when reading
file_format Source file format, or PCM_FORMAT_UNKNOWN to autodetect
Returns:
non-zero value if an error occurs.

Definition at line 28 of file pcm.c.

References pcm_close(), pcm_get_default_ch_mask(), pcm_set_sample_rate(), and pcmfile_init().

{
    int i;
    uint64_t samples;

    // check parameters
    if (num_files < 1 || num_files > PCM_MAX_CHANNELS) {
        fprintf(stderr, "invalid number of files: %d. must be > 0\n", num_files);
        return -1;
    }
    if (read_format < PCM_SAMPLE_FMT_U8 || read_format > PCM_SAMPLE_FMT_DBL) {
        fprintf(stderr, "invalid read format: %d\n", read_format);
        return -1;
    }
    if (file_format < PCM_FORMAT_UNKNOWN || file_format > PCM_FORMAT_CAFF) {
        fprintf(stderr, "invalid file format: %d\n", file_format);
        return -1;
    }

    memset(pc, 0, sizeof(PcmContext));
    samples = 0;
    for (i = 0; i < num_files; i++) {
        PcmFile *pf = &pc->pcm_file[i];
        if (pcmfile_init(pf, fp_list[i], read_format, file_format)) {
            fprintf(stderr, "error initializing file #%d\n", i);
            pcm_close(pc);
            return -1;
        }
        if (num_files > 1 && pf->channels != 1) {
            fprintf(stderr, "all files must be mono when using multiple input files\n");
            pcm_close(pc);
            return -1;
        }
        samples = MAX(samples, pc->pcm_file[i].samples);
    }

    pc->samples = samples;
    pc->num_files = num_files;
    pc->read_format = read_format;
    if (num_files == 1) {
        pc->channels = pc->pcm_file[0].channels;
        pc->ch_mask = pc->pcm_file[0].ch_mask;
    } else {
        pc->channels = num_files;
        pc->ch_mask = pcm_get_default_ch_mask(pc->channels);
    }
    pcm_set_sample_rate(pc, pc->pcm_file[0].sample_rate);

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index