/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

ziglang.org/
andrewkelley.me/post/intro-to-zig.html
github.com/zig-lang/zig
news.ycombinator.com/item?id=11060282
reddit.com/r/programming/comments/44skm2/introducing_the_zig_programming_language/
reddit.com/r/Zig/
youtube.com/watch?v=AiintPutWrE
infoworld.com/article/3113083/application-development/new-challenger-joins-rust-to-upend-c-language.html
stackoverflow.com/a/614420
jsfiddle.net/ez9Lf1wa/
twitter.com/NSFWRedditVideo

God I love anime

How would you implement a real-time software audio mixer without locking, given that you can afford to load whole uncompressed PCM files (yup, all 3-5MB right into RAM).
The interface is, of course, a callback from another thread, this is the way it works in PortAudio, SDL2 and libsoundio (which I'm using), where you have to fill the buffer.
The solution I've seen is a circular buffer, but it works bad when you want to loop a song, also this approach was designed with music streaming in mind. I'm looking for a simpler solution.
This is what I've come up so far:
typedef struct DgAudioTrack {
DgAudio *audio;
bool looping;
size_t index;
} DgAudioTrack;
struct DgAudio {
size_t bufferSize;
uint8_t *buffer;
};


The API is quite simple too:
1. Play sound.
2. Loop sound.
3. Stop sound (must be atomic operation).

Now the hardest thing is the callback: how to make it not to segfault in various circumstances that can could happen.

So I came up with this solution:
for each frame
for each track
retrieve audio pointer // must be atomic
// now at this moment either playSound or stopSound
// or loopSound could have been called, so *everything else*
// in DgAudioTrack may be utterly incorrect except
// the audio pointer
add audio frame // this must be always safe
// no matter what track.index and track.looping is
// it might be glitchy for 1/22050 of a second (playing
// invalid frame because track.index or track.looping has
// been corrupted immediately after the atomic audio
// pointer retrieval, however unlikely that might be), but it's
// ok


And playAudio and loopAudio is just:
stopTrack // atomic
track.looping = looping
track.index = 0
track.audio = audio


So this is blazingly fast and simple, in expense of heavy memory usage. What do you think?

Code in Zig!

ziglang.org/
andrewkelley.me/post/intro-to-zig.html
github.com/zig-lang/zig
news.ycombinator.com/item?id=11060282
reddit.com/r/programming/comments/44skm2/introducing_the_zig_programming_language/
reddit.com/r/Zig/
youtube.com/watch?v=AiintPutWrE
infoworld.com/article/3113083/application-development/new-challenger-joins-rust-to-upend-c-language.html

Writing a type-checker and machine-code compiler for a dependently-typed language based on QTT.

>How would you implement a real-time software audio mixer without locking
i dont really know what an audio mixer is nor what locking means in the context of audio

is what i think
anyways gl

>reddit
Go back

Bitch I'm gathering all resources I can

...

int main() {
double xpos, ypos, rad;
cin >> xpos >> ypos >> rad;
cout

1.8,1.99,20
1.8 0 6.95289e-310

>what locking means in the context of audio
Thread locking.

>what an audio mixer is
the audio driver needs some yummy samples to feed the speakers
its fat and lazy so it sends out her light servant, the callback
the callback finds all the tracks and asks them what music they're currently jagging to
they all say different things
the callback sums them up and carries back to the sound driver
driver is happy again (not for long though)

I had a dream that inspired to me to make a game, so I'm making one. I have this really strong gut feeling that it will make me super rich. Maybe not on the scale of Notch, but certainly on the scale of the Stardew Valley guy. Can't wait until I'm raking in the big ones and Sup Forums is calling me a fag or some shit.

you first need to make a non-locking software mixer

take this

fuck i slept too little, meant to link the other way around

hah, implying we won't call you a fag now
fag

>Thread locking.
what you mean deadlocks?

what's the difference between tracks and music though, isn't a track basically music or is track also a technical term

so basically you want your program to play multiple audio files at the same time in real time?

>const io = @import("std").io;

pub fn main() -> %void {
%%io.stdout.printf("Hello, world!\n");
}

Holy fuck no that looks worse than sepples and Rust

>AT&T syntax
tl;dr

>what you mean deadlocks
without needing to interrupt other thread (the callback thread). This can only be achieved with atomic operations.

>so basically you want your program to play multiple audio files at the same time in real time
precisely

>what's the difference between tracks and music though, isn't a track basically music or is track also a technical term

sample is the most basic sound element, an integer/float
channel can be 1 (mono) or 2 (stereo), or more but I don't support them
frame is the smallest sound slice, if mono it's a single sample, if stereo it's two samples (for left ear and right ear)
tracks are sounds playing/looping/mute at the same time
sounds are arrays of frames

Trying to learn how to work with Raspberry Pi to pull information from another machine and setting up a webserver with like xamp or something. How does nagios work? o.o

geez that's a lot of new words
im actually planning on making something music related so i'll have to learn about this sort of thing

thx for explaining

What book(s) should I get if I'm an intermediate level C++ programmer and want to learn Java from scratch?

What needs to be added?
What needs to be changed?

Zig needs to be put as the best lang

>%%
Why

deleting the whole thing

I just scraped all the usernames from the first page of Sup Forums with python, yey me

results:
users: ['Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous']

>In the fragment shader, there is no default precision given for floats: Every shader must declare a default float precision or specify the precision for every float variable. In addition, OpenGL ES 2.0 does not require that an implementation support high precision in the fragment shader.
Okay if the shader compiler doesn't support highp couldn't it just default to mediump and still compile even if you declare the default to be highp.
Not compiling is the most retarded way of dealing with this. Fucking opengl was mistake.

It's that famous hacker. He surely seems to spam a lot.

What are some good books on optimising and refactoring code?

stackoverflow.com/a/614420

this is bollocks right? why shouldn't your own project's headers go on the top?

there's a macro if highp is available you fucking retard

use ifdef

>have to write
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

>for every shader instead of the compiler just doing the right thing
Fuck opengl.

kill yourself clueless whiny fag

how does one post codeblock on 4chin?

just use mediump everywhere you fucking mong
no float precision will fix your shit being shit

"[C" your code here "C]"

markdown newfriend

>opengl couldn't just include macro for the highest available precicion
fuck off dumb khronos shill

code here [\/code]

Please don't mock the hacker known as Sup Forums

fucking pointless. if your shader works fine with mediump you should just use mediump. using highp cuts perf by ~50% and gl es devices are already constrained as it is

Rule 1: don't talk about the hacker

Rule 2: don't talk about the rules that talk about the hacker

Hey Sup Forums,

Will this work, or is this UB/potential troubles with aliasing?

Shared header file:
struct handle
{
int some_member;
};


void init_handle(struct handle** handle);

void free_handle(struct handle* handle);

Handle-related source file:
struct wrapper
{
int other_member;
struct handle actual_handle;
};


void init_handle(struct handle** handle)
{
struct wrapper* w = malloc(sizeof(struct wrapper));
return &w->actual_handle;
}


void free_handle(struct handle* handle)
{
struct wrapper* w = (struct wrapper*) (((unsigned char*) handle) - offsetof(struct wrapper, actual_handle));
free(w);
}

Some caller:
int main()
{
struct handle* handle;

init_handle(&handle);
// do stuff
free_handle(handle);
}

class CellRendererProgressWindow(Gtk.Window):

def __init__(self):
Gtk.Window.__init__(self, title="CellRendererProgress Example")

self.set_default_size(200, 200)

self.liststore = Gtk.ListStore(str, int, bool)
self.current_iter = self.liststore.append(["Sabayon", 0, False])
self.liststore.append(["Zenwalk", 0, False])
self.liststore.append(["SimplyMepis", 0, False])

treeview = Gtk.TreeView(model=self.liststore)

renderer_text = Gtk.CellRendererText()
column_text = Gtk.TreeViewColumn("Text", renderer_text, text=0)
treeview.append_column(column_text)

renderer_progress = Gtk.CellRendererProgress()
column_progress = Gtk.TreeViewColumn("Progress", renderer_progress,
value=1, inverted=2)
treeview.append_column(column_progress)

renderer_toggle = Gtk.CellRendererToggle()
renderer_toggle.connect("toggled", self.on_inverted_toggled)
column_toggle = Gtk.TreeViewColumn("Inverted", renderer_toggle,
active=2)
treeview.append_column(column_toggle)

self.add(treeview)

self.timeout_id = GObject.timeout_add(100, self.on_timeout, None)

def on_inverted_toggled(self, widget, path):
self.liststore[path][2] = not self.liststore[path][2]

def on_timeout(self, user_data):
new_value = self.liststore[self.current_iter][1] + 1
if new_value > 100:
self.current_iter = self.liststore.iter_next(self.current_iter)
if self.current_iter == None:
self.reset_model()
new_value = self.liststore[self.current_iter][1] + 1

self.liststore[self.current_iter][1] = new_value
return True

def reset_model(self):
for row in self.liststore:
row[1] = 0
self.current_iter = self.liststore.get_iter_first()

Rule 3: don't talk about the rules that talk about the rules that talk about the hacker.
Rule 4: don't talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 5: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 6: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 7: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 8: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 9: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 10: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.

@62267890
kys retard

this should work I think

>@

@Anonymous #62267908
:+1-skintone5:

Babby's first Python loop

So I'm not causing any potential problems for myself by doing this, except alignment issues for contiguous wrappers maybe?

This was in C faggot

I'm not an expert but I can't see why there would be any alignment issues at all

Okay, thanks.

Proof.
#include

int main(void) {
for (int rule = 3; rule < 11; ++rule) {
int repeat = rule - 1;
printf("Rules %d: don't ", rule);
for (int i = 0; i < repeat; ++i) {
printf("talk about the rule that ");
}
puts("talk about the hacker.");
}
}

And yes, the prototype was in Python:
for i in range(3, 11):
adder = i - 2
root = "Rule "+str(i)+": don't talk about the rules that "
for i in range(adder):
root += "talk about the rules that "
root += "talk about the hacker."
print(root)

Difficulty of writing a nintendo emulator in Rust from scratch? Im an "intermediate" programmer. Several years of school under my belt looking to improve my skills and emulators seem really neat

>int main
>No return value

rax is the return value

>the prototype was in Python
lol

fag

make a kernel in rust

make a better language in rust

make a kernel in haskell instead

>he doesn't know about 5.1.2.2.3
I'm better at both than you

A GameBoy Color emulator shouldn't be that hard I guess.

make a haskell in kernel

I have no respect for non-asm code.

make you a kernel

in haskell this is just >>= & fmap id

>the prototype was in Python
pathetic

What do you mean by Nintendo? If it's a game boy like some other user said then it won't require much work.

>>>= & fmap id
Can you give me a run-down on what this actually does m8?

linux, it does linux

I just ran it in GHC and got an erection

jsfiddle.net/ez9Lf1wa/

rate my fizzbuzz

Nobody knows

I see your productivity is evaluated based on the number of lines you write. 10/10

Should not be more difficult than writing an emulator in another language

this is 2 lines, the first one is empty

So, I actually did some benchmarks and on my particular compiler, allocating 256 mb of 4 1 byte sized record fields and filling them, then assigning to a variable, was twice slower than doing the same thing with 256 of 4 byte integers.
Both when compiled to 32 bit and 64 bit.

The compiler is pretty much a community project, so it was to be expected.
I guess it's time to write my own library: a record syntax wrapper around a 1D array of int.

And the bible is just a one line long string.

Got fired but they need me to fix an application due September 15th I'm sad

>they need me
>get fired
Makes sense.

I wish it did senpai

And how are you obligated in any way to do that?
Let alone legally when you are no longer being paid.

Sounds yummy. Care to explain in more detail for those of us that don't into type-checkers? What's all that funny stuff in your picture?

It's neither accurate nor ironic. Your memes are bad and you should not feel good.

That looks like a duck, hehe, quack quack.

Writing an implementation of ActivityPub

depends on the employment laws where he lives if it's a delay or he needs to work a bit longer to get his last paycheck or w/e

How can they be so stupid to not realize that they are only hired as PR candy? Nobody considers then nothing more than a joke in regards to coding, MS just hires couple of them to sit around and make coffee, and maybe write some html templates, so they look good to the public because "look at as we hire le coder wimenz"

Are you seriously saying that women all suck at programming? One of the best graduates in my class was female.

>language designed to make it a pain to write anything
I'm sure it won't.

Out of all women who call themselves programmers 98% of them suck cock at it
And the best programmers in the world are, big surprise, males

>language designed to stop you from doing retarded """shortcuts""" that end up making your program fail in the long run

Fixed.

>language designed to make it a pain to write segfaulting programs
fixed it, senpai

Don't worry, I'm sure if you change your fedora to a trilby the cute red haired girl in the office will date you then bro

You're right. Preventing users from write programs is a good way to make sure they won't do anything harmful!

Are there any legitimate alternatives to OOP? Like, is there anything on the horizon that might work in more than just a "look at this really elegant cherry picked example" kind of way?