| 43 | } |
| 44 | |
| 45 | void ScopeVisualProcessor::process() { |
| 46 | if (!isOutputEmpty()) { |
| 47 | return; |
| 48 | } |
| 49 | AudioThreadInputPtr audioInputData; |
| 50 | |
| 51 | if (input->try_pop(audioInputData)) { |
| 52 | |
| 53 | if (!audioInputData) { |
| 54 | return; |
| 55 | } |
| 56 | size_t i, iMax = audioInputData->data.size(); |
| 57 | if (!iMax) { |
| 58 | //discard audioInputData. |
| 59 | audioInputData = nullptr; |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | ScopeRenderDataPtr renderData = nullptr; |
| 64 | |
| 65 | if (scopeEnabled) { |
| 66 | iMax = audioInputData->data.size(); |
| 67 | if (iMax > maxScopeSamples) { |
| 68 | iMax = maxScopeSamples; |
| 69 | } |
| 70 | |
| 71 | renderData = outputBuffers.getBuffer(); |
| 72 | renderData->channels = audioInputData->channels; |
| 73 | renderData->inputRate = audioInputData->inputRate; |
| 74 | renderData->sampleRate = audioInputData->sampleRate; |
| 75 | |
| 76 | if (renderData->waveform_points.size() != iMax * 2) { |
| 77 | renderData->waveform_points.resize(iMax * 2); |
| 78 | } |
| 79 | |
| 80 | float peak = 1.0f; |
| 81 | |
| 82 | for (i = 0; i < iMax; i++) { |
| 83 | float p = fabs(audioInputData->data[i]); |
| 84 | if (p > peak) { |
| 85 | peak = p; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if (audioInputData->type == 1) { |
| 90 | iMax = audioInputData->data.size(); |
| 91 | if (renderData->waveform_points.size() != iMax * 2) { |
| 92 | renderData->waveform_points.resize(iMax * 2); |
| 93 | } |
| 94 | for (i = 0; i < iMax; i++) { |
| 95 | renderData->waveform_points[i * 2] = (((double) (i % (iMax/2)) / (double) iMax) * 2.0 - 0.5) * 2.0; |
| 96 | renderData->waveform_points[i * 2 + 1] = audioInputData->data[i] / peak; |
| 97 | } |
| 98 | renderData->mode = ScopePanel::SCOPE_MODE_2Y; |
| 99 | } else if (audioInputData->type == 2) { |
| 100 | iMax = audioInputData->data.size(); |
| 101 | if (renderData->waveform_points.size() != iMax) { |
| 102 | renderData->waveform_points.resize(iMax); |