wav.c 979 字节
Newer Older
B
bernard.xiong 已提交
1 2
#include <finsh.h>
#include <dfs_posix.h>
3
#include "netbuffer.h"
wuyangyong's avatar
wuyangyong 已提交
4
#include "stm32f10x.h"
B
bernard.xiong 已提交
5 6 7

static rt_err_t wav_tx_done(rt_device_t dev, void *buffer)
{
8 9
	/* release memory block */
	sbuf_release(buffer);
B
bernard.xiong 已提交
10 11 12 13 14 15 16

	return RT_EOK;
}

void wav(char* filename)
{
    int fd;
17
	rt_size_t block_size;
B
bernard.xiong 已提交
18

19 20
	block_size = sbuf_get_size();
	block_size = (block_size / 512) * 512;
B
bernard.xiong 已提交
21 22 23 24 25 26 27

    fd = open(filename, O_RDONLY, 0);
    if (fd >= 0)
    {
		rt_uint8_t* buf;
		rt_size_t 	len;
		rt_device_t device;
B
bernard.xiong 已提交
28

B
bernard.xiong 已提交
29 30 31 32 33
		/* open audio device and set tx done call back */
		device = rt_device_find("snd");
		rt_device_set_tx_complete(device, wav_tx_done);
		rt_device_open(device, RT_DEVICE_OFLAG_WRONLY);

34 35
		do
		{
36 37
			buf = sbuf_alloc();
			len = read(fd, (char*)buf, block_size);
B
bernard.xiong 已提交
38 39
			if (len > 0) rt_device_write(device, 0, buf, len);
		} while (len != 0);
B
bernard.xiong 已提交
40

B
bernard.xiong 已提交
41 42 43 44 45 46
		/* close device and file */
		rt_device_close(device);
		close(fd);
    }
}
FINSH_FUNCTION_EXPORT(wav, wav test)
47