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

bool aKode::SRCResampler::doFrame ( AudioFrame in,
AudioFrame out 
) [virtual]

Returns true if convertion was succesfull.

Implements aKode::Resampler.

Definition at line 96 of file src_resampler.cpp.

References aKode::AudioFrame::length, aKode::AudioFrame::pos, and aKode::AudioFrame::reserveSpace().

{
    // Ouch, I dont like this much mallocing
    float *tmp1 = new float[in->channels*in->length];
    float *tmp2 = new float[in->channels*in->length];

    // convert to float frames
    if (in->sample_width < 0) {
        _convert1(in, tmp1);
    } else
    if (in->sample_width <= 8) {
        _convert1<int8_t>(in, tmp1);
    } else
    if (in->sample_width <= 16) {
        _convert1<int16_t>(in, tmp1);
    } else
        _convert1<int32_t>(in, tmp1);

    float newspeed = speed * (in->sample_rate/(float)sample_rate);
    long outlength = (long)(in->length*newspeed);
    out->reserveSpace(in->channels, outlength, in->sample_width);
    out->sample_rate = sample_rate;
    out->channel_config = in->channel_config;
    out->surround_config = in->surround_config;
    out->pos = in->pos;

    // We should figure out if interleaving first is faster
    // than making a call per channel
//    for (int i=0; i<in->channels; i++) {
        SRC_DATA src_data;

        src_data.data_in = tmp1;
        src_data.data_out = tmp2;
        src_data.input_frames = in->length;
        src_data.output_frames = out->length;
        src_data.src_ratio = newspeed;

        src_simple(&src_data, SRC_SINC_MEDIUM_QUALITY, in->channels);
//    }

    // convert from float frames
    if (out->sample_width > 0) {
        if (out->sample_width <= 8) {
            _convert2<int8_t>(tmp2, out);
        } else
        if (out->sample_width <= 16) {
            _convert2<int16_t>(tmp2, out);
        } else
            _convert2<int32_t>(tmp2, out);
    } else
        _convert2(tmp2, out);


    delete[] tmp1;
    delete[] tmp2;

    return true;
}


Generated by  Doxygen 1.6.0   Back to index