public override bool Play() { if (!initialized) return false; var input = PlayList[currentIndex]; //Spec.callback = FillBuffer; for (int i = 0; i < formats.Length; i++) { Spec.format = formats[i]; Spec.freq = input.Frequency; Spec.channels = input.Channels; Spec.silence = 255; Spec.samples = Convert.ToUInt16(Math.Pow(2, 15) - 1); Spec.size = 0; try { currentDevice = SdlAudio.OpenAudioDevice(null, 0, ref Spec, out SdlAudioSpec obtained, (int)AudioAdjust.FORMAT_CHANGE); if (currentDevice != 0) { Spec = obtained; break; } } catch { continue; } } opened = currentDevice != 0; if (!opened) return false; SdlAudio.QueueAudio(currentDevice, input.data, input.length); SdlAudio.PauseAudioDevice(currentDevice, 0); return Loop; }
//SDL_LoadWAV protected static SdlAudioSpec LoadWAV(string file, ref SdlAudioSpec spec, out IntPtr audio_buf, out int audio_len) { SdlAudioSpec result; IntPtr rwops = RWFromFile(file, "rb"); IntPtr result_ptr = loadWAV_RW( rwops, 1, ref spec, out audio_buf, out audio_len ); result = result_ptr.ToStruct<SdlAudioSpec>(); return result; }
static extern int openAudioDevice(byte[] device, int iscapture, ref SdlAudioSpec desired, out SdlAudioSpec obtained, int allowed_changes);
//SDL_OpenAudioDevice protected static int OpenAudioDevice(string device, int iscapture, ref SdlAudioSpec desired, out SdlAudioSpec obtained, int allowed_changes) => openAudioDevice(Implementation.UTF8_ToNative(device), iscapture, ref desired, out obtained, allowed_changes);
static extern IntPtr loadWAV_RW(IntPtr src, int freesrc, ref SdlAudioSpec spec, out IntPtr audio_buf, out int audio_len);