예제 #1
0
static int morsecode_exec(struct ast_channel *chan, void *data)
{
	int res=0, ditlen, tone;
	char *digit;
	const char *ditlenc, *tonec;
	struct ast_module_user *u;

	u = ast_module_user_add(chan);

	if (ast_strlen_zero(data)) {
		ast_log(LOG_WARNING, "Syntax: Morsecode(<string>) - no argument found\n");
		ast_module_user_remove(u);
		return 0;
	}

	/* Use variable MORESEDITLEN, if set (else 80) */
	ditlenc = pbx_builtin_getvar_helper(chan, "MORSEDITLEN");
	if (ast_strlen_zero(ditlenc) || (sscanf(ditlenc, "%30d", &ditlen) != 1)) {
		ditlen = 80;
	}

	/* Use variable MORSETONE, if set (else 800) */
	tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
	if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
		tone = 800;
	}

	for (digit = data; *digit; digit++) {
		int digit2 = *digit;
		char *dahdit;
		if (digit2 < 0) {
			continue;
		}
		for (dahdit = morsecode[digit2]; *dahdit; dahdit++) {
			if (*dahdit == '-') {
				playtone(chan, tone, 3 * ditlen);
			} else if (*dahdit == '.') {
				playtone(chan, tone, 1 * ditlen);
			} else {
				/* Account for ditlen of silence immediately following */
				playtone(chan, 0, 2 * ditlen);
			}

			/* Pause slightly between each dit and dah */
			playtone(chan, 0, 1 * ditlen);
		}
		/* Pause between characters */
		playtone(chan, 0, 2 * ditlen);
	}

	ast_module_user_remove(u);
	return res;
}
예제 #2
0
void addvistrailer () {
    printf( "Adding VIS trailer to audio data.\n" ) ;
    
    playtone( 2300 , 300000 ) ;
    playtone( 1200 ,  10000 ) ;
    playtone( 2300 , 100000 ) ;
    playtone( 1200 ,  30000 ) ;
    
    // bit of silence
    playtone(    0 , 500000 ) ;
    
    printf( "Done adding VIS trailer to audio data.\n" ) ;    
}
예제 #3
0
파일: pisstv.c 프로젝트: AgriVision/pisstv
void buildaudio ()
{
    uint16_t x , y , k ;
    uint32_t pixel ;
    uint8_t r[320], g[320], b[320] ;
    
    printf( "Adding image to audio data.\n" ) ;
    
    for ( y=0 ; y<256 ; y++ )
    {
//        printf( "Row [%d] Sample [%d].\n" , y , g_samples ) ;
    
        // read image data
        for ( x=0 ; x<320 ; x++ )
        {
            pixel = gdImageGetTrueColorPixel( g_imgp, x, y ) ;
            //printf( "Got pixel.\n" ) ;
            
            // get color data
            r[x] = gdTrueColorGetRed( pixel ) ;
            g[x] = gdTrueColorGetGreen( pixel ) ;
            b[x] = gdTrueColorGetBlue( pixel ) ;
        }
        
        // add row markers to audio
        // sync
        playtone( 1200 , 4862 ) ;
        // porch 
        playtone( 1500 ,  572 ) ;
        
        // each pixel is 457.6us long in Martin 1
        
        // add audio for green channel for this row
        for ( k=0 ; k<320 ; k++ )
        { playtone( toneval( g[k] ) , 457.6 ) ; }
        
        // separator tone 
        playtone( 1500 , 572 ) ;
        
        // bloo channel
        for ( k=0 ; k<320 ; k++ )
        { playtone( toneval( b[k] ) , 457.6 ) ; }

        playtone( 1500 , 572 ) ;

        // red channel
        for ( k=0 ; k<320 ; k++ )
        { playtone( toneval( r[k] ) , 457.6 ) ; }

        playtone( 1500 , 572 ) ;
        
    }  // end for y
    
    printf( "Done adding image to audio data.\n" ) ;    
    
}  // end buildaudio    
예제 #4
0
파일: pisstv.c 프로젝트: BlueMustache/rpitx
void ProcessMartin1()
{
	static uint32_t FrequencyMartin1[3]={1200,1500,1500};
	static uint32_t TimingMartin1[3]={48720,5720,4576};
	
	
	
	int EndOfPicture=0;
	int NbRead=0;
	int VIS=1;
	static unsigned char Line[320*3];
	
	
				int Row;
				
				
				addvisheader();
				addvistrailer();
				while(EndOfPicture==0)
				{
					NbRead=read(FilePicture,Line,320*3);
					if(NbRead!=320*3) EndOfPicture=1;
					//MARTIN 1 Implementation
					//Horizontal SYNC
					playtone((double)FrequencyMartin1[0],TimingMartin1[0]);
					//Separator Tone
					playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
				
					for(Row=0;Row<320;Row++)
					{ 
						playtone((double)FrequencyMartin1[1]+Line[Row*3+1]*800/256,TimingMartin1[2]);
					
					}
					playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
				
					//Blue
					for(Row=0;Row<320;Row++)
					{ 
						playtone((double)FrequencyMartin1[1]+Line[Row*3+2]*800/256,TimingMartin1[2]);
					
					}
					playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
			
					//Red
					for(Row=0;Row<320;Row++)
					{ 
						playtone((double)FrequencyMartin1[1]+Line[Row*3]*800/256,TimingMartin1[2]);
					
					}
					playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
				}
				
}
예제 #5
0
//Builds audio scan data for the Scottie series of specifications.
//Applicable to Scottie 1, Scottie 2, Scottie  SSTV modes
//Each pixel is scanned for pixeltime microseconds
void buildaudio_s (double pixeltime) {
    uint16_t x , y , k ;
    uint32_t pixel ;
    uint8_t r[320], g[320], b[320] ;
    
    printf( "Adding image to audio data.\n" ) ;
    
    //add starting sync pulse
    playtone( 1200 , 9000);

    for ( y=0 ; y<256 ; y++ ) {
        // read image data
        for ( x=0 ; x<320 ; x++ ) {
            pixel = gdImageGetTrueColorPixel( g_imgp, x, y ) ;
            
            // get color data
            r[x] = gdTrueColorGetRed( pixel ) ;
            g[x] = gdTrueColorGetGreen( pixel ) ;
            b[x] = gdTrueColorGetBlue( pixel ) ;
        }
        //seperator pulse
        playtone(1500, 1500);
        
        // add audio for green channel for this row
        for ( k=0 ; k<320 ; k++ )
            playtone( toneval_rgb( g[k] ) , pixeltime ) ;

        // separator tone 
        playtone(1500, 1500) ;

        // blue channel
        for ( k=0 ; k<320 ; k++ )
            playtone( toneval_rgb( b[k] ) , pixeltime ) ; 
     

        //sync pulse
        playtone(1200, 9000);

        //sync porch
        playtone(1500 , 1500) ;

        // red channel
        for ( k=0 ; k<320 ; k++ )
            playtone( toneval_rgb( r[k] ) , pixeltime ) ;

        
    }  // end for y
    
    printf( "Done adding image to audio data.\n" ) ;    
    
}  // end buildaudio_s
예제 #6
0
static void
playstring(char *cp, int slen)
/* interpret and play an item from a notation string */
{
    int		pitch, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE;

#define GETNUM(cp, v)	for(v=0; slen > 0 && isdigit(cp[1]); ) \
				{v = v * 10 + (*++cp - '0'); slen--;}
    for (; slen--; cp++)
    {
	int		sustain, timeval, tempo;
	char	c = toupper(*cp);

#ifdef SPKRDEBUG
	printf("playstring: %c (%x)\n", c, c);
#endif /* SPKRDEBUG */

	switch (c)
	{
	case 'A':  case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':

	    /* compute pitch */
	    pitch = notetab[c - 'A'] + octave * OCTAVE_NOTES;

	    /* this may be followed by an accidental sign */
	    if (slen > 0 && (cp[1] == '#' || cp[1] == '+'))
	    {
		++pitch;
		++cp;
		slen--;
	    }
	    else if (slen > 0 && cp[1] == '-')
	    {
		--pitch;
		++cp;
		slen--;
	    }

	    /*
	     * If octave-tracking mode is on, and there has been no octave-
	     * setting prefix, find the version of the current letter note
	     * closest to the last regardless of octave.
	     */
	    if (octtrack && !octprefix)
	    {
		if (abs(pitch-lastpitch) > abs(pitch+OCTAVE_NOTES-lastpitch))
		{
		    if (octave < NOCTAVES - 1) {
			++octave;
			pitch += OCTAVE_NOTES;
		    }
		}

		if (abs(pitch-lastpitch) > abs((pitch-OCTAVE_NOTES)-lastpitch))
		{
		    if (octave > 0) {
			--octave;
			pitch -= OCTAVE_NOTES;
		    }
		}
	    }
	    octprefix = false;
	    lastpitch = pitch;

	    /* ...which may in turn be followed by an override time value */
	    GETNUM(cp, timeval);
	    if (timeval <= 0 || timeval > MIN_VALUE)
		timeval = value;

	    /* ...and/or sustain dots */
	    for (sustain = 0; slen > 0 && cp[1] == '.'; cp++)
	    {
		slen--;
		sustain++;
	    }

	    /* time to emit the actual tone */
	    playtone(pitch, timeval, sustain);
	    break;

	case 'O':
	    if (slen > 0 && (cp[1] == 'N' || cp[1] == 'n'))
	    {
		octprefix = octtrack = false;
		++cp;
		slen--;
	    }
	    else if (slen > 0 && (cp[1] == 'L' || cp[1] == 'l'))
	    {
		octtrack = true;
		++cp;
		slen--;
	    }
	    else
	    {
		GETNUM(cp, octave);
		if (octave >= NOCTAVES)
		    octave = DFLT_OCTAVE;
		octprefix = true;
	    }
	    break;

	case '>':
	    if (octave < NOCTAVES - 1)
		octave++;
	    octprefix = true;
	    break;

	case '<':
	    if (octave > 0)
		octave--;
	    octprefix = true;
	    break;

	case 'N':
	    GETNUM(cp, pitch);
	    for (sustain = 0; slen > 0 && cp[1] == '.'; cp++)
	    {
		slen--;
		sustain++;
	    }
	    playtone(pitch - 1, value, sustain);
	    break;

	case 'L':
	    GETNUM(cp, value);
	    if (value <= 0 || value > MIN_VALUE)
		value = DFLT_VALUE;
	    break;

	case 'P':
	case '~':
	    /* this may be followed by an override time value */
	    GETNUM(cp, timeval);
	    if (timeval <= 0 || timeval > MIN_VALUE)
		timeval = value;
	    for (sustain = 0; slen > 0 && cp[1] == '.'; cp++)
	    {
		slen--;
		sustain++;
	    }
	    playtone(-1, timeval, sustain);
	    break;

	case 'T':
	    GETNUM(cp, tempo);
	    if (tempo < MIN_TEMPO || tempo > MAX_TEMPO)
		tempo = DFLT_TEMPO;
	    whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / tempo;
	    break;

	case 'M':
	    if (slen > 0 && (cp[1] == 'N' || cp[1] == 'n'))
	    {
		fill = NORMAL;
		++cp;
		slen--;
	    }
	    else if (slen > 0 && (cp[1] == 'L' || cp[1] == 'l'))
	    {
		fill = LEGATO;
		++cp;
		slen--;
	    }
	    else if (slen > 0 && (cp[1] == 'S' || cp[1] == 's'))
	    {
		fill = STACCATO;
		++cp;
		slen--;
	    }
	    break;
	}
    }
}
예제 #7
0
파일: pisstv.c 프로젝트: AgriVision/pisstv
void addvisheader()
{
    printf( "Adding VIS header to audio data.\n" ) ;
    
    // bit of silence
    playtone(    0 , 500000 ) ;   

    // attention tones
    playtone( 1900 , 100000 ) ; // you forgot this one
    playtone( 1500 , 100000 ) ;
    playtone( 1900 , 100000 ) ;
    playtone( 1500 , 100000 ) ;
    playtone( 2300 , 100000 ) ;
    playtone( 1500 , 100000 ) ;
    playtone( 2300 , 100000 ) ;
    playtone( 1500 , 100000 ) ;
                    
    // VIS lead, break, mid, start
    playtone( 1900 , 300000 ) ;
    playtone( 1200 ,  10000 ) ;
//    playtone( 1500 , 300000 ) ;
    playtone( 1900 , 300000 ) ;
    playtone( 1200 ,  30000 ) ;

    // VIS data bits (Martin 1)
    playtone( 1300 ,  30000 ) ;
    playtone( 1300 ,  30000 ) ;
    playtone( 1100 ,  30000 ) ;
    playtone( 1100 ,  30000 ) ;
    playtone( 1300 ,  30000 ) ;
    playtone( 1100 ,  30000 ) ;
    playtone( 1300 ,  30000 ) ;
    playtone( 1100 ,  30000 ) ; 

    // VIS stop
    playtone( 1200 ,  30000 ) ; 
    
    printf( "Done adding VIS header to audio data.\n" ) ;
        
} // end addvisheader   
예제 #8
0
void getcontrols(void *pdata)
{

	int data, i;
	char cmd[3];

	for (i = 0; i < sizeof(cmd)/sizeof(cmd[0]); i++)
	{
		cmd[i] = 0;
	}
	i = 0;

	/* read and echo characters */
	while(1)
	{
		data = *(JTAG_UART_ptr);		 		// read the JTAG_UART data register
		if (data & 0x00008000)					// check RVALID to see if there is new data
		{
			data = data & 0x000000FF;			// the data is in the least significant byte
			/* echo the character */

			while ((char) data == '1' || (char) data == '2')
			{
				OSTimeDly(1);

				cmd[0] = data;
				data = *(JTAG_UART_ptr);		 		// read the JTAG_UART data register
				if (data & 0x00008000)					// check RVALID to see if there is new data
				{
					data = data & 0x000000FF;			// the data is in the least significant byte
					while (1)
					{
						OSTimeDly(1);

						cmd[1] = data;
						data = *(JTAG_UART_ptr);		 		// read the JTAG_UART data register
						if (data & 0x00008000)					// check RVALID to see if there is new data
						{
							data = data & 0x000000FF;			// the data is in the least significant byte
							while ((char) data == 'r' || (char) data == 'p')
							{
								OSTimeDly(1);

								cmd[2] = data;
								break;
							}
						}
						break;
					}
				}
				break;
			}
			if (cmd[0] != 0 && cmd[1] != 0 && cmd[2] != 0)
			{
				ALT_SEM_PEND(display,0);

				//		printf("\n");
				//		for (i = 0; i < sizeof(cmd)/sizeof(cmd[0]); i++)
				//		{
				//			printf("%c", cmd[i]);
				//		}
				//		printf("\n");
				alt_u16 x;
				alt_u8 y;
				switch(cmd[1])
				{
				case 'd':
					x = 81;
					y= 66;
					break;
				case 'c':
					x = 81;
					y = 81;
					break;
				case 'e':
					x = 216;
					y = 66;
					break;
				case  'z':
					x = 216;
					y = 81;
					break;
				case 'h':
					x = 81;
					y = 104;
					break;
				case 'g':
					x = 81;
					y = 134;
					break;
				case 'l':
					x = 65;
					y = 118;
					break;
				case 'r':
					x = 96;
					y= 118;
					break;
				case 'f':
					x = 133;
					y= 118;
					break;
				case 's':
					x = 163;
					y = 118;
					break;
				case 'y':
					x = 216;
					y = 102;
					break;
				case 'x':
					x = 201;
					y = 117;
					break;
				case 'b':
					x = 231;
					y = 117;
					break;
				case 'a':
					x = 216;
					y = 132;
					break;
				default:
					x = 0;
					y = 0;
					break;


				}


				switch(cmd[2])
				{
				case 'p':
					drawrectangle(pixel_buffer_start,x,y,8,8,0xFFFF);
					int i;
					int err;
					playtone(5000,10);
					playtone(8000,10);
					playtone(5000,10);







					*(RED_LED_ptr) = (1<<3);
					break;
				case 'r':
					drawrectangle(pixel_buffer_start,x,y,8,8,0x0000);
					*(RED_LED_ptr) = (0<<3);
					break;
				}
				for (i = 0; i < sizeof(cmd)/sizeof(cmd[0]); i++)
				{
					cmd[i] = 0;
				}
				i = 0;
			}
			OSTimeDly(1);
			ALT_SEM_POST(display);

		}
	}
}
예제 #9
0
//Builds audio scan data for the Robot 36.
//Applicable to only Robot 36.
void buildaudio_r36 () {

    uint16_t x , y , k ;
    uint32_t pixel1, pixel2;
    uint8_t r1, g1, b1, r2, g2, b2, avgr, avgg, avgb;
    uint8_t y1[320], y2[320], ry[320], by[320];

    printf( "Adding image to audio data.\n" ) ;
    
    for ( y=0 ; y<240 ; y+=2 ) {
    
        // read image data
        for ( x=0 ; x<320 ; x++ ) {

            //even line pixel
            pixel1 = gdImageGetTrueColorPixel( g_imgp, x, y ) ;
            //odd line pixel 
            pixel2 = gdImageGetTrueColorPixel( g_imgp, x, y+1) ;
            
            // get color data
            r1 = gdTrueColorGetRed( pixel1 ); //first line (even) of red intensities
            r2 = gdTrueColorGetRed( pixel2 ); //second line (odd) of red intensities
            g1 = gdTrueColorGetGreen( pixel1 );
            g2 = gdTrueColorGetGreen( pixel2 );
            b1 = gdTrueColorGetBlue( pixel1 );
            b2 = gdTrueColorGetBlue( pixel2 );

            avgr = (uint8_t)( ((uint16_t)r1 + (uint16_t)r2) / 2 );

            avgg = (uint8_t)( ((uint16_t)g1 + (uint16_t)g2) / 2 );

            avgb = (uint8_t)( ((uint16_t)b1 + (uint16_t)b2) / 2 );

            //Y value of even lines 
            y1[x] = 16.0 + (0.003906 * ((65.738 * (float)r1) + (129.057 * (float)g1) + (25.064 * (float)b1)));
            //Y value of odd lines
            y2[x] = 16.0 + (0.003906 * ((65.738 * (float)r2) + (129.057 * (float)g2) + (25.064 * (float)b2)));
            //R-Y value of the average of the two lines, to be transmitted even scans
            ry[x] = 128.0 + (0.003906 * ((112.439 * (float)avgr) + (-94.154 * (float)avgg) + (-18.285 * (float)avgb)));
            //B-Y value of the average of the two lines, to be transmitted odd scans
            by[x] = 128.0 + (0.003906 * ((-37.945 * (float)avgr) + (-74.494 * (float)avgg) + (112.439 * (float)avgb)));

        }
        
        //begin robot 36 code

        //even lines    
        //sync
        playtone( 1200 , 9000 ) ;
        //porch 
        playtone( 1500 , 3000 ) ;
        
        //y scan, even, 88ms total, 320 points, 275us per pixel
        for ( k = 0; k < 320; k++ ) {
            playtone( toneval_yuv( y1[k] ) , 275 ) ;
        }
        
        //even line seperator
        playtone( 1500 , 4500 );
        //porch
        playtone( 1900 , 1500 );

        //R-Y scan, 44ms total, 320 points, 137.5us per pixel
        for ( k = 0; k < 320; k++ ) {
            playtone( toneval_yuv( ry[k] ) , 137.5 );
        }

        //odd lines
        // sync
        playtone( 1200 , 9000 ) ;
        // porch 
        playtone( 1500 , 3000 ) ;

        //y scan, odd, 88ms total, 320 points, 275us per pixel
        for ( k = 0; k < 320; k++ ) {
                playtone( toneval_yuv( y2[k] ) , 275 ) ;
        }

        //odd line seperator
        playtone( 2300 , 4500 );
        //porch
        playtone( 1900 , 1500 );

        //B-Y scan, 44ms total, 320 points, 137.5us per pixel
        for ( k = 0; k < 320; k++) {
            playtone( toneval_yuv( by[k] ) , 137.5);
        }
  
    }  // end for y
    
    printf( "Done adding image to audio data.\n" ) ;    
    
}  // end buildaudio_r36
예제 #10
0
void addvisheader() {
    printf( "Adding VIS header to audio data.\n" ) ;
    
    // bit of silence
    playtone(    0 , 500000 ) ;   

    // attention tones
    playtone( 1900 , 100000 ) ; // you forgot this one
    playtone( 1500 , 100000 ) ;
    playtone( 1900 , 100000 ) ;
    playtone( 1500 , 100000 ) ;
    playtone( 2300 , 100000 ) ;
    playtone( 1500 , 100000 ) ;
    playtone( 2300 , 100000 ) ;
    playtone( 1500 , 100000 ) ;
                    
    // VIS lead, break, mid, start
    playtone( 1900 , 300000 ) ;
    playtone( 1200 ,  10000 ) ;
    playtone( 1900 , 300000 ) ;
    playtone( 1200 ,  30000 ) ;

    int i;
    int parity = 0;

    //write VIS data tones
    for(i = 1; i <= 64; i = i<<1) {
        if(i & g_protocol) { //digit is a 1
            playtone(1100, 30000);
            parity = !parity;
        }
        else {
            playtone(1300, 30000); //digit is a 0
        }
    }

    //parity bit
    if(parity) //odd parity
        playtone(1100, 30000);
    else       //even parity
        playtone(1300, 30000);

    // VIS stop
    playtone( 1200 ,  30000 ) ; 
    printf( "Done adding VIS header to audio data.\n" ) ;
        
} // end addvisheader