Sound/Windows

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Sound/Windows

Post by Nyyrazzilyss » Sun Nov 27, 2016 2:34 am

I've submitted a bug report for this:

https://bugs.launchpad.net/mudlet/+bug/1645064

I've just started layering up sounds using windows / 3.0 epsilon

If 5 unique sounds are attempted to be played simultaneously, mudlet locks up and crashes. The 2.1 wiki had mentioned that the limit on sounds was 4 at once - Being that's many versions ago, and more importantly a much older version of Qt, i'm not sure what the actual limit now -should- be. However, crashing isn't the right way to go about hitting the limit.

I don't know if this is windows specific or not.

(edit)

I glanced at the code, and it appears that their are variables defined in it mpMusicBox (1-4) for sounds: It looks like the sound limit is defined in mudlet, not Qt.

It appears that the 4th+ sound to be played would call (in mudlet.cpp)
Code: [show] | [select all] lua
else
    {
        mpMusicBox4->stop();
        mpMusicBox4->setMedia( QUrl::fromLocalFile( s ) );
        mpMusicBox4->play();
    }
I'm not familiar enough with c++, however, hopefully that points in the right direction

(edit: followup)

I've just done a search for limits to simultaneous wav playback in windows: I found very little information, other then someone asking circa 2011 about best way to go about 40 sounds at once - I'd guess most modern operating systems don't actually have a limit?

Would it be reasonable to change mpMusicBox (1-4) to a QList, then just add more entries as needed? As an aside from that, looking at the QSound class, it would appear to give a lot of options with playing sounds (in particular assigning individual volumes to a sound as it's played) - That could be useful to add to the lua function.

dicene
Posts: 47
Joined: Thu Sep 25, 2014 7:36 am

Re: Sound/Windows

Post by dicene » Sun Nov 27, 2016 10:02 pm

QT's sound stuff isn't too complicated, so adding in volume controls would be pretty easy. Biggest thing would just be figuring out how you want everything to work. My impression so far has been that it would be best to keep the existing playSoundFile mechanics available for those that want simple sound functionality, but it might be a good idea to expose some slightly more detailed controls for those that have more complicated needs.

Something along the lines of having 10 more soundboxes available and being able to control them(play a sound, stop playing, change volume) separately. If people can come to a consensus on how it should work, I could add it in the next time I end up working on Mudlet code(which I've been away from for the week but should be back to this next week probably).

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss » Mon Nov 28, 2016 12:07 am

Thanks, I could definitely see it taking a bit of thought.

While i'm not experienced with writing C++, I did write for a long time in C, so reading C++ isn't to much work for me. Lack of familiarity with the Qt libraries properly doesn't help either. I did however just look at QSound / QSoundEffect - Individual volume controls look like it would be more the QSoundEffect class.

It was more then a few months ago sound worked again in Windows, and I really put off taking advantage of it a bit longer then I should have. Layering up sounds was really easy though / and had a noticable effect with how well my script was working.

It really would be a question about what other people think also, but I do know eventually i'm going to have to look at layering in background music in addition to sound effects: I would think that would end up entailing 2 unique lua functions, one controlling sound (music), the other effects. Controlling volume/ or looping status individually would be great (not to mention getting rid of the fixed size limit at 4 samples)

Actually - This would probably be a good one for me to take the time with solving myself: It looks to be very minimal code change, mostly just me learning how to use QList/QSound/QSoundEffect (not to mention github) properly

User avatar
SlySven
Posts: 912
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Sound/Windows

Post by SlySven » Mon Nov 28, 2016 5:00 am

The sound playback is quite basic and currently supports four playback streams simultaneously. On the Linux platform one can see an output stream is created only for the duration of the playback (as far as my PulseAudio sub-system seems to report) which do have system volume controls - but they go away again once play-back has concluded - so it is a bit tricky to control the playback-level with transitory level controls!

Unfortunately the current code has no way for the user to allocate media files to a particular one of those four streams they are (or should) be just used in ascending order of availability (although I did suspect there was a subtle bug with the 2.1 release code, that uses the Phonon library in Qt4 but which was not carried forward into Qt5, in that detection of whether a channel was in-use may not have be correct for the first 3 streams but that is no longer a current issue even if I was right in my suspicions!)

Being able to optionally specifying a "player" might be a useful future development, but I am currently a little underwhelmed in the Qt5 sound capabilities because there does not appear to be any pan/position controls which would enable a mono-aural sound effect to be played at different levels on the, at least, stereo (L+R) or greater number of audio output channels. :-(

It might well be useful to have at least one "stream" dedicated to "background" music and making more use of the media control facilities which Qt provides (but we don't use) to queue and/or repeat/loop one or more audio files. One advantage IIRC of the current system compared to, I think QSoundEffect, is that the current system will play both .WAV and other related "raw" audio format files as well as compressed .MP3/.OGG files (basically what-ever the underlying system libraries support) though they have a degree of latency especially with the latter type files; OTOH I think that QSoundEffect is limited to the "raw" type formats but needs to preload/cache them so that play-back can be started much faster, i.e. with much less latency... :geek:

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss » Thu Dec 01, 2016 9:42 pm

Only took an hour, but I just fixed this to use a QLIst instead, and add additional entries as needed. It's compiled/looks to run properly with an unlimited number of simultaneous sounds.

It was only really a dozen lines of code, however, it's also my first time writing anything in C++ (rather then C), not to mention adding to the core mudlet program: I'll get a PR up later tonight, and would ask that you take a closer look at it then normal.

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss » Fri Dec 02, 2016 1:19 am

While it appears to work, I need to make sure i'm not creating objects when I shouldn't be.

What's the function call to output a text line to the errors window?

(edit)

Need to test, but think I found it: mpErrorConsole->print("*** starting new session ***\n");

User avatar
SlySven
Posts: 912
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Sound/Windows

Post by SlySven » Fri Dec 02, 2016 1:34 am

If you are not on Windoze you can use the qInfo()/qDebug()/qWarning()... Qt functions to output "debugging" type output to stderr (on 'Doze such text goes, erm, elsewhere :o ) but if you want to show things to the User, I tend to use the postMessage( (QString) ) function which appears in the Host class (but which actually sends the single QString argument it receives onto the cTelnet class that FIFOs the messages, colours and formats them according to the "[ ERROR ] - ", "[ ALERT ] - ", "[ WARN ] - ", "[ INFO ] - " or "[ OK ] - " prefix to the first line and then inserts them into the profile's main console when it can.) :ugeek:

Ah, you answered yourself whilst I was composing this, and yes, I think that will send text to the "Errors" window but I can't recall off-hand whether it does or does not also go the "Central Debug Console" (which is shared between all profiles BTW if the user is "Multiplaying")...

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss » Fri Dec 02, 2016 1:44 am

Difficulty right now is i'm familiar with C, not C++ :(

Trying to figure out how to access mpErrorConsole, it's declared in dlgTriggerEditor

Not declared in this scope-> extern it! (yeah right) -> invalid use of non-static data members etc etc... So I need to learn a bit about c++

User avatar
SlySven
Posts: 912
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Sound/Windows

Post by SlySven » Fri Dec 02, 2016 1:54 am

OTOH There is likely to be a mpHost (prefix 'm' = member of the class, prefix 'p' = pointer) in most Classes in the Mudlet application, which, provided you check that it is valid (not null) first you can use to access it's public method postMessage that I referred to above:

Code: Select all

// Prepare a warning for the user
QString errMsg = tr( "[ ALERT ] - Everything has just gone wrong in an interesting way..." );
Host * pHost = mpHost;
if( pHost ) {
    pHost->postMessage( errMsg );
}
etc...

FWIIW I came to Mudlet with a C background, knowing not too much about C++ - C is a high-level language that can get down low and talk dirty to the machine hardware; as a result you can easily shoot yourself (or the running application) in the foot with it. With C++ you get much more interesting ways to use and reuse code and to break it down into smaller and more complex bits, but you greatly increase the work that needs/has to be done to compile and execute the code and you exponentially increase the ways there are to blow several limbs off anything nearby if you get it wrong! :lol:

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss » Fri Dec 02, 2016 2:05 am

error 'mpHost' was not declared in this scope :(

(mudlet.cpp)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest