How do I save an audio files contents

Acid Reflvx

Member
Hello,
I'm almost done creating a rhythm game editor. I'm saving the objects placed as encoded numbers in a text file (I'm using the commands under file_text_~) and decoding the information to form the same object with all of the properties it had before. My editor allows you to import an .ogg file to use as the song. Now that I've got the level saved in a text file, I'm having trouble with saving the audio file. I know it would be cheesy to prompt you to open an .ogg when starting to play the level (but if it's the only way to make it work, I'll do it), and I know opening the audio file if it exists won't work since if you were to give the level to another computer, the computer would have to have the audio in its storage already. Therefore, I'm wondering if there's a way to save the contents of an audio file: maybe being able to put the data that makes up the song into the level file as it's being saved and reassembling the data to play the music when opening the level to play it. Any easy way to do that? xd

Another solution I can think of is what if I just imported the audio from a YouTube link, or a Newgrounds link, or whatever? Is there a way to do that?
Any other way will be appreciated! <3

Thank you!
 
maybe being able to put the data that makes up the song into the level file
If I understand you correctly, you want to, say, encode a .wav into a base64 text file, and on the other end "recompile" that text file in an actual .wav file, right?
I will party-poop, but, unless you're some level-99 wizard, there's no way you gonna do that in GML. Feel very free to surprise me, tho!
 

Acid Reflvx

Member
If I understand you correctly, you want to, say, encode a .wav into a base64 text file, and on the other end "recompile" that text file in an actual .wav file, right?
I will party-poop, but, unless you're some level-99 wizard, there's no way you gonna do that in GML. Feel very free to surprise me, tho!
I suppose so. I'm no level-99 wizard so thank you for making it clear I can't do it in gml before I waste 20+ hours on it. Is there a way to import audio through a link, though?
 
Oh yeah, you could definitely go with a downloadable link, with the url_* functions.
I'm not 100% clear on what your project is, and what you mean by "editor". Is this a tool, or is it a game?
I probably assume wrong that this is what you want to do, but if you're looking to have some sort of rhythm game, say like GH, for example, there's no way in hell you're going to be able to extract the rhythm data from an audio file the user loads in.
Try to explain your project and problem to me like if I was 6 years old, just to make sure we are on the same page!
 

TsukaYuriko

☄️
Forum Staff
Moderator
I may be missing something here, but...

My editor allows you to import an .ogg file to use as the song
Couldn't you just store the file name of this audio file in your level file and ship the audio file alongside the level file, then? That file already contains the audio file's contents - no need to get it out of there. Maybe pack it into a zip or something. Seems like the simplest solution to me.
 

Acid Reflvx

Member
Oh yeah, you could definitely go with a downloadable link, with the url_* functions.
I'm not 100% clear on what your project is, and what you mean by "editor". Is this a tool, or is it a game?
I probably assume wrong that this is what you want to do, but if you're looking to have some sort of rhythm game, say like GH, for example, there's no way in hell you're going to be able to extract the rhythm data from an audio file the user loads in.
Try to explain your project and problem to me like if I was 6 years old, just to make sure we are on the same page!
Okay, so what I mean by editor is a way to create your own levels. The editor lets you import audio to use as the level music. I save the level in a text file with all of the properties of each obstacle encoded into numbers. My problem is, it's not saving the song in the text file and I don't know how I should save it.

I may be missing something here, but...


Couldn't you just store the file name of this audio file in your level file and ship the audio file alongside the level file, then? That file already contains the audio file's contents - no need to get it out of there. Maybe pack it into a zip or something. Seems like the simplest solution to me.
Mmmm yes that would work. I'll try that. Thank you!
 

kburkhart84

Firehammer Games
Okay, so what I mean by editor is a way to create your own levels. The editor lets you import audio to use as the level music. I save the level in a text file with all of the properties of each obstacle encoded into numbers. My problem is, it's not saving the song in the text file and I don't know how I should save it.


Mmmm yes that would work. I'll try that. Thank you!
So your editor is only using homemade things? It isn't extracting song info, rather just trying to include the song? If that's the case, I see two options.

1. Simply always store the audio in some place. The editor could copy it to a "songs" folder that is in the folder the data file is(or right next to it). The catch with this is that if you expect the files to be moved, you have to move the song too.

2. You could switch to a binary file format instead of a text file. The .ogg file could then be loaded as a buffer(not played, just for storage) in the editor. Then you could save that buffer along with all the other level properties, using binary. You could come up with a nice little header for the file that does byte offsets like some formats do. So at the beginning you have a header maybe with some magic number(that confirms that file type). Then a number that is how many bytes into the file is the buffer for the audio, and then do all the level properties. Then do the audio file's buffer. Finally, when you load in the level, you can separate the buffer for the audio, save it to the .ogg, then load it in as an external audio file.
 

Acid Reflvx

Member
So your editor is only using homemade things? It isn't extracting song info, rather just trying to include the song? If that's the case, I see two options.

1. Simply always store the audio in some place. The editor could copy it to a "songs" folder that is in the folder the data file is(or right next to it). The catch with this is that if you expect the files to be moved, you have to move the song too.

2. You could switch to a binary file format instead of a text file. The .ogg file could then be loaded as a buffer(not played, just for storage) in the editor. Then you could save that buffer along with all the other level properties, using binary. You could come up with a nice little header for the file that does byte offsets like some formats do. So at the beginning you have a header maybe with some magic number(that confirms that file type). Then a number that is how many bytes into the file is the buffer for the audio, and then do all the level properties. Then do the audio file's buffer. Finally, when you load in the level, you can separate the buffer for the audio, save it to the .ogg, then load it in as an external audio file.
Option 2 sounds a bit complicated, so I'd like to try option one first. What commands in gml can I use to duplicate the audio file into a directory? Thank you
 
Top