Skip to content

Commit a988ee5

Browse files
committed
Port demo to mac. Add a test for the resampler
1 parent ccd35b9 commit a988ee5

File tree

5 files changed

+74
-15
lines changed

5 files changed

+74
-15
lines changed

CMakeLists.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ if (APPLE)
1717
"-framework Accelerate"
1818
"-framework Cocoa"
1919
"-framework CoreAudio"
20-
# "-framework Metal"
21-
# "-framework MetalKit"
22-
# "-framework QuartzCore"
20+
"-framework Metal"
21+
"-framework MetalKit"
22+
"-framework QuartzCore"
2323
)
2424
endif()
2525

@@ -35,12 +35,14 @@ install(TARGETS LabSoundDemo RUNTIME DESTINATION bin)
3535

3636
add_executable(LabSoundInteractive
3737
LabSoundInteractive.cpp ImGuiGridSlider.cpp ImGuiGridSlider.h imgui-app/imgui_app.cpp)
38-
target_link_libraries(LabSoundInteractive Lab::Sound)
38+
target_link_libraries(LabSoundInteractive Lab::Sound ${PLATFORM_LIBS})
3939
target_include_directories(LabSoundInteractive PRIVATE "${LABSOUNDDEMO_ROOT}")
4040
if(WIN32)
4141
target_compile_definitions(LabSoundInteractive PRIVATE SOKOL_D3D11 SOKOL_WIN32_FORCE_MAIN)
4242
elseif(APPLE)
4343
target_compile_definitions(LabSoundInteractive PRIVATE SOKOL_METAL)
44+
set_source_files_properties(imgui-app/imgui_app.cpp PROPERTIES
45+
COMPILE_FLAGS "-x objective-c++")
4446
elseif(UNIX)
4547
target_compile_definitions(LabSoundInteractive PRIVATE SOKOL_GLCORE33)
4648
endif()

ImGuiGridSlider.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bool SliderScalar2D(char const* pLabel, float* fValueX, float* fValueY, const fl
9595
ImVec2 vPos = ImGui::GetCursorScreenPos();
9696
ImRect oRect(vPos + vHeightOffset, vPos + vSize + vHeightOffset);
9797

98-
ImGui::Text(pLabel);
98+
ImGui::TextUnformatted(pLabel);
9999

100100
ImGui::PushID(iID);
101101

@@ -310,7 +310,7 @@ bool SliderScalar3D(char const* pLabel, float* pValueX, float* pValueY, float* p
310310
ImVec2 vPos = GetCursorScreenPos();
311311
ImRect oRect(vPos + vHeightOffset, vPos + vSize + vHeightOffset);
312312

313-
ImGui::Text(pLabel);
313+
ImGui::TextUnformatted(pLabel);
314314

315315
ImGui::PushID(iID);
316316

LabSoundDemo.config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef LABSOUNDEMOCONFIG_H
1+
#ifndef LABSOUNDDEMOCONFIG_H
22
#define LABSOUNDDEMOCONFIG_H
33

44
const char* asset_base = "@CMAKE_INSTALL_PREFIX@/share/LabSound/";

LabSoundDemo.cpp

+65-7
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ inline std::pair<AudioStreamConfig, AudioStreamConfig> GetDefaultAudioDeviceConf
193193
return {inputConfig, outputConfig};
194194
}
195195

196-
/////////////////////
196+
//-----------------//
197197
// ex_simple //
198-
/////////////////////
198+
//-----------------//
199199

200-
// ex_simple demonstrate the use of an audio clip loaded from disk and a basic sine oscillator.
200+
// demonstrate the use of an audio clip loaded from disk and a basic sine oscillator.
201201
struct ex_simple : public labsound_example
202202
{
203203
virtual void play(int argc, char** argv) override final
@@ -245,11 +245,67 @@ struct ex_simple : public labsound_example
245245

246246

247247

248+
//------------------------//
249+
// ex_test_resample //
250+
//------------------------//
251+
252+
// demonstrate the use of an audio clip loaded from disk and a basic sine oscillator.
253+
struct ex_test_resample : public labsound_example
254+
{
255+
virtual void play(int argc, char** argv) override final
256+
{
257+
std::unique_ptr<lab::AudioContext> context;
258+
const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration();
259+
context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first);
260+
lab::AudioContext& ac = *context.get();
261+
262+
auto musicClip = MakeBusFromSampleFile("samples/sin440-22050.wav", argc, argv);
263+
if (!musicClip)
264+
return;
265+
266+
std::shared_ptr<OscillatorNode> oscillator;
267+
std::shared_ptr<SampledAudioNode> musicClipNode;
268+
std::shared_ptr<GainNode> gain;
269+
270+
oscillator = std::make_shared<OscillatorNode>(ac);
271+
gain = std::make_shared<GainNode>(ac);
272+
gain->gain()->setValue(0.5f);
273+
274+
musicClipNode = std::make_shared<SampledAudioNode>(ac);
275+
{
276+
ContextRenderLock r(context.get(), "ex_test_resample");
277+
musicClipNode->setBus(r, musicClip);
278+
}
279+
context->connect(context->device(), musicClipNode, 0, 0);
280+
281+
// osc -> gain -> destination
282+
context->connect(gain, oscillator, 0, 0);
283+
context->connect(context->device(), gain, 0, 0);
284+
285+
oscillator->frequency()->setValue(440.f);
286+
oscillator->setType(OscillatorType::SINE);
287+
288+
_nodes.push_back(oscillator);
289+
_nodes.push_back(musicClipNode);
290+
_nodes.push_back(gain);
291+
292+
oscillator->start(0.0f);
293+
Wait(std::chrono::seconds(1));
294+
oscillator->stop(0.0f);
295+
Wait(std::chrono::milliseconds(500));
296+
musicClipNode->schedule(0.0);
297+
Wait(std::chrono::milliseconds(500));
298+
musicClipNode->detune()->setValue(1000.f);
299+
Wait(std::chrono::milliseconds(500));
300+
}
301+
};
302+
303+
248304

249305

250-
/////////////////////
306+
//-----------------//
251307
// ex_osc_pop //
252-
/////////////////////
308+
//-----------------//
253309

254310
// ex_osc_pop to test oscillator start/stop popping (it shouldn't pop).
255311
struct ex_osc_pop : public labsound_example
@@ -1666,6 +1722,7 @@ class Example
16661722
int main(int argc, char *argv[]) try
16671723
{
16681724
Example<ex_simple> simple;
1725+
Example<ex_test_resample> resample;
16691726
Example<ex_osc_pop> osc_pop;
16701727
Example<ex_playback_events> playback_events;
16711728
Example<ex_offline_rendering> offline_rendering;
@@ -1685,10 +1742,11 @@ int main(int argc, char *argv[]) try
16851742
Example<ex_granulation_node> granulation;
16861743
Example<ex_poly_blep> poly_blep;
16871744

1688-
// We can optionally play for a number of iterations as a way of testing lifetime & memory issues.
1745+
// We can optionally play for a number of iterations as a
1746+
// way of testing lifetime & memory issues.
16891747
for (int i = 0; i < iterations; ++i)
16901748
{
1691-
granulation.ex->play(argc, argv);
1749+
resample.ex->play(argc, argv);
16921750
}
16931751

16941752
return EXIT_SUCCESS;

imgui-app/imgui_app.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -26215,7 +26215,6 @@ Index of this file:
2621526215

2621626216
*/
2621726217

26218-
#pragma once
2621926218
#ifndef IMGUI_DISABLE
2622026219

2622126220
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)