Browse Source

use round() in pcm volume gain

Signed-off-by: qshi <qshi@123456.com>
master
qshi 8 years ago
parent
commit
df3d9d01b5
  1. 13
      demo/recv_voice.c
  2. 1
      src/common/config.h
  3. 2
      src/common/pcm2alaw.c
  4. 2
      src/zkbrc.json

13
demo/recv_voice.c

@ -9,7 +9,7 @@
#include <arpa/inet.h>
#include <errno.h>
#define HOST_IF_IP "192.168.0.191"
#define HOST_IF_IP "192.168.31.89"
#define GROUP_ADDR "225.0.0.5"
#define PORTRECV 8310
@ -30,8 +30,7 @@ int main(int argc, char *argv[])
int yes=1;
unsigned char buf[64] = {0};
signal(SIGTERM, sigterm);
signal(SIGINT, sigterm);
sock = socket(AF_INET,SOCK_DGRAM,0);
printf("sockfd: %d\n",sock);
if (sock == -1) {
@ -46,7 +45,7 @@ int main(int argc, char *argv[])
memset(&ser_addr,0,sizeof(ser_addr));
ser_addr.sin_family = AF_INET;
ser_addr.sin_addr.s_addr = inet_addr(HOST_IF_IP);
ser_addr.sin_addr.s_addr = INADDR_ANY;//inet_addr(GROUP_ADDR);
ser_addr.sin_port = htons(PORTRECV);
if (bind(sock,(struct sockaddr *) &ser_addr,sizeof(ser_addr)) < 0){
perror("bind");
@ -60,7 +59,9 @@ int main(int argc, char *argv[])
close(sock);
exit(1);
}
myfile = fopen("output.raw", "w");
while (!got_sig) {
slen = sizeof ser_addr;
memset(&ser_addr, 0, sizeof ser_addr);
@ -69,13 +70,15 @@ int main(int argc, char *argv[])
perror("recvfrom");
exit(1);
}
printf("recv data %d\n", count);
if (count == 64) {
if (buf[0] == 0xac && buf[1] == 0x93 && buf[63] == 0x14) {
fwrite(buf + 16, 1, 6, myfile);
}
}
//fflush(myfile);
}
printf("---------------\n");
fclose(myfile);
return 0;
}

1
src/common/config.h

@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include <sys/timerfd.h>

2
src/common/pcm2alaw.c

@ -160,7 +160,7 @@ int alaw2linear_buf_gain(unsigned char *lbuf, int llen, unsigned char *abuf, int
short *pcm16 = (short *)lbuf;
for (m = 0; m < alen; m++) {
pcm32 = alaw2linear(abuf[m]) * gain;
pcm32 = round(alaw2linear(abuf[m]) * gain);
if (pcm32 > 32767)
pcm32 = 32767;
if (pcm32 < -32768)

2
src/zkbrc.json

@ -23,5 +23,5 @@
"audio_local_play": 1,
"down_audio_play": [0, 0, 0, 0],
"alarm_audio_play": 1,
"play_volume": 9
"play_volume": 6
}

Loading…
Cancel
Save