There a way to run a sound directly from a TMemoryStream without using the net or going to save a file.
I only saw
uos_AddFromFile (PlayerIndex1, (pchar (SoundFilename)));
but a function of the type
uos_AddFromMStream (PlayerIndex1, ms);
or by passing the file extension if needed
uos_AddFromMStream (PlayerIndex1, ms, ext);
I have an encrypted data structure where I fetch the files and decode them. Everything happens in memory. So to me it is fundamental the use of TMemoryStream without writing anything. uos_AddFromFile () I can not use it. I saw that in "uos_libsndfile.pas" in addition to "sf_open ()" there is also "sf_open_virtual" I do not understand how to exploit it .
uos_CreatePlayer(0); // create the player
uos_AddIntoDevOut(0); // add a output to sound card
uos_AddFromFile(0,pchar(thesound)); // add a input from file
uos_PlayNoFree(0); // you may play how many times without re-load it
uos_FreePlayer(0); // when you do not need it anymore.
I am busy to add a new method: uos_AddFromFileIntoMemory().
It will copy the data of the file into memory.
Then you may play it directly from memory.
Hello, thank you for your work !!! I found this library a few days ago, and I'm thinking to use only this.
In this case, the real problem is that I do not have a PATH which can give uos_AddFromFile (0, pchar (???)). The data structure in question is a single file that contains different encrypted data such as sounds and more.
A very bad solution would be to save the TMemoryStream decrypted file so as to have the path to load. But this is what I want to avoid.
As well as in my case, this feature might be useful to those using a game engine combine with a data structure containing the sounds and other.
I saw the "AddFromFileIntoMemory ()" method just added but the problem is always the same that I have NO PATH. The audio files are ready to use it only in TMemoryStream memory.
sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
The problem is that this implementation will always depend on a PATH file
But if used:
sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
From site lib:
"Opens a soundfile from a virtual file I/O context which is provided by the caller. This is usually used to interface libsndfile to a stream or buffer based system. Apart from the sfvirtual and the user_data parameters this function behaves like sf_open."
In addition to the implementation through "PATH" and can implement a solution without asking for any file path using "sf_open_virtual"?
It is possible by storing in the structure, the preloaded data using libsndfile (buffer and parameters). But NOT in the original format. In practice by altering the encrypted data structure it is possible.
My goal is to use only UOS, but keeping the data structure as independent as possible.
In the future, if they will be available direct support for the TMemoryStream will be a nice addition.
sorry for the wait, I tested everything and works perfectly.
No need to use TResourceStream because it also works with TMemoryStream. It basically a bypass of linsndfile library (for the accuracy of all libraries for sound format). Using the decoded buffer and then just load only PortAudio. This is an interesting feature. But in my case, you lose the advantage of starting from files in original format as flac, mp3 .. Decrypt a large file such as .wav format is inconvenient.
It is true that sf_open_virtual can only solve for libsndfile but it would still be an additional feature (apart from a possible problem at the end of the sound seems that the solution was nearly reached "Tuos_Player.AddFromMStream").
Maybe I'm wrong to focus on sf_open_virtual but by a non-expert point of view, it may seem promising.
No and excuse me if I did not speak over this.
Of course it is a great addition and I will take a look asap.
But before to commit it, I want to do the same for mpg123 and opus.
It will not be very hard because it was already done for web-streaming.
I have just to adapt the code for a independent TMemoryStream of compressed audio.