Exemplo n.º 1
0
        public EsdSample CacheSample(string name, Stream stream, EsdChannels channels,
						int rate, EsdBits bits)
        {
            byte[] buffer = new byte[BufferSize];
            int len, id, format;
            IntPtr ptr;
            EsdSample sample;

            format = (int) bits | (int) channels
                    | (int) EsdMode.Stream
                    | (int) EsdFunc.Play;

            id = esd_sample_cache(socket, format, rate,
                        (int) stream.Length, name);
            if (id < 0)
                throw new EsdCacheException("Could not cache sample", null);

            ptr = Marshal.AllocHGlobal(BufferSize);

            while ((len = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                Marshal.Copy(buffer, 0, ptr, len);
                write(socket, ptr, len);
            }

            Marshal.FreeHGlobal(ptr);

            if (id != esd_confirm_sample_cache(socket))
                throw new EsdCacheException("Could not cache sample", null);

            sample = new EsdSample(this);
            sample.id = id;
            sample.name = name;
            return sample;
        }
Exemplo n.º 2
0
 public EsdCacheException(string message, EsdSample sample)
     : base(message)
 {
     this.sample = sample;
 }
Exemplo n.º 3
0
        public EsdSample CacheFile(string filename)
        {
            EsdSample sample;
            int id;

            id = esd_file_cache(socket, String.Empty, filename);
            if (id < 0)
                throw new EsdCacheException("Could not cache file", null);

            sample = new EsdSample(this);
            sample.id = id;
            sample.name = filename;
            return sample;
        }