INT32 DAUDIO_GetDirectAudioDeviceDescription(INT32 mixerIndex, DirectAudioDeviceDescription* description) { ALSA_AudioDeviceDescription adesc; adesc.index = (int) mixerIndex; adesc.strLen = DAUDIO_STRING_LENGTH; adesc.maxSimultaneousLines = (int*) (&(description->maxSimulLines)); adesc.deviceID = &(description->deviceID); adesc.name = description->name; adesc.vendor = description->vendor; adesc.description = description->description; adesc.version = description->version; return getAudioDeviceDescriptionByIndex(&adesc); }
INT32 DAUDIO_GetDirectAudioDeviceDescription(INT32 mixerIndex, DirectAudioDeviceDescription* description) { AudioDeviceDescription desc; if (getAudioDeviceDescriptionByIndex(mixerIndex, &desc, TRUE)) { description->maxSimulLines = desc.maxSimulLines; strncpy(description->name, desc.name, DAUDIO_STRING_LENGTH-1); description->name[DAUDIO_STRING_LENGTH-1] = 0; strncpy(description->vendor, desc.vendor, DAUDIO_STRING_LENGTH-1); description->vendor[DAUDIO_STRING_LENGTH-1] = 0; strncpy(description->version, desc.version, DAUDIO_STRING_LENGTH-1); description->version[DAUDIO_STRING_LENGTH-1] = 0; /*strncpy(description->description, desc.description, DAUDIO_STRING_LENGTH-1);*/ strncpy(description->description, "Solaris Mixer", DAUDIO_STRING_LENGTH-1); description->description[DAUDIO_STRING_LENGTH-1] = 0; return TRUE; } return FALSE; }
void DAUDIO_GetFormats(INT32 mixerIndex, INT32 deviceID, int isSource, void* creator) { int fd = -1; AudioDeviceDescription desc; am_sample_rates_t *sr; /* hardcoded bits and channels */ int bits[] = {8, 16}; int bitsCount = 2; int channels[] = {1, 2}; int channelsCount = 2; /* for querying sample rates */ int err; int ch, b, s; TRACE2("DAUDIO_GetFormats, mixer %d, isSource=%d\n", mixerIndex, isSource); if (getAudioDeviceDescriptionByIndex(mixerIndex, &desc, FALSE)) { fd = open(desc.pathctl, O_RDONLY); } if (fd < 0) { ERROR1("Couldn't open audio device ctl for device %d!\n", mixerIndex); return; } /* get sample rates */ sr = (am_sample_rates_t*) malloc(AUDIO_MIXER_SAMP_RATES_STRUCT_SIZE(MAX_SAMPLE_RATES)); if (sr == NULL) { ERROR1("DAUDIO_GetFormats: out of memory for mixer %d\n", (int) mixerIndex); close(fd); return; } sr->num_samp_rates = MAX_SAMPLE_RATES; sr->type = isSource?AUDIO_PLAY:AUDIO_RECORD; sr->samp_rates[0] = -2; err = ioctl(fd, AUDIO_MIXER_GET_SAMPLE_RATES, sr); if (err < 0) { ERROR1(" DAUDIO_GetFormats: AUDIO_MIXER_GET_SAMPLE_RATES failed for mixer %d!\n", (int)mixerIndex); ERROR2(" -> num_sample_rates=%d sample_rates[0] = %d\n", (int) sr->num_samp_rates, (int) sr->samp_rates[0]); /* Some Solaris 8 drivers fail for get sample rates! * Do as if we support all sample rates */ sr->flags = MIXER_SR_LIMITS; } if ((sr->flags & MIXER_SR_LIMITS) || (sr->num_samp_rates > MAX_SAMPLE_RATES)) { #ifdef USE_TRACE if ((sr->flags & MIXER_SR_LIMITS)) { TRACE1(" DAUDIO_GetFormats: floating sample rate allowed by mixer %d\n", (int)mixerIndex); } if (sr->num_samp_rates > MAX_SAMPLE_RATES) { TRACE2(" DAUDIO_GetFormats: more than %d formats. Use -1 for sample rates mixer %d\n", MAX_SAMPLE_RATES, (int)mixerIndex); } #endif /* * Fake it to have only one sample rate: -1 */ sr->num_samp_rates = 1; sr->samp_rates[0] = -1; } close(fd); for (ch = 0; ch < channelsCount; ch++) { for (b = 0; b < bitsCount; b++) { for (s = 0; s < sr->num_samp_rates; s++) { DAUDIO_AddAudioFormat(creator, bits[b], /* significant bits */ 0, /* frameSize: let it be calculated */ channels[ch], (float) ((int) sr->samp_rates[s]), DAUDIO_PCM, /* encoding - let's only do PCM */ (bits[b] > 8)?TRUE:TRUE, /* isSigned */ #if (X_WORD_ORDER == TRUE) FALSE /* little endian */ #else (bits[b] > 8)?TRUE:FALSE /* big endian */ #endif ); } } } free(sr); }
void* DAUDIO_Open(INT32 mixerIndex, INT32 deviceID, int isSource, int encoding, float sampleRate, int sampleSizeInBits, int frameSize, int channels, int isSigned, int isBigEndian, int bufferSizeInBytes) { int err = 0; int openMode; AudioDeviceDescription desc; SolPcmInfo* info; TRACE0("> DAUDIO_Open\n"); if (encoding != DAUDIO_PCM) { ERROR1(" DAUDIO_Open: invalid encoding %d\n", (int) encoding); return NULL; } info = (SolPcmInfo*) malloc(sizeof(SolPcmInfo)); if (!info) { ERROR0("Out of memory\n"); return NULL; } memset(info, 0, sizeof(SolPcmInfo)); info->frameSize = frameSize; info->fd = -1; if (isSource) { openMode = O_WRONLY; } else { openMode = O_RDONLY; } #ifndef __linux__ /* blackdown does not use NONBLOCK */ openMode |= O_NONBLOCK; #endif if (getAudioDeviceDescriptionByIndex(mixerIndex, &desc, FALSE)) { info->fd = open(desc.path, openMode); } if (info->fd < 0) { ERROR1("Couldn't open audio device for mixer %d!\n", mixerIndex); free(info); return NULL; } /* set to multiple open */ if (ioctl(info->fd, AUDIO_MIXER_MULTIPLE_OPEN, NULL) >= 0) { TRACE1("DAUDIO_Open: %s set to multiple open\n", desc.path); } else { ERROR1("DAUDIO_Open: ioctl AUDIO_MIXER_MULTIPLE_OPEN failed on %s!\n", desc.path); } AUDIO_INITINFO(&(info->info)); /* need AUDIO_GETINFO ioctl to get this to work on solaris x86 */ err = ioctl(info->fd, AUDIO_GETINFO, &(info->info)); /* not valid to call AUDIO_SETINFO ioctl with all the fields from AUDIO_GETINFO. */ AUDIO_INITINFO(&(info->info)); if (isSource) { info->info.play.sample_rate = sampleRate; info->info.play.precision = sampleSizeInBits; info->info.play.channels = channels; info->info.play.encoding = AUDIO_ENCODING_LINEAR; info->info.play.buffer_size = bufferSizeInBytes; info->info.play.pause = 1; } else { info->info.record.sample_rate = sampleRate; info->info.record.precision = sampleSizeInBits; info->info.record.channels = channels; info->info.record.encoding = AUDIO_ENCODING_LINEAR; info->info.record.buffer_size = bufferSizeInBytes; info->info.record.pause = 1; } err = ioctl(info->fd, AUDIO_SETINFO, &(info->info)); if (err < 0) { ERROR0("DAUDIO_Open: could not set info!\n"); DAUDIO_Close((void*) info, isSource); return NULL; } DAUDIO_Flush((void*) info, isSource); err = ioctl(info->fd, AUDIO_GETINFO, &(info->info)); if (err >= 0) { if (isSource) { info->bufferSizeInBytes = info->info.play.buffer_size; } else { info->bufferSizeInBytes = info->info.record.buffer_size; } TRACE2("DAUDIO: buffersize in bytes: requested=%d, got %d\n", (int) bufferSizeInBytes, (int) info->bufferSizeInBytes); } else { ERROR0("DAUDIO_Open: cannot get info!\n"); DAUDIO_Close((void*) info, isSource); return NULL; } TRACE0("< DAUDIO_Open: Opened device successfully.\n"); return (void*) info; }