Skip to content

Instantly share code, notes, and snippets.

@henkman
Last active August 29, 2015 14:07
Show Gist options
  • Save henkman/5e190ef96755fc1c754e to your computer and use it in GitHub Desktop.
Save henkman/5e190ef96755fc1c754e to your computer and use it in GitHub Desktop.
/*
gcc -s -O3 -Wall -o bitaudio bitaudio.c -lportaudio
*/
#include <portaudio.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
static PaStream *stream;
static int pa_callback(const void *in, void *out,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData)
{
fread(out, 1, framesPerBuffer, stdin);
return paContinue;
}
static void sigint(int signo)
{
Pa_StopStream(stream);
Pa_CloseStream(stream);
Pa_Terminate();
exit(0);
}
int main(int argc, char **argv)
{
PaStreamParameters outputParameters;
Pa_Initialize();
_setmode(_fileno(stdin), _O_BINARY);
outputParameters.device = Pa_GetDefaultOutputDevice();
outputParameters.channelCount = 1;
outputParameters.sampleFormat = paUInt8;
outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
Pa_OpenStream(&stream, NULL, &outputParameters, 8000, 256, 0, pa_callback, NULL);
Pa_StartStream(stream);
signal(SIGINT, sigint);
for(;;) {
Pa_Sleep(1000);
}
return 0;
}
/*
gcc -s -Wall -O3 -o foo foo.c && foo | bitaudio
*/
#include <stdio.h>
static char blipblop(unsigned int t)
{
return t * ((t>>9|t>>13)&25&t>>6);
}
int main(int argc, char **argv)
{
unsigned int t;
for(t = 0;;t++) {
fputc(blipblop(t), stdout);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment