Added a default website

This commit is contained in:
fls committed 2026-07-15 13:44:55 -03:00
1 parent d3d55f96f7
commit 1a8c9147b8
34 files changed
+2420

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
---
author: "Flávio Schiavoni"
description: Hey!
---
/*
Criado por {{ page.author }}
Disponível em {{ page.url }}
*/
#include <sys/stat.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
int main(int argc, char ** argv){
if(argc < 4){
printf("Usage:\n");
printf("%s sample_rate bit_depth\n", argv[0]);
exit(0);
}
char * filename = malloc(strlen(argv[1]));
strcpy(filename, argv[1]);
struct stat st;
stat(filename, &st);
uint32_t size = st.st_size; //limita o tamanho do arquivo!
printf("filesize: %d\n", size);
// Read file data
char * buffer = 0;
FILE * f = fopen (filename, "rb");
buffer = malloc(size);
fread (buffer, 1, size, f);
fclose (f);
char * newfilename = malloc(strlen(argv[1] + 4));
strcpy(newfilename, filename);
strcat(newfilename, ".wav");
FILE *fp = fopen(newfilename,"wb+");
fwrite("RIFF", 1, 4, fp);
int newsize = size + 32; // file size - 8
fwrite(&newsize, 1, sizeof(newsize), fp);
fwrite("WAVE", 1, 4, fp);
fwrite("fmt ", 1, 4, fp);
int flag = 16; // chunk size
fwrite(&flag, 1, 4, fp);
flag = 1; // compression code
fwrite(&flag, 1, 2, fp);
flag = 1; // number of channels
fwrite(&flag, 1, 2, fp);
flag = atoi(argv[2]); // sample rate
fwrite(&flag, 1, 4, fp);
flag = flag * atoi(argv[3]) / 8; // bytes per second
fwrite(&flag, 1, 4, fp);
flag = atoi(argv[3]) / 8; // block align
fwrite(&flag, 1, 2, fp);
flag = atoi(argv[3]); // significant bits per sample
fwrite(&flag, 1, 2, fp);
fwrite("data", 1, 4, fp);
fwrite(&size, 1, 4, fp);
fwrite(buffer, 1, size, fp);
fclose(fp);
}
+71
View File
@@ -0,0 +1,71 @@
---
author: "Flávio Schiavoni"
description: O bladi!
---
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <alsa/asoundlib.h>
int keep_walking;
static void sigint_handler(int i){
keep_walking = 0;
}
int main(int argc, char *argv[]) {
int note_time = 1000000; // 1 segundo (em microsegundos)
// Pega o Ctrl+C ou signal de Kill para a aplicação.
signal(SIGINT, &sigint_handler);
signal(SIGTERM, &sigint_handler);
keep_walking = 1;
// Crio o dispositivo MIDI
snd_seq_t *seq_handle;
int portid;
if (snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
fprintf(stderr, "Error opening ALSA sequencer.\n");
exit(1);
}
snd_seq_set_client_name(seq_handle, "My App Midi");
if ((portid = snd_seq_create_simple_port(seq_handle, "My Midi Port",
SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
fprintf(stderr, "Error creating sequencer port.\n");
exit(1);
}
snd_seq_event_t ev;
snd_seq_ev_clear(&ev);
snd_seq_ev_set_source(&ev, 0);
snd_seq_ev_set_subs(&ev);
snd_seq_ev_set_direct(&ev);
while (keep_walking) {
// Note on
snd_seq_ev_set_noteon(&ev, 0, 60, 127);
snd_seq_event_output(seq_handle, &ev);
snd_seq_drain_output(seq_handle);
// Duration
usleep(note_time);
// Note off
snd_seq_ev_set_noteoff(&ev, 0, 60, 0);
snd_seq_event_output(seq_handle, &ev);
snd_seq_drain_output(seq_handle);
// Duration
usleep(note_time / 6);
}
snd_seq_close(seq_handle);
return 0;
}
+86
View File
@@ -0,0 +1,86 @@
---
author: "Flávio Schiavoni"
description: Obla dá!
---
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <alsa/asoundlib.h>
extern struct timespec timespec_diff(struct timespec start, struct timespec end);
extern double timespec_millis(struct timespec time);
snd_seq_t *open_seq();
void midi_action(snd_seq_t *seq_handle);
int keep_walking;
static void sigint_handler(int i){
keep_walking = 0;
}
int main(int argc, char *argv[]) {
int note_on_time = 1000000; // 1 segundo
int note_off_time = 1000000; // 1 segundo (em microsegundos)
signal(SIGINT, &sigint_handler);
signal(SIGTERM, &sigint_handler);
keep_walking = 1;
// Crio o dispositivo MIDI
snd_seq_t *seq_handle;
int portid;
if (snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
fprintf(stderr, "Error opening ALSA sequencer.\n");
exit(1);
}
snd_seq_set_client_name(seq_handle, "Teclado");
if ((portid = snd_seq_create_simple_port(seq_handle, "keyb",
SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
fprintf(stderr, "Error creating sequencer port.\n");
exit(1);
}
snd_seq_event_t ev;
snd_seq_ev_clear(&ev);
snd_seq_ev_set_source(&ev, 0);
snd_seq_ev_set_subs(&ev);
snd_seq_ev_set_direct(&ev);
while (keep_walking) {
int key = getchar();
printf("Pressionou o %d\n", key);
switch(key){
case 'a':
snd_seq_ev_set_noteon(&ev, 0, 60, 127);
snd_seq_event_output(seq_handle, &ev);
snd_seq_drain_output(seq_handle);
usleep(note_on_time / 3);
snd_seq_ev_set_noteoff(&ev, 0, 60, 0);
snd_seq_event_output(seq_handle, &ev);
snd_seq_drain_output(seq_handle);
break;
case 's':
snd_seq_ev_set_noteon(&ev, 0, 62, 127);
snd_seq_event_output(seq_handle, &ev);
snd_seq_drain_output(seq_handle);
usleep(note_on_time / 3);
snd_seq_ev_set_noteoff(&ev, 0, 62, 0);
snd_seq_event_output(seq_handle, &ev);
snd_seq_drain_output(seq_handle);
}
}
snd_seq_close(seq_handle);
return 0;
}
+66
View File
@@ -0,0 +1,66 @@
---
author: "Flávio Schiavoni"
description: Comunicador Alsa MIDI
---
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <alsa/asoundlib.h>
int keep_walking;
static void sigint_handler(int i){
keep_walking = 0;
}
int main(int argc, char *argv[]) {
int note_time = 1000000; // 1 segundo (em microsegundos)
// Pega o Ctrl+C ou signal de Kill para a aplicação.
signal(SIGINT, &sigint_handler);
signal(SIGTERM, &sigint_handler);
keep_walking = 1;
// Crio o dispositivo MIDI
snd_seq_t *seq_handle;
int portid;
if (snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
fprintf(stderr, "Error opening ALSA sequencer.\n");
exit(1);
}
snd_seq_set_client_name(seq_handle, "My App Midi");
if ((portid = snd_seq_create_simple_port(seq_handle, "My Midi Port",
SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
fprintf(stderr, "Error creating sequencer port.\n");
exit(1);
}
snd_seq_event_t ev;
snd_seq_ev_clear(&ev);
snd_seq_ev_set_source(&ev, 0);
snd_seq_ev_set_subs(&ev);
snd_seq_ev_set_direct(&ev);
int value = 0;
while (keep_walking) {
// Note on
snd_seq_ev_set_controller(&ev, 0, 0, value);
snd_seq_event_output(seq_handle, &ev);
snd_seq_drain_output(seq_handle);
// Duration
usleep(note_time);
// value = (value < 127) ? value + 1 : 0;
}
snd_seq_close(seq_handle);
return 0;
}
+64
View File
@@ -0,0 +1,64 @@
---
author: "Flávio Schiavoni"
description: O Blesq Blom!
---
#include <sys/stat.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <math.h>
#define SAMPLE_RATE 44100
#define TIME 1 //seconds
#define SAMPLE_SIZE 32 // 32 bits float
#define PI 3.141592653
int main(int argc, char ** argv){
char filename[10];
strcpy(filename, "output.wav");
FILE *fp = fopen(filename,"wb+");
fwrite("RIFF", 1, 4, fp);
int size = SAMPLE_RATE * TIME * SAMPLE_SIZE / 8; // 44100 * 10 seconds * 4 bytes per sample
fwrite(&size, 1, sizeof(size), fp);
fwrite("WAVE", 1, 4, fp);
fwrite("fmt ", 1, 4, fp);
int flag = 16; // chunk size
fwrite(&flag, 1, 4, fp);
flag = 0x0003; // compression code
fwrite(&flag, 1, 2, fp);
flag = 1; // number of channels
fwrite(&flag, 1, 2, fp);
flag = SAMPLE_RATE; // sample rate
fwrite(&flag, 1, 4, fp);
flag = SAMPLE_RATE * SAMPLE_SIZE / 8; // bytes per second
fwrite(&flag, 1, 4, fp);
flag = SAMPLE_SIZE / 8; // block align
fwrite(&flag, 1, 2, fp);
flag = SAMPLE_SIZE; // significant bits per sample
fwrite(&flag, 1, 2, fp);
fwrite("data", 1, 4, fp);
fwrite(&size, 1, 4, fp);
float buffer[SAMPLE_RATE * TIME];
float freq = 440.0f;
float step = 2.0f * PI / ((float)SAMPLE_RATE / freq);
printf("Step: %f\n", step);
int i = 0;
for(i = 0 ; i < SAMPLE_RATE * TIME; i++){
buffer[i] = sin((float)i * step);
}
fwrite(buffer, 1, size, fp);
fclose(fp);
}
+114
View File
@@ -0,0 +1,114 @@
---
author: "Flávio Schiavoni"
description: O Blesq Blom!
---
#include <stdio.h>
#include <portmidi.h>
#define INPUT_BUFFER_SIZE 100
#define OUTPUT_BUFFER_SIZE 0
#define DRIVER_INFO NULL
#define TIME_PROC ((int32_t (*)(void *)) Pt_Time)
#define TIME_INFO NULL
#define TIME_START Pt_Start(1, 0, 0) /* timer started w/millisecond accuracy */
#define STRING_MAX 80 /* used for console input */
#define chord_size 5
int32_t latency = 0;
int main(int argc, char* argv) {
PmStream * midi;
char line[80];
int32_t off_time;
int chord[] = { 60, 67, 76, 83, 90 };
PmEvent buffer[chord_size];
PmTimestamp timestamp;
/* determine which output device to use */
int i = get_number("Type output number: ");
/* It is recommended to start timer before PortMidi */
TIME_START;
/* open output device -- since PortMidi avoids opening a timer
when latency is zero, we will pass in a NULL timer pointer
for that case. If PortMidi tries to access the time_proc,
we will crash, so this test will tell us something. */
Pm_OpenOutput(&midi,
i,
DRIVER_INFO,
OUTPUT_BUFFER_SIZE,
(latency == 0 ? NULL : TIME_PROC),
(latency == 0 ? NULL : TIME_INFO),
latency);
printf("Midi Output opened with %ld ms latency.\n", (long) latency);
/* output note on/off w/latency offset; hold until user prompts */
printf("ready to send program 1 change... (type RETURN):");
fgets(line, STRING_MAX, stdin);
/* if we were writing midi for immediate output, we could always use
timestamps of zero, but since we may be writing with latency, we
will explicitly set the timestamp to "now" by getting the time.
The source of timestamps should always correspond to the TIME_PROC
and TIME_INFO parameters used in Pm_OpenOutput(). */
buffer[0].timestamp = TIME_PROC(TIME_INFO);
/* Send a program change to increase the chances we will hear notes */
/* Program 0 is usually a piano, but you can change it here: */
#define PROGRAM 0
buffer[0].message = Pm_Message(0xC0, PROGRAM, 0);
Pm_Write(midi, buffer, 1);
printf("ready to note-on... (type RETURN):");
fgets(line, STRING_MAX, stdin);
buffer[0].timestamp = TIME_PROC(TIME_INFO);
buffer[0].message = Pm_Message(0x90, 60, 100);
Pm_Write(midi, buffer, 1);
printf("ready to note-off... (type RETURN):");
fgets(line, STRING_MAX, stdin);
buffer[0].timestamp = TIME_PROC(TIME_INFO);
buffer[0].message = Pm_Message(0x90, 60, 0);
Pm_Write(midi, buffer, 1);
/* output short note on/off w/latency offset; hold until user prompts */
printf("ready to note-on (short form)... (type RETURN):");
fgets(line, STRING_MAX, stdin);
Pm_WriteShort(midi, TIME_PROC(TIME_INFO),
Pm_Message(0x90, 60, 100));
printf("ready to note-off (short form)... (type RETURN):");
fgets(line, STRING_MAX, stdin);
Pm_WriteShort(midi, TIME_PROC(TIME_INFO),
Pm_Message(0x90, 60, 0));
/* output several note on/offs to test timing.
Should be 1s between notes */
printf("chord will arpeggiate if latency > 0\n");
printf("ready to chord-on/chord-off... (type RETURN):");
fgets(line, STRING_MAX, stdin);
timestamp = TIME_PROC(TIME_INFO);
for (i = 0; i < chord_size; i++) {
buffer[i].timestamp = timestamp + 1000 * i;
buffer[i].message = Pm_Message(0x90, chord[i], 100);
}
Pm_Write(midi, buffer, chord_size);
off_time = timestamp + 1000 + chord_size * 1000;
while (TIME_PROC(TIME_INFO) < off_time)
/* busy wait */;
for (i = 0; i < chord_size; i++) {
buffer[i].timestamp = timestamp + 1000 * i;
buffer[i].message = Pm_Message(0x90, chord[i], 0);
}
Pm_Write(midi, buffer, chord_size);
/* close device (this not explicitly needed in most implementations) */
printf("ready to close and terminate... (type RETURN):");
fgets(line, STRING_MAX, stdin);
Pm_Close(midi);
Pm_Terminate();
printf("done closing and terminating...\n");
}
+76
View File
@@ -0,0 +1,76 @@
---
author: "Flávio Schiavoni"
description: O Blesq Blom!
---
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <alsa/asoundlib.h>
snd_seq_t *open_seq();
void midi_action(snd_seq_t *seq_handle);
snd_seq_t *open_seq() {
snd_seq_t *seq_handle;
int portid;
if (snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
fprintf(stderr, "Error opening ALSA sequencer.\n");
exit(1);
}
snd_seq_set_client_name(seq_handle, "ALSA Sequencer Demo");
if ((portid = snd_seq_create_simple_port(seq_handle, "ALSA Sequencer Demo",
SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
fprintf(stderr, "Error creating sequencer port.\n");
exit(1);
}
return(seq_handle);
}
void midi_action(snd_seq_t *seq_handle) {
snd_seq_event_t *ev;
do {
snd_seq_event_input(seq_handle, &ev);
switch (ev->type) {
case SND_SEQ_EVENT_CONTROLLER:
fprintf(stderr, "Control event on Channel %2d: %5d \r",
ev->data.control.channel, ev->data.control.value);
break;
case SND_SEQ_EVENT_PITCHBEND:
fprintf(stderr, "Pitchbender event on Channel %2d: %5d \r",
ev->data.control.channel, ev->data.control.value);
break;
case SND_SEQ_EVENT_NOTEON:
fprintf(stderr, "Note On event on Channel %2d: %5d \r",
ev->data.control.channel, ev->data.note.note);
break;
case SND_SEQ_EVENT_NOTEOFF:
fprintf(stderr, "Note Off event on Channel %2d: %5d \r",
ev->data.control.channel, ev->data.note.note);
break;
}
snd_seq_free_event(ev);
} while (snd_seq_event_input_pending(seq_handle, 0) > 0);
}
int main(int argc, char *argv[]) {
snd_seq_t *seq_handle;
int npfd;
struct pollfd *pfd;
seq_handle = open_seq();
npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
while (1) {
if (poll(pfd, npfd, 100000) > 0) {
midi_action(seq_handle);
}
}
}