bool COSSAudioSource::Init(void) { bool rc = InitAudio(true); if (!rc) { return false; } if (!InitDevice()) { return false; } rc = SetAudioSrc( PCMAUDIOFRAME, m_channelsConfigured, m_pConfig->GetIntegerValue(CONFIG_AUDIO_SAMPLE_RATE)); if (!rc) { return false; } // for live capture we can match the source to the destination m_audioSrcSamplesPerFrame = m_audioDstSamplesPerFrame; m_pcmFrameSize = m_audioSrcSamplesPerFrame * m_audioSrcChannels * sizeof(u_int16_t); if (m_audioOssMaxBufferSize > 0) { size_t array_size; m_audioOssMaxBufferFrames = m_audioOssMaxBufferSize / m_pcmFrameSize; if (m_audioOssMaxBufferFrames == 0) { m_audioOssMaxBufferFrames = 1; } array_size = m_audioOssMaxBufferFrames * sizeof(*m_timestampOverflowArray); m_timestampOverflowArray = (Timestamp *)Malloc(array_size); memset(m_timestampOverflowArray, 0, array_size); } m_pcmFrameBuffer = (u_int8_t*)malloc(m_pcmFrameSize); if (!m_pcmFrameBuffer) { goto init_failure; } // maximum number of passes in ProcessAudio, approx 1 sec. m_maxPasses = m_audioSrcSampleRate / m_audioSrcSamplesPerFrame; return true; init_failure: debug_message("audio initialization failed"); free(m_pcmFrameBuffer); m_pcmFrameBuffer = NULL; close(m_audioDevice); m_audioDevice = -1; return false; }
bool CALSAAudioSource::Init(void) { bool rc = InitAudio(true); if (!rc) { return false; } if (!InitDevice()) { return false; } //#error we will have to remove this below - the sample rate will be rc = SetAudioSrc( PCMAUDIOFRAME, m_channelsConfigured, m_pConfig->GetIntegerValue(CONFIG_AUDIO_SAMPLE_RATE)); if (!rc) { return false; } // for live capture we can match the source to the destination // m_audioSrcSamplesPerFrame = m_audioDstSamplesPerFrame; // gets set m_pcmFrameSize = m_audioSrcSamplesPerFrame * m_audioSrcChannels * sizeof(u_int16_t); if (m_audioMaxBufferSize > 0) { size_t array_size; m_audioMaxBufferFrames = m_audioMaxBufferSize / m_pcmFrameSize; if (m_audioMaxBufferFrames == 0) { m_audioMaxBufferFrames = 1; } array_size = m_audioMaxBufferFrames * sizeof(*m_timestampOverflowArray); m_timestampOverflowArray = (Timestamp *)Malloc(array_size); memset(m_timestampOverflowArray, 0, array_size); } // maximum number of passes in ProcessAudio, approx 1 sec. m_maxPasses = m_audioSrcSampleRate / m_audioSrcSamplesPerFrame; return true; #if 0 init_failure: debug_message("audio initialization failed"); snd_pcm_close(m_pcmHandle); m_pcmHandle = -1; return false; #endif }