Not signed in (Sign In)

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    •  
      CommentAuthorbq
    • CommentTimeMar 13th 2009 edited
     
    This discussion forum is open to any questions, feedback, or debate about the Rubber Band Library. If you're working with the open source edition or considering any work with the commercial edition, feel free to discuss it here. (If you'd prefer to talk privately, just use the Contact link above.)

    -bq
    •  
      CommentAuthorkunitoki
    • CommentTimeOct 2nd 2009 edited
     
    Nice work.

    i've been adding support for Julius Smith's and Dominique Mazzoni's libresample in the Resampler.cpp code in the library:

    is there a way to post a code snippet in a nice way ?
    •  
      CommentAuthorbq
    • CommentTimeOct 2nd 2009 edited
     

    Mm, good question. I think it should be possible using Markdown, let's give it a try:

    #include <stdio.h>
    int main(int argc, char **argv)
    {
        printf("Hello world!\n");
        return 0;
    }
    

    OK, that works, though it's not ideal to enter -- you have to indent every line in the code block by at least four spaces for Markdown to identify it as code (which of course means you have to edit it rather than just paste it in). And make sure you select the "Format comments as [x] Markdown" option when posting.

    I'm not all that keen on Markdown either... perhaps it's just lack of familiarity, or perhaps we should see about other input format plugins for this forum.

    (Looks like Markdown supports a backquote bracket syntax like this (that was `like this`) for individual code terms, but you have to use indentation for whole blocks.)

    -bq

    •  
      CommentAuthorkunitoki
    • CommentTimeOct 2nd 2009 edited
     

    Good catch ! Here it is:

    class D_RESAMPLE : public ResamplerImpl
    {
    public:
        D_RESAMPLE(Resampler::Quality quality, int channels, int maxBufferSize,
              int m_debugLevel);
        ~D_RESAMPLE();
    
        int resample(const float *const R__ *const R__ in,
                     float *const R__ *const R__ out,
                     int incount,
                     float ratio,
                     bool final);
    
        void reset();
    
    protected:
        void *m_src;
        float *m_iin;
        float *m_iout;
        float m_lastRatio;
        int m_channels;
        int m_iinsize;
        int m_ioutsize;
        int m_debugLevel;
    };
    
    D_RESAMPLE::D_RESAMPLE(Resampler::Quality quality, int channels, int maxBufferSize,
                 int debugLevel) :
        m_src(0),
        m_iin(0),
        m_iout(0),
        m_lastRatio(1.f),
        m_channels(channels),
        m_iinsize(0),
        m_ioutsize(0),
        m_debugLevel(debugLevel)
    {
        if (m_debugLevel > 0) {
            std::cerr << "Resampler::Resampler: using libresample implementation"
                      << std::endl;
        }
    
        float min_factor = 0.125f;
        float max_factor = 8.0f;
    
        m_src = resample_open(quality == Resampler::Best ? 1 : 0, min_factor, max_factor);
    
        if (!m_src) {
            std::cerr << "Resampler::Resampler: failed to create libresample resampler: " 
                      << std::endl;
            throw Resampler::ImplementationError; //!!! of course, need to catch this!
        }
    
        if (maxBufferSize > 0 && m_channels > 1) {
            m_iinsize = maxBufferSize * m_channels;
            m_ioutsize = maxBufferSize * m_channels * 2;
            m_iin = allocFloat(m_iinsize);
            m_iout = allocFloat(m_ioutsize);
        }
    
        reset();
    }
    
    D_RESAMPLE::~D_RESAMPLE()
    {
        resample_close(m_src);
        if (m_iinsize > 0) {
            free(m_iin);
        }
        if (m_ioutsize > 0) {
            free(m_iout);
        }
    }
    
    int
    D_RESAMPLE::resample(const float *const R__ *const R__ in,
                    float *const R__ *const R__ out,
                    int incount,
                    float ratio,
                    bool final)
    {
        float* data_in;
        float* data_out;
        int input_frames, output_frames, end_of_input, source_used;
        float src_ratio;
    
        int outcount = lrintf(ceilf(incount * ratio));
    
        if (m_channels == 1) {
            data_in = const_cast<float *>(*in); //!!!???
            data_out = *out;
        } else {
            if (incount * m_channels > m_iinsize) {
                m_iinsize = incount * m_channels;
                m_iin = allocFloat(m_iin, m_iinsize);
            }
            if (outcount * m_channels > m_ioutsize) {
                m_ioutsize = outcount * m_channels;
                m_iout = allocFloat(m_iout, m_ioutsize);
            }
            for (int i = 0; i < incount; ++i) {
                for (int c = 0; c < m_channels; ++c) {
                    m_iin[i * m_channels + c] = in[c][i];
                }
            }
            data_in = m_iin;
            data_out = m_iout;
        }
    
        input_frames = incount;
        output_frames = outcount;
        src_ratio = ratio;
        end_of_input = (final ? 1 : 0);
    
        int output_frames_gen = resample_process(m_src,
                                                 src_ratio,
                                                 data_in,
                                                 input_frames,
                                                 end_of_input,
                                                 &source_used,
                                                 data_out,
                                                 output_frames);
    
        if (output_frames_gen < 0) {
            std::cerr << "Resampler::process: libresample error: "
                      << std::endl;
            throw Resampler::ImplementationError; //!!! of course, need to catch this!
        }
    
        if (m_channels > 1) {
            for (int i = 0; i < output_frames_gen; ++i) {
                for (int c = 0; c < m_channels; ++c) {
                    out[c][i] = m_iout[i * m_channels + c];
                }
            }
        }
    
        m_lastRatio = ratio;
    
        return output_frames_gen;
    }
    
    void
    D_RESAMPLE::reset()
    {
    }
    

    Hope this is of use for anyone !

    •  
      CommentAuthorbq
    • CommentTimeOct 2nd 2009
     

    Thanks for that! libresample is LGPL, is that correct?

    -bq

    •  
      CommentAuthorkunitoki
    • CommentTimeOct 2nd 2009
     

    Yes you are correct !