2009-08-19 22:06:56 +08:00
|
|
|
#include <finsh.h>
|
|
|
|
#include <dfs_posix.h>
|
2009-10-14 23:41:47 +08:00
|
|
|
#include "netbuffer.h"
|
2009-10-08 22:43:07 +08:00
|
|
|
#include "stm32f10x.h"
|
2009-08-19 22:06:56 +08:00
|
|
|
|
|
|
|
static rt_err_t wav_tx_done(rt_device_t dev, void *buffer)
|
|
|
|
{
|
2009-10-14 23:41:47 +08:00
|
|
|
/* release memory block */
|
|
|
|
sbuf_release(buffer);
|
2009-08-19 22:06:56 +08:00
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wav(char* filename)
|
|
|
|
{
|
|
|
|
int fd;
|
2009-10-14 23:41:47 +08:00
|
|
|
rt_size_t block_size;
|
2009-08-19 22:06:56 +08:00
|
|
|
|
2009-10-14 23:41:47 +08:00
|
|
|
block_size = sbuf_get_size();
|
|
|
|
block_size = (block_size / 512) * 512;
|
2009-08-19 22:06:56 +08:00
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY, 0);
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
rt_uint8_t* buf;
|
|
|
|
rt_size_t len;
|
|
|
|
rt_device_t device;
|
2009-08-28 17:52:20 +08:00
|
|
|
|
2009-08-19 22:06:56 +08:00
|
|
|
/* 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);
|
|
|
|
|
2009-10-08 21:47:58 +08:00
|
|
|
do
|
|
|
|
{
|
2009-10-14 23:41:47 +08:00
|
|
|
buf = sbuf_alloc();
|
|
|
|
len = read(fd, (char*)buf, block_size);
|
2009-08-19 22:06:56 +08:00
|
|
|
if (len > 0) rt_device_write(device, 0, buf, len);
|
2009-11-24 07:34:58 +08:00
|
|
|
else sbuf_release(buf);
|
2009-08-19 22:06:56 +08:00
|
|
|
} while (len != 0);
|
2009-08-28 17:52:20 +08:00
|
|
|
|
2009-08-19 22:06:56 +08:00
|
|
|
/* close device and file */
|
|
|
|
rt_device_close(device);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FINSH_FUNCTION_EXPORT(wav, wav test)
|
2009-10-14 23:41:47 +08:00
|
|
|
|