/** * @author Edouard DUPIN * * @license like MIT (see license file) */ #ifdef __ANDROID_JAVA__ #include #include #include #include #include airtaudio::Api* airtaudio::api::Android::Create() { ATA_INFO("Create Android device ... "); return new airtaudio::api::Android(); } airtaudio::api::Android::Android() { ATA_INFO("new Android"); // On android, we set a static device ... ATA_INFO("get context"); ewol::Context& tmpContext = ewol::getContext(); ATA_INFO("done p=" << (int64_t)&tmpContext); int32_t deviceCount = tmpContext.audioGetDeviceCount(); ATA_ERROR("Get count devices : " << deviceCount); for (int32_t iii=0; iii listProperty = etk::split(property, ':'); airtaudio::DeviceInfo tmp; tmp.name = listProperty[0]; std::vector listFreq = etk::split(listProperty[2], ','); for(size_t fff=0; fff listFormat = etk::split(listProperty[4], ','); tmp.nativeFormats = 0; for(size_t fff=0; fff(_userData); myClass->callBackEvent(_data, _frameRate/2); } bool airtaudio::api::Android::probeDeviceOpen(uint32_t _device, airtaudio::api::StreamMode _mode, uint32_t _channels, uint32_t _firstChannel, uint32_t _sampleRate, airtaudio::format _format, uint32_t *_bufferSize, airtaudio::StreamOptions *_options) { ATA_INFO("Probe : device=" << _device << " channels=" << _channels << " firstChannel=" << _firstChannel << " sampleRate=" << _sampleRate); if (_mode != OUTPUT) { ATA_ERROR("Can not start a device input or duplex for Android ..."); return false; } m_stream.userFormat = _format; m_stream.nUserChannels[_mode] = _channels; ewol::Context& tmpContext = ewol::getContext(); bool ret = false; if (_format == SINT8) { ret = tmpContext.audioOpenDevice(_device, _sampleRate, _channels, 0, androidCallBackEvent, this); } else { ret = tmpContext.audioOpenDevice(_device, _sampleRate, _channels, 1, androidCallBackEvent, this); } m_stream.bufferSize = 256; m_stream.sampleRate = _sampleRate; m_stream.doByteSwap[_mode] = false; // for endienness ... // TODO : For now, we write it in hard ==> to bu update later ... m_stream.deviceFormat[_mode] = SINT16; m_stream.nDeviceChannels[_mode] = 2; m_stream.deviceInterleaved[_mode] = true; m_stream.doConvertBuffer[_mode] = false; if (m_stream.userFormat != m_stream.deviceFormat[_mode]) { m_stream.doConvertBuffer[_mode] = true; } if (m_stream.nUserChannels[_mode] < m_stream.nDeviceChannels[_mode]) { m_stream.doConvertBuffer[_mode] = true; } if ( m_stream.userInterleaved != m_stream.deviceInterleaved[_mode] && m_stream.nUserChannels[_mode] > 1) { m_stream.doConvertBuffer[_mode] = true; } if (m_stream.doConvertBuffer[_mode] == true) { // Allocate necessary internal buffers. uint64_t bufferBytes = m_stream.nUserChannels[_mode] * m_stream.bufferSize * formatBytes(m_stream.userFormat); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); if (m_stream.userBuffer[_mode] == nullptr) { ATA_ERROR("airtaudio::api::Android::probeDeviceOpen: error allocating user buffer memory."); } setConvertInfo(_mode, _firstChannel); } ATA_INFO("device format : " << m_stream.deviceFormat[_mode] << " user format : " << m_stream.userFormat); ATA_INFO("device channels : " << m_stream.nDeviceChannels[_mode] << " user channels : " << m_stream.nUserChannels[_mode]); ATA_INFO("do convert buffer : " << m_stream.doConvertBuffer[_mode]); if (ret == false) { ATA_ERROR("Can not open device."); } return ret; } #endif