| 21 | } |
| 22 | |
| 23 | void JsonUiAudioInternal::updateInternal(const fl::json &value) FL_NOEXCEPT { |
| 24 | if (value.contains("audioData")) { |
| 25 | fl::json audioDataArray = value["audioData"]; |
| 26 | |
| 27 | if (audioDataArray.is_array()) { |
| 28 | for (size_t i = 0; i < audioDataArray.size(); ++i) { |
| 29 | fl::json bufferJson = audioDataArray[i]; |
| 30 | if (bufferJson.is_object()) { |
| 31 | fl::vector<i16> samples; |
| 32 | u32 timestamp = bufferJson["timestamp"] | 0; |
| 33 | |
| 34 | if (bufferJson.contains("samples") && |
| 35 | bufferJson["samples"].is_array()) { |
| 36 | fl::json samplesArray = bufferJson["samples"]; |
| 37 | for (size_t j = 0; j < samplesArray.size(); ++j) { |
| 38 | samples.push_back(samplesArray[j] | 0); |
| 39 | } |
| 40 | } |
| 41 | // Create AudioBuffer equivalent and process |
| 42 | // This part of the loop is now inside the if |
| 43 | // (bufferJson.is_object()) and directly uses 'samples' and |
| 44 | // 'timestamp' |
| 45 | const fl::vector<i16> ¤t_samples = samples; |
| 46 | u32 current_timestamp = timestamp; |
| 47 | |
| 48 | if (!current_samples.empty()) { |
| 49 | audio::SampleImplPtr sample = |
| 50 | fl::make_shared<audio::SampleImpl>(); |
| 51 | sample->assign(current_samples.begin(), |
| 52 | current_samples.end(), |
| 53 | current_timestamp); |
| 54 | mAudioSampleImpls.push_back(sample); |
| 55 | |
| 56 | while (mAudioSampleImpls.size() > 10) { |
| 57 | mAudioSampleImpls.erase(mAudioSampleImpls.begin()); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } // namespace fl |