9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] bipieren
@ 2021-04-05  6:27 Eli Cohen
  0 siblings, 0 replies; only message in thread
From: Eli Cohen @ 2021-04-05  6:27 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 165 bytes --]

Ich habe ein smol bipprogramm gemacht. seit wir haben etwas wie dieser?

ps.
sollt Ich von jetzt sprechen Deutsche vor usieren la OS? hopen Sie understanden!

phew!

[-- Attachment #2: beep.c --]
[-- Type: text/x-csrc, Size: 969 bytes --]

// produce waveform for a "beep"
#include <u.h>
#include <libc.h>

void
usage(void)
{
	fprint(2, "usage: %s [-f hz] [-d decay] [-l samples] [-s slide] [-v volume]\n", argv0);
	exits("usage");
}


void
main(int argc, char **argv)
{
	char *buffer;
	short s;
	int i;
	double hz = 440;
	double decay = 0.9998;
	int samples = 11025;
	double slide = 1.0001;
	double volume = 0.3;

	ARGBEGIN{
	case 'f':
		hz = atof(EARGF(usage()));
		break;
	case 'd':
		decay = atof(EARGF(usage()));
		break;
	case 'l':
		samples = atoi(EARGF(usage()));
		break;
	case 's':
		slide = atof(EARGF(usage()));
		break;
	case 'v':
		volume = atof(EARGF(usage()));
		break;
	default:
		usage();
	}ARGEND

	buffer = malloc(samples * 4);

	for (i = 0; i < samples; i++) {
		s = cos((double)i/44100 * 2 * PI * (hz - pow(slide, i))) * 32767 * volume * pow(decay, i);
		buffer[i*4+0] = buffer[i*4+2] = s & 0xFF;
		buffer[i*4+1] = buffer[i*4+3] = (s >> 8) & 0xFF;
	}

	write(1, buffer, samples * 4);
}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-05  7:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-05  6:27 [9front] bipieren Eli Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).