Help - Search - Members - Calendar
Full Version: .wav import for DSP plugin
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
Eric89GXL
How do I import a stereo wav file in a DSP plugin? Seems like it should be easy considering fb2k is an audio app.

Right now I'm using a 3rd-party dll to do it, but it seems a little ridiculous. Plus I hate needing to have two dll's for my plugin. All I need to do is read the data from two stereo wav files when my DSP plugin initializes so I can perform stereo convolution.

A note on why stereo convolution is useful: the current "convolve" plugin is R->R and L->L capable only. Stereo convolution sends the R signal to the L channel (under one convolution) and to the R channel (under a different convolution), and the same for L->(L and R). This way I can perform head-related transfer functions (HRTFs) to my music to improve headphone listening. HRTFs are approximated by crossfeed and bs2b, but why be approximate when you can be precise?

I have all the basics complete now---wav input, config dialog, efficient stereo convolution using DHT---so it's time to clean up the code, debug, and add safeguards. Wav importing is my first target for improvement.
gfngfgf
I'm not sure if this is correct, but I figured I'd throw the idea out there since there haven't been any responses yet. Have you looked at what's available in "input.h", specifically input_decoder and input_entry? Just from inspection, it looks like those classes (along with audio_chunk) should be exactly what you need to open and decode a WAV file. Again, I haven't tried it personally.
foosion
Here's some code (quickly adapted from fingerprint generation in foo_sic, so it might not compile right away):
CODE
bool void g_decode_file(char const * p_path, abort_callback & p_abort)
{
    try
    {
        input_helper helper;
        file_info_impl info;

        // open input
        helper.open(service_ptr_t<file>(), make_playable_location(p_path, 0), input_flag_simpledecode, p_abort);

        helper.get_info(0, info, p_abort);
        if (info.get_length() <= 0)
            throw pfc::exception("Track length invalid");

        audio_chunk_impl chunk;

        if (!helper.run(chunk, p_abort)) return false;


        t_uint64 length_samples = audio_math::time_to_samples(info.get_length(), chunk.get_sample_rate());
        //chunk.get_channels();

        while (true)
        {
            // Store the data somewhere.

            bool decode_done = !helper.run(chunk, p_abort);
            if (decode_done) break;
        }

        // We now have the full data.

        return true;
    }
    catch (const exception_aborted &) {throw;}
    catch (const std::exception & exc)
    {
        console::formatter() << exc << ": " << p_path;
        return false;
    }
};
Eric89GXL
QUOTE(foosion @ May 16 2007, 09:48) *

Here's some code (quickly adapted from fingerprint generation in foo_sic, so it might not compile right away)


I looked a bit at input.h---I'll take a longer look (and try that other code) later tonight. Other than revamping the .wav input, the plugin is pretty much done.
Eric89GXL
QUOTE(Eric89GXL @ May 16 2007, 14:43) *

I looked a bit at input.h---I'll take a longer look (and try that other code) later tonight. Other than revamping the .wav input, the plugin is pretty much done.


That code worked very well. The plugin is all set. It's available with source at:

http://people.bu.edu/edlarson/stereoconv.html

Thanks for your help.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.