简体   繁体   English

无法打开/ dev / dsp

[英]Cannot open /dev/dsp

I am trying to learn audio recording, so I compiled The following code that I found online , but for some reason I cannot open /dev/dsp . 我正在尝试学习录音,所以我编译了在网上找到的以下代码,但是由于某些原因,我无法打开/dev/dsp I tried killing pulseaudio, but it re-opens as soon as I killall it. 我试图杀死的PulseAudio,但它重新打开,只要我killall它。 I really don't know what I am doing; 我真的不知道我在做什么。 I've been struggling for the latter part of the week. 在本周的下半段,我一直在苦苦挣扎。 Please help. 请帮忙。

I also tried chmod o+rw /dev/dsp 我也尝试过chmod o+rw /dev/dsp

/*
 * parrot.c
 * Program to illustrate /dev/dsp device
 * Records several seconds of sound, then echoes it back.
 * Runs until Control-C is pressed.
 */
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h> 
#include <stdio.h>
#include <linux/soundcard.h>

#define LENGTH 3    /* how many seconds of speech to store */
#define RATE 8000   /* the sampling rate */
#define SIZE 8      /* sample size: 8 or 16 bits */
#define CHANNELS 1  /* 1 = mono 2 = stereo */

/* this buffer holds the digitized audio */
unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];

int main()
{
  int fd;       /* sound device file descriptor */
  int arg;      /* argument for ioctl calls */
  int status;   /* return status of system calls */

  /* open sound device */
  fd = open("/dev/dsp", O_RDWR);
  if (fd < 0) {
    perror("open of /dev/dsp failed");
    exit(1);
  }

  /* set sampling parameters */
  arg = SIZE;      /* sample size */
  status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
  if (status == -1)
    perror("SOUND_PCM_WRITE_BITS ioctl failed");
  if (arg != SIZE)
    perror("unable to set sample size");

  arg = CHANNELS;  /* mono or stereo */
  status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
  if (status == -1)
    perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
  if (arg != CHANNELS)
    perror("unable to set number of channels");

  arg = RATE;      /* sampling rate */
  status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
  if (status == -1)
    perror("SOUND_PCM_WRITE_WRITE ioctl failed");

  while (1) { /* loop until Control-C */
    printf("Say something:\n");
    status = read(fd, buf, sizeof(buf)); /* record some sound */
    if (status != sizeof(buf))
      perror("read wrong number of bytes");
    printf("You said:\n");
    status = write(fd, buf, sizeof(buf)); /* play it back */
    if (status != sizeof(buf))
      perror("wrote wrong number of bytes");
    /* wait for playback to complete before recording again */
    status = ioctl(fd, SOUND_PCM_SYNC, 0); 
  if (status == -1)
    perror("SOUND_PCM_SYNC ioctl failed");
  }
}   

See, /dev/dsp was used on older versions of ubuntu linux. 可以看到,/ dev / dsp用于旧版本的ubuntu linux。 It's no longer available in newer versions of ubuntu. 在较新版本的ubuntu中不再可用。 I think it was gone with 10.04. 我认为10.04已经不存在了。 Things changed from 10.10. 事情从10.10改变了。

From one of the websites: 从其中一个网站:

10.10 Maverick finally disabled the very old OSS drivers (which provided /dev/dsp, so the padsp wrapper is the easiest way to handle if it you can't select ALSA or PulseAudio directly. 10.10 Maverick最终禁用了非常老的OSS驱动程序(该驱动程序提供了/ dev / dsp,因此,如果您不能直接选择ALSA或PulseAudio,则padsp包装器是最简单的处理方式。

See this http://manpages.ubuntu.com/manpages/hardy/man1/padsp.1.html 看到这个http://manpages.ubuntu.com/manpages/hardy/man1/padsp.1.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM