Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: .wav import for DSP plugin (Read 4418 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

.wav import for DSP plugin

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.

.wav import for DSP plugin

Reply #1
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.

.wav import for DSP plugin

Reply #2
Here's some code (quickly adapted from fingerprint generation in foo_sic, so it might not compile right away):
Code: [Select]
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;
    }
};

.wav import for DSP plugin

Reply #3
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.