tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
30
Task/Record-sound/C/record-sound.c
Normal file
30
Task/Record-sound/C/record-sound.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
void * record(size_t bytes)
|
||||
{
|
||||
int fd;
|
||||
if (-1 == (fd = open("/dev/dsp", O_RDONLY))) return 0;
|
||||
void *a = malloc(bytes);
|
||||
read(fd, a, bytes);
|
||||
close(fd);
|
||||
return a;
|
||||
}
|
||||
|
||||
int play(void *buf, size_t len)
|
||||
{
|
||||
int fd;
|
||||
if (-1 == (fd = open("/dev/dsp", O_WRONLY))) return 0;
|
||||
write(fd, buf, len);
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
void *p = record(65536);
|
||||
play(p, 65536);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue