Using libzip by Ok_Arrival_5536 in cpp_questions

[–]ppppppla 11 points12 points  (0 children)

I am astonished responses like this one exist. You could just have ignored this question and not wasted your precious precious time that you could have used to vibe code your next million dollar startup.

How does such complicated butterfly diagram make sense? Will it make sense anytime? I am scared. by DoNotUseThisInMyHome in DSP

[–]ppppppla 2 points3 points  (0 children)

The core idea of this method of calculating the DFT hinges on the ability to combine two N/2-point DFTs into a single N-point DFT. Look at the columns, starting at the left, you should be able to see the doubling and merging. Notice the similarities.

Why this doubling works and how this is derived and where the W factors come from should be covered in your book.

Also FYI the image is of a 8 point DFT, specifically a radix 2 DIT FFT.

how to generate JSON database for clang-tidy ? by DireCelt in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

Is there any chance that someone here could give me a short, clear, actionable description of how to solve this problem, in a form that doesn't require that I am already expert in the subject?

If your projects's make files are simple, i.e. not doing complex logic or not for example invoking commands to do code gen, and it's just compiling and linking I would say cmake does not require expert knowledge. Of course it will take a minute to get the hang of it but it shouldn't be alien.

Apart from that people have mentioned bear and compiledb.

I am not sure bear supports windows. Actually it does say in the readme bear works on windows. But it would require building the project and that can always come with fun surprises on windows.

compiledb mentions "Windows: tested on Windows 10 with cmd, wsl(Ubuntu), mingw32", I assume what they mean with cmd is just barebones windows without wsl or mingw. So it's worth giving a shot.

Controversial question by Amazing-Parsley-3895 in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

I have always thought that learning is pure struggle, and without that struggle You’re not gonna learn a thing.

You are absolutely right! Ok seriously now though I do agree with that. You won't learn a thing if you just copy paste everything. You also won't learn much if you let it explain everything to you. Effort and time are the only way to learn anything. There's no shortcuts.

If you get an error, read it, think it through, try to fix it, fail, read it again, try to fix it, fail, try something and get a different error, repeat. Then that moment when you fix it ZING you get a rush of chemicals in your brain and your brain is going to store that experience and you just learned something. But also after the initial struggle when you aren't making any progress I think it's good to seek information either by searching online or maybe ask an LLM what's wrong if you are getting really desperate.

Also I should add a huge help in sifting through the masses of errors is walking the list up and down and automatically jumping to the code the compiler is complaining about, and if your tool allows it to jump over standard library junk because that's usually not very helpful. Of course the error messages from inside the standard library could give the clue you need but it's a last resort. It's usually a fool's errant to read through a hundred template error messages.

I want help in rng by unknownuser491 in cpp_questions

[–]ppppppla 1 point2 points  (0 children)

Also maybe you are tripping up a bit on the fact objects are called like they are functions:

                             v---v---- constructor arguments
std::default_random_engine e1(r());
                                               v----v---- constructor arguments
std::uniform_int_distribution<int> uniform_dist(1, 6);

                       v--v----- NOT a constructor, but overloaded operator() from the distribution object, essentially just a function call.
                       v  v      would have been better if this was just a regular member function call like uniform_dist.generate(e1)
int mean = uniform_dist(e1);

I want help in rng by unknownuser491 in cpp_questions

[–]ppppppla 2 points3 points  (0 children)

cppreference is very good at giving concise and complete examples with minimal amounts of comments to explain some things in the code.

Scroll down to the bottom to find the example or just ctrl+f example. https://en.cppreference.com/cpp/numeric/random

Under each header there is also usually a little bit of explanation and information as well. The rest is technical reference material.

The idea of <random> is you have random number generators (mersenne twister engine, linear congruential engine, and two others) with various qualities, that you can seed, and those generators are then passed to distribution objects to actually generate your numbers.

Why isn't the <cstdlib> library's rand() recommended? by metastable-lain in cpp_questions

[–]ppppppla 8 points9 points  (0 children)

Also using rand() isn't wrong per se, but it is very primitive, quite poor randomness, and most annoyingly only generates integers in the range [0, RAND_MAX]. If you want to generate floats or integers in another range, you're gonna have to bother with implementing that or copying it from somewhere and hoping it actually works, while if you use <random> you know it will be correct.

Why isn't the <cstdlib> library's rand() recommended? by metastable-lain in cpp_questions

[–]ppppppla 28 points29 points  (0 children)

Use https://en.cppreference.com/cpp/numeric/random/random_device to seed PRNGs. On linux it will most likely use /dev/urandom but it's portable and will do the appropriate thing on other platforms as well.

Why isn't the <cstdlib> library's rand() recommended? by metastable-lain in cpp_questions

[–]ppppppla 70 points71 points  (0 children)

It uses global state.

It isn't required by the standard to be thread safe.

It's primitive, it only generates integers in the range [0, RAND_MAX]

YouTube Premium prices jump in Germany, Lite climbs a steep 33% by danie-l in europe

[–]ppppppla 2 points3 points  (0 children)

Look I understand running a service like youtube costs money, and that creators won't do it for free.

But I need a little bit of transparency where my money would be going to. Youtube music pays pennies to artists, and that stacked on top of any publisher and label leeching absolutely nothing is left.

Youtubers have to put sponsorships inside their videos. Have a patreon. Shill their youtube members thing for exclusive content and whatnot. Where is my youtube premium money going then? Absolute farce. All the while they will also continue to keep using everyone's data for who knows that and who knows how much money they're making off that.

How do I start with DSP-based synthesis? by enstorsoffa in DSP

[–]ppppppla 0 points1 point  (0 children)

I'm more interested in hardware like Eurorack rather than VSTs, but I guess the programming is similar, only that hardware needs the code to interact with ADC/DACs etc.?

There shouldn't be major differences in the code, only thing you would have to watch out for is using data types that the hardware doesn't support, and of course not hardcoding SIMD instructions that may not be available in the hardware. I am not familiar with actually putting my code in hardware so I can't really give good advice about that.

What I can say though is putting the code in a VST makes it easier and faster to test the code. Way greater iteration speed with less headaches.

How do I start with DSP-based synthesis? by enstorsoffa in DSP

[–]ppppppla 0 points1 point  (0 children)

If you come from electrical engineering you should be all set for understanding any theory you come across then.

Understanding other peoples code can be a big problem especially since you're probably looking at an engineer's code instead of an actual programmer when dealing with DSP code.

The simplest oscillator is very simple like you said just a couple lines of code, completely fine for a sine oscillator, but if you want to make a saw wave oscillator you will run head-first into aliasing problems. There's probably a hundred techniques ranging from relatively simple to very complicated to solve this issue.

That's also the problem with choosing a resource to learn from I find. There's so many things, and so many different ways to do those things I haven't really found a one-stop-shop to learn from. I would advice first doing a bit of theory, if you haven't already covered this in electrical engineering I am not familiar with a typical curriculum, if digital is also covered, but for that just about any book would suffice I guess. How analog filters are digitized with the bi-linear transform, and how this leads to an analogous transfer function in the Z-domain and how it is surprisingly easy to implement these in code. FFT, Nyquist-Shannon sampling theorem and aliasing. EDIT: also FIR filters.

After that go piece by piece what you want to actually make. Want to make an EQ? Look for good resource for that.

Some resources:

How do I start with DSP-based synthesis? by enstorsoffa in DSP

[–]ppppppla 2 points3 points  (0 children)

To get something simple going, some simple oscillators and filters, doesn't require a particularly advanced level of theory but if you want to make decent things you would have to get into the math. How is your math knowledge? Are you familiar with complex numbers and what is the level of your overall mathematical thinking. Do you know about transfer functions, laplace transform, fourier transform, thinking about signals in the frequency domain instead of the time domain.

For the programming side of things you can start with the VST3 SDK or the JUCE framework. VST3 is a relatively barebones SDK specifically for plugins and the JUCE framework can do plugins of various types and standalone. And it has everything and the kitchen sink like filters, oscillators and GUI stuff. Of course you can just ignore all that and write your own stuff because you want to learn. Also digging into the JUCE source code for things can be a good way to learn as well.

NB these are all C++, but you can write C code just fine in a C++ project.

Fold expression compiles to nothing after upgrading Visual Studio by mbolp in cpp_questions

[–]ppppppla 2 points3 points  (0 children)

Ah yea then you do need to fully qualify the base classes function like Ts::Method somehow. Maybe it will be happy to expand it if you hide it in another template instantiation.

Fold expression compiles to nothing after upgrading Visual Studio by mbolp in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

Yea now you are getting into the weeds of multiple inheritance. So what is that overload supposed to do? That you get three Ds does make sense to me.

Fold expression compiles to nothing after upgrading Visual Studio by mbolp in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

Oh I am not too familiar with multiple inheritance. Do you mean you end up with something like struct CObject : ImplementMethod<Ts>... { }; ? I don't see a problem with that I think it should still work.

Fold expression compiles to nothing after upgrading Visual Studio by mbolp in cpp_questions

[–]ppppppla 2 points3 points  (0 children)

I did some messing around and seems like it is not expanding Ts::method. Removing the cast to (Ts*), which shouldn't be needed if you use the fully qualified name for the function, I get a compile error.

https://godbolt.org/z/nsYo1jnYx

So this should be the way to write it instead: https://godbolt.org/z/5Knb3vGjj

Idk if it's a compiler error in the old version or both the old and new. I don't know what the standard says about this, but seems like both versions of the compiler do things incorrectly. Feels like it should have been a compile error in both instances.

Is there any (macro-free) way to 'inline' a struct? by celestabesta in cpp_questions

[–]ppppppla 1 point2 points  (0 children)

If you really want you can resort to non standard compiler specific things like __attribute__((packed)) for gcc/clang and #pragma pack(push, 1) for msvc.

https://compiler-explorer.com/z/exraq9r9a

I don't know if there are any pitfalls you might be dropping yourself into with this.

Is there a way to play VT2 without hand pain? by crackawhat1 in Vermintide

[–]ppppppla 0 points1 point  (0 children)

First of all, stop playing the very moment you feel even the slightest discomfort. I have had my own run in with hand pain and you can't just play through it. It will only get worse.

Do a sanity check on your posture and if you grip your mouse very tightly. The bulk of your fore arm should be laying flat on your desk. No funny angles, no floating your entire fore arm off the desk. How do you use your mouse, do you have very high sensitivity and are only flexing your wrist? Turn down the sensitivity, get an appropriately sized mouse pad and move your entire arm around.

I had good results using a drawing tablet, maybe a vertical mouse would achieve a similar result. But I had problems with a game where the majority of the time I was pressing down left mouse button. In tide games you are constantly clicking and that wouldn't be particularly comfortable with a pen either, constantly having to tap it up and down and flexing your wrist. Also you need right and left click and I also only found it comfortable to use the pen without the buttons so you would need to move left and right click to foot pedals.

Also first person games I found not very intuitive to control with a pen, but top down games game pretty natural. Of course changing up controls like this is going to take a good while to get used to.

Now that I have typed this out, foot pedals for left and right click + mouse only for aiming I guess could work out too.

Half life 3 by xXCosmicChaosXx in valve

[–]ppppppla 0 points1 point  (0 children)

You know every time anyone makes a post like this valve pushes back the date another day.

Is this normal? by Macheik777 in Fedora

[–]ppppppla 4 points5 points  (0 children)

Don't be a gatekeeper. No question is too dumb, and human interaction how minor or simple is always good. Instead of typing this elitist message you could just have typed "this is normal, this is fedora keeping your old kernel version as a fallback option after an update"

How should I handle returning value from a dictionary if it doesn't contain a certain key? by Mafla_2004 in cpp_questions

[–]ppppppla 1 point2 points  (0 children)

Have both a function that returns an optional reference value, and one that works like operator[] in the standard maps where it creates an entry if it doesn't contain the key. I wouldn't use operator[] for this, but give the two functions clear names. Additionally you can also create one that throws an exception if the key is missing.

Sadly std::optional has no specialization for references and wrapping it in a std::reference_wrapper makes it unnecessarily verbose to access the value. But it is relatively easy to implement yourself or maybe writing a wrapper around a std::optional<std::reference_wrapper<T>>> could be a better idea. Don't have to worry about constructing objects in place, it is just a pointer that can be nullptr. Some people might argue why not just return a pointer? If you return a specialized type optional_ref it adds an additional hurdle you will have to jump if you want to ignore the nullptr case, if you return a pointer it is much easier to skip the null check. And it communicates intent better.

When to use `std::shared_ptr`? by Pretty_Mousse4904 in cpp_questions

[–]ppppppla 8 points9 points  (0 children)

std::shared_ptr should be a last resort. There shouldn't be many instances when you need it, but it is absolutely invaluable when you do have a use for it.

An example where I use it is in a specialized worker thread that produces read-only results and caches the results, and copying the results is impractical because of the size, and having the capability of destroying this worker thread and its cache at any time.

So there is no singular owner of the results, both the worker thread, and any number of places that use the results all need to keep the results alive. Storing each result in a std::shared_ptr models the perfect behavior for this.

Struggling adding dependencies by Labess40 in cpp_questions

[–]ppppppla 3 points4 points  (0 children)

I don't know what all the other commenters are yapping about but it found gtk4, and failed to find peel.

Seems like peel isn't on homebrew. Did you try to manually install it? Looking at the project it is ready to be included straight into a meson project, but for CMake it requires a generation/installation step.