0
0

Hi!

I’m developing a videogame where I need to mix a long song with short clips and then export the result to an OGG/MP3 file. I’m using Unity and the main target platform is iOS and Android.

I’ve managed to get an AudioClip with the sound I want, but I can’t find any way to export it on a compressed file (I’ve seen scripts exporting to WAV but the size is too much).

As Unity uses FMOD I came here asking for if anyone knows about exporting the clip from a C# script.

Thanks in advance!

  • You must to post comments
0
0

If you want to export audio to .ogg for playback in the game you can use a tool like [url=http://audacity.sourceforge.net/download/:337edusi]Audacity[/url:337edusi] which is free. If you want to export .ogg from the game (on the phone), there is no inbuilt functionality to do that. You would need to add an ogg vorbis encoder to your game.

  • You must to post comments
0
0

Yes, I wanted to export an .ogg from the game on the phone.
So then I should create an extension/plugin to do that.
Thanks! :)

Wouldn’t you know where I could find any encoder suitable for Unity?

  • You must to post comments
0
0

If you are familiar with creating native code plugins, the https://www.xiph.org/ provide open source encoders/decoders for Ogg Vorbis. You could try compiling their encoders to native code plugins for Unity and interfacing with them from your C# code. You would also need to find a way to get the raw audio stream out of Unity, I’m not sure whether that is possible.

  • You must to post comments
0
0

Thanks! :)
I’ll take a look at creating native code plugins.

You can get the raw audio of an AudioClip using the GetData function, and passing as parameter an array of floats.
I’m using that for extracting data of each clip, and then mixing mini clips into the main song, then with SetData you can put the raw data into an AudioClip and later playing it.

Here it is a code snippet for if someone needs it:
[code:3gz3tzc1]
AudioClip clipSong = song.audio.clip;
AudioClip resultClip = AudioClip.Create("resultSong",clipSong.samples,clipSong.channels,clipSong.frequency,_3d,stream);
float[] songData = new float[(clipSong.samples * clipSong.channels)];
clipSong.GetData(songData,0);

//modify songData as you would like

resultClip.SetData(songData,0);
[/code:3gz3tzc1]

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.