c++findautodev-c++synthesizer

How do I access Sound Hardware in Dev-C++?


I was following a video tutorial for playing music in c++:

https://www.youtube.com/watch?v=tgamhuQnOkM&t=1030s

I am using Dev-C++ and I keep getting an error in the header file that "I'm not supposed to worry about"

The line is:

auto d = std::find(devices.begin(), devices.end(), sOutputDevice);

And the error says:

>92 68  C:\Users\benna\Documents\Starting Over\wave_music\olcNoiseMaker.h   [Error] no matching function for call to 'find(std::vector<std::basic_string<wchar_t> >::iterator, std::vector<std::basic_string<wchar_t> >::iterator, std::wstring&)'

I am a noob here and I really don't get it.

My code is the same, and I've looked at linkers, project settings and other IDEs (VS Code & Eclipse) and nothing changes. (Especially the other IDEs, I can't even get them to run "Hello World".)

I just thought I could learn something through a little experimentation but I am getting nowhere. Is it a problem with my software?

I think it may be a problem with accessing my sound hardware.

I am still learning so any help would be appreciated, thank you!

The header file is here: https://github.com/OneLoneCoder/synth/blob/master/olcNoiseMaker.h

And my main file is this:

using namespace std;

#include "olcNoiseMaker.h"

atomic<double> dFrequencyOutput = 0.0;


double MakeNoise(double dTime)
{
    return 0.5 * sin(440.0 * 2 * 3.14159 * dTime);
    //double dOutput 1.0* sin(dFrequencyOutput * 2.0 * 3.14159 * dTime);
    
    //return dOutput * 0.5;
    
    //if (dOutput > 0.0)
    //  return 0.2;
    //else
    //  return -0.2;
    
}

int main()
{
    wcout << "onelonecoder.com - Synthesizer Part 1" << endl;
    
    // Get all sound hardware
    vector<wstring> devices = olcNoiseMaker<short>::Enumerate();
    
    // Display findings
    for (auto d : devices) wcout << "Found Output Device:" << d << endl;
    
    // Create sound machine!!
    olcNoiseMaker<short> sound(devices[0], 44100, 1, 8, 512);
    
    // Link make noise function with sound machine
    sound.SetUserFunction(MakeNoise);
    
    
    while (1)
    {
        
    }
    
    return 0;
}

Solution

  • This is a bug in the linked header file. It should include <algorithm> which is required for std::find, but doesn't.


    I haven't checked the rest of the header file or your posted code for bugs, but I also noticed

    while (1)
    {
        
    }
    

    Infinite loops without IO, atomic, volatile or synchronization operations have undefined behavior in C++. You can't use such a loop to infinitely pause the program or thread.


    The header seems to not be tested well in multiple different environments. For example this issue mentions similar problems to get it working under MinGW and has a list of changes that user needed to make.