From f90ce63ee860d5e9786b6eb29feff0ead65af6df Mon Sep 17 00:00:00 2001 From: "N.N." Date: Mon, 25 May 2009 05:39:51 +0000 Subject: reformat svn path=/trunk/; revision=11491 --- desiredata/src/s_audio_oss.c | 94 +++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 59 deletions(-) (limited to 'desiredata/src/s_audio_oss.c') diff --git a/desiredata/src/s_audio_oss.c b/desiredata/src/s_audio_oss.c index 2a22da1c..5c795158 100644 --- a/desiredata/src/s_audio_oss.c +++ b/desiredata/src/s_audio_oss.c @@ -147,13 +147,11 @@ void oss_configure(t_oss_dev *dev, int srate, int dac, int skipblocksize) { fragbytes = linux_fragsize * (dev->bytespersamp * nchannels); logfragsize = ilog2(fragbytes); if (fragbytes != (1 << logfragsize)) - post("warning: OSS takes only power of 2 blocksize; using %d", - (1 << logfragsize)/(dev->bytespersamp * nchannels)); + post("warning: OSS takes only power of 2 blocksize; using %d", (1<bytespersamp*nchannels)); if (sys_verbose) post("setting nfrags = %d, fragsize %d", nfragment, fragbytes); param = orig = (nfragment<<16) + logfragsize; - if (ioctl(fd,SNDCTL_DSP_SETFRAGMENT, ¶m) == -1) - error("OSS: Could not set or read fragment size"); + if (ioctl(fd,SNDCTL_DSP_SETFRAGMENT, ¶m) == -1) error("OSS: Could not set or read fragment size"); if (param != orig) { nfragment = ((param >> 16) & 0xffff); logfragsize = (param & 0xffff); @@ -169,15 +167,13 @@ void oss_configure(t_oss_dev *dev, int srate, int dac, int skipblocksize) { we should figure out what to do if the requested scheduler advance is greater than this buffer size; for now, we just print something out. */ - int defect; if (ioctl(fd, SOUND_PCM_GETOSPACE,&ainfo) < 0) error("OSS: ioctl on output device failed"); dev->bufsize = ainfo.bytes; - defect = sys_advance_samples * (dev->bytespersamp * nchannels) - - dev->bufsize - OSS_XFERSIZE(nchannels, dev->bytespersamp); - if (defect > 0) { + int defect = sys_advance_samples*(dev->bytespersamp*nchannels) - dev->bufsize - OSS_XFERSIZE(nchannels, dev->bytespersamp); + if (defect>0) { if (sys_verbose || defect > (dev->bufsize >> 2)) error("OSS: requested audio buffer size %d limited to %d", - sys_advance_samples * (dev->bytespersamp * nchannels), dev->bufsize); + sys_advance_samples*(dev->bytespersamp*nchannels), dev->bufsize); sys_advance_samples = (dev->bufsize-OSS_XFERSAMPS(nchannels)) / (dev->bytespersamp*nchannels); } } @@ -217,26 +213,23 @@ int oss_open_audio(int nindev, int *indev, int nchin, int *chin, int capabilities = 0; int inchannels = 0, outchannels = 0; char devname[20]; - int n, i, fd, flags; + int fd, flags; char buf[OSS_MAXSAMPLEWIDTH * sys_dacblocksize * OSS_MAXCHPERDEV]; - int wantmore=0; - linux_nindevs = linux_noutdevs = 0; /* mark devices unopened */ for (int i=0; i= 0 ? outdev[n] : 0); int wantchannels = (nchout>n) ? chout[n] : wantmore; fd = -1; if (!wantchannels) goto end_out_loop; if (thisdevice > 0) sprintf(devname, "/dev/dsp%d", thisdevice); else sprintf(devname, "/dev/dsp"); /* search for input request for same device. Succeed only if the number of channels matches. */ - for (j = 0; j < nindev; j++) if (indev[j] == thisdevice && chin[j] == wantchannels) inindex = j; + for (int j=0; j= 0) { sys_setalarm(1000000); @@ -279,15 +272,13 @@ int oss_open_audio(int nindev, int *indev, int nchin, int *chin, chin[inindex] = gotchans; } } - /* LATER think about spreading large numbers of channels over - various dsp's and vice-versa */ + /* LATER think about spreading large numbers of channels over various dsp's and vice-versa */ wantmore = wantchannels - gotchans; end_out_loop: ; } - /* open input devices */ wantmore = 0; - for (n = 0; n < nindev; n++) { + for (int n=0; n= 0 ? indev[n] : 0); int wantchannels = (nchin>n)?chin[n]:wantmore; @@ -334,10 +325,10 @@ int oss_open_audio(int nindev, int *indev, int nchin, int *chin, if (sys_verbose) post("...done."); } /* now go and fill all the output buffers. */ - for (i = 0; i < linux_noutdevs; i++) { + for (int i=0; i d.bufsize - sys_advance_samples*d.nchannels*d.bytespersamp) { if (!zeroed) { - for (unsigned int i = 0; i < OSS_XFERSAMPS(d.nchannels); i++) buf[i] = 0; + for (unsigned int i=0; i 3 * OSS_XFERSIZE(linux_adcs[dev].nchannels, linux_adcs[dev].bytespersamp)) goto badsync; @@ -478,6 +454,8 @@ int oss_send_dacs() { } /* do output */ timeref = sys_getrealtime(); + t_oss_int16 *sp; + t_oss_int32 *lp; for (int dev=0, thischan = 0; dev < linux_noutdevs; dev++) { t_oss_dev d = linux_dacs[dev]; int nchannels = d.nchannels; @@ -485,17 +463,13 @@ int oss_send_dacs() { else { fp1 = sys_soundout + sys_dacblocksize*thischan; if (d.bytespersamp == 4) { - for (i = sys_dacblocksize * nchannels, lp = (t_oss_int32 *)buf; i--; fp1++, lp++) { - float f = *fp1 * 2147483648.; - *lp = int(f >= 2147483647. ? 2147483647. : (f < -2147483648. ? -2147483648. : f)); - } + lp = (t_oss_int32 *)buf; + for (int i=sys_dacblocksize * nchannels; i--; fp1++, lp++) *lp = int(clip(*fp1*2147483648.,-2147483648.,2147483647.)); } else { - for (i = sys_dacblocksize, sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels) { - for (j=0, fp2 = fp1; j 32767) s = 32767; else if (s < -32767) s = -32767; - sp[j] = s; - } + sp = (t_oss_int16 *)buf; + for (int i=sys_dacblocksize; i--; fp1++, sp += nchannels) { + fp2 = fp1; + for (int j=0; j