DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
PitchShifter.h
1// DSPark - Professional Audio DSP Framework
2// Copyright (c) 2026 Cristian Moresi - MIT License
3
4#pragma once
5
81#include "../Core/AudioBuffer.h"
82#include "../Core/AudioSpec.h"
83#include "../Core/DenormalGuard.h"
84#include "../Core/DspMath.h"
85#include "../Core/Interpolation.h"
86#include "../Core/StateBlob.h"
87#include "detail/PhaseVocoderEngine.h"
88#include "detail/StudioVocoder.h"
89
90#include <algorithm>
91#include <atomic>
92#include <cmath>
93#include <cstddef>
94#include <cstdint>
95#include <vector>
96
97namespace dspark {
98
105template <FloatType T>
107{
108public:
109 // -- Lifecycle -------------------------------------------------------------
110
129 void prepare(const AudioSpec& spec, int fftSize = 0)
130 {
131 if (!spec.isValid()) return;
132 if (fftSize != 0 && ((fftSize & (fftSize - 1)) != 0
133 || fftSize < 256 || fftSize > (1 << 20)))
134 return;
135
136 prepared_.store(false, std::memory_order_relaxed);
137
138 numChannels_ = std::max(1, spec.numChannels);
139 // 0 selects about 43 ms for every engine (2048 at 44.1 and 48 kHz,
140 // the published rendering; 4096 at 88.2 and 96 kHz).
141 if (fftSize == 0) fftSize = defaultFrame(spec.sampleRate);
142 const int fftStudio = fftSize;
143
144 // The reader trails the write head by readOffset_; the window/OLA
145 // chain adds another fftSize - synthHop, so the measured wet latency
146 // is readOffset_ + fftSize - synthHop = 2 * fftSize (exact at unity
147 // ratio). The dry path must delay by the SAME value or partial mixes
148 // comb-filter.
149 const int synthHop = fftSize / 4;
150 readOffset_ = fftSize + synthHop;
151 latencyLegacy_ = readOffset_ + fftSize - synthHop;
152 // Studio: the resample reader runs at the pitch ratio behind the
153 // completed stream. At ratio a an input sample reaches the completed
154 // stream after half a frame, a frame of analysis, the onset
155 // lookahead and one analysis hop, and the reader needs its sinc
156 // reach beyond that; the worst case is the lowest ratio, 0.5:
157 // N/(2a) + N/2 + lookahead + taps/a = 1.5 N + lookahead + 32. A
158 // strike anchor may move an analysis frame ahead of the nominal
159 // timeline by up to a quarter frame at that ratio, which the last
160 // term covers. One fixed latency for every ratio, so the dry path
161 // and host compensation hold at any pitch.
162 studio_.prepare(spec.sampleRate, numChannels_, fftStudio, true);
163 studio_.setAnchorLeadLimit(static_cast<double>(fftStudio / 4));
164 latencyStudio_ = fftStudio + fftStudio / 2 + studio_.lookahead() + fftStudio / 4 + 64;
165 drySize_ = 1;
166 while (drySize_ < std::max(latencyLegacy_, latencyStudio_) + 1) drySize_ <<= 1;
167 dryMask_ = drySize_ - 1;
168
169 // The engine owns the analysis rings, spectral state and OLA ring;
170 // resample-back compensation stages (anti-alias taper, formant
171 // pre-warp target) are enabled because this owner resamples.
172 //
173 // The three remaining capabilities are refused, and the last two are
174 // written out rather than defaulted because a future default that
175 // flips would change what this effect sounds like. The locked
176 // analysis hop breaks the resample-back reader's Ra = Rs/ratio
177 // assumption and buys nothing here. The spectral-flux onset detector
178 // fires earlier and more often than the frame-energy test, and every
179 // firing resets phase, so adopting it smears energy ahead of a strike
180 // - audible pre-echo on percussive material - and re-renders every
181 // release already in a user's hands. A mix finished last month is not
182 // restored by a release note. How large the smear is depends on the
183 // material and on the estimator it is measured with, so no figure is
184 // quoted here; that it is audible on percussive material is the
185 // durable part, and it is why this effect keeps the detector it
186 // shipped with.
187 engine_.prepare(spec.sampleRate, numChannels_, fftSize, true, false, false, false);
188 mixMaxStep_ = static_cast<T>(1.0 / std::max(1.0, spec.sampleRate * 0.02));
189 accumMask_ = engine_.olaMask();
190
191 dryRing_.assign(static_cast<size_t>(numChannels_), {});
192 for (int ch = 0; ch < numChannels_; ++ch)
193 dryRing_[static_cast<size_t>(ch)].assign(static_cast<size_t>(drySize_), T(0));
194
195 publishEngineParams();
196 prepared_.store(true, std::memory_order_relaxed);
197 reset();
198 }
199
201 void reset() noexcept
202 {
203 if (!prepared_.load(std::memory_order_relaxed)) return;
204 studioActive_ = quality_.load(std::memory_order_relaxed) == Quality::Studio;
205 latency_.store(studioActive_ ? latencyStudio_ : latencyLegacy_,
206 std::memory_order_relaxed);
207 engine_.reset();
208 studio_.reset();
209 for (auto& r : dryRing_) std::fill(r.begin(), r.end(), T(0));
210 studioOut_ = 0;
211 {
212 // The reader starts where output 0 shows input -latency, and
213 // advances at the pitch ratio from there.
214 const double start = studio_.streamPositionOf(-static_cast<double>(latencyStudio_));
215 studioReadInt_ = static_cast<int64_t>(std::floor(start));
216 studioReadFrac_ = start - static_cast<double>(studioReadInt_);
217 }
218
219 dryPos_ = 0;
220 readPosInt_ = engine_.writeHead() - readOffset_;
221 readPosFrac_ = 0.0;
222 currentMix_ = mix_.load(std::memory_order_relaxed);
223 highReader_ = quality_.load(std::memory_order_relaxed) != Quality::Standard;
224 readerFadeLeft_ = 0; // start settled on the selected reader
225 }
226
227 // -- Parameters (thread-safe) -----------------------------------------------
228
230 enum class Quality
231 {
232 Standard,
233 High,
234 Studio
235 };
236
244 void setQuality(Quality quality) noexcept
245 {
246 quality = static_cast<Quality>(std::clamp(static_cast<int>(quality), 0,
247 static_cast<int>(Quality::Studio)));
248 quality_.store(quality, std::memory_order_relaxed);
249 }
250
252 [[nodiscard]] Quality getQuality() const noexcept
253 {
254 return quality_.load(std::memory_order_relaxed);
255 }
256
264 void setSemitones(T st) noexcept
265 {
266 if (!std::isfinite(st)) return;
267 semitones_.store(std::clamp(st, T(-12), T(12)), std::memory_order_relaxed);
268 publishEngineParams();
269 }
270
273 void setPitchRatio(T ratio) noexcept
274 {
275 if (!std::isfinite(ratio)) return;
276 ratio = std::clamp(ratio, T(0.5), T(2));
277 semitones_.store(static_cast<T>(12.0 * std::log2(static_cast<double>(ratio))),
278 std::memory_order_relaxed);
279 publishEngineParams();
280 }
281
286 void setMix(T mix) noexcept
287 {
288 if (!std::isfinite(mix)) return;
289 mix_.store(std::clamp(mix, T(0), T(1)), std::memory_order_relaxed);
290 }
291
293 void setTransientPreserve(bool enabled) noexcept
294 {
295 transientPreserve_.store(enabled, std::memory_order_relaxed);
296 publishEngineParams();
297 }
298
308 void setFormantPreserve(bool enabled) noexcept
309 {
310 formantPreserve_.store(enabled, std::memory_order_relaxed);
311 publishEngineParams();
312 }
313
315 [[nodiscard]] T getSemitones() const noexcept
316 {
317 return semitones_.load(std::memory_order_relaxed);
318 }
319
321 [[nodiscard]] T getMix() const noexcept { return mix_.load(std::memory_order_relaxed); }
322
324 [[nodiscard]] bool getTransientPreserve() const noexcept
325 {
326 return transientPreserve_.load(std::memory_order_relaxed);
327 }
328
330 [[nodiscard]] bool getFormantPreserve() const noexcept
331 {
332 return formantPreserve_.load(std::memory_order_relaxed);
333 }
334
340 [[nodiscard]] int getLatency() const noexcept
341 {
342 return prepared_.load(std::memory_order_relaxed)
343 ? latency_.load(std::memory_order_relaxed)
344 : 0;
345 }
346
348 [[nodiscard]] std::vector<uint8_t> getState() const
349 {
350 StateWriter w(stateId("PSHF"), 1);
351 w.write("semitones", static_cast<float>(semitones_.load(std::memory_order_relaxed)));
352 w.write("mix", static_cast<float>(mix_.load(std::memory_order_relaxed)));
353 w.write("transient", transientPreserve_.load(std::memory_order_relaxed));
354 w.write("formant", formantPreserve_.load(std::memory_order_relaxed));
355 w.write("quality", static_cast<int32_t>(quality_.load(std::memory_order_relaxed)));
356 return w.blob();
357 }
358
360 bool setState(const uint8_t* data, size_t size)
361 {
362 StateReader r(data, size);
363 if (!r.isValid() || r.processorId() != stateId("PSHF")) return false;
364 setSemitones(static_cast<T>(r.read("semitones", 0.0f)));
365 setMix(static_cast<T>(r.read("mix", 1.0f)));
366 setTransientPreserve(r.read("transient", true));
367 setFormantPreserve(r.read("formant", false));
368 setQuality(static_cast<Quality>(r.read("quality", 0))); // clamped inside
369 return true;
370 }
371
372 // -- Processing --------------------------------------------------------------
373
382 void processBlock(AudioBufferView<T> buffer) noexcept
383 {
384 if (!prepared_.load(std::memory_order_relaxed)) return;
385 DenormalGuard guard;
386
387 const int nCh = std::min(buffer.getNumChannels(), numChannels_);
388 const int nS = buffer.getNumSamples();
389 // Crossing between Studio and the Standard/High engine restarts the stream:
390 // the two run different latencies, so no crossfade can join them.
391 if ((quality_.load(std::memory_order_relaxed) == Quality::Studio) != studioActive_)
392 reset();
393 if (studioActive_)
394 {
395 processStudio(buffer, nCh, nS);
396 return;
397 }
398
399 const int latency = latency_.load(std::memory_order_relaxed);
400
401 // Rate-limited mix ramp (moveTowards, exact landing; settled it
402 // reduces to the constant, bit-identically). A per-block ramp landed
403 // in 0.7 ms with 32-sample blocks.
404 const T mixTarget = mix_.load(std::memory_order_relaxed);
405 const T mixStart = currentMix_;
406
407 // Reader selection: a change crossfades from the old reader to the
408 // new one over kReaderFade samples (the readers differ at HF).
409 const bool highQuality = quality_.load(std::memory_order_relaxed) == Quality::High;
410 if (highQuality != highReader_)
411 {
412 highReader_ = highQuality;
413 readerFadeLeft_ = kReaderFade;
414 }
415
416 int i = 0;
417 while (i < nS)
418 {
419 const int chunk = std::min(nS - i, engine_.samplesToNextHop());
420
421 // 1. Push input into the analysis ring and the dry-compensation ring.
422 for (int ch = 0; ch < nCh; ++ch)
423 {
424 const T* in = buffer.getChannel(ch) + i;
425 engine_.pushInput(ch, in, chunk);
426 auto& dry = dryRing_[static_cast<size_t>(ch)];
427 int dp = dryPos_;
428 for (int k = 0; k < chunk; ++k)
429 {
430 dry[static_cast<size_t>(dp)] = std::isfinite(in[k]) ? in[k] : T(0);
431 dp = (dp + 1) & dryMask_;
432 }
433 }
434
435 // 2. Produce output: fractional read of the synthesis stream + mix.
436 const double ratio = engine_.activeRatio();
437 int64_t rpEnd = readPosInt_;
438 double rfEnd = readPosFrac_;
439 for (int ch = 0; ch < nCh; ++ch)
440 {
441 T* out = buffer.getChannel(ch) + i;
442 const T* acc = engine_.olaData(ch);
443 const auto& dry = dryRing_[static_cast<size_t>(ch)];
444
445 int64_t rp = readPosInt_;
446 double rf = readPosFrac_;
447 int dp = dryPos_;
448 int fadeLeft = readerFadeLeft_;
449
450 for (int k = 0; k < chunk; ++k)
451 {
452 T wet = readWet(highReader_, acc, rp, rf);
453 if (fadeLeft > 0)
454 {
455 const T w = static_cast<T>(fadeLeft) * (T(1) / T(kReaderFade));
456 const T old = readWet(!highReader_, acc, rp, rf);
457 wet += (old - wet) * w;
458 --fadeLeft;
459 }
460 const int dryIdx = (dp - latency) & dryMask_;
461 const T drySample = dry[static_cast<size_t>(dryIdx)];
462 const T mixVal = moveTowards(mixStart, mixTarget, mixMaxStep_ * static_cast<T>(i + k + 1));
463 // Two-product blend: exact at both ends (mix 1 emits the
464 // wet stream bit-exactly, mix 0 the delayed dry).
465 out[k] = drySample * (T(1) - mixVal) + wet * mixVal;
466
467 rf += ratio;
468 const auto adv = static_cast<int64_t>(rf);
469 rp += adv;
470 rf -= static_cast<double>(adv);
471 dp = (dp + 1) & dryMask_;
472 }
473 if (ch == 0) { rpEnd = rp; rfEnd = rf; } // recurrence result
474 }
475
476 // Commit shared positions once per chunk, using the SAME
477 // per-sample recurrence result the output loops computed (taken
478 // from channel 0, whose loop ran it already): a single
479 // frac + ratio * chunk product rounds differently for different
480 // chunk sizes, and chunk boundaries follow the host block size,
481 // so committing the product form made the output depend on how
482 // the host chopped the stream (~1 ulp per flip, but a bit-exact
483 // contract is a bit-exact contract).
484 {
485 if (nCh == 0) // channel-less call: advance the stream anyway
486 {
487 for (int k = 0; k < chunk; ++k)
488 {
489 rfEnd += ratio;
490 const auto adv = static_cast<int64_t>(rfEnd);
491 rpEnd += adv;
492 rfEnd -= static_cast<double>(adv);
493 }
494 }
495 readPosInt_ = rpEnd;
496 readPosFrac_ = rfEnd;
497 dryPos_ = (dryPos_ + chunk) & dryMask_;
498 readerFadeLeft_ = std::max(0, readerFadeLeft_ - chunk);
499 }
500
501 // 3. Advance the engine (runs an STFT hop at the analysis boundary).
502 engine_.commitInput(chunk, nCh);
503
504 i += chunk;
505 }
506
507 currentMix_ = moveTowards(mixStart, mixTarget, mixMaxStep_ * static_cast<T>(nS));
508 }
509
510private:
521 void processStudio(AudioBufferView<T> buffer, int nCh, int nS) noexcept
522 {
523 const int latency = latency_.load(std::memory_order_relaxed);
524 const T mixTarget = mix_.load(std::memory_order_relaxed);
525 const T mixStart = currentMix_;
526 const int64_t mask = studio_.olaMask();
527 int i = 0;
528 while (i < nS)
529 {
530 const int need = studio_.samplesToNextHop();
531 if (need == 0)
532 {
533 studio_.commitInput(0, nCh);
534 continue;
535 }
536 const int chunk = std::min(nS - i, need);
537 for (int ch = 0; ch < nCh; ++ch)
538 {
539 const T* in = buffer.getChannel(ch) + i;
540 studio_.pushInput(ch, in, chunk);
541 auto& dry = dryRing_[static_cast<size_t>(ch)];
542 int dp = dryPos_;
543 for (int k = 0; k < chunk; ++k)
544 {
545 dry[static_cast<size_t>(dp)] = std::isfinite(in[k]) ? in[k] : T(0);
546 dp = (dp + 1) & dryMask_;
547 }
548 }
549
550 const double ratio = studio_.activeRatio();
551 int64_t rpEnd = studioReadInt_;
552 double rfEnd = studioReadFrac_;
553 for (int ch = 0; ch < nCh; ++ch)
554 {
555 T* out = buffer.getChannel(ch) + i;
556 const T* acc = studio_.olaData(ch);
557 const auto& dry = dryRing_[static_cast<size_t>(ch)];
558 int64_t rp = studioReadInt_;
559 double rf = studioReadFrac_;
560 int dp = dryPos_;
561 for (int k = 0; k < chunk; ++k)
562 {
563 const T wet = reader_.readRing(acc, mask, rp, rf);
564 const T drySample = dry[static_cast<size_t>((dp - latency) & dryMask_)];
565 const T mixVal = moveTowards(mixStart, mixTarget, mixMaxStep_ * static_cast<T>(i + k + 1));
566 out[k] = drySample * (T(1) - mixVal) + wet * mixVal;
567 rf += ratio;
568 const auto adv = static_cast<int64_t>(rf);
569 rp += adv;
570 rf -= static_cast<double>(adv);
571 dp = (dp + 1) & dryMask_;
572 }
573 if (ch == 0) { rpEnd = rp; rfEnd = rf; }
574 }
575 if (nCh == 0)
576 {
577 for (int k = 0; k < chunk; ++k)
578 {
579 rfEnd += ratio;
580 const auto adv = static_cast<int64_t>(rfEnd);
581 rpEnd += adv;
582 rfEnd -= static_cast<double>(adv);
583 }
584 }
585 studioReadInt_ = rpEnd;
586 studioReadFrac_ = rfEnd;
587 dryPos_ = (dryPos_ + chunk) & dryMask_;
588 studioOut_ += chunk;
589
590 // Steer the frame after the next one: where the reader will stand
591 // on the input timeline when it reaches that frame's centre.
592 const double c = studio_.nextStreamCentre() + static_cast<double>(studio_.synthHop());
593 const double here = static_cast<double>(studioReadInt_) + studioReadFrac_;
594 studio_.steerTimeline(static_cast<double>(studioOut_) + (c - here) / ratio
595 - static_cast<double>(latencyStudio_));
596 studio_.commitInput(chunk, nCh);
597 i += chunk;
598 }
599 currentMix_ = moveTowards(mixStart, mixTarget, mixMaxStep_ * static_cast<T>(nS));
600 }
601
603 [[nodiscard]] static int defaultFrame(double sampleRate) noexcept
604 {
605 int n = 256;
606 while (n < (1 << 16) && static_cast<double>(n) * 1.5 < 0.0427 * sampleRate) n <<= 1;
607 return n;
608 }
609
611 [[nodiscard]] T readWet(bool high, const T* acc, int64_t ip, double frac) const noexcept
612 {
613 return high ? reader_.readRing(acc, accumMask_, ip, frac)
614 : readCatmullRom(acc, ip, frac);
615 }
616
618 [[nodiscard]] T readCatmullRom(const T* acc, int64_t ip, double frac) const noexcept
619 {
620 const int64_t m = accumMask_;
621 const T x0 = acc[static_cast<size_t>((ip - 1) & m)];
622 const T x1 = acc[static_cast<size_t>(ip & m)];
623 const T x2 = acc[static_cast<size_t>((ip + 1) & m)];
624 const T x3 = acc[static_cast<size_t>((ip + 2) & m)];
625 const T f = static_cast<T>(frac);
626 return x1 + T(0.5) * f * (x2 - x0
627 + f * (T(2) * x0 - T(5) * x1 + T(4) * x2 - x3
628 + f * (T(3) * (x1 - x2) + x3 - x0)));
629 }
630
633 void publishEngineParams() noexcept
634 {
635 typename detail::PhaseVocoderEngine<T>::Params p;
636 p.targetSemitones = static_cast<double>(semitones_.load(std::memory_order_relaxed));
637 p.transientPreserve = transientPreserve_.load(std::memory_order_relaxed);
638 p.formantPreserve = formantPreserve_.load(std::memory_order_relaxed);
639 engine_.publishParams(p);
640 typename detail::StudioVocoder<T>::Params q;
641 q.targetSemitones = p.targetSemitones;
642 q.transientPreserve = p.transientPreserve;
643 q.formantPreserve = p.formantPreserve;
644 studio_.publishParams(q);
645 }
646
647 // -- Members -----------------------------------------------------------------
648 int numChannels_ = 0;
649 std::atomic<bool> prepared_ { false };
650
651 int readOffset_ = 2560;
652 std::atomic<int> latency_ { 4096 };
654 int drySize_ = 8192;
655 int dryMask_ = 8191;
656 int64_t accumMask_ = 8191;
657
658 detail::PhaseVocoderEngine<T> engine_;
659 detail::StudioVocoder<T> studio_;
660 bool studioActive_ = true;
661 int latencyStudio_ = 5184;
662 int latencyLegacy_ = 4096;
663 int64_t studioReadInt_ = 0;
664 double studioReadFrac_ = 0.0;
665 int64_t studioOut_ = 0;
666 SincInterpolator<T> reader_;
669 static constexpr int kReaderFade = 64;
670 bool highReader_ = false;
671 int readerFadeLeft_ = 0;
672
673 std::vector<std::vector<T>> dryRing_;
674
675 int dryPos_ = 0;
676 int64_t readPosInt_ = 0;
677 double readPosFrac_ = 0.0;
678 T currentMix_ = T(1);
679 T mixMaxStep_ = T(1.0 / 960.0);
680
681 std::atomic<T> semitones_ { T(0) };
682 std::atomic<T> mix_ { T(1) };
683 std::atomic<bool> transientPreserve_ { true };
684 std::atomic<bool> formantPreserve_ { false };
685 std::atomic<Quality> quality_ { Quality::Studio };
686};
687
688} // namespace dspark
Non-owning view over audio channel data.
Definition AudioBuffer.h:53
RAII scope guard to disable denormalised (subnormal) floating-point numbers.
Real-time phase-vocoder pitch shifter (+-12 semitones, stereo-linked).
void setQuality(Quality quality) noexcept
Selects the engine and reader. Thread-safe. Standard and High crossfade into each other over 64 sampl...
bool getFormantPreserve() const noexcept
Quality getQuality() const noexcept
void setTransientPreserve(bool enabled) noexcept
Enables phase reset on detected transients (default on).
T getSemitones() const noexcept
bool setState(const uint8_t *data, size_t size)
Restores parameters from a blob (tolerant; rejects foreign ids).
std::vector< uint8_t > getState() const
Serializes the parameter state (setup/UI threads; allocates).
void reset() noexcept
Clears all signal state (keeps parameters). Safe on the audio thread.
void setMix(T mix) noexcept
Dry/wet mix, [0, 1]. The dry path is latency-compensated and the mix is ramped over at least 20 ms (t...
void setSemitones(T st) noexcept
Sets the pitch shift in semitones, clamped to +-12.
void setFormantPreserve(bool enabled) noexcept
Keeps formants (vocal timbre) in place while pitch moves.
void prepare(const AudioSpec &spec, int fftSize=0)
Allocates all rings and spectral state.
int getLatency() const noexcept
Reports total latency in samples. Studio: 1.5 * fftSize + lookahead + fftSize / 4 + 64 (5184,...
void setPitchRatio(T ratio) noexcept
Sets the pitch shift as a frequency ratio, clamped to [0.5, 2]. Non-finite values are ignored.
void processBlock(AudioBufferView< T > buffer) noexcept
Processes audio in-place.
bool getTransientPreserve() const noexcept
Quality
Engine and resample-back reader (see the file overview).
@ High
Standard/High engine, 32-tap windowed-sinc reader: transparent HF.
@ Studio
Studio engine (default): see the file overview.
@ Standard
Standard/High engine, 4-point Catmull-Rom reader: the earlier default rendering.
T getMix() const noexcept
Tolerant reader: missing keys yield defaults, unknown keys are skipped.
Definition StateBlob.h:171
float read(const char *key, float defaultValue) const
Reads a float, or defaultValue when the key is absent.
Definition StateBlob.h:214
bool isValid() const noexcept
Definition StateBlob.h:209
uint32_t processorId() const noexcept
Definition StateBlob.h:210
Serializes key/value parameters into a versioned blob.
Definition StateBlob.h:53
std::vector< uint8_t > blob() const
Finalizes and returns the blob.
Definition StateBlob.h:112
void write(const char *key, float value)
Writes a float parameter.
Definition StateBlob.h:71
Main namespace for the DSPark framework.
T moveTowards(T from, T to, T maxDelta) noexcept
Moves a value toward a target by at most a given distance.
Definition DspMath.h:137
constexpr uint32_t stateId(const char(&tag)[5]) noexcept
Builds a FOURCC processor id, e.g. dspark::stateId("COMP").
Definition StateBlob.h:672
Describes the audio environment for a DSP processor.
Definition AudioSpec.h:37
constexpr bool isValid() const noexcept
Checks if the specification contains valid, processable parameters.
Definition AudioSpec.h:71
int numChannels
Number of audio channels (e.g., 1 = mono, 2 = stereo).
Definition AudioSpec.h:58
double sampleRate
Sample rate in Hz.
Definition AudioSpec.h:45