Record sound: Difference between revisions

Content deleted Content added
omission list extended
Line 3:
Record a monophonic 16-bit PCM sound into either memory space, a file or array.
 
=={{header|C}}==
Read/write raw device <code>/dev/dsp</code>. On Linux you need access to said device, meaning probably you should be in audio user group.
<lang c>#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;
}</lang>
=={{header|PicoLisp}}==
<lang PicoLisp>(in '(rec -q -c1 -tu16 - trim 0 2) # Record 2 seconds