예제 #1
0
////////////////////////////////////////////////////
// 功能: 
// 输入: 
// 输出:
// 返回: 
// 说明: 
////////////////////////////////////////////////////
int DacClose(HANDLE hdac)
{
	PDAC_DEVICE dac;

	kMutexWait(hDacMutex);
	dac = (PDAC_DEVICE)hdac;
	kdebug(mod_audio, PRINT_INFO, "dac error data number = %d\n",nErrorData);
	if(dac)
	{
		ListRemove(&dac->Link);
		if(ListEmpty(&DacList))
		{
			//MillinsecoundDelay(20);

			SetMuteMode(0);

			//关闭功放
			SetPowerAmplifier(0);

			//MillinsecoundDelay(20);

			SetMoseCe(0);

			// 关闭耳机设备
			DacHeadphoneClose();		

			// 关闭DA设备
			DacDeviceClose();

			// 没有这个耳机会有爆破音.
			//MillinsecoundDelay(20);
		}

		DacDestorySamplerate(dac);	//释放resample数据
		DacDestoryWsola(hdac);		//释放wsola数据
#ifdef DAC_SAVE_PCM
		{
			HANDLE fp;
			fp = kfopen("d:\\pcm.bin","w+b");
			kfwrite(dac_buf,1,dac_offset,fp);
			kfclose(fp);

			fp = kfopen("d:\\source.bin","w+b");
			kfwrite(dac_source_buf,1,dac_source_offset,fp);
			kfclose(fp);
		}
#endif
		kfree(dac);
		kMutexRelease(hDacMutex);
		return 0;
	}
	nErrorData = 0;
	kMutexRelease(hDacMutex);
	return -1;
}
예제 #2
0
파일: devctl.c 프로젝트: andreiw/polaris
int
fwrite_nvlist(char *filename, nvlist_t *nvl)
{
	char	*buf;
	char	*nvbuf;
	kfile_t	*fp;
	char	*newname;
	int	len, err, err1;
	size_t	buflen;
	ssize_t	n;

	ASSERT(modrootloaded);

	nvbuf = NULL;
	err = nvlist_pack(nvl, &nvbuf, &buflen, NV_ENCODE_NATIVE, 0);
	if (err != 0) {
		KFIOERR((CE_CONT, "%s: error %d packing nvlist\n",
			filename, err));
		return (err);
	}

	buf = kmem_alloc(sizeof (nvpf_hdr_t) + buflen, KM_SLEEP);
	bzero(buf, sizeof (nvpf_hdr_t));

	((nvpf_hdr_t *)buf)->nvpf_magic = NVPF_HDR_MAGIC;
	((nvpf_hdr_t *)buf)->nvpf_version = NVPF_HDR_VERSION;
	((nvpf_hdr_t *)buf)->nvpf_size = buflen;
	((nvpf_hdr_t *)buf)->nvpf_chksum = nvp_cksum((uchar_t *)nvbuf, buflen);
	((nvpf_hdr_t *)buf)->nvpf_hdr_chksum =
		nvp_cksum((uchar_t *)buf, sizeof (nvpf_hdr_t));

	bcopy(nvbuf, buf + sizeof (nvpf_hdr_t), buflen);
	kmem_free(nvbuf, buflen);
	buflen += sizeof (nvpf_hdr_t);

	len = strlen(filename) + MAX_SUFFIX_LEN + 2;
	newname = kmem_alloc(len, KM_SLEEP);


	(void) sprintf(newname, "%s.%s",
		filename, NEW_FILENAME_SUFFIX);

	/*
	 * To make it unlikely we suffer data loss, write
	 * data to the new temporary file.  Once successful
	 * complete the transaction by renaming the new file
	 * to replace the previous.
	 */

	if ((err = kfcreate(newname, &fp)) == 0) {
		err = kfwrite(fp, buf, buflen, &n);
		if (err) {
			KFIOERR((CE_CONT, "%s: write error - %d\n",
				newname, err));
		} else {
			if (n != buflen) {
				KFIOERR((CE_CONT,
				    "%s: partial write %ld of %ld bytes\n",
				    newname, n, buflen));
				KFIOERR((CE_CONT,
				    "%s: filesystem may be full?\n", newname));
				err = EIO;
			}
		}
		if ((err1 = kfclose(fp)) != 0) {
			KFIOERR((CE_CONT, "%s: close error\n", newname));
			if (err == 0)
				err = err1;
		}
		if (err != 0) {
			if (kfremove(newname) != 0) {
				KFIOERR((CE_CONT, "%s: remove failed\n",
				    newname));
			}
		}
	} else {
		KFIOERR((CE_CONT, "%s: create failed - %d\n",
			filename, err));
	}

	if (err == 0) {
		if ((err = kfrename(newname, filename)) != 0) {
			KFIOERR((CE_CONT, "%s: rename from %s failed\n",
				newname, filename));
		}
	}

	kmem_free(newname, len);
	kmem_free(buf, buflen);

	return (err);
}