powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Программирование [игнор отключен] [закрыт для гостей] / Работа со звуком - ...
6 сообщений из 6, страница 1 из 1
Работа со звуком - ...
    #33814597
coder_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Уважаемые знатоки, прошу поделиться опытом с менее опытным в деле кодинга

Проблема вот в чем.

Требутся:
Органмзовать многокальный запись с входов аудиокарты (), содновременной записью в файл и чтенеи с этого же файла (т.е. воспроизведение). Т.е. типа "AudioSpy"
и не менее, или другое ПО который free.

Можете приводить все что у вас есть, исходники, инфу по работе со звуковыми картами и т.п.


Куда копать?
...
Рейтинг: 0 / 0
Работа со звуком - ...
    #33814768
coder_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Ну хотяб пример листинга Записи со входа аудиокарты (микрофон)в wav файл
...
Рейтинг: 0 / 0
Работа со звуком - ...
    #33815569
c127
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Читает из микрофона, пишет в файл. Прослушивается:
cat xxx > /dev/dsp

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <stdlib.h>

#include <ioctl.h>
#include <fcntl.h>
#include <sys/soundcard.h>

#define DEV0 "/dev/dsp"
#define DEV1 "/dev/dsp"
#define AUD_FMT AFMT_S8_LE
#define BFF_SZ  4096 

int audio_fdi=- 1 ;
int audio_fdo=- 1 ;
uchar audio_bff[BFF_SZ];

int pcmSet(int fd,int fmt,int spd) {
  int rc=ERR;
  int fmt0=fmt;

  do {
    fmt=fmt0;
    if (- 1 ==ioctl(fd,SNDCTL_DSP_SETFMT,&fmt)) {
        perror("SNDCTL_DSP_SETFMT");
        break;
        }
    if (fmt0!=fmt) {
        /* The device doesn't support the requested audio format. The
        program should use another format (for example the one returned
        in "format") or alternatively it must display an error message
        and to abort. */
        }
    if (- 1 ==ioctl(fd,SNDCTL_DSP_SPEED,&spd)) {
        perror("SNDCTL_DSP_SPEED");
        break;
        }
    rc=OK;
    } while ( 0 );
  return rc;
  }

int main(int argc, char *argv[]) {
...........................
  do {
    size_t len;
    int iloop= 0 ;

    // opening IO devices
    if (- 1 ==(audio_fdi=open("/dev/dsp",O_RDONLY))) {
        perror(arg[CMDL_DEV_I].val);
        break;
        }
    if (- 1 ==(audio_fdo=open("xxx",O_WRONLY | O_CREAT))) {
        perror(arg[CMDL_DEV_O].val);
        break;
        }
    if (pcmSet(audio_fdi,AFMT_S8_LE, 14400 )) break;

    while ( 1 ) {
      iloop++;
      if (- 1 ==(len=read(audio_fdi,audio_bff,BFF_SZ))) {
          perror("audio read");
          break;
          }
      fprintf(log,"%7i; read: %i;  ",iloop,len);
      if (!len) break;
      if (- 1 ==(len=write(audio_fdo,audio_bff,len))) {
          perror("audio write");
          break;
          }
      fprintf(log,"write: %i\n",len);
      if (!len) break;
      }

    rc=OK;
    } while( 0 );

  CLOSE(audio_fdi);
  CLOSE(audio_fdo);
  fclose((FILE*)log);

  return rc;
  }
...
Рейтинг: 0 / 0
Работа со звуком - ...
    #33815574
c127
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
почитать можно тут, я читал по второму, если не ошибаюсь:

http://www.4front-tech.com/pguide/audio.html
http://www.opensound.com/pguide/oss.pdf
...
Рейтинг: 0 / 0
Работа со звуком - ...
    #33815805
coder_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Доброе утро. (сегодня эт точно)
2 c127 ,сапасибо :), буду пробовать
...
Рейтинг: 0 / 0
Работа со звуком - ...
    #33818504
Akh
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Тестирует каналы, форматы и воспроизводит файл:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/soundcard.h>
#include <errno.h>
#include <string.h>

//Макрос создания структуры идентификатора с описанием
#define IS(x) { x, #x }
//Структура - идентификатор с описанием
typedef struct {
	int id;
	char *s;
} is;

//Десткрипторы устройств
is mixer={ 0 , "/dev/mixer"};
is numberic={ 0 , "/dev/dsp"};
is file={ 0 , NULL};

#define returnclean(err_string) {clean_up(err_string); return  0 ;}
#define returncleanone(err_string, err_param) {char __s[ 1024 ]; sprintf(__s, err_string, err_param); returnclean(__s);}
void clean_up(char *err_string) {
#define CLEAN_UP(x) 		\
   if (x.id> 0 ) { 			\
		if (close(x.id)) printf("ERROR: Can't may close %s\n", x.s);	\
		else		     printf("%s closed\n", x.s); 					\
		x.id=0;				\
   }
	printf("%s", err_string);
	CLEAN_UP(mixer);
	CLEAN_UP(numberic);
	CLEAN_UP(file);
#undef CLEAN_UP
}

#define opening(x, reg) \
    if ((x.id=open(x.s, reg))==-1) returncleanone("ERROR: Can't open %s\n", x.s) \
    else printf("%s opened\n", x.s);

/********************************************************************************************************************/

#define print_std(x) \
    for (i= 0  ; i<x##s_std_n ; i++) { \
        printf("%s %s(%02x) \t%s\n", #x, x##s_std[i].s,x##s_std[i].id , (mask & x##s_std[i].id) ? "supported" : "not supported"); \
		mask = mask & (~(x##s_std[i].id)); \
    } \
    printf("Not parsed mask: %02x\n", mask);

			//MIXER
#define channels_std_n  16 
int test_mixer() {
    int i;
	//Маски каналов
    is channels_std[channels_std_n]={IS(SOUND_MASK_VOLUME), IS(SOUND_MASK_TREBLE), IS(SOUND_MASK_BASS),
									IS(SOUND_MASK_SYNTH), IS(SOUND_MASK_PCM), IS(SOUND_MASK_SPEAKER),
									IS(SOUND_MASK_LINE), IS(SOUND_MASK_MIC), IS(SOUND_MASK_CD),
									IS(SOUND_MASK_RECLEV),
									IS(SOUND_MASK_ALTPCM), IS(SOUND_MASK_RADIO), IS(SOUND_MASK_VIDEO),
									IS(SOUND_MASK_PHONEIN), IS(SOUND_MASK_PHONEOUT), IS(SOUND_MASK_MONITOR)};
	opening(mixer, O_RDWR);
    int mask= 0 ;
    if (ioctl(mixer.id, SOUND_MIXER_READ_DEVMASK, &mask)==- 1 ) returnclean("ERROR: Can't get list of channals\n");
	print_std(channel);

    returnclean("Closing mixer... ");
}

#define formats_std_n 11
int test_numberic() {
    int i;
	//Маски форматов
    is formats_std[formats_std_n]={IS(AFMT_MU_LAW),  IS(AFMT_A_LAW), IS(AFMT_IMA_ADPCM), IS(AFMT_U8),
                                    IS(AFMT_S16_LE), IS(AFMT_S16_BE), IS(AFMT_S8),
									IS(AFMT_U16_LE), IS(AFMT_U16_BE), IS(AFMT_MPEG), IS(AFMT_AC3)};
	opening(numberic, O_RDONLY);
    int mask=AFMT_QUERY;
    if (ioctl(numberic.id, SNDCTL_DSP_GETFMTS, &mask)) returnclean("ERROR: Can't get formats\n");
    print_std(format);

    returnclean("Closing numbering... ");
}

/*******************************************************************************************************************/

#define BUF_SIZE  1024 
#define VOLUME  70 
int play_file() {
	//Описание формата файла
	int file_tag;
	int file_channels;
	long file_rate;
	int file_bits;

    //Устанавливаем микшер
    opening(mixer, O_RDWR);
    int g_vol= 0 ;
    if (ioctl(mixer.id, SOUND_MIXER_READ_VOLUME, &g_vol)) returnclean("ERROR: Can't get global volume\n")
    else printf("Global volume seted to %d\n", g_vol);
    if (g_vol != VOLUME) {
		g_vol=VOLUME;
		if (ioctl(mixer.id, SOUND_MIXER_WRITE_VOLUME, &g_vol)) returnclean("ERROR: Can't set global volume\n");
		if (g_vol != VOLUME) returncleanone("ERROR: Can't set global volume to %d\n", VOLUME);
		printf("Global volume setting to %d\n", VOLUME);
    }


    //Проигрываем файл
    opening(file, O_RDONLY);
    opening(numberic, O_WRONLY);

    //Определяем формат
    int format, _format;
    int channels, _channels;
    int rate, _rate;

    int actlen, actlen2, offset;
    unsigned char buf[BUF_SIZE];
    actlen=read(file.id, buf, 16);
    if (actlen!=16) returnclean("ERROR: Can't read RIFFxxxxWAVEfmt \n");
    actlen=read(file.id, &offset,  4 );
    if (actlen!= 4 ) returnclean("ERROR: Can't read len fmt\n");
    file_tag=0;
    actlen=read(file.id, &file_tag, 2);
    if (actlen!=2) returnclean("ERROR: Can't read tag\n");
    file_channels= 0 ;
    actlen=read(file.id, &file_channels,  2 );
    if (actlen!= 2 ) returnclean("ERROR: Can't read channels\n");
    file_rate=0;
    actlen=read(file.id, &file_rate, 4);
    if (actlen!=4) returnclean("ERROR: Can't read read\n");
    actlen=read(file.id, buf,  6 );
    if (actlen!= 6 ) returnclean("ERROR: Can't read to bits\n");
    file_bits=0;
    actlen=read(file.id, &file_bits, 2);
    if (actlen!=2) returnclean("ERROR: Can't read bits\n");
    if (offset- 16 > 0 ) {
        actlen=read(file.id, buf, offset- 16 );
		if (actlen!=offset- 16 ) returnclean("ERROR: Can't read to end fmt\n");
    }
    actlen2=1;
    while (actlen2 && 8==read(file.id, buf, 8)) {
	if (strncmp((const char *)buf, "data", 4)) {
	    offset=buf[4]+buf[5]*256+buf[6]*256*256+buf[7]*256*256*256;
	    actlen=read(file.id, buf, offset);
	    if (actlen!=offset) returnclean("ERROR: Can't read to end next header\n");
	} else
	    actlen2= 0 ;
    }

    if (actlen2== 1 ) returnclean("Can't may find data\n");

    _channels=channels=file_channels;
    _rate=rate=file_rate;
    format=0;
    switch (file_tag) {
	case 7://MULAW
	    format=AFMT_MU_LAW;
	    break;
	case 1://PCM
	    if (file_bits==16) {
		format=AFMT_S16_LE;
	    }
	    if (file_bits==8) {
		format=AFMT_U8;
	    }
	    break;
    }
    if (format==0) returnclean("ERROR: Can't support this format\n");
    _format=format;

    //setting
    if (ioctl(numberic.id, SNDCTL_DSP_SETFMT, &format)) returnclean("ERROR: Can't set format\n");
    if (format != _format) returncleanone("ERROR: Can't set format (%02x)\n", format);

    if (ioctl(numberic.id, SNDCTL_DSP_CHANNELS, &channels)) returnclean("ERROR: Can't set channels\n");
    if (channels != _channels) returnclean("ERROR: Can't set channels 1\n");

    if (ioctl(numberic.id, SNDCTL_DSP_SPEED, &rate)) returnclean("ERROR: Can't set rate\n");
    if (rate != _rate) returnclean("ERROR: Can't set rate to 8000\n");

    //playing
    printf("Playing started...");
    while ((actlen=read(file.id, buf, BUF_SIZE))> 0 ) {
		if ((actlen2=write(numberic.id, buf, actlen))!=actlen) {
			printf("Error writing!");
			fflush(stdout);
		}
		printf(".");
		fflush(stdout);
    }
    printf("\nPlaying stop\n");

    returnclean("Closing all... \n");
}

/*******************************************************************************************************************/

#include "stdlib.h"
int main(int argc, char **argv) {
	printf(">Testing mixer...\n");
    test_mixer();
	printf("\n>Testing numberic...\n");
    test_numberic();
    printf("\n");

	printf(">Playing file...\n");
    if (argc!= 2 ) {
		printf("Use: ./main <file>\n");
		_exit( 0 );
    }
    file.s=argv[ 1 ];
    play_file();
    printf("\n");

	printf("Program working successfull\n");
    return  0 ;
}

...
Рейтинг: 0 / 0
6 сообщений из 6, страница 1 из 1
Форумы / Программирование [игнор отключен] [закрыт для гостей] / Работа со звуком - ...
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]