protected unsafe void OnButton1Clicked(object sender, System.EventArgs e) { IntPtr ptr; WaveNative.snd_pcm_open (out ptr, "default", WaveNative.snd_pcm_stream_t.SND_PCM_STREAM_PLAYBACK, 0); Console.WriteLine (ptr.ToString ()); IntPtr param; WaveNative.snd_pcm_hw_params_malloc (out param); WaveNative.snd_pcm_hw_params_any (ptr, param); WaveNative.snd_pcm_hw_params_set_access (ptr, param, WaveNative.snd_pcm_access_t.SND_PCM_ACCESS_RW_INTERLEAVED); WaveNative.snd_pcm_hw_params_set_format (ptr, param, WaveNative.snd_pcm_format_t.SND_PCM_FORMAT_S16_LE); uint srate = 44100; WaveNative.snd_pcm_hw_params_set_rate_near (ptr, param, ref srate, null); WaveNative.snd_pcm_hw_params_set_channels (ptr, param, 1); WaveNative.snd_pcm_hw_params (ptr, param); WaveNative.snd_pcm_hw_params_free (param); WaveNative.snd_pcm_prepare (ptr); sine_gen sg = new sine_gen (100.0 / 44100); short[] buf = new short[4096]; fixed(short* bufp=buf) { while (true) { sg.generate (buf, buf.Length, 0, short.MaxValue); WaveNative.snd_pcm_writei (ptr, bufp, (ulong)buf.Length); } } }
protected unsafe void OnButton1Clicked(object sender, System.EventArgs e) { IntPtr ptr; WaveNative.snd_pcm_open(out ptr, "default", WaveNative.snd_pcm_stream_t.SND_PCM_STREAM_PLAYBACK, 0); Console.WriteLine(ptr.ToString()); IntPtr param; WaveNative.snd_pcm_hw_params_malloc(out param); WaveNative.snd_pcm_hw_params_any(ptr, param); WaveNative.snd_pcm_hw_params_set_access(ptr, param, WaveNative.snd_pcm_access_t.SND_PCM_ACCESS_RW_INTERLEAVED); WaveNative.snd_pcm_hw_params_set_format(ptr, param, WaveNative.snd_pcm_format_t.SND_PCM_FORMAT_S16_LE); uint srate = 44100; WaveNative.snd_pcm_hw_params_set_rate_near(ptr, param, ref srate, null); WaveNative.snd_pcm_hw_params_set_channels(ptr, param, 1); WaveNative.snd_pcm_hw_params(ptr, param); WaveNative.snd_pcm_hw_params_free(param); WaveNative.snd_pcm_prepare(ptr); sine_gen sg = new sine_gen(100.0 / 44100); short[] buf = new short[4096]; fixed(short *bufp = buf) { while (true) { sg.generate(buf, buf.Length, 0, short.MaxValue); WaveNative.snd_pcm_writei(ptr, bufp, (ulong)buf.Length); } } }