Multiple Sound Files Playing

KatKaDe's icon

A problem occurs when another file is chosen to play after being stopped by clicking on a button but then the first file is still heard.
I have many sound files, and when trying to listen to another and another it's a cacophony.

How can: once the sound file is done listening, which does not have to be until the end of the sound file and then another sound file is chosen to listen, the first file is not heard anymore.
Here is the patch.

Thank you

WhatIsThisInstrument?.maxpat
WhatIsThisInstrument 69.66 KB

Source Audio's icon

very unefficient and clumsy programmed patch,
but it can not play more than 1 audio file at once.
So the "cacophony" you hear must be comming from somewhere else,
or you are running multiple instances of that patch

KatKaDe's icon

Yes, I have many patches like this with sound files to be played.
But, the "cacophony" happens even when only one patch is opened.
Maybe it is the sound file as ilogical may seem? When the sound file is stopped and another one is chosen to play, the first one is also heard. When opened another patch like this and a sound file is chosen the previous file still plays.
Help

Source Audio's icon

As I allready wrote - one instance of sfplay~ object can play only one sound file
at same time.
That patch you posted is simply bad, but can not play more than 1 audio file at same time.

KatKaDe's icon

So, the solutions is: sfplay object assigned for every sound file?
23 audio files = 23 sfplay objects?
Thanks

Mark Durham's icon

One way is to have 23 sfplay objects, yes. Probably the simplest method, and should work.

The other method is to use something like polybuffer~ and play~ or using an mc object for it. These are more complex, but perhaps more elegant solutions.

Remember also that you will likely need to attenuate if your user is able to play them all at the same time.

Source Audio's icon

As I understanf you want opposite - only one sound at a time
to avoid this misterious "cacophony"
This becomes a joke, you can preload hundreds of sound files into sfplay and trigger them
as you want.
That patch you posted is preloading sounds and turning dsp on/off at every cue trigger,
which is the main mistake inside

KatKaDe's icon

@ SOURCE AUDIO
" preloading sounds and turning dsp on/off at every cue trigger,..."

You mean by "turning dsp on/off" turning the ezdac on/off ?
Or?

Source Audio's icon

yes.
And - preloading sound files is meant to preload a bunch of files for fast playback switching
and in that patch every trigger and even worse start and stop of playback does
1 preload audio file again
2 toggle dsp on/off

can't be done worse than that.

You are even better off sending message to sfplay :
open sound-blabla.wav, 1
to open sound file and play it.
In adition, that playback toggles should be exclusive,
means if you turn number 4 On, all others should go Off
etc etc
here without preloading with 2 sound files.

one common stop

KatKaDe's icon

@source audio
I have tried to replicate your suggestion,but it doesn't play the audio file.
I may be doing something wrong.
Do you mind sending it in a patch?
I really need to resolve it.
Thanks

Source Audio's icon

here is folder with patch and 2 soundfiles,
to make sure sfplay can find the files

player.zip
application/zip 273.81 KB

KatKaDe's icon

@source audio
My audio files are .aiff, and yours are wav. Does that make a difference, because I have included my .aiff audio file and it does not play.

Source Audio's icon

As long as audio files are in proper format and in search path, sfplay plays them
no matter wave or aiff.
You are doing something wrong if they don't play.
Starting from where the files are or if they have spaces in the name
which would break the path.

KatKaDe's icon

@source audio
I assumed that aiff or wav wouldn't make any difference.
They are in the same folder player that you've send, and the audio file does not have any spaces in the name.
But sfplay still does not play the new sound file.
Other audio files do have space in the name. Should I get rid of the spaces? Will sfplay still play them?
sfplay still does not play the new sound file.

player.maxpat
Max Patch

Source Audio's icon

is that audio file really named sound-AaronCoplandFanfareForTheCommonMan.aiff ?
or did you by mistake prepend sound- ?
If files have spaces either get rid of them,
or enclose names using double quotas, like

aaa bbb.aiff
"aaa bbb.aiff"
so
open "aaa bbb.aiff", 1
to open file and play it

KatKaDe's icon

@source audio
yes, the audio file is really named AaronCoplandFanfareForTheCommonMan.aiff
Is it a problem that the words are capitalised?

Here is another file which I have got rid of spaces:
1Mozart/SonataK.330/C-dur/domaggioreI/AllegroModerato.aiff

Source Audio's icon

NO - patch you posted had sound-AaronCoplandFanfareForTheCommonMan.aiff

and NOT
AaronCoplandFanfareForTheCommonMan.aiff

Read first carefully before replying ....

And you can't add slashes or colons to path, that breaks it
use - or _ insted, or quotas

KatKaDe's icon

@source audio

my mistake, SORRY

THANK YOU
They work now.
I will let you know if anything goes wrong.

Source Audio's icon

I hope you will not let me know every time you produce a mistake using max, ha ha
Now without joking, if you need a help, just post, but it is easier to provide help
if you provide enough infos about the project, so that better suggestions can be offered.

KatKaDe's icon

@source audio

I assume you can't use # in the sound file?
Or, can you?

Source Audio's icon

surprise ---- yes you can.
Easy to test or ?
You can use just about anything in file name if quoted

KatKaDe's icon

@source audio
and if not quoted you can't use in audio file name.

Source Audio's icon

but one warning :
using message to open a file, and then play it
will play previously loaded file if the one asked to open can't be found.
because comma separated message in max is executing anyway.
to make sure one would do :
fclose, open aaa.aiff, 1

KatKaDe's icon

@source audio
And, the stop message translated in another language works for now.

How is this now, check out the patch

KatKaDe's icon

@source audio

player2.maxpat
Max Patch

KatKaDe's icon

@source audio
Up to how many audio files can I have in one patch? Is there a limit?

Source Audio's icon

There is no limit.
Why should there be limit ?
You can play 10000 audio files if they are in search path
like this - opening and not preloading them.
Audio files ARE NOT IN THE PATCH.
You just tell sfplay to play them.
But you should not do mistakes.

I see you started posting in max forum 2008
that is 12 years ago.
In that time you should have learned at least some basics in Max.
So read help files of objects you use in first place.
this post :

https://cycling74.com/forums/problem-with-build-in-application-on-windows-because-i-have-154-sound-files
probably remaind unanswered because even a short read about building standalones
would tell you that you DON'T include media files into collective or mxf file
when building a standalone, but place them in search path,
or create path to media files detection.

KatKaDe's icon

@source audio
Thank you for the reply.
I have been out a while because I have been busy with my doctorate project in Media Arts, and I have just being back to Max.

The solution worked like a charm in Max. But, in the application the audio files don't play.

I have included the audio files in the application Contents folder as it always works, but
sfplay~: can't find file MozartAveVerumCorpusInDK618.aiff
sfplay~: no open file
I am sure the solution is simple and obvious, but ...

Thanks

Source Audio's icon

If you want to keep it as simple as in max patch,
without using absolute paths etc,
try activating "Search for missing files"
in standalone inspector, and try to help the app
to easily find them by placing audio files either next to mxf file
or next to app executable.
BUT- allways put Standalone app in own folder.
this works :

this also:


this does not:

because app can't directly see audio files.
Inside of resources folder it does even if files are in audio folder,
because "Search for Missing files" forces app to search inside

KatKaDe's icon

@source audio
Thanks, I'll do that, and let you know

KatKaDe's icon

@source audio
YAY, it worked :D

It seems that you have the solution for everything.

And, on standalone application for Windows?
Thanks

Source Audio's icon

same thing on windows