src/experiments/obrero/visualTracker/frame.cc
int Frame::ExtractAudio( void *sound ) const
{
	AudioInfo info;

	if ( GetAudioInfo( info ) == true )
	{
#ifdef HAVE_LIBDV

		int n, i;
		int16_t* s = ( int16_t * ) sound;

		dv_decode_full_audio( decoder, data, ( int16_t ** ) audio_buffers );
		for ( n = 0; n < info.samples; ++n )
			for ( i = 0; i < info.channels; i++ )
				*s++ = audio_buffers[ i ][ n ];

	}
	else
		info.samples = 0;

#else
		/* Collect the audio samples */
		char* s = ( char * ) sound;

		switch ( info.frequency )
		{
		case 32000:

			/* This is 4 channel audio */

			if ( IsPAL() )
			{
				short * p = ( short* ) sound;
				for ( int n = 0; n < info.samples; ++n )
				{
					register int r = ( ( unsigned char* ) data ) [ palmap_2ch1[ n ] + 1 ]; // LSB
					*p++ = compmap[ ( ( ( unsigned char* ) data ) [ palmap_2ch1[ n ] ] << 4 ) + ( r >> 4 ) ];   // MSB
					*p++ = compmap[ ( ( ( unsigned char* ) data ) [ palmap_2ch1[ n ] + 1 ] << 4 ) + ( r & 0x0f ) ];
				}


			}
			else
			{
				short* p = ( short* ) sound;
				for ( int n = 0; n < info.samples; ++n )
				{
					register int r = ( ( unsigned char* ) data ) [ ntscmap_2ch1[ n ] + 1 ]; // LSB
					*p++ = compmap[ ( ( ( unsigned char* ) data ) [ ntscmap_2ch1[ n ] ] << 4 ) + ( r >> 4 ) ];   // MSB
					*p++ = compmap[ ( ( ( unsigned char* ) data ) [ ntscmap_2ch1[ n ] + 1 ] << 4 ) + ( r & 0x0f ) ];
				}
			}
			break;

		case 44100:
		case 48000:

			/* this can be optimized significantly */

			if ( IsPAL() )
			{
				for ( int n = 0; n < info.samples; ++n )
				{
					*s++ = ( ( char* ) data ) [ palmap_ch1[ n ] + 1 ]; /* LSB */
					*s++ = ( ( char* ) data ) [ palmap_ch1[ n ] ];     /* MSB */
					*s++ = ( ( char* ) data ) [ palmap_ch2[ n ] + 1 ]; /* LSB */
					*s++ = ( ( char* ) data ) [ palmap_ch2[ n ] ];     /* MSB */
				}
			}
			else
			{
				for ( int n = 0; n < info.samples; ++n )
				{
					*s++ = ( ( char* ) data ) [ ntscmap_ch1[ n ] + 1 ]; /* LSB */
					*s++ = ( ( char* ) data ) [ ntscmap_ch1[ n ] ];     /* MSB */
					*s++ = ( ( char* ) data ) [ ntscmap_ch2[ n ] + 1 ]; /* LSB */
					*s++ = ( ( char* ) data ) [ ntscmap_ch2[ n ] ];     /* MSB */
				}
			}
			break;

			/* we can't handle any other format in the moment */

		default:
			info.samples = 0;
		}

	}
/** retrieves the audio data from the frame
 
    The DV frame contains audio data mixed in the video data blocks, 
    which can be retrieved easily using this function.
 
    The audio data consists of 16 bit, two channel audio samples (a 16 bit word for channel 1, followed by a 16 bit word
    for channel 2 etc.)
 
    \param sound a pointer to a buffer that holds the audio data
    \return the number of bytes put into the buffer, or 0 if no audio data could be retrieved */
retrieves the audio data from the frame
The DV frame contains audio data mixed in the video data blocks,
which can be retrieved easily using this function.

The audio data consists of 16 bit, two channel audio samples (a 16 bit word for channel 1, followed by a 16 bit word
for channel 2 etc.)

\param sound a pointer to a buffer that holds the audio data
\return the number of bytes put into the buffer, or 0 if no audio data could be retrieved
retrieves the audio data from the frame The DV frame contains audio data mixed in the video data blocks which can be retrieved easily using this function . The audio data consists of 16 bit two channel audio samples ( a 16 bit word for channel 1 followed by a 16 bit word for channel 2 etc . ) \ param sound a pointer to a buffer that holds the audio data \ return the number of bytes put into the buffer or 0 if no audio data could be retrieved
int Frame::ExtractAudio( void *sound ) const
{
	AudioInfo info;
	if ( GetAudioInfo( info ) == true )
	{
#ifdef HAVE_LIBDV
		int n, i;
		int16_t* s = ( int16_t * ) sound;
		dv_decode_full_audio( decoder, data, ( int16_t ** ) audio_buffers );
		for ( n = 0; n < info.samples; ++n )
			for ( i = 0; i < info.channels; i++ )
				*s++ = audio_buffers[ i ][ n ];
	}
	else
		info.samples = 0;
#else
		char* s = ( char * ) sound;
		switch ( info.frequency )
		{
		case 32000:
			if ( IsPAL() )
			{
				short * p = ( short* ) sound;
				for ( int n = 0; n < info.samples; ++n )
				{
					register int r = ( ( unsigned char* ) data ) [ palmap_2ch1[ n ] + 1 ]; 
					*p++ = compmap[ ( ( ( unsigned char* ) data ) [ palmap_2ch1[ n ] ] << 4 ) + ( r >> 4 ) ];   
					*p++ = compmap[ ( ( ( unsigned char* ) data ) [ palmap_2ch1[ n ] + 1 ] << 4 ) + ( r & 0x0f ) ];
				}
			}
			else
			{
				short* p = ( short* ) sound;
				for ( int n = 0; n < info.samples; ++n )
				{
					register int r = ( ( unsigned char* ) data ) [ ntscmap_2ch1[ n ] + 1 ]; 
					*p++ = compmap[ ( ( ( unsigned char* ) data ) [ ntscmap_2ch1[ n ] ] << 4 ) + ( r >> 4 ) ];   
					*p++ = compmap[ ( ( ( unsigned char* ) data ) [ ntscmap_2ch1[ n ] + 1 ] << 4 ) + ( r & 0x0f ) ];
				}
			}
			break;
		case 44100:
		case 48000:
			if ( IsPAL() )
			{
				for ( int n = 0; n < info.samples; ++n )
				{
					*s++ = ( ( char* ) data ) [ palmap_ch1[ n ] + 1 ]; 
					*s++ = ( ( char* ) data ) [ palmap_ch1[ n ] ];     
					*s++ = ( ( char* ) data ) [ palmap_ch2[ n ] + 1 ]; 
					*s++ = ( ( char* ) data ) [ palmap_ch2[ n ] ];     
				}
			}
			else
			{
				for ( int n = 0; n < info.samples; ++n )
				{
					*s++ = ( ( char* ) data ) [ ntscmap_ch1[ n ] + 1 ]; 
					*s++ = ( ( char* ) data ) [ ntscmap_ch1[ n ] ];     
					*s++ = ( ( char* ) data ) [ ntscmap_ch2[ n ] + 1 ]; 
					*s++ = ( ( char* ) data ) [ ntscmap_ch2[ n ] ];     
				}
			}
			break;
		default:
			info.samples = 0;
		}
	}
int Frame :: ExtractAudio ( void * sound ) const { AudioInfo info ; if ( GetAudioInfo ( info ) == true ) { #ifdef HAVE_LIBDV int n , i ; int16_t * s = ( int16_t * ) sound ; dv_decode_full_audio ( decoder , data , ( int16_t * * ) audio_buffers ) ; for ( n = 0 ; n < info . samples ; ++ n ) for ( i = 0 ; i < info . channels ; i ++ ) * s ++ = audio_buffers [ i ] [ n ] ; } else info . samples = 0 ; #else 
		char* s = ( char * ) sound; switch ( info . frequency ) { case 32000 : if ( IsPAL ( ) ) { short * p = ( short * ) sound ; for ( int n = 0 ; n < info . samples ; ++ n ) { register int r = ( ( unsigned char * ) data ) [ palmap_2ch1 [ n ] + 1 ] ; * p ++ = compmap [ ( ( ( unsigned char * ) data ) [ palmap_2ch1 [ n ] ] << 4 ) + ( r >> 4 ) ] ; * p ++ = compmap [ ( ( ( unsigned char * ) data ) [ palmap_2ch1 [ n ] + 1 ] << 4 ) + ( r & 0x0f ) ] ; } } else { short * p = ( short * ) sound ; for ( int n = 0 ; n < info . samples ; ++ n ) { register int r = ( ( unsigned char * ) data ) [ ntscmap_2ch1 [ n ] + 1 ] ; * p ++ = compmap [ ( ( ( unsigned char * ) data ) [ ntscmap_2ch1 [ n ] ] << 4 ) + ( r >> 4 ) ] ; * p ++ = compmap [ ( ( ( unsigned char * ) data ) [ ntscmap_2ch1 [ n ] + 1 ] << 4 ) + ( r & 0x0f ) ] ; } } break ; case 44100 : case 48000 : if ( IsPAL ( ) ) { for ( int n = 0 ; n < info . samples ; ++ n ) { * s ++ = ( ( char * ) data ) [ palmap_ch1 [ n ] + 1 ] ; * s ++ = ( ( char * ) data ) [ palmap_ch1 [ n ] ] ; * s ++ = ( ( char * ) data ) [ palmap_ch2 [ n ] + 1 ] ; * s ++ = ( ( char * ) data ) [ palmap_ch2 [ n ] ] ; } } else { for ( int n = 0 ; n < info . samples ; ++ n ) { * s ++ = ( ( char * ) data ) [ ntscmap_ch1 [ n ] + 1 ] ; * s ++ = ( ( char * ) data ) [ ntscmap_ch1 [ n ] ] ; * s ++ = ( ( char * ) data ) [ ntscmap_ch2 [ n ] + 1 ] ; * s ++ = ( ( char * ) data ) [ ntscmap_ch2 [ n ] ] ; } } break ; default : info . samples = 0 ; } }
retrieves the audio data from the frame
The DV frame contains audio data mixed in the video data blocks,
which can be retrieved easily using this function.
retrieves the audio data from the frame The DV frame contains audio data mixed in the video data blocks which can be retrieved easily using this function .

		/* Collect the audio samples */ /* This is 4 channel audio */ // LSB // MSB // LSB // MSB /* this can be optimized significantly */ /* LSB */ /* MSB */ /* LSB */ /* MSB */ /* LSB */ /* MSB */ /* LSB */ /* MSB */ /* we can't handle any other format in the moment */