Puppy In-House Development

Under development: PCMCIA, wireless, etc.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#256 Post by technosaurus »

Are we planning to (eventually) implement kdbus functionality in future kernels for interprocess communication? rox, tinyx*,
... I ask because I was considering patching the xserver and tinyX to use kdbus vs unix domain (or even slower tcp) sockets to help make up for the speed difference of accelerated Xorg drivers.

Other TODOs :
Check Xservers for accelerated functions (pretty sure Xorg devs aren't watching this too closely, so here they are for reference):
  • /* fb ops */
    static struct fb_ops {
    .fb_open
    .fb_release
    .fb_check_var
    .fb_set_par
    .fb_setcolreg
    .fb_blank
    .fb_pan_display
    .fb_fillrect
    .fb_copyarea
    .fb_imageblit
    .fb_cursor
    .fb_sync
    .fb_ioctl
    .fb_mmap
    .fb_read
    .fb_write
    };
Refactor X11 - only 4 different basic types of messages are sent, with 3-4 different actions, so the shared lib can be as small as 20-30 functions with the rest in headers as static inlined functions (this will actually produce smaller executables due to the dumbass way X11 has 10s of parameters in functions instead of a struct pointer) The current method of including each function in the shared library has to push each parameter to the stack, set the stack pointer call another function which has to pop them to do stuff, return a value and then have the caller restore its stack.

fyi, the order you put parameters in makes a huge difference in how optimizable they are as exported functions, for instance:

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);
....
}
}
can be optimized to a single pop and a jump table
whereas the following has to pop all of the parameters first:

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);
....
}
}
The reason I bring this up is because X11 does this really poorly and code size could be reduce by having the standard function be a macro (or static inline helper function if we want C++ support) that swaps the parameters in the more efficient order ... this is why MS uses a different calling convention (pass by register vs stack) - it is faster and reduces code size
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#257 Post by Iguleder »

Trying to get the upstream LibreSSL to work with musl. At the moment, musl requires two sets of #ifdefs.

It's pretty much impossible to build a static OpenSSL without tons of hacks, but LibreSSL is an entirely different story - it uses autoconf. Very convenient! I got many applications to build statically against musl and LibreSSL (Dillo, Sylpheed, x11vnc, X-Chat, Lynx and more).
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#258 Post by technosaurus »

glibc has _versioning_ which is really annoying sometimes, but the very reason the runtime check is pointless... they should use a blacklist method and error on glibc<whatever.version, include their own version if it is missing or use the libc version ... not some random whitelist system that assumes that all other programmers are stupid... if they want to do that crap they should just have a #define PARANOID that only uses their versions of everything.

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);
}
Edit2: @Iguleder, I noticed you also made an ogg player with stb_vorbis ... is there an advantage to using tinyalsa over /dev/dsp directly? ... aside from possibly missing a symlink from /dev/dspX like mixing multiple sources or support for platforms without OSS
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#259 Post by Ibidem »

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);
}
char *file, not char **argv.
Also, xopen() and xioctl(), unless you're expecting someone to create /dev/dsp while the player is running.
s/long/int/g
#include <linux/soundcard.h>

And endianness, what fun!
(It doesn't work on x86, since the bytes are the other way round. I tried to fix with strncmp.)
OK, I have a version that gets to the second ioctl().

And this works:

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);
}

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#260 Post by technosaurus »

Ibidem wrote: And this works:
Thanks, I was planning on #ifdeffing the endian stuff instead of strcmp
After reviewing the spec it looks like

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
//note need to add Subchunk1Size==16 && AudioFormat==??

1 (0x0001) PCM/uncompressed
2 (0x0002) Microsoft ADPCM
6 (0x0006) ITU G.711 a-law
7 (0x0007) ITU G.711 µ-law
17 (0x0011) IMA ADPCM
20 (0x0016) ITU G.723 ADPCM (Yamaha)
49 (0x0031) GSM 6.10
64 (0x0040) ITU G.721 ADPCM
80 (0x0050) MPEG

for PCM the format is little endian based on bits per sample
AFMT_U16_LE, AFMT_U24_LE and AFMT_U32_LE
TODO check AFMT_IMA_ADPCM, AFMT_MU_LAW, AFMT_A_LAW and wait, wtf MPEG == AFMT_MPEG ?can we play mp2 audio?

Re: s/long/int/
actually it seems neither is _always_ correct - int32_t? (the kernel uses be32 and le32 types )
to avoid the ifdefs we could use these or these

Now I need to be able to set the volume on it, so need to toybox my previous mixer (probably split the list part into a separate command)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#261 Post by Ibidem »

All UNIX-like systems are ILP32 or LP64 (if it purports to be POSIX, sizeof(int)==4 and sizeof(long)==sizeof(void*)).
But Windows is ILP64, where sizeof(int) == sizeof(long).
int32_t is ISO C, which is aimed at both Windows and *nix even though MS refuses to update their compiler past C89.

Toybox is aimed only at systems where sizeof(int)==4. It also expects POSIX2008 support.
The strncmp was done that way because I wanted to see why it wasn't playing.
A more toybox-ish way would be

Code: Select all

 if (strncmp(a, b, 4) || strncmp(c, d, 4) || strncmp(e, f, 4)){
  perror_msg("bad WAV header: %s", wav_file);
  return;
}
All the bswap_* stuff can be done via SWAP_BE*.
This could also be used for the comparisons if you don't want to do strncmp().

Code: Select all

   if (IS_LITTLE_ENDIAN) {
    //endianness-switching
  } else {
    //big-endian code
  }
is actually the "proper" style for toybox; modern compilers will turn if (1) {a;} into {a;}.

On the mixer, -l and -r would be nice; optstring would look about like this:
"l#<0>100r#<0>100"
This way the initialization code converts it to a long and checks the range.
Making list a separate command seems rather pointless; both need to open the mixer and call some ioctls on it.
Also, it's a standard part of most CLI mixers.
Last edited by Ibidem on Tue 15 Jul 2014, 21:02, edited 1 time in total.

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#262 Post by Iguleder »

technosaurus wrote: Edit2: @Iguleder, I noticed you also made an ogg player with stb_vorbis ... is there an advantage to using tinyalsa over /dev/dsp directly? ... aside from possibly missing a symlink from /dev/dspX like mixing multiple sources or support for platforms without OSS
Nothing but abstraction. Yes, I know it's not that complicated to kick tinyalsa, but it's ready, works well and small. Couldn't do it better myself.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#263 Post by technosaurus »

What about a whole new paradigm?
Rather than having packages at all, just install all supported packages to the root of a web server and use something akin to httpfs as a replacement for the pup*.sfs (underlying read only filesystem)

Then only items that a user actually uses get downloaded (though a cache with rsync capability to the rw layer if available would be a nice addon)

With this I think we could get the distributed image down to ~1mb and not worry about updates, package management, and all that goes along with that.

@Iguleder, does LUUFS support the equivalent of whiteout files? --- something to allow the user to hide some .desktop files so the menu doesn't become unmanageable.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#264 Post by Iguleder »

No, it doesn't. It doesn't allow the user to overwrite files from the read-only layer.

EDIT: @technosaurus, mouse wheel scrolling doesn't work in DSLR, with a 64-bit tinyxserver Xfbdev and GTK 1.x. Do you have any idea how to solve this problem? I know there was some magical X patch for this, but it's already merged into tinyxserver AFAIK. When I scroll xev it doesn't receive any events.

EDIT 2: I think evdev is the way go. I'm working on getting the vanilla X.Org 1.2 to build against tinyxlib, which lacks lots of required proto stuff.

EDIT 3: this is far too complex. Maybe adding evdev support to tinyxserver is the way to go.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#265 Post by technosaurus »

Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#266 Post by Iguleder »

The KDrive input interface changed a lot, so this doesn't help much.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#267 Post by goingnuts »

Iguleder wrote:No, it doesn't. It doesn't allow the user to overwrite files from the read-only layer.

EDIT: @technosaurus, mouse wheel scrolling doesn't work in DSLR, with a 64-bit tinyxserver Xfbdev and GTK 1.x. Do you have any idea how to solve this problem? I know there was some magical X patch for this, but it's already merged into tinyxserver AFAIK. When I scroll xev it doesn't receive any events.

EDIT 2: I think evdev is the way go. I'm working on getting the vanilla X.Org 1.2 to build against tinyxlib, which lacks lots of required proto stuff.

EDIT 3: this is far too complex. Maybe adding evdev support to tinyxserver is the way to go.
Why not try the tinyXlib derived from XFree86-4.8.0? I found that this is much less complicated than using tinyxlib. Patches included in pUPnGO-2014-412 0.6Gb ISO

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#268 Post by Iguleder »

I couldn't get it to build with a modern GCC and musl, on x86_64. Remember, you use the ancient 4.12.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#269 Post by goingnuts »

Actually using toolchain from here - guess with headers from even older kernel than P412 carries. Well - it was just a thought - you did manage to patch tinyxlib to build x86_64+musl.

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#270 Post by Iguleder »

It's the build system that's so problematic. It's a nightmare to cross-compile this thing.

Also, there are many tinyxlib incompatibilities in proto stuff. Since tinyxlib contains old xproto and other protocol headers, most X servers fail to build against it, so it's a chicken and egg problem. I can't get XFree86 or Xorg 6.9.0 to build, both the server and Xlib.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#271 Post by technosaurus »

Sorry about that. I assumed it wouldn't patch cleanly but it looked to me that there were only a relatively few number of changes to be manually patched ... adding evdev.c and modifying some lines in kdrive/linux/* Should I use Isaacs's branch or Dima's to have a blind stab at it?

here is the player: haven't toyboxed the mixer yet (just trying to get enough to test sound in aboriginal builds, so will need the mixer to ensure volume is audible)

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 <fcntl.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
#include "toys.h"

void do_wav(int fd, char *name){

  struct {
    char      ChunkID[4]; // "RIFF"
    uint32_t  ChunkSize;
    char      Format[4]; // "WAVE"
    char      Subchunk1ID[4]; // "fmt "
    uint32_t  Subchunk1Size;
    uint16_t  AudioFormat; //1
    uint16_t  NumChannels; //1==mono, 2==stereo
    uint32_t  SampleRate; //8000, 44100,...
    uint32_t  ByteRate;
    uint16_t  BlockAlign;
    uint16_t  BitsPerSample;
    char      Subchunk2ID[4]; //0x64617461 "data"
    uint32_t  Subchunk2Size;
  } *hdr = (void *) &toybuf; //to save 44 bytes

  read(fd,hdr,44);
  if (
    memcmp(hdr->ChunkID,"RIFF",4)     ||
    memcmp(hdr->Format,"WAVE",4)      ||
    memcmp(hdr->Subchunk1ID,"fmt ",4) ||
    memcmp(hdr->Subchunk2ID,"data",4) ||
    (1 != hdr->AudioFormat) //or mulaw, alaw, ima-adpcm?
  ) return;
#if !IS_LITTLE_ENDIAN
  bswap_32(hdr->SampleRate);
  bswap_16(hdr->NumChannels);
  bswap_16(hdr->BitsPerSample); 
#endif
  int value, dsp=open("/dev/dsp",O_WRONLY);
  if (dsp<0) return;
  value=hdr->NumChannels;
  xioctl(dsp, SNDCTL_DSP_CHANNELS, &value);
  value=hdr->SampleRate;
  xioctl(dsp, SNDCTL_DSP_SPEED, &value);
  value=hdr->BitsPerSample;
  xioctl(dsp, SNDCTL_DSP_SETFMT, &value);
  while ((value=readall(fd,toybuf,sizeof(toybuf))))
    writeall(dsp,toybuf,value);
  close(dsp);
}

void wav_main(void){
  loopfiles(toys.optargs, do_wav);
}
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#272 Post by Iguleder »

I think tinyxserver isn't worth the effort. It's too old and limited - evdev support is a minor problem compared to other deal breakers (e.g the lack of GTK+ 2.x support).

Ideally, I'd like to have working Xlib and Xfbdev/Xvesa in one sources tree, with makefiles, without redundant BSD/Windows/whatever code, support for cross-compilation and a -DTINY flag which disables big, unneeded features.

I really like Tiny Core's tinyx - they just stripped X.Org 1.2. However, you still need X.Org's protocol headers and libraries, so it kinda misses the point. It takes ages to build and maintaining so many small packages is a big burden.
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#273 Post by technosaurus »

I can try to revert the xvesa removal from mainline and have patches that remove bulky non-features... replace the static table based builtin iconv for at least the large asian locales with system iconv calls (or all of them? Leaving it up to iconv whether to use static tables ... just removing support for builtin large asian locales reduces x11 to ~850k and I already made a patch for that)

I also have a preliminary toybox mixer (improved) that I will post soon... feel free to scrape it for coding a tiny alsa version for dslr.

Edit:
Here is my working copy of mix.c - I had to make a sudden trip out of town for a funeral and forgot my linux flash drives (posting from win7 -yuk). It was pretty close to working IIRC, so give it a try if you wish.

Code: Select all

/* mix.c - A very basic mixer.
 *
 * Copyright 2014 Brad Conroy, dedicated to the Public Domain.
 *

USE_MIX(NEWTOY(mix, "m:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))
config MIX
  bool "mix"
  default n
  help
   usage: mix [-m mixer] [-d device] [-l level / left level] [-r right level]

   Lists/sets mixer devices/levels.
*/

#define FOR_mix
#include <linux/soundcard.h>
#include "toys.h"


GLOBALS(
   char *mixer;
   char *device;
   int level;
   int right;
)

void mix_main(void)
{

  const char *devices[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
  char *mixer_name=(toys.optflags & FLAG_m)?TT.mixer:"/dev/mixer";
  int i, mask, device=-1, level, mixer=xopen(mixer_name, O_RDWR|O_NONBLOCK);

  xioctl(mixer, SOUND_MIXER_READ_DEVMASK,&mask);

  if (!(toys.optflags & FLAG_d)){
    for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i)
      if (1<<i & mask) printf("%s\n",devices[i]);
    return;
  }else{
    for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i){
      if (!strcmp(devices[i], TT.device)){
        if (1<<i & mask) device=i;
        else return; //with error
        break;
      }
    }
  }

  if (-1==device)
    return; //with error

  if (!(toys.optflags & FLAG_l)){
    xioctl(mixer, MIXER_READ(device),&level);
    printf("%s:%s = %d\n",mixer_name,devices[device],level);
    //todo - handle left and right channels w/ bitops. if (level&0xff00)...
    return;
  }

  level=TT.level;
  if (!(toys.optflags & FLAG_r))
    level = TT.right | (level<<8);

  xioctl(mixer, MIXER_WRITE(device),&level);
  close(mixer);
}
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Iguleder
Posts: 2026
Joined: Tue 11 Aug 2009, 09:36
Location: Israel, somewhere in the beautiful desert
Contact:

#274 Post by Iguleder »

Mouse scrolling works in tinyxserver!

I decided to see how DSL behaves - somehow, it doesn't recognize the Super keys, like tinyxserver, but mouse scrolling works. I couldn't find DSL's source code to see why. Its changelogs mention some patch that made mouse scrolling work, but I couldn't find any trace of it, in both DSL's stuff and X.Org's git.

I took a look at complaints of DSL users about mouse issues - in one of them, I saw a suggestion to run the X server with "-mouse /dev/psaux,5". I knew 5 means 5 buttons, after reading so much ugly X server code, so I grepped tinyxserver's code for mouse\". I found it in hw/kdrive/kdrive.c - there's a function that accepts this string and parses it. If you look closely enough, you'll see a variable which specifies the number of buttons - the default is 3.

I just changed the default to 5, since pretty much all mice have a scroll wheel these days. Now, when you run tinyxserver without any options, it uses the first mouse it finds and assumes it has a scroll wheel. Perfect :D
[url=http://dimakrasner.com/]My homepage[/url]
[url=https://github.com/dimkr]My GitHub profile[/url]

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#275 Post by Ibidem »

technosaurus wrote: Edit:
Here is my working copy of mix.c - I had to make a sudden trip out of town for a funeral and forgot my linux flash drives (posting from win7 -yuk). It was pretty close to working IIRC, so give it a try if you wish.

Code: Select all

/* mix.c - A very basic mixer.
 *
 * Copyright 2014 Brad Conroy, dedicated to the Public Domain.
 *

USE_MIX(NEWTOY(mix, "m:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))
config MIX
  bool "mix"
  default n
  help
   usage: mix [-m mixer] [-d device] [-l level / left level] [-r right level]

   Lists/sets mixer devices/levels.
*/

#define FOR_mix
#include <linux/soundcard.h>
#include "toys.h"


GLOBALS(
   char *mixer;
   char *device;
   int level;
   int right;
)

void mix_main(void)
{

  const char *devices[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
  char *mixer_name=(toys.optflags & FLAG_m)?TT.mixer:"/dev/mixer";
  int i, mask, device=-1, level, mixer=xopen(mixer_name, O_RDWR|O_NONBLOCK);

  xioctl(mixer, SOUND_MIXER_READ_DEVMASK,&mask);

  if (!(toys.optflags & FLAG_d)){
    for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i)
      if (1<<i & mask) printf("%s\n",devices[i]);
    return;
  }else{
    for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i){
      if (!strcmp(devices[i], TT.device)){
        if (1<<i & mask) device=i;
        else return; //with error
        break;
      }
    }
  }

  if (-1==device)
    return; //with error

  if (!(toys.optflags & FLAG_l)){
    xioctl(mixer, MIXER_READ(device),&level);
    printf("%s:%s = %d\n",mixer_name,devices[device],level);
    //todo - handle left and right channels w/ bitops. if (level&0xff00)...
    return;
  }

  level=TT.level;
  if (!(toys.optflags & FLAG_r))
    level = TT.right | (level<<8);

  xioctl(mixer, MIXER_WRITE(device),&level);
  close(mixer);
}
Big issue is that GLOBALS() must be in the reverse order of the NEWTOY optstring, which makes for a segfault if -d is passed.
You can drop char *mixer_name and instead do:

Code: Select all

  int mixer = xopen(TT.mixer?TT.mixer:"/dev/mixer", O_RDWR | O_NONBLOCK);
(make sure to give mixer its own line, even if you don't add a separate "int" declaration.)
The "else return" in the loop can go; it catches a strict subset of cases of "if (-1==device) return;" because the break statement would leave the loop with device still set to -1.
Properly all the ints in GLOBALS() should be longs.
And I thought that the mixer ioctls took a (unsigned?) short not an int, which could explain why I can't get this to reset vol on my system...

Post Reply