void audio_encoder_queue_lame_impl::send_audio(const audio_data_timed * audioDataTimed)
{
    if (audioDataTimed)
    {
        audio_data_ptr audioData = audioDataTimed->get_media_data();
        send_audio(audioData.get());        
    }
}
Пример #2
0
void *capture_audio(void *data)
{
	/* This thread captures audio samples from audio device */
	/* TODO: add mechanism to end this thread when desired,
	 * perhaps by passing flags for indicating end of call? */
	struct connection_data conn = *((struct connection_data *)data);

	int ret;
	int rc;
	unsigned int rate = 8000;
        int size;
	short audio_samples[SAMPLES_PER_PERIOD];
        int fd;
	int frame_size = 2;

        snd_pcm_t *handle;
        snd_pcm_hw_params_t *params;
	snd_pcm_uframes_t frames;
        int buffer_size = SAMPLES_PER_PERIOD * sizeof(short);

        printf("rate is =%d \n", rate);

        ret = voip_init_pcm(&handle, &params, &buffer_size, &rate, RECORD);
	if (ret) {
                fprintf(stderr, "Unable to initialize PCM \n");
                goto capture_failure;
        }
        printf("In record main \n");
        printf("Pointer address to handle=%p \n", &handle);
        printf("Pointer to handle=%p \n", handle);
        printf("Pointer to params=%p \n", params);

	printf("Size of buffer to accomodate period of data : %d \n", buffer_size);
	while(1) {
                rc = voip_capture(handle, buffer_size / frame_size, audio_samples);
#if 0	
		rc = read(fd, audio_samples, sizeof audio_samples);
	
		if (rc == 0) {
			printf("EOF reached \n");
			break;
		} else if (rc < 0) {
			fprintf(stderr, "Error reading file \n");
			break;
		}
#endif
	
		printf("Read %d frames from capture source \n", rc);
		ring_write(sbuff, (char *)audio_samples, sizeof audio_samples);
		rc = send_audio(&conn);

		if (rc < 0) {
			fprintf(stderr,
				"Failed to transmit audio: %s \n",
				strerror(rc));
			/* TODO: Gracefully handle error condition, close socket etc */
			break;		
		}
        }
	ret = rc;

capture_end:
        voip_end_pcm(handle);
capture_failure:
	pthread_exit(NULL);

}
Пример #3
0
/*
 * Update the time
 */
void update_calendar( void )
{
	calendar.hour++;

	if ( calendar.hour == HOUR_MIDNIGHT )
	{
		DESCRIPTOR_DATA *d;

		calendar.hour = 0;
		calendar.day++;

		if ( calendar.day >= DAYS_IN_MONTH )
		{
			calendar.day = 0;
			calendar.month++;
	
			if ( calendar.month >= MONTHS_IN_YEAR )
			{
				calendar.month = 0;
				calendar.year++;
			}
		}

		for ( d = first_descriptor;  d;  d = d->next )
		{
			ANNIVERSARY_DATA *anniversary;

			bool msend = FALSE;	/* Indica se ha inviato un messaggio al pg evitando di visualizzare il cielo */

			if ( d->connected != CON_PLAYING )	continue;
			if ( !d->character->in_room )		continue;

			for ( anniversary = first_anniversary;  anniversary;  anniversary = anniversary->next )
			{
				if ( anniversary->month != calendar.month )		continue;
				if ( anniversary->day != calendar.day )			continue;

				if ( HAS_BIT(anniversary->races, d->character->race) )
					ch_printf( d->character, "%s\r\n", anniversary->message );
			}

			if ( calendar.day == 0 )
			{
				if ( calendar.month == 0 )
				{
					set_char_color( AT_GREEN, d->character );
					send_to_char( d->character, "Oggi è il primo dell'anno!\r\n" );
				}
				else
				{
					set_char_color( AT_DGREEN, d->character );
					ch_printf( d->character, "Oggi è il primo giorno del mese %s\r\n", month_name[calendar.month] );
				}
				msend = TRUE;
			}

			if ( !is_outside(d->character) )	continue;
			if ( !is_awake(d->character) )		continue;
#ifdef T2_MSP
			send_audio( d, "midnight.wav", TO_CHAR );
#endif
			if ( !msend && d->character->in_room->area && d->character->in_room->area->weather )
			{
				int precip;

				precip = ( d->character->in_room->area->weather->precip + (meteo.weath_unit*3) - 1 ) / meteo.weath_unit;
				if ( precip <= 1 )
					send_command( d->character, "sky", CO );
			}
		}
	}

	/* Invia l'echo sulla base dell'ora trascorsa e del weather dell'area */
	send_time_echo( );

	/* Salva il calendario ogni ora-mud */
	save_calendar( );
}
Пример #4
0
/*
 * Get echo messages according to time changes...
 * some echoes depend upon the weather so an echo must be
 * found for each area
 */
void send_time_echo( void )
{
	AREA_DATA		*pArea;
	DESCRIPTOR_DATA *d;

	for ( pArea = first_area;  pArea;  pArea = pArea->next )
	{
		char			 echo[MSL];
		int				 color = AT_GREY;
		int				 n;
		int				 pindex;

		if ( !pArea->weather )
			continue;

		echo[0] = '\0';
		n = number_bits( 2 );
		pindex = ( pArea->weather->precip + (meteo.weath_unit*3) - 1 ) / meteo.weath_unit;
	
		switch ( calendar.hour )
		{
		  case HOUR_SUNRISE-1:
		  {
			char *echo_strings[4] =
			{
				"Comincia un nuovo giorno.\r\n",
				"E' un nuovo giorno.\r\n",
				"Il cielo lentamente si rischiara, nell'alba di un nuovo giorno.\r\n",
				"S'affaccia adagio il sole, al giorno appena nato.\r\n"
			};
			calendar.sunlight = SUN_RISE;
			strcpy( echo, echo_strings[n] );
			color = AT_YELLOW;
			break;
		  }

		  case HOUR_SUNRISE:
		  {
			char *echo_strings[4] =
			{
				"Il sole nasce di raggi tiepidi, sorgendo ad est..\r\n",
				"L'Oriente si rischiara: il sole sta sorgendo.\r\n",
				"Un sole fosco alza lo sguardo sul piatto dell'orizzonte..\r\n",
				"Un giorno nuovo saluta il mondo all'ascesa di un pallido sole..\r\n"
			};
			calendar.sunlight = SUN_LIGHT;
			strcpy( echo, echo_strings[n] );
			color = AT_ORANGE;
			break;
		  }

		  case HOUR_NOON:
		  {
			if ( pindex > 0 )
				strcpy( echo, "E' mezzogiorno.\r\n" );
			else
			{
				char *echo_strings[2] =
				{
					"Il sole è alto nel cielo, l'intensità del suo diadema infuocato annuncia il mezzogiorno di luce..\r\n",
					"La luce del sole è vigorosa, nel cielo disegna un bagliore acceso: è mezzogiorno.\r\n"
				};
				strcpy( echo, echo_strings[n%2] );
			}
			calendar.sunlight = SUN_LIGHT;
			color  = AT_WHITE;
			break;
		  }
	
		  case HOUR_SUNSET:
		  {
			char *echo_strings[4] =
			{
				"L'occidente riluce dell'abbraccio infuocato del sole che tramonta..\r\n",
				"L'orizzonte è tagliato dalla corona rossa del sole in tramonto..\r\n",
				"Il cielo si dipinge d'oro rosso brillante, il sole ruotando adagio tramonta oltre lo sguardo.. \r\n",
				"Il sole finisce il suo viaggio portando i raggi splendenti nel sonno del tramonto..\r\n"
			};
	
			calendar.sunlight = SUN_SET;
			strcpy( echo, echo_strings[n] );
			color = AT_RED;

			break;
		  }
	
		  case HOUR_SUNSET+1:
		  {
			if ( pindex > 0 )
			{
				char *echo_strings[2] =
				{
					"Cala la sera.\r\n",
					"Avanza lento il crepuscolo..\r\n"
				};
				strcpy( echo, echo_strings[n%2] );
			}
			else
			{
				char *echo_strings[2] =
				{
					"Il chiarore gentile della luna si diffonde attraverso il cielo, annunciando la sera..\r\n",
					"Mille punti di luci tenui occhieggiano nel cielo serale, contornando una pallida luna..\r\n"
				};
				strcpy( echo, echo_strings[n%2] );
			}
			calendar.sunlight = SUN_DARK;
			color = AT_BLUE;
			break;
		  }
		} /* chiude lo switch su calendar.hour */

		for ( d = first_descriptor;  d;  d = d->next )
		{
			if ( d->connected != CON_PLAYING )			continue;
			if ( !is_outside(d->character) )			continue;
			if ( !is_awake(d->character) )				continue;
			if ( !d->character->in_room )				continue;
			if ( d->character->in_room->area != pArea )	continue;

			/* Se è stato creato un'echo viene inviato */
			if ( VALID_STR(echo) )
			{
				set_char_color( color, d->character );
				send_to_char( d->character, echo );
			}
#ifdef T2_MSP
			/* Invia i suoni */
			if ( calendar.hour == HOUR_SUNSET )
				send_audio( d, "sunset.wav", TO_CHAR );
#endif
		}	/* ciclo for dei descrittori */
	}	/* ciclo for delle aree */
}