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

int pcmfile_init ( PcmFile *  pf,
FILE *  fp,
enum PcmSampleFormat  read_format,
int  file_format 
)

Initializes PcmFile structure using the given input file pointer. Examines the header (if present) to get audio information and has the file pointer aligned at start of data when it exits. Returns non-zero value if an error occurs.

Definition at line 28 of file pcmfile.c.

Referenced by pcm_init().

{
    if (pf == NULL || fp == NULL) {
        fprintf(stderr, "null input to pcmfile_init()\n");
        return -1;
    }

    pf->read_to_eof = 0;
    pf->file_format = file_format;
    pf->read_format = read_format;

    // attempt to get file size
    pf->file_size = 0;
    pf->seekable = 0;
#ifdef _WIN32
    // in Windows, don't try to detect seeking support for stdin
    if (fp != stdin)
        pf->seekable = !fseek(fp, 0, SEEK_END);
#else
    pf->seekable = !fseek(fp, 0, SEEK_END);
#endif
    if (pf->seekable) {
        // TODO: portable 64-bit ftell
        long fs = ftell(fp);
        // ftell should return an error if value cannot fit in return type
        if (fs < 0) {
            fprintf(stderr, "Warning, unsupported file size.\n");
            pf->file_size = 0;
        } else {
            pf->file_size = (uint64_t)fs;
        }
        fseek(fp, 0, SEEK_SET);
    }
    pf->filepos = 0;
    if (byteio_init(&pf->io, fp)) {
        fprintf(stderr, "error initializing byte buffer\n");
        return -1;
    }

    // detect file format if not specified by the user
    pcmfile_register_all_formats();
    if (pf->file_format == PCM_FORMAT_UNKNOWN) {
        uint8_t probe_data[12];
        byteio_peek(probe_data, 12, &pf->io);
        pf->pcm_format = pcmfile_probe_format(probe_data, 12);
        pf->file_format = pf->pcm_format->format;
    } else {
        pf->pcm_format = pcmfile_find_format(pf->file_format);
    }
    if (pf->pcm_format == NULL) {
        fprintf(stderr, "unable to detect file format\n");
        return -1;
    }

    // initialize format
    if (pf->pcm_format->init && pf->pcm_format->init(pf))
        return -1;

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index