| 181 | } |
| 182 | |
| 183 | void MxSetChannelRawSrc(MixerChannel *mc, const std::shared_ptr<std::vector<std::byte>> &mem, uint rate, bool is16bit) |
| 184 | { |
| 185 | mc->memory = mem; |
| 186 | mc->frac_pos = 0; |
| 187 | mc->pos = 0; |
| 188 | |
| 189 | mc->frac_speed = (rate << 16U) / _play_rate; |
| 190 | |
| 191 | size_t size = mc->memory->size(); |
| 192 | if (is16bit) size /= 2; |
| 193 | /* Less 1 to allow for padding sample for the resampler. */ |
| 194 | size -= 1; |
| 195 | |
| 196 | /* adjust the magnitude to prevent overflow */ |
| 197 | while (size >= _max_size) { |
| 198 | size >>= 1; |
| 199 | rate = (rate >> 1) + 1; |
| 200 | } |
| 201 | |
| 202 | /* Scale number of samples by play rate. */ |
| 203 | mc->samples_left = (uint)size * _play_rate / rate; |
| 204 | mc->is16bit = is16bit; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Set volume and pan parameters for a sound. |