/// 現在の再生位置を取得する。再生中でない場合負の値となる。 public float get_play_time() { #if DEBUG cadencii.debug.push_log("WavePlay.get_play_time"); #endif if (s_playing) { MMTIME mmt = new MMTIME(); mmt.cb = (uint)sizeof(MMTIME); mmt.wType = win32.TIME_MS; uint ret = win32.waveOutGetPosition(s_hwave_out, ref mmt, (uint)sizeof(MMTIME)); #if DEBUG cadencii.debug.push_log(" ret=" + ret); #endif float ms = 0.0f; switch (mmt.wType) { case win32.TIME_MS: return(mmt.ms * 0.001f); case win32.TIME_SAMPLES: return((float)mmt.sample / (float)s_wave_formatx.nSamplesPerSec); case win32.TIME_BYTES: return((float)mmt.cb / (float)s_wave_formatx.nAvgBytesPerSec); default: return(-1.0f); } } else { return(-1.0f); } }
public static double SoundGetPosition() { if (IntPtr.Zero == wave_out) { return(-1.0); } MMTIME mmt = new MMTIME(); mmt.wType = win32.TIME_MS; win32.waveOutGetPosition(wave_out, ref mmt, (uint)sizeof(MMTIME)); float ms = 0.0f; switch (mmt.wType) { case win32.TIME_MS: return(mmt.ms * 0.001); case win32.TIME_SAMPLES: return((double)mmt.sample / (double)wave_format.nSamplesPerSec); case win32.TIME_BYTES: return((double)mmt.cb / (double)wave_format.nAvgBytesPerSec); default: return(-1.0); } return(0.0); }
/// <summary>Get the playback position in the stream</summary> /// <returns>position</returns> public uint GetPosition() { if (!this.Playing) { return(0); } // set up the struct MMTIME udtTime = new MMTIME(); udtTime.wType = (int)TIME_FORMAT.TIME_BYTES; // pass it in waveOutGetPosition(_pWaveOut, ref udtTime, Marshal.SizeOf(udtTime)); // format time int x = (int)(udtTime.u / this.AvgBytesPerSecond) * 1000; switch (udtTime.wType) { case (int)TIME_FORMAT.TIME_BYTES: return((uint)(udtTime.u / this.AvgBytesPerSecond) * 1000); case (int)TIME_FORMAT.TIME_SAMPLES: return((uint)(udtTime.u / this.SamplesPerSecond) * 1000); case (int)TIME_FORMAT.TIME_MS: return((uint)udtTime.u); default: return(0); } }
public static extern MmResult midiStreamPosition(IntPtr hMidiStream, [MarshalAs(UnmanagedType.Struct)] ref MMTIME lpmmt, int cbmmt);
protected static extern Wave.MMSYSERR waveOutGetPosition(IntPtr hwo, MMTIME pmmt, uint cbmmt);
public static extern MMSYSERROR waveOutGetPosition(WaveOutSafeHandle hwo, ref MMTIME pmmt, int cbmmt);
static extern int midiStreamPosition(IntPtr handle, ref MMTIME lpMMTime, int uSize);
public static extern MmResult midiStreamPosition(IntPtr hMidiStream, ref MMTIME lpmmt, int cbmmt);
public static extern int waveOutGetPosition(IntPtr hwo, ref MMTIME pmmt, int cbmmt);
public static extern int timeGetSystemTime(ref MMTIME pmmt, int cbmmt);
public static extern int waveOutGetPosition(IntPtr hWaveOut, ref MMTIME pmmt, int uSize);
public static extern MMRESULT timeGetSystemTime(out MMTIME pmmt, uint cbmmt = 8);
private static extern MMSYSERR waveOutGetPosition(IntPtr hWaveOut, ref MMTIME lpInfo, int uSize);