/** * Device initialization: check device capability and open for recording. * * @param sfreq [in] required sampling frequency. * @param dummy [in] a dummy data * * @return TRUE on success, FALSE on failure. */ boolean adin_mic_standby(int sfreq, void *dummy) { long rate; long prec = AL_SAMPLE_16; long encd = AL_SAMPFMT_TWOSCOMP; long chan = AL_MONO; /* global setup */ rate = sfreq; if (adin_o2_setup_global((double)rate) == FALSE) { /* failed */ jlog("Error: adin_o2: cannot setup microphone device (global)\n"); return(FALSE); } /* local parameter setup */ if ((ac = ALnewconfig()) == 0) { jlog("Error: adin_o2: cannot config microphone device (local)\n"); return(FALSE); } ALsetqueuesize(ac, rate * 2 * 1); /* 2 sec. of mono. */ ALsetwidth(ac, prec); ALsetchannels(ac, chan); ALsetsampfmt(ac, encd); jlog("Stat: adin_o2: local microphone port successfully initialized\n"); return(TRUE); }
static int setaudio(struct xmp_options *o) { int bsize = 32 * 1024; ALconfig config; long pvbuffer[2]; char *token, **parm; int i; parm_init(); chkparm1("buffer", bsize = strtoul(token, NULL, 0)); parm_end(); if ((config = ALnewconfig()) == 0) return XMP_ERR_DINIT; /* * Set sampling rate */ pvbuffer[0] = AL_OUTPUT_RATE; #if 0 /* DOESN'T WORK */ for (i = 0; srate[i]; i++) { if (srate[i] <= o->freq) pvbuffer[1] = o->freq = srate[i]; } #endif /* DOESN'T WORK */ /* * This was flawed as far as I can tell - it just progressively lowered * the sample rate to the lowest possible! * * o->freq = 44100 * * i = 0 / if (48000 <= 44100) * i = 1 / if (44100 <= 44100) * then pvbuffer[1] = o->freq = 44100 * i = 2 / if (32000 <= 44100) * then pvbuffer[1] = o->freq = 32000 * i = 3 / if (22050 <= 32000) * then pvbuffer[1] = o->freq = 22050 * etc... * * Below is my attempt to write a new one. It picks the next highest * rate available up to the maximum. This seems a lot more reasonable. * * - 19990706 bdowning */ for (i = 0; srate[i]; i++) ; /* find the end of the array */ while (i-- > 0) { if (srate[i] >= o->freq) { pvbuffer[1] = o->freq = srate[i]; break; } } if (i == 0) pvbuffer[1] = o->freq = srate[0]; /* 48 kHz. Wow! */ if (ALsetparams(AL_DEFAULT_DEVICE, pvbuffer, 2) < 0) return XMP_ERR_DINIT; /* * Set sample format to signed integer */ if (ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP) < 0) return XMP_ERR_DINIT; /* * Set sample width; 24 bit samples are not currently supported by xmp */ if (o->resol > 8) { if (ALsetwidth(config, AL_SAMPLE_16) < 0) { if (ALsetwidth(config, AL_SAMPLE_8) < 0) return XMP_ERR_DINIT; o->resol = 8; } else al_sample_16 = 1; } else { if (ALsetwidth(config, AL_SAMPLE_8) < 0) { if (ALsetwidth(config, AL_SAMPLE_16) < 0) return XMP_ERR_DINIT; o->resol = 16; } else al_sample_16 = 0; } /* * Set number of channels; 4 channel output is not currently supported */ if (o->outfmt & XMP_FMT_MONO) { if (ALsetchannels(config, AL_MONO) < 0) { if (ALsetchannels(config, AL_STEREO) < 0) return XMP_ERR_DINIT; o->outfmt &= ~XMP_FMT_MONO; } } else { if (ALsetchannels(config, AL_STEREO) < 0) { if (ALsetchannels(config, AL_MONO) < 0) return XMP_ERR_DINIT; o->outfmt |= XMP_FMT_MONO; } } /* * Set buffer size */ if (ALsetqueuesize(config, bsize) < 0) return XMP_ERR_DINIT; /* * Open the audio port */ if ((audio_port = ALopenport("xmp", "w", config)) == 0) return XMP_ERR_DINIT; return 0; }
void *Audio_Irix::open (AudioConfig& cfg, const char *) { // Copy input parameters. May later be replaced with driver defaults. _settings = cfg; _config = ALnewconfig(); // Set sample format ALsetsampfmt(_config, AL_SAMPFMT_TWOSCOMP); // stereo or mono mode _settings.channels = cfg.channels >= 2 ? 2 : 1; if (_settings.channels == 2) ALsetchannels(_config, AL_STEREO); else ALsetchannels(_config, AL_MONO); // 16 or 8 bit sample _settings.precision = cfg.precision >= 16 ? 16 : 8; if (_settings.precision == 16) ALsetwidth(_config, AL_SAMPLE_16); else ALsetwidth(_config, AL_SAMPLE_8); // Frequency long chpars[] = {AL_OUTPUT_RATE, 0}; if (cfg.frequency > 48000) chpars[1] = AL_RATE_48000; else if (cfg.frequency > 44100) chpars[1] = AL_RATE_44100; else if (cfg.frequency > 32000) chpars[1] = AL_RATE_32000; else if (cfg.frequency > 22050) chpars[1] = AL_RATE_22050; else if (cfg.frequency > 16000) chpars[1] = AL_RATE_16000; else chpars[1] = AL_RATE_11025; ALsetparams(AL_DEFAULT_DEVICE, chpars, 2); ALgetparams(AL_DEFAULT_DEVICE, chpars, 2); _settings.frequency = (uint_least32_t) chpars[1]; // Allocate sound buffers and set audio queue ALsetqueuesize(_config, chpars[1]); // open audio device _audio = ALopenport("SIDPLAY2 sound", "w", _config); if (_audio == NULL) { perror("AUDIO:"); _errorString = "ERROR: Could not open audio device.\n See standard error output."; ALfreeconfig(_config); return 0; } // Setup internal Config _settings.encoding = AUDIO_SIGNED_PCM; _settings.bufSize = (uint_least32_t) chpars[1]; // Update the users settings getConfig (cfg); // Allocate memory same size as buffer #ifdef HAVE_EXCEPTIONS _sampleBuffer = new(std::nothrow) int_least8_t[chpars[1]]; #else _sampleBuffer = new int_least8_t[chpars[1]]; #endif _errorString = "OK"; return (void *) _sampleBuffer; }
int sgi_audio_open(audio_desc_t ad, audio_format* ifmt, audio_format *ofmt) { ALconfig c; long cmd[8]; if (audio_fd != -1) { sgi_audio_close(ad); } if (ifmt->encoding != DEV_S16) return FALSE; if ((c = ALnewconfig()) == NULL) { fprintf(stderr, "ALnewconfig error\n"); exit(1); } switch(ifmt->channels) { case 1: ALsetchannels(c, AL_MONO); break; case 2: ALsetchannels(c, AL_STEREO); break; default: sgi_audio_close(ad); } ALsetwidth(c, AL_SAMPLE_16); ALsetqueuesize(c, QSIZE); ALsetsampfmt(c, AL_SAMPFMT_TWOSCOMP); if ((wp = ALopenport("RAT write", "w", c)) == NULL) { fprintf(stderr, "ALopenport (write) error\n"); sgi_audio_close(ad); return FALSE; } if ((rp = ALopenport("RAT read", "r", c)) == NULL) { fprintf(stderr, "ALopenport (read) error\n"); sgi_audio_close(ad); return FALSE; } cmd[0] = AL_OUTPUT_RATE; cmd[1] = ofmt->sample_rate; cmd[2] = AL_INPUT_RATE; cmd[3] = ifmt->sample_rate; cmd[4] = AL_MONITOR_CTL; cmd[5] = AL_MONITOR_OFF; /*cmd[6] = AL_INPUT_SOURCE;*/ /*cmd[7] = AL_INPUT_MIC;*/ if (ALsetparams(AL_DEFAULT_DEVICE, cmd, 6L/*was 8L*/) == -1) { fprintf(stderr, "audio_open/ALsetparams error\n"); sgi_audio_close(ad); } /* Get the file descriptor to use in select */ audio_fd = ALgetfd(rp); if (ALsetfillpoint(rp, ifmt->bytes_per_block) < 0) { debug_msg("ALsetfillpoint failed (%d samples)\n", ifmt->bytes_per_block); } bytes_per_block = ifmt->bytes_per_block; /* We probably should free the config here... */ return TRUE; }