• gm_bass_edit - The improved gm_bass.
    118 replies, posted
[QUOTE=geblubber;38262465]Still the same problem [CODE]require("bass2"); [/CODE] put gmsv_bass2_win32.dll and gmcl_bass2_win32.dll to "../garrysmod/lua/bin" and the rest of .dll next to to hl2.exe Still get [CODE]Couldn't include file 'includes\modules\bass2.lua' (File not found) [/CODE][/QUOTE] Well, we fixed it in Steam. The Problem was the missing of gm_bass2 on the client's machine. Putting DLLs on the server will not send it to the client... :v:
I'm having a issue when the client dosent have base module they get kicked because of the too many errors, is there a way to stop the script if the client dosent have base module sorry for the noob question lol
if(not require("bass2")) then return end
I just updated the module: [CODE]- Recompile to use latest headers and DLLs. - Added support for *.MOD and similar files. - Fixed a possible crash with negative numbers. - Removed the time offset argument from BASS.StreamFileURL and BASS.StreamFile, they didn't work. - Added channel:fft4096(), channel:fft8192() and channel:fft16384() - Added support for AC3 and ALAC[/CODE] [QUOTE=Map in a box;36289991]Uhh, [URL="http://en.wikipedia.org/wiki/Module_file"]modules[/URL][/QUOTE] Have fun, it's working fine now. To play them you use BASS.StreamFile. BASS.StreamFileURL can't play them, because BASS doesn't support streams of MOD-files. Edit: I will change how these fft* functions are working to increase performance. Edit2: Update is done: [CODE] - Changed how the fft* functions are working. They change a given table with their date instead of crating a new table. - That should unburden the garbage collector. - Backward compatibility to the old version of gm_bass is lost now! Example use: local stuff = {} channel:fft256(stuff) someRendering(stuff)[/CODE]
I wish this was lower level but yay modules.
[QUOTE=Map in a box;39465277]I wish this was lower level but yay modules.[/QUOTE] What do you mean with lower level in this case? Also the VGModFileSystemXX, how do I use it? I'm kinda new to c++, so please excuse these questions.
VGModFileSystemXX is basically VALVe's filesystem with the ability to open GMAD files (I think). It is also pretty similar to GLua's file library. So you have the filesystem in the variable fs. [code]FileHandle_t file = fs->Open( "filepath", "file open options like r and w", "pathID for example GAME" ); int size = (int)fs->Size( file ); char *read_data = new char[size]; int size_read = fs->Read( read_data, size, file ); //size_read is how much it read in case the variable size is bigger than the file size fs->Close( file ); //Always do it when you're done with the file delete [] read_data; //Always do it when you're done with the data (remember, you need [] to tell delete that read_data is an array and not just a single char)[/code] Also, I don't think gm_bass couldn't get any more lower level than this. This is pretty much how BASS works.
BASS doesn't work like this. [url]http://www.un4seen.com/doc/[/url] Grocel if you need any more help just PM me, I'll try to help.
[QUOTE=Map in a box;39475301]BASS doesn't work like this. [URL]http://www.un4seen.com/doc/[/URL] Grocel if you need any more help just PM me, I'll try to help.[/QUOTE] I guess don't need help yet, because I have done it. :downs: [CODE]- channel:stop() will free the channel now, by default. If you don't want this, put a true in the first argument. - Gm_bass uses the file system of the game.[/CODE] I had do some tricks, because BASS's memory management is a bitch. It won't let you clear the file data while it's playing. I guess that was the problem you implied, isn't it?
You should close the file after the sound is closed or __gc is called.
[QUOTE=Map in a box;39475829]You should close the file after the sound is closed or __gc is called.[/QUOTE] It's done already. ClearChannel() does it. It's the counterpart of AddChannel() that is called when a non-mod file (mod file's data can be freed directly after channel creation) is opened. AddChannel() saves the the header and the pointer of the data so they can be freed with ClearChannel(). ClearChannel() is called in __gc and channel:stop(false/nil). I don't know if there is a callback function that gets called after a channel is freed. :tinfoil: In case you meant the file header itself and not the data then why shouldn't I close it directly? BASS wants the file's data to be loaded into memory, not the file. Maybe the way I have done it is a bit inefficient, but it works. :smile: It would be nice if you could show me a working and more efficient way to do it better.
Stream the file, not load it all at once. I thought thats' what you were doing. Regardless you should close the file when it's done with, not just the channel.
[QUOTE=Map in a box;39487166][B]Stream the file[/B], not load it all at once. I thought thats' what you were doing. Regardless you should [B]close the file when it's done[/B] with, [B]not just the channel[/B].[/QUOTE] Now I would like to know how? Bass takes data to create a channel. But how do I know when to add new data and even how to add new data without creating a new channel. Maybe I haven't posted it clear enough: The file is closed right after getting the data. The data and the channel is freed/removed in ClearChannel(). Also please read the code more closely you haven't jet.
Why do you read the whole file at once and feed it to BASS? You can just create a stream by using the filepath on BASS_StreamCreateFile. This way, BASS will only load in memory what it needs.
Because I want to use the filesystem of GMod?
Thanks I'm no using this for scars.
[QUOTE=Grocel;39493548]Now I would like to know how? Bass takes data to create a channel. But how do I know when to add new data and even how to add new data without creating a new channel. Maybe I haven't posted it clear enough: The file is closed right after getting the data. The data and the channel is freed/removed in ClearChannel(). Also please read the code more closely you haven't jet.[/QUOTE] Busy atm, i'll post more later: Here is what I did in Java for streaming a file, it's possible in C++ as well. [csharp] public Music(final InputStream in){ stream=BASS_StreamCreate(44100, 2, 0, new STREAMPROC() { @Override public int STREAMPROC(HSTREAM arg0, ByteBuffer arg1, int arg2, Pointer arg3) { byte[] buffer=new byte[arg2]; try { in.read(buffer); } catch (IOException e) { return 0; } arg1.put(buffer); return buffer.length; } }, null); initChannels(); } [/csharp]
I see we are getting closer to it. With your hint I just took a look the Bass' documentation again and found several ways to do file streaming, but yours seems to be the easiest one. In the help file there is the fallowing example: [CODE]FILE *file; ...//some file stuff // the stream writing callback DWORD CALLBACK MyStreamWriter(HSTREAM handle, void *buf, DWORD len, void *user) { DWORD c=fread(buf, 1, len, file); // read the file into the buffer <- That seems to be a short cut for reading a the file block wise. Is the something similar in GMod's file system? if (feof(file)) c|=BASS_STREAMPROC_END; // end of the file/stream <- That's what I needed! There will be the file closing, I guess. return c; } ... HSTREAM stream=BASS_StreamCreate(44100, 2, 0, &MyStreamWriter, 0); // create the stream[/CODE] Does Bass clear the void *buf by after using it? Is there a check for the end-of-file indicator (feof(file)) in GMod's file system too?
If that buffer is handled by BASS then it should delete when it's not needed anymore. Also, there is a function to check if the file read position is indeed end-of-file. It's bool IFileSystem::EndOfFile( FileHandle_t file );
[QUOTE=Grocel;39516337]I see we are getting closer to it. With your hint I just took a look the Bass' documentation again and found several ways to do file streaming, but yours seems to be the easiest one. In the help file there is the fallowing example: [CODE]FILE *file; ...//some file stuff // the stream writing callback DWORD CALLBACK MyStreamWriter(HSTREAM handle, void *buf, DWORD len, void *user) { DWORD c=fread(buf, 1, len, file); // read the file into the buffer <- That seems to be a short cut for reading a the file block wise. Is the something similar in GMod's file system? if (feof(file)) c|=BASS_STREAMPROC_END; // end of the file/stream <- That's what I needed! There will be the file closing, I guess. return c; } ... HSTREAM stream=BASS_StreamCreate(44100, 2, 0, &MyStreamWriter, 0); // create the stream[/CODE] Does Bass clear the void *buf by after using it? Is there a check for the end-of-file indicator (feof(file)) in GMod's file system too?[/QUOTE] Use the user* variable, and not currently sure on the FS, but i know you can read streams.
Can you explain me what the user* variable is for? I have read the docs, but I didn't understand how and why to use it.
It can be anything. A Lua reference, a class with data, anything that is stored in the memory (can't be from the stack). It is passed to callbacks through the variable user (usually, it is).
Basically I could pass the file handle for the use in it trough it? Does it accept multiple arguments or has it to be a table of data then?
It's a single argument of course. How do you think you're going to pass multiple arguments through a single variable? What you can do is create a new struct which can hold many values and pass that through user (it needs to be registered in memory, I can't stress this enough! use new or malloc).
What he said, use a struct if you need to hold more than one variable.
I have tried to implement your suggestions, but I wasn't very successfully. :tinfoil: I have fallowed the given examples and, I think, I have placed the file functions the right places. But bass' [URL="http://www.un4seen.com/doc/#bass/BASS_StreamCreateFileUser.html"]BASS_StreamCreateFileUser()[/URL] doesn't seem to work properly for me. It reads the first kilobytes of a file, jump to the end and then returns error 41 ("File format not supported"). The given file itself is valid. I have seen that there is a connection between the return value of [URL="http://www.un4seen.com/doc/#bass/FILELENPROC.html"]FILELENPROC[/URL] and the position [URL="http://www.un4seen.com/doc/#bass/FILESEEKPROC.html"]FILESEEKPROC[/URL] function seeks to: Bass seems to seek to the file size, which results hitting the file end. If I change the return of FILESEEKPROC to a smaller number (like 4096) the playback works a bit. But it only plays mp3s even Bass should support much more. The playback seems broken to. It start some were in the middle sometimes. StreamCreate is not an alternative because it only support samples, it can't play mp3s and stuff. If someone wants to help me, please take a look at the code I have uploaded here: [url]https://dl.dropbox.com/u/16654098/gmod/Bass/gm_bass2.zip[/url] The problem area is between line 417 and 620. Use [I]"channel, err = BASS.StreamFile2(string file [, bool Play3D, bool PlayLoop])"[/I] for testing in-game. While trying to play the given file, it will print some stuff to the console. So you will see what gm_bass and Bass is trying to do.
Just a small heads up (haven't tested this idea). On StreamSeekProc, you're returning true only if the file handle is valid and it has not reached the end of the file. This is not what the boolean returned means. The boolean you return should be true if the seek was successful. Basically, you should compare g_FileSystem->Tell(file) to QWORD offset. What BASS might be doing is seeking to the end of the file (by using StreamSeekProc) and check the boolean returned to see if the length returned by StreamLenProc is valid.
[QUOTE=danielga;39550186]Just a small heads up (haven't tested this idea). On StreamSeekProc, you're returning true only if the file handle is valid and it has not reached the end of the file. This is not what the boolean returned means. The boolean you return should be true if the seek was successful. Basically, you should compare g_FileSystem->Tell(file) to QWORD offset. What BASS might be doing is seeking to the end of the file (by using StreamSeekProc) and check the boolean returned to see if the length returned by StreamLenProc is valid.[/QUOTE] Good idea. I have checked it, but nothing changes. Let's take a look at the console: [CODE] ] Bass_testchannel_play mp3 Open: sound/test/mp3_test1.mp3 Open (ID: 115078240) Size: 979763 B Read read_len: 4096 Read length: 4096 Read Tell: 4096 Read EndOfFile: 0 Read read_len: 10182 Read length: 10182 Read Tell: 14278 Read EndOfFile: 0 Read read_len: 4096 Read length: 4096 Read Tell: 18374 Read EndOfFile: 0 Seek Offset: 979620 Seek Tell: 979620 Read read_len: 143 Read length: 4096 Read Tell: 979763 Read EndOfFile: 1 Close Start Close End (ID: 115078240) sound/test/mp3_test1.mp3: 41, Unsupported file format!, false ] Bass_testchannel_play wav Open: sound/test/wav_test1.wav Open (ID: 115078240) Size: 5322392 B Read read_len: 4096 Read length: 4096 Read Tell: 4096 Read EndOfFile: 0 Seek Offset: 5322284 Seek Tell: 5322284 Read read_len: 108 Read length: 4096 Read Tell: 5322392 Read EndOfFile: 1 Close Start Close End (ID: 115078240) sound/test/wav_test1.wav: 41, Unsupported file format!, false ] Bass_testchannel_play aac Open: sound/test/aac_test1.aac Open (ID: 115078240) Size: 985184 B Read read_len: 4096 Read length: 4096 Read Tell: 4096 Read EndOfFile: 0 Seek Offset: 973936 Seek Tell: 973936 Read read_len: 4096 Read length: 4096 Read Tell: 978032 Read EndOfFile: 0 Seek Offset: 984908 Seek Tell: 984908 Read read_len: 276 Read length: 4096 Read Tell: 985184 Read EndOfFile: 1 Close Start Close End (ID: 115078240) sound/test/aac_test1.aac: 41, Unsupported file format!, false [/CODE] Seek StreamSeekProc looks like this now: [CPP]BOOL CALLBACK StreamSeekProc(QWORD offset, void *param) { FileHandle_t file = param; if(!file) return false; if(!g_FileSystem) return false; if(!g_FileSystem->IsOk(file)) return false; //DEBUG("Seek (ID: %i)", file); DEBUG("Seek Offset: %i", (int)offset); g_FileSystem->Seek(file, (int)offset, FILESYSTEM_SEEK_HEAD); DEBUG("Seek Tell: %i\n", g_FileSystem->Tell(file)); //return !g_FileSystem->EndOfFile(file) && g_FileSystem->IsOk(file); // seek to offset return ((QWORD)g_FileSystem->Tell(file) == offset); // seek to offset }[/CPP]
Noticed another grave issue. StreamReadProc returns -1 when you're in end of file while the return type is an unsigned one! Remove that check completely since BASS should take the file size in account already. EDIT: Forget it. Read the docs. Find it a bit dumb though to make devs do it this way though.
Well what about this? [url]http://www.un4seen.com/doc/#bass/FILEREADPROC.html[/url] [QUOTE][B]Return value[/B] The number of bytes read... -1 = end of file, 0 = end of file (buffered file stream only).[/QUOTE] (I use an unbuffered stream. Buffering would load the whole file into memory.) I will try it out anyway.
Sorry, you need to Log In to post a reply to this thread.