Problem combining music and sounds in µpython

I prefer compile-time constexpr variables because they have almost all the benefits of macros with none of the downsides (they respect scope, they don’t ‘poison’ the code, the compiler actually knows about them).

1 Like

@jonne , as there are no strong objections, could you merge the PR to PokittoLib?

It’s done, thanks!

@Pharap constexpr is not supported in the mbed online compiler.

@jonne @Hanski if you insist on defines, we should at least make it less confusing, as right now we have a lot of project defines only for sound playing.

#define PROJ_SOUND_BUFFERED
#define PROJ_STREAMING_MUSIC
#define PROJ_SDFS_STREAMING
#define PROJ_DISABLE_MIXING_SFX_WITH_SD_STREAMING

we can change this to be less confusing, like those two

#define PROJ_ENABLE_SFX
#define PROJ_ENABLE_SD_MUSIC

and we could keep them compatible with old ones

#ifdef PROJ_ENABLE_SFX
	#ifndef PROJ_ENABLE_SOUND
		#define PROJ_ENABLE_SOUND 1
	#end
	
	#ifndef PROJ_STREAMING_MUSIC
		#define PROJ_STREAMING_MUSIC 1
	#end
	
	#ifndef PROJ_ENABLE_SD_MUSIC
		#define PROJ_DISABLE_MIXING_SFX_WITH_SD_STREAMING 1
	#end
#endif

#ifdef PROJ_ENABLE_SD_MUSIC
	#ifndef PROJ_ENABLE_SOUND
		#define PROJ_ENABLE_SOUND 1
	#end
	
	#ifndef PROJ_STREAMING_MUSIC
		#define PROJ_STREAMING_MUSIC 1
	#end
	
	#ifndef PROJ_SDFS_STREAMING
		#define PROJ_SDFS_STREAMING 1
	#end
#endif
2 Likes

I’m aware, but we have enough other IDE options.
I can’t wait for the day that we can finally say “PokittoLib won’t work on the mbed online compiler, please use one of these other options”.

C++11 was such a massive leap forward that it seems silly to leave the library stuck in the past.

1 Like

Thanks, I did just that. No more needed to define PROJ_ENABLE_SOUND, PROJ_STREAMING_MUSIC, etc. I also changed “PROJ_DISABLE_MIXING_SFX_WITH_SD_STREAMING” to “PROJ_DISABLE_SD_STREAMING” if someone for some reason wants to use it.

@jonne, could you merge the new PR?

1 Like

Yep, firing up comp right now

Edit: merged

2 Likes

@fmanga Could you update Python Editor with the latest official PokittoLib, as the audio mixing do not work correctly in the current version? No need to update MicroPython.

So you can use both:
#define PROJ_ENABLE_SFX
#define PROJ_ENABLE_SD_MUSIC

And ditch PROJ_ENABLE_SOUND and PROJ_STREAMING_MUSIC in my_settings.h.

I updated the PokittoLib in PokittoPython, but I haven’t look at your changes yet. Should I add those option flags to the interface?

Thanks!

Those flags are not necessarily needed in Python Editor as MP resets the stream buffers to 127, when the audio is initialized. So it does not bother if the SD streaming audio is not really used.
Maybe, we should keep it simple and not put the flags there.

1 Like