3535// / //
3636// / // The engine processes output samples synchronously. Therefore, `Process` should typically be
3737// / // called from an audio thread process callback in real-time audio applications.
38- // / constexpr int kChannelCount = 2;
39- // / constexpr int kFrameCount = 512;
38+ // / constexpr int32_t kChannelCount = 2;
39+ // / constexpr int32_t kFrameCount = 512;
4040// / float output_samples[kChannelCount * kFrameCount];
4141// / engine.Process(output_samples, kChannelCount, kFrameCount, timestamp);
4242// / @endcode
221221#endif // __cplusplus
222222
223223// / Default engine configuration.
224- #define BARELY_ENGINE_CONFIG_DEFAULT (sample_rate ) \
225- { \
226- .sample_ ##rate = sample_rate, \
227- .max_instrument_count = 100 , \
228- .max_performer_count = 100 , \
229- .max_task_count = 5000 , \
230- .max_command_count = 8192 , \
231- .max_frame_count = 2048 , \
232- .max_slice_count = 1000 , \
233- .max_voice_count = 200 , \
224+ #define BARELY_ENGINE_CONFIG_DEFAULT (sample_rate ) \
225+ { \
226+ .sample_ ##rate = sample_rate, .max_instrument_count = 100 , .max_performer_count = 100 , \
227+ .max_task_count = 5000 , .max_command_count = 8192 , .max_frame_count = 2048 , \
228+ .max_slice_count = 1000 , .max_voice_count = 200 , \
234229 }
235230
236231// / Engine control types.
@@ -349,21 +344,6 @@ typedef struct BarelyEngineConfig {
349344 int32_t max_voice_count;
350345} BarelyEngineConfig;
351346
352- // / Slice of sample data.
353- typedef struct BarelySlice {
354- // / Array of mono samples.
355- const float * samples;
356-
357- // / Number of mono samples.
358- int32_t sample_count;
359-
360- // / Sampling rate in hertz.
361- int32_t sample_rate;
362-
363- // / Root note pitch.
364- float root_pitch;
365- } BarelySlice;
366-
367347// / Musical quantization.
368348typedef struct BarelyQuantization {
369349 // / Subdivision of a beat.
@@ -388,6 +368,21 @@ typedef struct BarelyScale {
388368 int32_t mode;
389369} BarelyScale;
390370
371+ // / Slice of sample data.
372+ typedef struct BarelySlice {
373+ // / Array of mono samples.
374+ const float * samples;
375+
376+ // / Number of mono samples.
377+ int32_t sample_count;
378+
379+ // / Sampling rate in hertz.
380+ int32_t sample_rate;
381+
382+ // / Root note pitch.
383+ float root_pitch;
384+ } BarelySlice;
385+
391386#ifdef __cplusplus
392387extern " C" {
393388#endif // __cplusplus
@@ -730,7 +725,7 @@ struct EngineConfig : public BarelyEngineConfig {
730725 // / Constructs a new `EngineConfig`.
731726 // /
732727 // / @param sample_rate Sampling rate in hertz.
733- constexpr explicit EngineConfig (int sample_rate)
728+ constexpr explicit EngineConfig (int32_t sample_rate)
734729 : EngineConfig(BARELY_ENGINE_CONFIG_DEFAULT (sample_rate)) {}
735730
736731 // / Constructs a new `EngineConfig` from a raw type.
@@ -751,28 +746,6 @@ struct EngineConfig : public BarelyEngineConfig {
751746 }
752747};
753748
754- // / Slice of sample data.
755- struct Slice : public BarelySlice {
756- // / Default constructor.
757- Slice () noexcept = default ;
758-
759- // / Constructs a new `Slice`.
760- // /
761- // / @param samples Span of mono samples.
762- // / @param sample_rate Sampling rate in hertz.
763- // / @param root_pitch Root pitch.
764- constexpr Slice (std::span<const float > samples, int sample_rate, float root_pitch) noexcept
765- : Slice({samples.data (), static_cast <int32_t >(samples.size ()), sample_rate, root_pitch}) {
766- assert (sample_rate >= 0 );
767- }
768-
769- // / Constructs a new `Slice` from a raw type.
770- // /
771- // / @param slice Raw slice.
772- // NOLINTNEXTLINE(google-explicit-constructor)
773- constexpr Slice (BarelySlice slice) noexcept : BarelySlice{slice} {}
774- };
775-
776749// / Musical quantization.
777750struct Quantization : public BarelyQuantization {
778751 public:
@@ -784,8 +757,8 @@ struct Quantization : public BarelyQuantization {
784757 // / @param subdivision Subdivision of a beat.
785758 // / @param amount Amount.
786759 // NOLINTNEXTLINE(google-explicit-constructor)
787- constexpr Quantization (int subdivision, float amount = 1 .0f ) noexcept
788- : Quantization(BarelyQuantization{static_cast < int32_t >( subdivision) , amount}) {}
760+ constexpr Quantization (int32_t subdivision, float amount = 1 .0f ) noexcept
761+ : Quantization(BarelyQuantization{subdivision, amount}) {}
789762
790763 // / Constructs a new `Quantization` from a raw type.
791764 // /
@@ -822,9 +795,10 @@ struct Scale : public BarelyScale {
822795 // / @param root_pitch Root pitch.
823796 // / @param mode Mode.
824797 // NOLINTNEXTLINE(google-explicit-constructor)
825- constexpr Scale (std::span<const float > pitches, float root_pitch = 0 .0f , int mode = 0 ) noexcept
826- : Scale(BarelyScale{pitches.data (), static_cast <int32_t >(pitches.size ()), root_pitch,
827- static_cast <int32_t >(mode)}) {}
798+ constexpr Scale (std::span<const float > pitches, float root_pitch = 0 .0f ,
799+ int32_t mode = 0 ) noexcept
800+ : Scale(BarelyScale{pitches.data (), static_cast <int32_t >(pitches.size ()), root_pitch, mode}) {
801+ }
828802
829803 // / Constructs a new `Scale` from a raw type.
830804 // /
@@ -840,19 +814,34 @@ struct Scale : public BarelyScale {
840814 // /
841815 // / @param degree Degree.
842816 // / @return Pitch.
843- [[nodiscard]] float GetPitch (int degree) const noexcept {
817+ [[nodiscard]] float GetPitch (int32_t degree) const noexcept {
844818 float pitch = 0 .0f ;
845819 [[maybe_unused]] const bool success = BarelyScale_GetPitch (this , degree, &pitch);
846820 assert (success);
847821 return pitch;
848822 }
823+ };
824+
825+ // / Slice of sample data.
826+ struct Slice : public BarelySlice {
827+ // / Default constructor.
828+ Slice () noexcept = default ;
849829
850- // / Returns the number of pitches in the scale .
830+ // / Constructs a new `Slice` .
851831 // /
852- // / @return Number of pitches.
853- [[nodiscard]] constexpr int GetPitchCount () const noexcept {
854- return static_cast <int >(pitch_count);
832+ // / @param samples Span of mono samples.
833+ // / @param sample_rate Sampling rate in hertz.
834+ // / @param root_pitch Root pitch.
835+ constexpr Slice (std::span<const float > samples, int32_t sample_rate, float root_pitch) noexcept
836+ : Slice({samples.data (), static_cast <int32_t >(samples.size ()), sample_rate, root_pitch}) {
837+ assert (sample_rate >= 0 );
855838 }
839+
840+ // / Constructs a new `Slice` from a raw type.
841+ // /
842+ // / @param slice Raw slice.
843+ // NOLINTNEXTLINE(google-explicit-constructor)
844+ constexpr Slice (BarelySlice slice) noexcept : BarelySlice{slice} {}
856845};
857846
858847// / Task callback function.
@@ -1022,9 +1011,8 @@ class Task {
10221011 // / Sets the priority.
10231012 // /
10241013 // / @param priority Priority.
1025- void SetPriority (int priority) noexcept {
1026- [[maybe_unused]] const bool success =
1027- BarelyTask_SetPriority (engine_, task_id_, static_cast <int32_t >(priority));
1014+ void SetPriority (int32_t priority) noexcept {
1015+ [[maybe_unused]] const bool success = BarelyTask_SetPriority (engine_, task_id_, priority);
10281016 assert (success);
10291017 }
10301018
@@ -1096,7 +1084,8 @@ class Performer {
10961084 // / @param priority Task priority.
10971085 // / @param callback Task callback.
10981086 // / @return Task.
1099- Task CreateTask (double position, double duration, int priority, TaskCallback callback) noexcept {
1087+ Task CreateTask (double position, double duration, int32_t priority,
1088+ TaskCallback callback) noexcept {
11001089 uint32_t task_id = 0 ;
11011090 [[maybe_unused]] bool success = BarelyPerformer_CreateTask (
11021091 engine_, performer_id_, position, duration, priority, nullptr , nullptr , &task_id);
@@ -1220,7 +1209,7 @@ class Engine {
12201209 // / Constructs a new `Engine`.
12211210 // /
12221211 // / @param sample_rate Sampling rate in hertz.
1223- explicit Engine (int sample_rate) noexcept : Engine(EngineConfig(sample_rate)) {}
1212+ explicit Engine (int32_t sample_rate) noexcept : Engine(EngineConfig(sample_rate)) {}
12241213
12251214 // / Constructs a new `Engine`.
12261215 // /
@@ -1329,18 +1318,16 @@ class Engine {
13291318 // / @param output_channel_count Number of output channels.
13301319 // / @param output_frame_count Number of output frames.
13311320 // / @param timestamp Timestamp in seconds.
1332- void Process (float * output_samples, int output_channel_count, int output_frame_count,
1321+ void Process (float * output_samples, int32_t output_channel_count, int32_t output_frame_count,
13331322 double timestamp) noexcept {
1334- [[maybe_unused]] const bool success =
1335- BarelyEngine_Process (engine_, output_samples, static_cast <int32_t >(output_channel_count),
1336- static_cast <int32_t >(output_frame_count), timestamp);
1323+ [[maybe_unused]] const bool success = BarelyEngine_Process (
1324+ engine_, output_samples, output_channel_count, output_frame_count, timestamp);
13371325 assert (success);
13381326 }
13391327
13401328 // / Resets the random number generator seed.
1341- void ResetSeed (int seed) noexcept {
1342- [[maybe_unused]] const bool success =
1343- BarelyEngine_ResetSeed (engine_, static_cast <int32_t >(seed));
1329+ void ResetSeed (int32_t seed) noexcept {
1330+ [[maybe_unused]] const bool success = BarelyEngine_ResetSeed (engine_, seed);
13441331 assert (success);
13451332 }
13461333
0 commit comments