????2????mono?е??ù????
??????.net????????????????DllImport?????????á?????mono???ù????mono??????????????ú????????Interop with Native Libraries????
???????monoDevolop?????????????????????????????????libTest1.so?????????/bin/Debug???
??????Program.cs????????????′???
using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
namespace helloworld
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("the app is started ");
PlayPCM();
Thread thread = new Thread(new ThreadStart(PlayPCM));
thread.Start();
while (true)
{
if (Console.ReadLine() == "quit")
{
thread.Abort();
Console.WriteLine("the app is stopped ");
return;
}
}
}
/// <summary>
/// Plaies the PC.
/// </summary>
static void PlayPCM()
{
using (FileStream fs = File.OpenRead("Ireland.pcm"))
{
byte[] data = new byte[4000];
PcmOpen();
while (true)
{
int readcount = fs.Read(data?? 0?? data.Length);
if (readcount > 0)
{
Play(data?? data.Length);
}
else
{
break;
}
}
PcmClose();
}
}
[DllImport("libTest1.so")]
static extern int PcmOpen();
[DllImport("libTest1.so")]
static extern int Play(byte[] buffer?? int length);
[DllImport("libTest1.so")]
static extern int PcmClose();
}
}
???????????????????а???????????????????????????????????????
????3???й?PCM??????Щ??????
?????????е?Ireland.pcm?????????PCMU???????????8000Hz??????????1???????????1????Щ?????snd_pcm_set_params????????????????????????????趨pcm?????????????????????????????????PCM???????????????????????