/** * read a single port - function required for wiringPi interface * @param pin - port relative to pinBase * @return true - port is active, false - port is inactive */ bool Max7312::readPort(int pin){ bool portIsInput = isPortInput(pin); if(isLowerPort(pin)){ if (portIsInput){ wiringPiI2CWrite(fd, INPUT_PORT_1); } else { wiringPiI2CWrite(fd, OUTPUT_PORT_1); } } else { if (portIsInput){ wiringPiI2CWrite(fd, INPUT_PORT_2); } else { wiringPiI2CWrite(fd, OUTPUT_PORT_2); } } int port_data=wiringPiI2CRead(fd); if(isLowerPort(pin)){ _port1_data = port_data; } else { _port2_data = port_data; } return isPortActive(pin); }
UtlBoolean MprBridge::doProcessFrame(MpBufPtr inBufs[], MpBufPtr outBufs[], int inBufsSize, int outBufsSize, UtlBoolean isEnabled, int samplesPerFrame, int samplesPerSecond) { int i; int inIdx; int outIdx; int n; int scale; int inputs; int N = samplesPerFrame; MpBufPtr in; MpBufPtr out; Sample* input; Sample* output; Sample* outstart; if (0 == outBufsSize) { Zprintf("MprBridge::doPF: outBufsSize = %d! (inBufsSize=%d)\n", outBufsSize, inBufsSize, 0,0,0,0); return FALSE; } if (inBufsSize != outBufsSize) { Zprintf("MprBridge::doPF: outBufsSize(%d) != inBufsSize(%d)\n", outBufsSize, inBufsSize, 0,0,0,0); return FALSE; } if (0 == inBufsSize) return FALSE; // no input buffers, not allowed for (i=0; i < outBufsSize; i++) { outBufs[i] = NULL; } if (!isEnabled) { // Disabled. Mix all remote inputs onto local speaker, and copy // our local microphone to all remote outputs. // First, count how many contributing inputs inputs = 0; for (inIdx=1; inIdx < inBufsSize; inIdx++) { if (isPortActive(inIdx)) { if((MpBuf_getSpeech(inBufs[inIdx]) != MP_SPEECH_SILENT) && (MpBuf_getSpeech(inBufs[inIdx]) != MP_SPEECH_COMFORT_NOISE)) inputs++; } } if (inputs > 0) { // Compute a scale factor to renormalize (approximately) scale = 0; while (inputs > 1) { scale++; inputs = inputs >> 1; } out = MpBuf_getBuf(MpMisc.UcbPool, N, 0, MP_FMT_T12); if (NULL == out) { Zprintf( "MprBridge::doPF(line #%d): MpBuf_getBuf() returned NULL!\n", __LINE__, 0,0,0,0,0); return FALSE; } outstart = MpBuf_getSamples(out); memset((char *) outstart, 0, N * sizeof(Sample)); for (inIdx=1; inIdx < inBufsSize; inIdx++) { if (isPortActive(inIdx)) { output = outstart; //Mix only non-silent audio if((MpBuf_getSpeech(inBufs[inIdx]) != MP_SPEECH_COMFORT_NOISE) && (MpBuf_getSpeech(inBufs[inIdx]) != MP_SPEECH_SILENT) ) { input = MpBuf_getSamples(inBufs[inIdx]); n = min(MpBuf_getNumSamples(inBufs[inIdx]), samplesPerFrame); for (i=0; i<n; i++) *output++ += (*input++) >> scale; } } }