Example #1
0
/**
 * @fn		static void audio_cb( int *in, int *out, int nBlocks , int nChannels )
 * @brief	Audio Driver Callback
 * @param	in audio input buffer
 * @param	out audio output buffer
 * @param	nBlocks is the number of the audio blocks
 * @param	nChannels is the number of the audio channels in one block.
 */
static void audio_cb( int *in, int *out, int nBlocks, int nChannels )
{
	int i,j;
	for(j=0;j<nBlocks;++j)
	{
		for(i=0;i<nChannels;++i)
			*out++ = fir_process( &fir[i], *in++ );	
	}
}
Example #2
0
static void auresamp_lowpass(struct auresamp *ar, int16_t *buf, size_t nsamp,
			     int channels)
{
	while (nsamp > 0) {

		size_t len = min(nsamp, FIR_MAX_INPUT_LEN);

		fir_process(&ar->fir, ar->coeffv, buf, buf, len, ar->coeffn,
			    channels);

		buf   += (len*channels);
		nsamp -= len;
	}
}
Example #3
0
int main(int argc, char *argv[])
{
    int status              = EXIT_FAILURE;
    FILE *infile            = NULL;
    FILE *outfile           = NULL;

    int16_t *inbuf = NULL, *tempbuf = NULL;
    struct complex_sample *outbuf = NULL;

    struct fir_filter *filt = NULL;

    static const unsigned int max_chunk_size = 1024 * 1024 * 1024;

    unsigned int chunk_size = 4096;
    size_t n_read, n_written;
    bool done = false;

    if (argc < 3 || argc > 4) {
        fprintf(stderr,
                "Filter sc16q11 samples from <infile> and write"
                "them to <outfile>.\n\n");

        fprintf(stderr,
                "Usage: %s <infile> <outfile> [# chunk size(samples)]\n",
                argv[0]);

        return EXIT_FAILURE;
    }

    if (argc == 4) {
        bool valid;
        chunk_size = str2uint(argv[3], 1, max_chunk_size, &valid);
        if (!valid) {
            fprintf(stderr, "Invalid chunk size: %s samples\n", argv[3]);
            return EXIT_FAILURE;
        }
    }

    filt = fir_init(rx_ch_filter, rx_ch_filter_len);
    if (!filt) {
        fprintf(stderr, "Failed to allocate filter.\n");
        return EXIT_FAILURE;
    }

    inbuf = calloc(2*sizeof(int16_t), chunk_size);
    if (!inbuf) {
        perror("calloc");
        goto out;
    }
    tempbuf = calloc(2*sizeof(int16_t), chunk_size);
    if (!tempbuf) {
        perror("calloc");
        goto out;
    }

    outbuf = calloc(sizeof(struct complex_sample), chunk_size);
    if (!outbuf) {
        perror("calloc");
        goto out;
    }

    infile = fopen(argv[1], "rb");
    if (!infile) {
        perror("Failed to open input file");
        goto out;
    }

    outfile = fopen(argv[2], "wb");
    if (!outfile) {
        perror("Failed to open output file");
        goto out;
    }

    while (!done) {
        n_read = fread(inbuf, 2*sizeof(int16_t), chunk_size, infile);
        done = n_read != chunk_size;

        fir_process(filt, inbuf, outbuf, n_read);
        //convert
        conv_struct_to_samples(outbuf, (unsigned int) n_read, tempbuf);

        n_written = fwrite(tempbuf, 2*sizeof(int16_t), n_read, outfile);
        if (n_written != n_read) {
            fprintf(stderr, "Short write encountered. Exiting.\n");
            status = -1;
            goto out;
        }
    }

    status = 0;

out:
    if (infile) {
        fclose(infile);
    }

    if (outfile) {
        fclose(outfile);
    }
    free(tempbuf);
    free(inbuf);
    free(outbuf);
    fir_deinit(filt);

    return status;
}