//[return: MarshalAs(UnmanagedType.U4)] public static extern uint waveOutOpen(ref IntPtr hWaveOut, int uDeviceID, ref WAVEFORMATEX lpFormat, delegateWaveOutProc dwCallback, IntPtr dwInstance, uint dwFlags);
//[return: MarshalAs(UnmanagedType.U4)] public static extern uint waveOutOpen( ref IntPtr hWaveOut, int uDeviceID, ref WAVEFORMATEX lpFormat, delegateWaveOutProc dwCallback, IntPtr dwInstance, uint dwFlags );
/// 初期化関数 public WavePlay( int block_size, int sample_rate ) { #if DEBUG Console.WriteLine( "waveplay..ctor" ); #endif s_block_size = block_size; s_sample_rate = sample_rate; //s_ptr_wave_formatx = Marshal.AllocHGlobal( sizeof( WAVEFORMATEX ) ); s_wave_formatx = new WAVEFORMATEX(); //Marshal.PtrToStructure( s_ptr_wave_formatx, s_wave_formatx ); s_wave_formatx.cbSize = (ushort)sizeof( WAVEFORMATEX ); #if DEBUG Console.WriteLine( " s_wave_fomratx.cbSize=" + s_wave_formatx.cbSize ); Console.WriteLine( " sizeof( WAVEHDR )=" + sizeof( WAVEHDR ) ); #endif s_wave_formatx.wFormatTag = win32.WAVE_FORMAT_PCM; s_wave_formatx.nChannels = 2; s_wave_formatx.wBitsPerSample = 16; s_wave_formatx.nBlockAlign = (ushort)(s_wave_formatx.nChannels * s_wave_formatx.wBitsPerSample / 8); s_wave_formatx.nSamplesPerSec = (uint)s_sample_rate; s_wave_formatx.nAvgBytesPerSec = s_wave_formatx.nSamplesPerSec * s_wave_formatx.nBlockAlign; s_wave_callback = new delegateWaveOutProc( wave_callback ); s_hwave_out = IntPtr.Zero; Console.WriteLine( " calling waveOutOpen..." ); uint ret = win32.waveOutOpen( ref s_hwave_out, win32.WAVE_MAPPER, ref s_wave_formatx, s_wave_callback, IntPtr.Zero, (uint)win32.CALLBACK_FUNCTION ); Console.WriteLine( " ...done; ret=" + ret ); #if DEBUG cadencii.debug.push_log( " s_hwave_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) ); #endif for ( int k = 0; k < _NUM_BUF; k++ ) { s_ptr_wave[k] = Marshal.AllocHGlobal( sizeof( uint ) * s_block_size ); s_wave[k] = (uint*)s_ptr_wave[k];// = (ulong*)calloc( sizeof( ulong ), s_block_size ); s_ptr_wave_header[k] = Marshal.AllocHGlobal( sizeof( WAVEHDR ) ); s_wave_header[k] = (WAVEHDR)Marshal.PtrToStructure( s_ptr_wave_header[k], typeof( WAVEHDR ) ); s_wave_header[k].lpData = s_ptr_wave[k]; s_wave_header[k].dwBufferLength = (uint)(sizeof( uint ) * s_block_size); s_wave_header[k].dwFlags = win32.WHDR_BEGINLOOP | win32.WHDR_ENDLOOP; s_wave_header[k].dwLoops = 1; #if DEBUG Console.WriteLine( "calling waveOutPrepareHeader..." ); #endif uint ret2 = win32.waveOutPrepareHeader( s_hwave_out, ref s_wave_header[k], (uint)sizeof( WAVEHDR ) ); #if DEBUG Console.WriteLine( "...done; ret2=" + ret2 ); #endif s_wave_header[k].dwUser = new IntPtr( k ); } #if DEBUG cadencii.debug.push_log( " exit waveplay..ctor; s_hwave_out=0x" + Convert.ToString( s_hwave_out.ToInt32(), 16 ) ); #endif }