Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running the example results in no wave file playback #144

Closed
tom-23 opened this issue Sep 25, 2020 · 18 comments · Fixed by #147
Closed

Running the example results in no wave file playback #144

tom-23 opened this issue Sep 25, 2020 · 18 comments · Fixed by #147
Assignees
Labels

Comments

@tom-23
Copy link

tom-23 commented Sep 25, 2020

Hi there,

I've just cloned the master again and tried running the example (e_simple) but noticed how the sine wave is playing but the audio file is not.

I've also updated the library in a project that I am developing and have come across the exact same issue.

Here is the log produced by running the example project:

Toms-MacBook-Pro:bin tombutcher$ ./LabSoundExample 
11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/extended/LabSound.cpp:33: MakeAudioDeviceList()
11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:42: using rtaudio api macos_coreaudio
11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/extended/LabSound.cpp:39: GetDefaultOutputAudioDeviceIndex()
11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/extended/LabSound.cpp:45: GetDefaultInputAudioDeviceIndex()
11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/extended/LabSound.cpp:51: MakeRealtimeAudioContext()
11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:124: using output device idx: 1
11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:125: using output device name: Apple Inc.: Built-in Output
11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:130: using input device idx: -1
11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/core/AudioHardwareDeviceNode.cpp:47: MakePlatformSpecificDevice() 
	* Sample Rate:     48000.000000 
	* Input Channels:  0 
	* Output Channels: 2   
11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/core/AudioContext.cpp:287: Begin UpdateGraphThread

I've ensured that the samples folder copied from the assets directory is present:

Toms-MacBook-Pro:bin tombutcher$ ls
LabSoundExample	samples
Toms-MacBook-Pro:bin tombutcher$ 

The previous commit I used which worked was: https://github.com/LabSound/LabSound/commit/c0d778fef727432ad2280863e818280e6669c92e

Sorry for annoying you guys by constantly submitting issues. This is a really good library.

@meshula meshula self-assigned this Sep 29, 2020
@meshula meshula added the bug label Sep 29, 2020
@meshula
Copy link
Member

meshula commented Sep 29, 2020

Thanks for the report and kind words. I think it's time to merge dev to master, although it might have to wait for the weekend.

@tom-23
Copy link
Author

tom-23 commented Jan 15, 2021

I've just gone ahead and moved over to the latest commit and the issue still persists. I've tried loading mp3 files and uncompressed wav files and I am not getting any output. I have connected an analyser node and can see no data being passed through. I'm guessing its something to do with the SampledAudioNode not scheduling playback or something? Also, I am able to access the raw sample data through AudioBus so it seems the file it getting loaded but not getting played.

I am running macOS 11 Big Sur but I have tried it on machines running macOS Catalina but it issue persists.

This occurs with both audio miniaudio and rtaudio.

@meshula
Copy link
Member

meshula commented Jan 16, 2021

@tom-23 Okay, I've merged the development branch, to a new main branch called "main".

I just tried on a MacMini a clean build as follows:

cd /var/tmp
git clone git@github.com:LabSound/LabSound.git --recursive
cd LabSound
mkdir build;cd build
cmake .. -DCMAKE_INSTALL_PREFIX=./install
make -j8 install
cd install/share/LabSound
../../bin/LabSoundExample

and got this result while a 440Hz tone played:

23:02:33 TRACE /var/tmp/LabSound/src/extended/LabSound.cpp:33: MakeAudioDeviceList()
23:02:33 INFO  /var/tmp/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:42: using rtaudio api macos_coreaudio
23:02:33 TRACE /var/tmp/LabSound/src/extended/LabSound.cpp:39: GetDefaultOutputAudioDeviceIndex()
23:02:33 TRACE /var/tmp/LabSound/src/extended/LabSound.cpp:45: GetDefaultInputAudioDeviceIndex()

RtApiCore::getDefaultInputDevice: No default device found!

23:02:33 TRACE /var/tmp/LabSound/src/extended/LabSound.cpp:51: MakeRealtimeAudioContext()
23:02:33 INFO  /var/tmp/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:124: using output device idx: 0
23:02:33 INFO  /var/tmp/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:125: using output device name: Apple Inc.: External Headphones
23:02:33 INFO  /var/tmp/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:130: using input device idx: -1
23:02:33 INFO  /var/tmp/LabSound/src/core/AudioHardwareDeviceNode.cpp:47: MakePlatformSpecificDevice()
	* Sample Rate:     48000.000000
	* Input Channels:  0
	* Output Channels: 2
23:02:33 TRACE /var/tmp/LabSound/src/core/AudioContext.cpp:287: Begin UpdateGraphThread
23:02:39 TRACE /var/tmp/LabSound/src/core/AudioContext.cpp:101: Begin AudioContext::~AudioContext()
23:02:39 TRACE /var/tmp/LabSound/src/core/AudioContext.cpp:461: End UpdateGraphThread
23:02:39 TRACE /var/tmp/LabSound/src/core/AudioContext.cpp:162: AudioContext::uninitialize()
23:02:39 INFO  /var/tmp/LabSound/src/core/AudioContext.cpp:124: Finish AudioContext::~AudioContext()

Could you try that and let me know what happens?

@tom-23
Copy link
Author

tom-23 commented Jan 16, 2021

Following the steps exactly produces this result (Using a MacBook Pro):

23:14:48 TRACE /var/tmp/LabSound/src/extended/LabSound.cpp:33: MakeAudioDeviceList()
23:14:49 INFO  /var/tmp/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:42: using rtaudio api macos_coreaudio
23:14:49 TRACE /var/tmp/LabSound/src/extended/LabSound.cpp:39: GetDefaultOutputAudioDeviceIndex()
23:14:49 TRACE /var/tmp/LabSound/src/extended/LabSound.cpp:45: GetDefaultInputAudioDeviceIndex()
23:14:49 TRACE /var/tmp/LabSound/src/extended/LabSound.cpp:51: MakeRealtimeAudioContext()
23:14:49 INFO  /var/tmp/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:124: using output device idx: 1
23:14:49 INFO  /var/tmp/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:125: using output device name: Apple Inc.: Built-in Output
23:14:49 INFO  /var/tmp/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:130: using input device idx: -1
23:14:49 INFO  /var/tmp/LabSound/src/core/AudioHardwareDeviceNode.cpp:47: MakePlatformSpecificDevice() 
	* Sample Rate:     48000.000000 
	* Input Channels:  0 
	* Output Channels: 2   
23:14:49 TRACE /var/tmp/LabSound/src/core/AudioContext.cpp:287: Begin UpdateGraphThread
23:14:55 TRACE /var/tmp/LabSound/src/core/AudioContext.cpp:101: Begin AudioContext::~AudioContext()
23:14:55 TRACE /var/tmp/LabSound/src/core/AudioContext.cpp:461: End UpdateGraphThread
23:14:55 TRACE /var/tmp/LabSound/src/core/AudioContext.cpp:162: AudioContext::uninitialize()
23:14:55 INFO  /var/tmp/LabSound/src/core/AudioContext.cpp:124: Finish AudioContext::~AudioContext()

It seems RtAudio has successfully identified the correct audio device without any issues. The 440Hz sine wave played but the stereo-music-clip.wav file didn't.

Is the wave file not playing on your end?

@tom-23
Copy link
Author

tom-23 commented Jan 18, 2021

@meshula after messing around with the example project, I've found out that the schedule() method isn't working but start() is.

@meshula
Copy link
Member

meshula commented Jan 18, 2021

Oh geez, I rewrote how schedule/start work for the 1.0 release. Thanks for mentioning that, I clearly messed something up. version 1.0.1, here we come...

@meshula
Copy link
Member

meshula commented Jan 18, 2021

@tom-23, the bug is cross platform. I pushed a fix, but have not tagged a release, when you have a moment to try it again...

@meshula meshula changed the title On macOS, running the example results in no wave file playback Running the example results in no wave file playback Jan 18, 2021
@tom-23
Copy link
Author

tom-23 commented Jan 28, 2021

@meshula Sorry for the late reply but I can confirm the sampled audio node is working again! However, in the process of testing the latest commit from the master branch, I noted when resetting a SampledAudioNode then trying to play it again results in no playback. Not sure if this is a bug or not but maybe I have to reconnect the node? Also, performance wise, having a lot (tested with 27), playback seems really choppy. Probably not a priority but I can probably work around this (and also, the library probably isn't designed to handle that many SANs too). Great work thougt!

@meshula
Copy link
Member

meshula commented Jan 29, 2021

I'm glad you have sound now :) In terms of code, what do you mean by reset a SAN, and try to play it again?
Are you playing the same SAN 27 times, like in a supersaw effect where it is one sample played a lot, or are you playing 27 different SANs?

@tom-23
Copy link
Author

tom-23 commented Jan 29, 2021

SAN as in SampledAudioNode. Got fed up with typing SampledAudioNode😅. I'm calling the reset() function to reset the node so I can play it again. #92 is basically what I'm trying to do but it results in no audio.

@meshula
Copy link
Member

meshula commented Jan 29, 2021

Got it! Thanks. I'll try to reproduce the problem.

@tom-23
Copy link
Author

tom-23 commented Jan 29, 2021

Thanks!

@meshula
Copy link
Member

meshula commented Jan 31, 2021

@tom-23 37c6945 Fixes the bug with reset(). If you pull latest, it should be fine now.

I'm going to look at your "27 times" issue next.

@tom-23
Copy link
Author

tom-23 commented Feb 21, 2021

@meshula After some investigation, I've discovered its a macOS related issue. When I try to play 27 sampled audio nodes on windows, I'm only seeing 18% to 20% CPU utilisation when profiling in visual studio but on macOS, I see well over 100%. Maybe is to do with the whole audio file being loaded into RAM? I'm not too sure but I hope this helps narrows down the issue.

@meshula
Copy link
Member

meshula commented Feb 22, 2021

That helps, thanks.

@meshula
Copy link
Member

meshula commented Feb 24, 2021

@tom-23 Does your code look something like the below? Based on some experimenting, I do wonder if you are running a Debug build, rather than Release. It might be instructive to try running the sample below in your own application, to see how your numbers compare to mine.

2020 MacMini

Debug

32 instances - 55%
64 - 80, sound broke up, audio callback starving

Release

32 instances - 15
64 instances - 25, sound is fine
128 - 52%
256 - 60%, sound breaking up, audio callback starving

I'm starting to profile now, as I was expecting lower numbers nonetheless.

        std::unique_ptr<lab::AudioContext> context;
        const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration();
        context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first);
        lab::AudioContext& ac = *context.get();

        auto musicClip = MakeBusFromSampleFile("samples/stereo-music-clip.wav", argc, argv);
        if (!musicClip)
            return;

        const int count = 64;
        std::array<std::shared_ptr<SampledAudioNode>, count> musicClipNode;
        std::array<std::shared_ptr<GainNode>, count> gain;

        for (int i = 0; i < count; ++i)
        {
            gain[i] = std::make_shared<GainNode>(ac);
            gain[i]->gain()->setValue(1.f/static_cast<float>(count));
            _nodes.push_back(gain[i]);

            musicClipNode[i] = std::make_shared<SampledAudioNode>(ac);
            {
                ContextRenderLock r(context.get(), "ex_simple32");
                musicClipNode[i]->setBus(r, musicClip);
            }
            musicClipNode[i]->schedule(0.0);

            // osc -> gain -> destination
            context->connect(gain[i], musicClipNode[i], 0, 0);
            context->connect(context->device(), gain[i], 0, 0);

            _nodes.push_back(musicClipNode[i]);
        }

@meshula
Copy link
Member

meshula commented Apr 10, 2021

performance issues are addressed by this PR #147

@meshula meshula linked a pull request Apr 12, 2021 that will close this issue
@meshula
Copy link
Member

meshula commented Apr 14, 2021

@tom-23 The new code is pushed on main, if you have a chance to re-test, please let me know if the performance problems persist on your mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants