Code: Select all
wget -r -l1 --no-parent http://cgit.openembedded.org/openembedded/plain/recipes/xorg-xserver
Code: Select all
wget -r -l1 --no-parent http://cgit.openembedded.org/openembedded/plain/recipes/xorg-xserver
Code: Select all
//diet gcc -Os -finline-small-functions oggplay.c -ffunction-sections -fdata-sections -fmerge-all-constants -Wl,--gc-sections,-s -o oggplay -lm
#define STB_ONLY
#include "stb.h" /* http://nothings.org/stb.h */
#include "stb_vorbis.c"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
#include <errno.h>
static inline void write2(char *msg){
fputs(msg,stderr);
}
int main(int argc, char **argv){
int error,
value = AFMT_S16_LE ,
pcm = open("/dev/dsp", O_WRONLY);
if (pcm < 0)
write2("cannot get fd\n");
if (ioctl(pcm, SNDCTL_DSP_SETFMT, &value) < 0)
write2("cannot set audio format: %s\n");
while (--argc) {
short *decoded;
int channels, len, sample_rate;
len = stb_vorbis_decode_filename(argv[argc], &channels, &sample_rate, &decoded);
if (ioctl(pcm, SNDCTL_DSP_CHANNELS, &channels) < 0)
write2("cannot set channels");
if (ioctl(pcm, SNDCTL_DSP_SPEED, &sample_rate) < 0)
write2("cannot set sample rate");
write(pcm,decoded,len*channels);
}
close(pcm);
return 0;
}
Code: Select all
#!/bin/awk -f
BEGIN{
FS="[^a-zA-Z_]"
#supported functions are comma-separate in "allfuncs" file
while ((getline line < "allfuncs") > 0)
allfuncs=allfuncs line
close("allfuncs")
}
{
for(i=1;i<NF;i++)
if (index(allfuncs,","$i","))
if (needed[$i]) needed[$i]++;
else needed[$i]=1
}
END{
printf "#ifndef BQC_CONFIG_H\n#define BQC_CONFIG_H\n"
for (i in needed) print "#include <" i ".h> //uses = " needed[i]
print "#endif"
}
Code: Select all
int f0(int a, int b){return a+b;} //ADD
int f1(int a, int b){return a-b;} //SUBTRACT
int f2(int a, int b){return a*b;} //MULTIPLY
int f3(int a, int b){return a/b;} //DIVIDE
//use these to access the function in the array
enum{ ADD, SUBTRACT, MULTIPLY, DIVIDE, NUM_FUNCS};
//assign the corresponding functions in same order as enum above
//type checking and number of parameters are for wusses
int (*f[NUM_FUNCS]) () = {f0,f1,f2,f3};
#define F(x,...) (*f[x]) (__VA_ARGS__)
#define add(...) F(ADD,__VA_ARGS__)
//note, the compiler probably won't complain if you add("hello","world")
//....
I do like the concept of something called Mite Linux or AcarinaPup(py) which would be quite nice.technosaurus wrote:I could have just edited my last post, but in case anyone is following the thread, I wanted to get input on setting up a github team. As it goes most listings of the most difficult things in programming include "naming stuff". After considering PNG (short for puppy next generation after DSLR tradition of ungoogleable names) I thought Mite would be fitting for several reasons:
worlds fastest animal by size
some of the most powerful animals by size
their makeup defies traditional wisdom based on other species
they make use of stuff left behind by others
they occupy a wide range of niches
There are almost 50000 species to choose from for code-naming sub projects each with varying characteristics.
The os could be called Acari (the taxonomy subclass of all mites) or Acarina.
Any thoughts? I'm also amenable to a whole dinosaur based naming scheme.
Code: Select all
> ls -l
d????????? ? ? ? ? ? target/
> ls target
ls: cannot access target: No such file or directory
> mount
...
luufs on /mnt/live/tmp/scratch/luufs/target type fuse.luufs (rw,nosuid,nodev,relatime,user_id=0,group_id=0)
Code: Select all
/*This linux mixer dedicated to the Public Domain by Brad Conroy*/
#include <fcntl.h>
#include <linux/soundcard.h>
int get_dev(const char *name){
int i;
const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i)
if (!strcmp(names[i], name)) return i;
return -1;
}
#ifdef NOPRINTF
void putd(unsigned d){
if (d==0){
write(1,"0",1);
}else{
unsigned i=1000000000;
char s[1];
while (i > d) i/=10;
while (0<i){
*s='0'+(d/i);
write(1,s,1);
if (i<=d) d%=i;
i/=10;
}
}
write(1,"\n",1);
}
#else
#include <stdio.h>
#endif
int main(int argc, char **argv){ //mix /dev/mixer dev [value]
int fd=open(argv[1], O_RDWR|O_NONBLOCK),
dev=get_dev(argv[2]),
buf;
if (fd<0 || dev<0) return -1;
if (argc>3){
buf=atoi(argv[3]);
if(ioctl(fd, MIXER_WRITE(dev),&buf)<0) return -1;
}
if(ioctl(fd, MIXER_READ(dev),&buf)<0) return -1;
#ifdef NOPRINTF
putd(buf);
#else
printf("%d\n",buf);
#endif
close(fd);
return 0;
}
Code: Select all
/*This linux mixer dedicated to the Public Domain by Brad Conroy*/
#include <fcntl.h>
#include <string.h>
#include <linux/soundcard.h>
#ifdef NOPRINTF
void putd(unsigned d){
if (d==0){
write(1,"0",1);
}else{
unsigned i=1000000000;
char s[1];
while (i > d) i/=10;
while (0<i){
*s='0'+(d/i);
write(1,s,1);
if (i<=d) d%=i;
i/=10;
}
}
write(1,"\n",1);
}
#else
#include <stdio.h>
#define putd(d) printf("%d\n",d)
#endif
int fd,dev,buf,i,mask; //global kludge
int get_dev(const char *name){
const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
if (!strncmp("list", name, 4)){
ioctl(fd, SOUND_MIXER_READ_DEVMASK,&mask);
for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i)
if (1<<i & mask) {
write(1,names[i],strlen(names[i]));
if (name[4]==':'){
write(1,":",1);
if(ioctl(fd, MIXER_READ(i),&buf)<0) return -1;
putd(buf);
}else write(1,"\n",1);
}
}else for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i)
if (!strcmp(names[i], name)) return i;
return -1;
}
int main(int argc, char **argv){ //mix /dev/mixer dev [value]
fd=open(argv[1], O_RDWR|O_NONBLOCK);
dev=get_dev(argv[2]);
if (fd<0 || dev<0) return -1;
if (argc>3){
buf=atoi(argv[3]);
if(ioctl(fd, MIXER_WRITE(dev),&buf)<0) return -1;
}
if(ioctl(fd, MIXER_READ(dev),&buf)<0) return -1;
putd(buf);
close(fd);
return 0;
}
Code: Select all
mega_func(a,b,c,d,e,f,g,h,i){
switch(a){
case 0 : return func0(b,c,d,e,f,g,h);
....
}
}
Code: Select all
mega_func(a,b,c,d,e,f,g,h,i){
switch(i){
case 0 : return func0(a,b,c,d,e,f,g,h);
....
}
}
Code: Select all
/* wav.c - Plays wav file(s).
*
* Copyright 2014 Brad Conroy <bconroy@uis.edu>
*
* See https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
USE_WAV(NEWTOY(wav, "<1", TOYFLAG_BIN))
config WAV
bool "wav"
default n
help
usage: wav [wav file...]
Plays wav files.
*/
#define FOR_wav
#include "toys.h"
void do_wav(int wav, char **argv){
struct {
long ChunkID; //0x52494646 "RIFF"
long ChunkSize;
long Format; //0x57415645 "WAVE"
long Subchunk1ID; //0x666d7420 "fmt "
long Subchunk1Size;
short AudioFormat; //1
short NumChannels; //1==mono, 2==stereo
long SampleRate; //8000, 44100,...
long ByteRate;
short BlockAlign;
short BitsPerSample;
long Subchunk2ID; //0x64617461 "data"
long Subchunk2Size;
} *wav_hdr=&toybuf;
int error,dsp;
read(wav,wav_hdr,44);
if (wav_hdr->Format==0x57415645 &&
wav_hdr->Subchunk1ID==0x666d7420 &&
wav_hdr->Subchunk2ID==0x64617461){
if (dsp=open("/dev/dsp",O_WRONLY) >= 0 &&
ioctl(dsp, SNDCTL_DSP_SPEED, &wav_hdr->SampleRate) >= 0 &&
ioctl(dsp, SNDCTL_DSP_CHANNELS, &wav_hdr->NumChannels) >= 0
&& ioctl(dsp, SNDCTL_DSP_SETFMT, &wav_hdr->BitsPerSample) >= 0){
while (readall(wav,toybuf,sizeof(toybuf))
writeall(dsp,toybuf,sizeof(toybuf));
close(dsp);
}else perror("dsp");
}
}
void wav_main(void){
loopfiles(toys.optargs, do_wav);
}
char *file, not char **argv.technosaurus wrote:Edit: I've been putting together another audio app, but this time just a .wav player for toybox (on windows box without a compiler, so it is probably full of errors) -- in case anyone wants to see if it will build/play
Code: Select all
/* wav.c - Plays wav file(s). * * Copyright 2014 Brad Conroy <bconroy@uis.edu> * * See https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ USE_WAV(NEWTOY(wav, "<1", TOYFLAG_BIN)) config WAV bool "wav" default n help usage: wav [wav file...] Plays wav files. */ #define FOR_wav #include "toys.h" void do_wav(int wav, char **argv){ struct { long ChunkID; //0x52494646 "RIFF" long ChunkSize; long Format; //0x57415645 "WAVE" long Subchunk1ID; //0x666d7420 "fmt " long Subchunk1Size; short AudioFormat; //1 short NumChannels; //1==mono, 2==stereo long SampleRate; //8000, 44100,... long ByteRate; short BlockAlign; short BitsPerSample; long Subchunk2ID; //0x64617461 "data" long Subchunk2Size; } *wav_hdr=&toybuf; int error,dsp; read(wav,wav_hdr,44); if (wav_hdr->Format==0x57415645 && wav_hdr->Subchunk1ID==0x666d7420 && wav_hdr->Subchunk2ID==0x64617461){ if (dsp=open("/dev/dsp",O_WRONLY) >= 0 && ioctl(dsp, SNDCTL_DSP_SPEED, &wav_hdr->SampleRate) >= 0 && ioctl(dsp, SNDCTL_DSP_CHANNELS, &wav_hdr->NumChannels) >= 0 && ioctl(dsp, SNDCTL_DSP_SETFMT, &wav_hdr->BitsPerSample) >= 0){ while (readall(wav,toybuf,sizeof(toybuf)) writeall(dsp,toybuf,sizeof(toybuf)); close(dsp); }else perror("dsp"); } } void wav_main(void){ loopfiles(toys.optargs, do_wav); }
Code: Select all
/* wav.c - Plays wav file(s).
*
* Copyright 2014 Brad Conroy <bconroy@uis.edu>
*
* See https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
USE_WAV(NEWTOY(wav, "<1", TOYFLAG_BIN))
config WAV
bool "wav"
default n
help
usage: wav [wav file...]
Plays wav files.
*/
#define FOR_wav
#include "toys.h"
#include <linux/soundcard.h>
void do_wav(int wav, char *wavfile){
struct {
char ChunkID[4]; //0x52494646 "RIFF"
int ChunkSize;
char Format[4]; //0x57415645 "WAVE"
char Subchunk1ID[4]; //0x666d7420 "fmt "
int Subchunk1Size;
short AudioFormat; //1
short NumChannels; //1==mono, 2==stereo
int SampleRate; //8000, 44100,...
int ByteRate;
short BlockAlign;
short BitsPerSample;
char Subchunk2ID[4]; //0x64617461 "data"
int Subchunk2Size;
} *wav_hdr = (void*)toybuf;
int dsp, tmp;
readall(wav,wav_hdr, 44);
if (strncmp(wav_hdr->Format, "WAVE", 4)) {
printf("format: %.4s", wav_hdr->Format);
return;
}
if (strncmp(wav_hdr->Subchunk1ID,"fmt ", 4)) {
printf("ID1: %.4s", wav_hdr->Subchunk1ID);
return;
}
if (strncmp(wav_hdr->Subchunk2ID, "data", 4)) {
printf("ID2: %.4s", wav_hdr->Subchunk2ID);
return;
}
dsp = xopen("/dev/dsp",O_WRONLY);
#if IS_LITTLE_ENDIAN
bswap_32(wav_hdr->SampleRate);
bswap_16(wav_hdr->NumChannels);
bswap_16(wav_hdr->BitsPerSample);
#endif
xioctl(dsp, SNDCTL_DSP_SPEED, &wav_hdr->SampleRate);
tmp = wav_hdr->NumChannels;
xioctl(dsp, SNDCTL_DSP_CHANNELS, &tmp);
xioctl(dsp, SNDCTL_DSP_SETFMT, &wav_hdr->BitsPerSample);
while (readall(wav,toybuf,sizeof(toybuf)))
writeall(dsp,toybuf,sizeof(toybuf));
close(dsp);
}
void wav_main(void){
loopfiles(toys.optargs, do_wav);
}
Thanks, I was planning on #ifdeffing the endian stuff instead of strcmpIbidem wrote: And this works:
Code: Select all
#if IS_LITTLE_ENDIAN
if (wav_hdr->Format==0x45564157 && wav_hdr->Subchunk1ID==0x20746d66 && wav_hdr->Subchunk2ID==0x61746164){
#else
bswap_32(wav_hdr->SampleRate);
bswap_16(wav_hdr->NumChannels);
bswap_16(wav_hdr->BitsPerSample);
if (wav_hdr->Format==0x57415645 && wav_hdr->Subchunk1ID==0x666d7420 && wav_hdr->Subchunk2ID==0x64617461){
#endif