// **** Audio card support // Aquire and enabled audio card // return 0 if ok, -1 if failed int HAE_AquireAudioCard(void *context, unsigned long sampleRate, unsigned long channels, unsigned long bits) { int flag; long bufferSize; short int bufferTime; flag = 0; g_activeDoubleBuffer = FALSE; g_shutDownDoubleBuffer = TRUE; g_audioFramesToGenerate = HAE_GetMaxSamplePerSlice(); // get number of frames per sample rate slice g_synthFramesPerBlock = HAE_FRAMES_PER_BLOCK; bufferTime = (HAE_GetSliceTimeInMicroseconds() / 1000) * g_synthFramesPerBlock; if (bits == 8) { bufferSize = (sizeof(char) * g_audioFramesToGenerate); } else { bufferSize = (sizeof(short int) * g_audioFramesToGenerate); } bufferSize *= channels; g_audioByteBufferSize = bufferSize; // try and configure card to match our audio output g_waveDevice = R0CARD_AcquireSoundCard(sampleRate, channels, bits, bufferTime, &g_audioByteBufferSize, PV_AudioHardwareCallback); if (g_waveDevice) { g_shutDownDoubleBuffer = FALSE; g_activeDoubleBuffer = TRUE; // must enable process, before thread begins flag = 0; // ok } else { flag = -1; // failed; HAE_ReleaseAudioCard(context); } return flag; }
// **** Audio card support // Aquire and enabled audio card // return 0 if ok, -1 if failed int HAE_AquireAudioCard(void *context, UINT32 sampleRate, UINT32 channels, UINT32 bits) { int flag; short int count; INT32 error; audio_info_t sunAudioHeader; char* pAudioDev = HAE_GetAudioDevPlay(g_currentDeviceID, 0); flag = 0; g_activeDoubleBuffer = FALSE; g_shutDownDoubleBuffer = TRUE; g_audioFramesToGenerate = HAE_GetMaxSamplePerSlice(); // get number of frames per sample rate slice // we're going to build this many buffers at a time g_synthFramesPerBlock = HAE_SOLARIS_FRAMES_PER_BLOCK; g_audioPeriodSleepTime = HAE_SOLARIS_SOUND_PERIOD; g_bitSize = bits; g_channels = channels; if (bits == 8) { g_audioByteBufferSize = ((INT32)sizeof(char) * g_audioFramesToGenerate); } else { g_audioByteBufferSize = ((INT32)sizeof(short int) * g_audioFramesToGenerate); } g_audioByteBufferSize *= channels; flag = 1; // allocate buffer blocks g_audioBufferBlock = HAE_Allocate(g_audioByteBufferSize * HAE_SOLARIS_FRAMES_PER_BLOCK); if (g_audioBufferBlock) { // try to open wave device // $$kk: 12.17.97: need O_NONBLOCK flag to be compatible with windows #ifdef __linux__ g_waveDevice = open(pAudioDev,O_WRONLY); #else g_waveDevice = open(pAudioDev,O_WRONLY|O_NONBLOCK); #endif if (g_waveDevice > 0) { /* set to multiple open */ if (ioctl(g_waveDevice, AUDIO_MIXER_MULTIPLE_OPEN, NULL) >= 0) { TRACE1("HAE_AquireAudioCard: %s set to multiple open\n", pAudioDev); } else { ERROR1("HAE_AquireAudioCard: ioctl AUDIO_MIXER_MULTIPLE_OPEN failed on %s!\n", pAudioDev); } AUDIO_INITINFO(&sunAudioHeader); // $$kk: 12.17.97: need AUDIO_GETINFO ioctl to get this to work on solaris x86 // add next 1 line error = ioctl(g_waveDevice, AUDIO_GETINFO, &sunAudioHeader); // $$kk: 03.16.98: not valid to call AUDIO_SETINFO ioctl with all the fields from AUDIO_GETINFO, // so let's try init'ing again.... AUDIO_INITINFO(&sunAudioHeader); // Set rendering format of the sun device. sunAudioHeader.play.sample_rate = sampleRate; sunAudioHeader.play.precision = bits; sunAudioHeader.play.channels = channels; sunAudioHeader.play.encoding = AUDIO_ENCODING_LINEAR; error = ioctl(g_waveDevice, AUDIO_SETINFO, &sunAudioHeader); if (error == 0) { g_shutDownDoubleBuffer = FALSE; g_activeDoubleBuffer = TRUE; // must enable process, before thread begins /* Spin threads for device service and possibly * stream service. */ // create thread to manage and render audio frames error = HAE_CreateFrameThread(context, PV_AudioWaveOutFrameThread); if (error == 0) { // ok flag = 0; #ifdef USE_RAWDATA_CHECK { char* fname = "javasound_debug_output.pcm"; debugrawfile = HAE_FileOpenForWrite(fname); } #endif } else { flag = 1; g_activeDoubleBuffer = FALSE; } } } } if (flag) { // something failed HAE_ReleaseAudioCard(context); } return flag; }