GP2X Writing To /dev/dsp/ (and Telnet-ing)


mrsnature

Member
Joined
Jul 22, 2003
Messages
462
About to start work on some sound output using/dev/dsp/, and having never used this before I would appreciate any help on a few questions...

Is the buffer size fixed? If so, does anybody have a figure for this on the '2x, else, how do you change it?

When i overflow the buffer, can I check this by checking the return value of write(), to see how many bytes were written? I.e, if i try to write 32bytes but only 24byte are free in the buffer, will 24bytes be written and the value 24 returned?

Oh, and while i'm here, to avoid starting another thread, can anybody tell me how to telnet to my GP2x from linux so I can check printf's etc, tried messing with the network options but didn't really know what i was doing.

Thanks,

Sam
 
About to start work on some sound output using/dev/dsp/, and having never used this before I would appreciate any help on a few questions...

Is the buffer size fixed? If so, does anybody have a figure for this on the '2x, else, how do you change it?

When i overflow the buffer, can I check this by checking the return value of write(), to see how many bytes were written? I.e, if i try to write 32bytes but only 24byte are free in the buffer, will 24bytes be written and the value 24 returned?

Oh, and while i'm here, to avoid starting another thread, can anybody tell me how to telnet to my GP2x from linux so I can check printf's etc, tried messing with the network options but didn't really know what i was doing.

Thanks,

Sam
Here's a good place to start:

http://www.oreilly.de/catalog/multilinux/excerpt/ch14-05.htm
 
Last edited by a moderator:
Well, the buffer size can be fixed or variable, depending on the underlying system itself.

On the GP2X, you can change the buffer size, or request the default (getospace).

By default, if you try and write more data than there is buffer space for, the write will block (suspend your app) until there is buffer space available. You can modify this though if you use an asynchronous write or specify no-block in your device open.
 
thanks Squidge, now I understand it better i think i was able to find out what I need, but just to be sure...

...i can get how many fragments are free by using

ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info);

and only write to the buffer if there is enough space available, so my program is not blocked?

EDIT: Oh, and if I specificy no-blocking, the write will just return an error if the buffer is full.
 
Yup :)

Most people seem to just leave the call as blocking and throw the write call into another thread by using pthreads - it's the easiest way to do it. You can then use a circular sound buffer between your main app and your sound thread, or have your sound thread calculate the next chunk of sound data after it's just finished writing to the dsp.
 
Yup :)

Most people seem to just leave the call as blocking and throw the write call into another thread by using pthreads - it's the easiest way to do it. You can then use a circular sound buffer between your main app and your sound thread, or have your sound thread calculate the next chunk of sound data after it's just finished writing to the dsp.
In my article series on Demo Development, episode #5 presented a nonblocking scheme for audio which might not be too hard to adapt. I am irritated by the little glitches that switching to an audio thread causes so I'm moving to a single thread model for all my personal development. The method that Squidge presents is certainly simpler to get going though.
 
Last edited by a moderator:
Oh, and while i'm here, to avoid starting another thread, can anybody tell me how to telnet to my GP2x from linux so I can check printf's etc, tried messing with the network options but didn't really know what i was doing.

Thanks,

Sam

Before you start you may need to replace the g_ether module in the kernel. See this thread.

Here's what you do:
  1. Set the IP address of the GP2X to a different network from your PC e.g. if eth0 is 192.168.x.x, use 10.0.0.x I'll use 10.0.0.2 as an example
  2. Enable telnet server on the GP2X
  3. Restart the GP2X connected to the PC
  4. As root type ifconfig usb0 10.0.0.1
You should now be able to do telnet 10.0.0.2 user name root, no password

You'll have to do the ifconfig usb0 10.0.0.1 every time you reconnect the GP2X unless you put an entry in /etc/network/interfaces for usb0 to add it automatically but I can't remember the format right now
 
Last edited by a moderator:
Back
Top