| 928 | } |
| 929 | |
| 930 | SLresult openSLstartRecording(opensl_stream2 *p) { |
| 931 | SLresult result; |
| 932 | if (p->recorderRecord != NULL) { |
| 933 | // in case already recording, stop recording and clear buffer queue |
| 934 | result = (*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_STOPPED); |
| 935 | if (result != SL_RESULT_SUCCESS) { |
| 936 | SMILE_ERR(3, "openSL: failed to set recorder state to stopped."); |
| 937 | return result; |
| 938 | } |
| 939 | result = (*p->recorderBufferQueue)->Clear(p->recorderBufferQueue); |
| 940 | if (result != SL_RESULT_SUCCESS) { |
| 941 | SMILE_ERR(3, "openSL: failed to clear recorder buffer queue."); |
| 942 | return result; |
| 943 | } |
| 944 | // the current one will be the first to be enqueued, before we wait for the first buffer to be filled |
| 945 | // in audioIn. This is why we don't enqueue it here (NUM_RECORDING_BUFFERS - 1 in above loop). |
| 946 | // p->currentDeviceInputBuffer = NUM_RECORDING_BUFFERS - 1; |
| 947 | |
| 948 | // start recording |
| 949 | result = (*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING); |
| 950 | if (result != SL_RESULT_SUCCESS) { |
| 951 | SMILE_ERR(3, "openSL: failed to set recorder state to started."); |
| 952 | return result; |
| 953 | } |
| 954 | SMILE_MSG(3, "openSL: recording: set state = recording, success"); |
| 955 | // for streaming recording, we enqueue at least 2 empty buffers to start things off) |
| 956 | p->currentDeviceInputBuffer = 0; |
| 957 | p->internalBufferCurW = 0; |
| 958 | p->internalBufferCurR = 0; |
| 959 | p->hasNewInternalData_ = 0; |
| 960 | p->hasNewInputData_ = 0; |
| 961 | for (int i = 0; i < NUM_RECORDING_BUFFERS /* - 1*/; ++i) { |
| 962 | result = (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, |
| 963 | p->deviceInputBuffers[i], p->inBufSamples * sizeof(int16_t)); |
| 964 | // the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT, |
| 965 | // which for this code example would indicate a programming error |
| 966 | if (result != SL_RESULT_SUCCESS) { |
| 967 | SMILE_ERR(3, "openSL: failed to enqueue audio buffer # %i for streaming recording.", i); |
| 968 | return result; |
| 969 | } |
| 970 | } |
| 971 | } else { |
| 972 | SMILE_ERR(1, "openSL: no recorder present, cannot start recording"); |
| 973 | return -1; |
| 974 | } |
| 975 | return SL_RESULT_SUCCESS; |
| 976 | } |
| 977 | |
| 978 | // close the OpenSL IO and destroy the audio engine |
| 979 | void openSLDestroyEngine(opensl_stream2 *p) { |
no test coverage detected