Example #1
0
int
main(
    int                                 argc,
    char **                             argv)
{
    int                                 fd;
	int                                 count;
    SoundSample *                       ss;
    int                                 buf_len;
    int                                 l;
    int                                 r;
    int                                 ml = 1;
    int                                 mr = 1;
    int                                 x;
    int                                 i;
    char                                VU[16];
    char                                packet[128];
    float                               xf;
    struct sockaddr_in                  si_other;
    int                                 s;
    int                                 slen=sizeof(si_other);
    int                                 rc;
    char *                              srv_ip;

    srv_ip = argv[1];

    slen = sizeof(si_other);
    if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
    {
        printf("failed to make the socket\n");
        exit(1);
    }
    memset((char *) &si_other, 0, sizeof(si_other));
    si_other.sin_family = AF_INET;
    si_other.sin_port = htons(PORT);
    if (inet_aton(srv_ip, &si_other.sin_addr)==0)
    {
        fprintf(stderr, "inet_aton() failed\n");
        exit(1);
    }

    memset(VU, '\0', 16);
    memset(packet, '\0', 128);
    fd = esd_monitor_stream(
        SOUND_FORMAT, SAMPLE_RATE, NULL, "gkrellmss");
    if (fd < 0)
    {
        printf("vouldnt open it succa\n");
		esd_close(fd);
        return;
    }

    signal(2, cnt_c);
    count = 1024;
    ss = (SoundSample *) calloc(sizeof(SoundSample), count);
    while(!g_done)
    {
        buf_len = sizeof(SoundSample) * count;
	    count = read(fd, ss, buf_len);
    	if (count < 0)
        {
            goto err;
        }
        l = abs(ss[0].left);
        r = abs(ss[0].right);
        l = l * 707 / 1000;
        r = r * 707 / 1000;

        if(l > ml) ml = l;
        if(r > mr) mr = r;
/*
        printf("%f %f \r", (float)l/ml, (float)r/mr);
*/
        memset(VU, ' ', 15);
        xf = 10.0 * (float)l/(float)ml;
        
        x = (int)xf;
        if (xf - (float)x > 0.5)
        {
            x++;
        } 
        x--;
        for(i = 0; i < x; i++)
        {
            VU[i] = 'F';
        }
        printf("%s\r", VU);

        buf_len = strlen(packet);
        sprintf(packet, "uid 0FFFFFFFFF 0%s", VU);
        rc = sendto(s, packet, buf_len, 0, &si_other, slen);
        if(rc < 0)
        {
            printf("failed to send a packet");
            exit(3);
        }
        
        sprintf(packet, "cab 0FFFFFFFFF 0%s", VU);
        rc = sendto(s, packet, buf_len, 0, &si_other, slen);
        if(rc < 0)
        {
            printf("failed to send a packet");
            exit(3);
        }

        usleep(10);
    }
    close(s);
    esd_close(fd);

    printf("\n");
    printf("done\n");
    return 0;

err:
    esd_close(fd);

    return 1;
}
Example #2
0
static int open_esd(void * data,
                    gavl_audio_format_t * format,
                    gavl_video_format_t * video_format,
                    gavl_metadata_t * m)
  {
  int esd_format;
  const char * esd_host;
  char * name;
  char hostname[128];
  
  esd_t * e = data;

  e->samples_read = 0;
  
  /* Set up format */

  memset(format, 0, sizeof(*format));
    
  format->interleave_mode = GAVL_INTERLEAVE_ALL;
  format->samplerate = 44100;
  format->sample_format = GAVL_SAMPLE_S16;
  format->samples_per_frame = ESD_BUF_SIZE / 4;

  format->num_channels = 2;
  gavl_set_channel_setup(format);
  
  gavl_audio_format_copy(&e->format, format);
  
  e->f = gavl_audio_frame_create(format);
    
  if(!e->hostname || (*(e->hostname) == '\0'))
    {
    esd_host = NULL;
    }
  else
    esd_host = e->hostname;
    
  esd_format = ESD_STREAM | ESD_PLAY;
  if(e->do_monitor)
    esd_format |= ESD_MONITOR;
  else
    esd_format |= ESD_RECORD;
  
  esd_format |= (ESD_STEREO|ESD_BITS16);

  gethostname(hostname, 128);
    
  name = bg_sprintf("gmerlin@%s pid: %d", hostname, getpid());
  
  if(e->do_monitor)
    e->esd_socket = esd_monitor_stream(esd_format, format->samplerate,
                                       e->hostname, name);
  else
    e->esd_socket = esd_record_stream(esd_format, format->samplerate,
                                      e->hostname, name);

  free(name);
  if(e->esd_socket < 0)
    {
    bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Cannot connect to daemon");
    return 0;
    }
  e->bytes_per_frame = 4;
  e->src = gavl_audio_source_create(read_func_esd, e,
                                    GAVL_SOURCE_SRC_FRAMESIZE_MAX,
                                    format);
  return 1;
  }