There is something to open the specified audio (from the file system) into a given AudioClip?
something like:
clip = new AudioClip(filename);
or something similar to the UnityEngine.WWW but which works on the local file system? like:
clip = new WWW(filename).oggVorbis;
I need to load at runtime an audio file (a wave) into an AudioClip to play it.
Can you help me, please?
Thanks.
Its a bit puzzeling that AudioClip doesn’t have a constructor taking a byte array like Texture2D does, but couldn’t you just use the WWW class via “file://”?
I will try
Thanks
Someone knows a dll or a piece of c# code to convert wav to ogg?
Since I use wav and WWW uses only ogg I need to convert them on the fly…
I am trying to translate a piece of C code to C# code to convert a WAV to OGG:
The piece of C code is “examples/encoder_example.c”
in this archive: http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.0.zip
This is what I did:
[StructLayout(LayoutKind.Sequential)]
public struct WaveHdr
{
public IntPtr lpData; // pointer to locked data buffer
public int dwBufferLength; // length of data buffer
public int dwBytesRecorded; // used for input only
public IntPtr dwUser; // for client's use
public int dwFlags; // assorted flags (see defines)
public int dwLoops; // loop control counter
public IntPtr lpNext; // PWaveHdr, reserved for driver
public int reserved; // reserved for driver
}
public struct vorbis_info
{
public int version;
public int channels;
public long rate;
public long bitrate_upper;
public long bitrate_nominal;
public long bitrate_lower;
public long bitrate_window;
unsafe public void* codec_setup;
}
[DllImport("vorbisenc.dll")]
unsafe public static extern int vorbis_encode_init(vorbis_info* vi, long channels, long rate, long max_bitrate, long nominal_bitrate, long min_bitrate);
vorbis_info vi;
int ret;
unsafe public void ConvertToOGG (String filename)
{
fixed (vorbis_info* ptr = &vi){
ret = vorbis_encode_init(ptr, 2, 44100, -1, 128000, -1);
if (ret != 0) return;
}
}
I get an error at the line:
ret = vorbis_encode_init(ptr, 2, 44100, -1, 128000, -1);
it that says that it can not find the dll…
I don’t know how to successfully import/use that function… please, help me!
P.S.: I attach the vorbisenc.dll I used
107037–4088–$vorbisenc_792.rar (91.9 KB)
I receive always “DllNotFoundException”
I have put the Dll in the same directory of the executable and also in C:\WINDOWS\System32…
Is the dll that doesn’t work? Or I made other mistakes?
Someone can help me?
If someone has the “vorbisenc.dll” working in windows, please post it.