Skip to content

Commit e1db977

Browse files
committed
Passing StorableCallback by reference where possible to reduce reference counting.
1 parent a8a0f33 commit e1db977

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

Source/DFPSR/api/soundAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace dsr {
99

1010
// See the Source/soundManagers folder for implementations of sound_streamToSpeakers for different operating systems.
11-
bool sound_streamToSpeakers_fixed(int32_t channels, int32_t sampleRate, int32_t periodSamplesPerChannel, StorableCallback<bool(SafePointer<float> fixedTarget)> soundOutput) {
11+
bool sound_streamToSpeakers_fixed(int32_t channels, int32_t sampleRate, int32_t periodSamplesPerChannel, const StorableCallback<bool(SafePointer<float> fixedTarget)> &soundOutput) {
1212
int32_t bufferSamplesPerChannel = 0;
1313
int32_t blockBytes = channels * sizeof(float);
1414
Buffer fixedBuffer;

Source/DFPSR/api/soundAPI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ namespace dsr {
2626
// Call sound_streamToSpeakers with desired channels and sampleRate from a separate thread.
2727
// Handle callbacks to soundOutput by feeding the next packed sound samples and letting it return false when done.
2828
// Close the thread and let the sound engine clean up resources.
29-
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, StorableCallback<bool(dsr::SafePointer<float> target, int32_t length)> soundOutput);
29+
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, const StorableCallback<bool(dsr::SafePointer<float> target, int32_t length)> &soundOutput);
3030

3131
// Wrapper for sound_streamToSpeakers to allow working with a fixed size period for better determinism across different hardware.
3232
// The target elements should be filled for indices 0 to (periodSamplesPerChannel * channels) - 1
3333
// This allow using SIMD vectorization with a perfectly aligned period size without wasting any padding, even if the hardware's period size is an odd number.
3434
// A fixed period can also be used for perfect timing when playing music.
3535
// Pre-condition: periodSamplesPerChannel must be a power of two.
36-
bool sound_streamToSpeakers_fixed(int32_t channels, int32_t sampleRate, int32_t periodSamplesPerChannel, StorableCallback<bool(dsr::SafePointer<float> fixedTarget)> soundOutput);
36+
bool sound_streamToSpeakers_fixed(int32_t channels, int32_t sampleRate, int32_t periodSamplesPerChannel, const StorableCallback<bool(dsr::SafePointer<float> fixedTarget)> &soundOutput);
3737

3838
// A sound buffer with packed channels of 32-bit floats.
3939
// The duration in seconds equals samplesPerChannel / sampleRate

Source/soundManagers/AlsaSound.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void terminateSound() {
3030
}
3131
}
3232

33-
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, StorableCallback<bool(SafePointer<float> data, int32_t length)> soundOutput) {
33+
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, const StorableCallback<bool(SafePointer<float> data, int32_t length)> &soundOutput) {
3434
int errorCode;
3535
if ((errorCode = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
3636
terminateSound();

Source/soundManagers/CoreAudioSound.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static void initializeSound() {
107107
playing = true;
108108
}
109109

110-
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, StorableCallback<bool(SafePointer<float> data, int32_t length)> soundOutput) {
110+
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, const StorableCallback<bool(SafePointer<float> data, int32_t length)> &soundOutput) {
111111
engineChannels = channels;
112112
engineSampleRate = sampleRate;
113113
engineCallback = soundOutput;

Source/soundManagers/NoSound.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace dsr {
55

6-
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, StorableCallback<bool(SafePointer<float>, int32_t)> soundOutput) {
6+
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, const StorableCallback<bool(SafePointer<float>, int32_t)> &soundOutput) {
77
return false;
88
}
99

Source/soundManagers/WinMMSound.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void terminateSound() {
5353
}
5454
}
5555

56-
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, StorableCallback<bool(SafePointer<float> data, int32_t length)> soundOutput) {
56+
bool sound_streamToSpeakers(int32_t channels, int32_t sampleRate, const StorableCallback<bool(SafePointer<float> data, int32_t length)> &soundOutput) {
5757
bufferEndEvent = CreateEvent(0, FALSE, FALSE, 0);
5858
if (bufferEndEvent == 0) {
5959
terminateSound();

0 commit comments

Comments
 (0)