~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to modules/visualization/visual/effects.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * effects.c : Effects for the visualization system
3
3
 *****************************************************************************
4
4
 * Copyright (C) 2002-2009 the VideoLAN team
5
 
 * $Id: 267611ab55a7e137ade406b105f291ccdc2b1f7f $
 
5
 * $Id: a5726be86348e0f6031fba3ae1219772b32834e0 $
6
6
 *
7
7
 * Authors: Clément Stenac <zorglub@via.ecp.fr>
8
8
 *          Adrien Maglo <magsoft@videolan.org>
48
48
/*****************************************************************************
49
49
 * dummy_Run
50
50
 *****************************************************************************/
51
 
int dummy_Run( visual_effect_t * p_effect, aout_instance_t *p_aout,
52
 
               aout_buffer_t * p_buffer , picture_t * p_picture)
 
51
int dummy_Run( visual_effect_t * p_effect, vlc_object_t *p_aout,
 
52
               const block_t * p_buffer , picture_t * p_picture)
53
53
{
54
54
    VLC_UNUSED(p_effect); VLC_UNUSED(p_aout); VLC_UNUSED(p_buffer);
55
55
    VLC_UNUSED(p_picture);
59
59
/*****************************************************************************
60
60
 * spectrum_Run: spectrum analyser
61
61
 *****************************************************************************/
62
 
int spectrum_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
63
 
                 aout_buffer_t * p_buffer , picture_t * p_picture)
 
62
int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
 
63
                 const block_t * p_buffer , picture_t * p_picture)
64
64
{
65
65
    spectrum_data *p_data = p_effect->p_data;
66
66
    float p_output[FFT_BUFFER_SIZE];  /* Raw FFT Result  */
100
100
    int16_t  *p_buffs;                    /* int16_t converted buffer */
101
101
    int16_t  *p_s16_buff;                 /* int16_t converted buffer */
102
102
 
103
 
    p_s16_buff = malloc( p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
104
 
    if( !p_s16_buff )
105
 
        return -1;
106
 
 
107
 
    p_buffs = p_s16_buff;
108
 
    i_80_bands = config_GetInt ( p_aout, "visual-80-bands" );
109
 
    i_peak     = config_GetInt ( p_aout, "visual-peaks" );
110
 
 
111
 
    if( i_80_bands != 0)
112
 
    {
113
 
        xscale = xscale2;
114
 
        i_nb_bands = 80;
115
 
    }
116
 
    else
117
 
    {
118
 
        xscale = xscale1;
119
 
        i_nb_bands = 20;
120
 
    }
121
 
 
 
103
    /* Create p_data if needed */
122
104
    if( !p_data )
123
105
    {
124
106
        p_effect->p_data = p_data = malloc( sizeof( spectrum_data ) );
125
107
        if( !p_data )
126
 
        {
127
 
            free( p_s16_buff );
128
108
            return -1;
129
 
        }
130
109
 
131
110
        p_data->peaks = calloc( 80, sizeof(int) );
132
111
        p_data->prev_heights = calloc( 80, sizeof(int) );
133
112
 
134
 
        peaks = ( int * )p_data->peaks;
135
 
        prev_heights = ( int * )p_data->prev_heights;
 
113
        p_data->i_prev_nb_samples = 0;
 
114
        p_data->p_prev_s16_buff = NULL;
 
115
    }
 
116
    peaks = (int *)p_data->peaks;
 
117
    prev_heights = (int *)p_data->prev_heights;
 
118
 
 
119
    /* Allocate the buffer only if the number of samples change */
 
120
    if( p_buffer->i_nb_samples != p_data->i_prev_nb_samples )
 
121
    {
 
122
        free( p_data->p_prev_s16_buff );
 
123
        p_data->p_prev_s16_buff = malloc( p_buffer->i_nb_samples *
 
124
                                          p_effect->i_nb_chans *
 
125
                                          sizeof(int16_t));
 
126
        p_data->i_prev_nb_samples = p_buffer->i_nb_samples;
 
127
        if( !p_data->p_prev_s16_buff )
 
128
            return -1;
 
129
    }
 
130
    p_buffs = p_s16_buff = p_data->p_prev_s16_buff;
 
131
 
 
132
    i_80_bands = var_InheritInteger( p_aout, "visual-80-bands" );
 
133
    i_peak     = var_InheritInteger( p_aout, "visual-peaks" );
 
134
 
 
135
    if( i_80_bands != 0)
 
136
    {
 
137
        xscale = xscale2;
 
138
        i_nb_bands = 80;
136
139
    }
137
140
    else
138
141
    {
139
 
        peaks = (int *)p_data->peaks;
140
 
        prev_heights = (int *)p_data->prev_heights;
 
142
        xscale = xscale1;
 
143
        i_nb_bands = 20;
141
144
    }
142
145
 
143
 
 
144
146
    height = malloc( i_nb_bands * sizeof(int) );
145
147
    if( !height )
146
148
    {
147
 
        free( p_s16_buff );
148
149
        return -1;
149
150
    }
150
151
    /* Convert the buffer to int16_t  */
163
164
    if( !p_state)
164
165
    {
165
166
        free( height );
166
 
        free( p_s16_buff );
167
167
        msg_Err(p_aout,"unable to initialize FFT transform");
168
168
        return -1;
169
169
    }
327
327
 
328
328
    fft_close( p_state );
329
329
 
330
 
    free( p_s16_buff );
331
330
    free( height );
332
331
 
333
332
    return 0;
337
336
/*****************************************************************************
338
337
 * spectrometer_Run: derivative spectrum analysis
339
338
 *****************************************************************************/
340
 
int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
341
 
                 aout_buffer_t * p_buffer , picture_t * p_picture)
 
339
int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
 
340
                     const block_t * p_buffer , picture_t * p_picture)
342
341
{
343
342
#define Y(R,G,B) ((uint8_t)( (R * .299) + (G * .587) + (B * .114) ))
344
343
#define U(R,G,B) ((uint8_t)( (R * -.169) + (G * -.332) + (B * .500) + 128 ))
387
386
    fft_state *p_state;                 /* internal FFT data */
388
387
 
389
388
    int i , j , k;
390
 
    int i_line;
 
389
    int i_line = 0;
391
390
    int16_t p_dest[FFT_BUFFER_SIZE];      /* Adapted FFT result */
392
391
    int16_t p_buffer1[FFT_BUFFER_SIZE];   /* Buffer on which we perform
393
392
                                             the FFT (first channel) */
397
396
    int16_t  *p_buffs;                    /* int16_t converted buffer */
398
397
    int16_t  *p_s16_buff;                /* int16_t converted buffer */
399
398
 
400
 
    i_line = 0;
401
 
 
402
 
    p_s16_buff = malloc( p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t) );
403
 
    if( !p_s16_buff )
404
 
        return -1;
405
 
 
406
 
    p_buffs = p_s16_buff;
407
 
    i_original     = config_GetInt ( p_aout, "spect-show-original" );
408
 
    i_80_bands     = config_GetInt ( p_aout, "spect-80-bands" );
409
 
    i_separ        = config_GetInt ( p_aout, "spect-separ" );
410
 
    i_amp          = config_GetInt ( p_aout, "spect-amp" );
411
 
    i_peak         = config_GetInt ( p_aout, "spect-show-peaks" );
412
 
    i_show_base    = config_GetInt ( p_aout, "spect-show-base" );
413
 
    i_show_bands   = config_GetInt ( p_aout, "spect-show-bands" );
414
 
    i_rad          = config_GetInt ( p_aout, "spect-radius" );
415
 
    i_sections     = config_GetInt ( p_aout, "spect-sections" );
416
 
    i_extra_width  = config_GetInt ( p_aout, "spect-peak-width" );
417
 
    i_peak_height  = config_GetInt ( p_aout, "spect-peak-height" );
418
 
    color1         = config_GetInt ( p_aout, "spect-color" );
 
399
    /* Create the data struct if needed */
 
400
    spectrometer_data *p_data = p_effect->p_data;
 
401
    if( !p_data )
 
402
    {
 
403
        p_data = malloc( sizeof(spectrometer_data) );
 
404
        if( !p_data )
 
405
            return -1;
 
406
        p_data->peaks = calloc( 80, sizeof(int) );
 
407
        if( !p_data->peaks )
 
408
        {
 
409
            free( p_data );
 
410
            return -1;
 
411
        }
 
412
        p_data->i_prev_nb_samples = 0;
 
413
        p_data->p_prev_s16_buff = NULL;
 
414
        p_effect->p_data = (void*)p_data;
 
415
    }
 
416
    peaks = p_data->peaks;
 
417
 
 
418
    /* Allocate the buffer only if the number of samples change */
 
419
    if( p_buffer->i_nb_samples != p_data->i_prev_nb_samples )
 
420
    {
 
421
        free( p_data->p_prev_s16_buff );
 
422
        p_data->p_prev_s16_buff = malloc( p_buffer->i_nb_samples *
 
423
                                          p_effect->i_nb_chans *
 
424
                                          sizeof(int16_t));
 
425
        p_data->i_prev_nb_samples = p_buffer->i_nb_samples;
 
426
        if( !p_data->p_prev_s16_buff )
 
427
            return -1;
 
428
    }
 
429
    p_buffs = p_s16_buff = p_data->p_prev_s16_buff;
 
430
 
 
431
    i_original     = var_InheritInteger( p_aout, "spect-show-original" );
 
432
    i_80_bands     = var_InheritInteger( p_aout, "spect-80-bands" );
 
433
    i_separ        = var_InheritInteger( p_aout, "spect-separ" );
 
434
    i_amp          = var_InheritInteger( p_aout, "spect-amp" );
 
435
    i_peak         = var_InheritInteger( p_aout, "spect-show-peaks" );
 
436
    i_show_base    = var_InheritInteger( p_aout, "spect-show-base" );
 
437
    i_show_bands   = var_InheritInteger( p_aout, "spect-show-bands" );
 
438
    i_rad          = var_InheritInteger( p_aout, "spect-radius" );
 
439
    i_sections     = var_InheritInteger( p_aout, "spect-sections" );
 
440
    i_extra_width  = var_InheritInteger( p_aout, "spect-peak-width" );
 
441
    i_peak_height  = var_InheritInteger( p_aout, "spect-peak-height" );
 
442
    color1         = var_InheritInteger( p_aout, "spect-color" );
419
443
 
420
444
    if( i_80_bands != 0)
421
445
    {
428
452
        i_nb_bands = 20;
429
453
    }
430
454
 
431
 
    if( !p_effect->p_data )
432
 
    {
433
 
        p_effect->p_data=(void *)malloc( 80 * sizeof(int) );
434
 
        if( !p_effect->p_data )
435
 
        {
436
 
            free( p_s16_buff );
437
 
            return -1;
438
 
        }
439
 
        peaks = (int *)p_effect->p_data;
440
 
        for( i = 0 ; i < i_nb_bands ; i++ )
441
 
        {
442
 
           peaks[i] = 0;
443
 
        }
444
 
    }
445
 
    else
446
 
    {
447
 
        peaks =(int *)p_effect->p_data;
448
 
    }
449
 
 
450
 
    height = (int *)malloc( i_nb_bands * sizeof(int) );
 
455
    height = malloc( i_nb_bands * sizeof(int) );
451
456
    if( !height)
452
 
    {
453
 
        free( p_effect->p_data );
454
 
        free( p_s16_buff );
455
457
        return -1;
456
 
    }
457
458
 
458
459
    /* Convert the buffer to int16_t  */
459
460
    /* Pasted from float32tos16.c */
472
473
    {
473
474
        msg_Err(p_aout,"unable to initialize FFT transform");
474
475
        free( height );
475
 
        free( p_effect->p_data );
476
 
        free( p_s16_buff );
477
476
        return -1;
478
477
    }
479
478
    p_buffs = p_s16_buff;
487
486
            p_buffs = p_s16_buff;
488
487
    }
489
488
    fft_perform( p_buffer1, p_output, p_state);
490
 
    for(i= 0; i< FFT_BUFFER_SIZE ; i++ )
491
 
        p_dest[i] = ( (int) sqrt( p_output [ i ] ) ) >> 8;
 
489
    for(i = 0; i < FFT_BUFFER_SIZE; i++)
 
490
    {
 
491
        int sqrti = sqrt(p_output[i]);
 
492
        p_dest[i] = sqrti >> 8;
 
493
    }
492
494
 
493
495
    i_nb_bands *= i_sections;
494
496
 
504
506
        y >>=7;/* remove some noise */
505
507
        if( y != 0)
506
508
        {
507
 
            height[i] = (int)log(y)* y_scale;
508
 
               if(height[i] > 150)
509
 
                  height[i] = 150;
 
509
            int logy = log(y);
 
510
            height[i] = logy * y_scale;
 
511
            if(height[i] > 150)
 
512
                height[i] = 150;
510
513
        }
511
514
        else
512
515
        {
781
784
 
782
785
    fft_close( p_state );
783
786
 
784
 
    free( p_s16_buff );
785
787
    free( height );
786
788
 
787
789
    return 0;
791
793
/*****************************************************************************
792
794
 * scope_Run: scope effect
793
795
 *****************************************************************************/
794
 
int scope_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
795
 
              aout_buffer_t * p_buffer , picture_t * p_picture)
 
796
int scope_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
 
797
              const block_t * p_buffer , picture_t * p_picture)
796
798
{
797
799
    VLC_UNUSED(p_aout);
 
800
 
798
801
    int i_index;
799
802
    float *p_sample ;
800
803
    uint8_t *ppp_area[2][3];
801
804
 
802
 
 
803
 
        for( i_index = 0 ; i_index < 2 ; i_index++ )
 
805
    for( i_index = 0 ; i_index < 2 ; i_index++ )
 
806
    {
 
807
        for( int j = 0 ; j < 3 ; j++ )
804
808
        {
805
 
            int j;
806
 
            for( j = 0 ; j < 3 ; j++ )
807
 
            {
808
 
                ppp_area[i_index][j] =
809
 
                    p_picture->p[j].p_pixels + i_index * p_picture->p[j].i_lines
810
 
                                / 2 * p_picture->p[j].i_pitch;
811
 
            }
 
809
            ppp_area[i_index][j] =
 
810
                p_picture->p[j].p_pixels + i_index * p_picture->p[j].i_lines
 
811
                / 2 * p_picture->p[j].i_pitch;
812
812
        }
813
 
 
814
 
        for( i_index = 0, p_sample = (float *)p_buffer->p_buffer;
815
 
             i_index < __MIN( p_effect->i_width, p_buffer->i_nb_samples );
816
 
             i_index++ )
817
 
        {
818
 
            uint8_t i_value;
819
 
 
820
 
            /* Left channel */
821
 
            i_value =  p_sample[p_effect->i_idx_left] * 127;
822
 
            *(ppp_area[0][0]
823
 
               + p_picture->p[0].i_pitch * i_index / p_effect->i_width
824
 
               + p_picture->p[0].i_lines * i_value / 512
825
 
                   * p_picture->p[0].i_pitch) = 0xbf;
826
 
            *(ppp_area[0][1]
 
813
    }
 
814
 
 
815
    for( i_index = 0, p_sample = (float *)p_buffer->p_buffer;
 
816
            i_index < __MIN( p_effect->i_width, (int)p_buffer->i_nb_samples );
 
817
            i_index++ )
 
818
    {
 
819
        uint8_t i_value;
 
820
 
 
821
        /* Left channel */
 
822
        i_value =  p_sample[p_effect->i_idx_left] * 127;
 
823
        *(ppp_area[0][0]
 
824
                + p_picture->p[0].i_pitch * i_index / p_effect->i_width
 
825
                + p_picture->p[0].i_lines * i_value / 512
 
826
                * p_picture->p[0].i_pitch) = 0xbf;
 
827
        *(ppp_area[0][1]
827
828
                + p_picture->p[1].i_pitch * i_index / p_effect->i_width
828
829
                + p_picture->p[1].i_lines * i_value / 512
829
 
                   * p_picture->p[1].i_pitch) = 0xff;
830
 
 
831
 
 
832
 
           /* Right channel */
833
 
           i_value = p_sample[p_effect->i_idx_right] * 127;
834
 
           *(ppp_area[1][0]
835
 
              + p_picture->p[0].i_pitch * i_index / p_effect->i_width
836
 
              + p_picture->p[0].i_lines * i_value / 512
837
 
                 * p_picture->p[0].i_pitch) = 0x9f;
838
 
           *(ppp_area[1][2]
839
 
              + p_picture->p[2].i_pitch * i_index / p_effect->i_width
840
 
              + p_picture->p[2].i_lines * i_value / 512
 
830
                * p_picture->p[1].i_pitch) = 0xff;
 
831
 
 
832
 
 
833
        /* Right channel */
 
834
        i_value = p_sample[p_effect->i_idx_right] * 127;
 
835
        *(ppp_area[1][0]
 
836
                + p_picture->p[0].i_pitch * i_index / p_effect->i_width
 
837
                + p_picture->p[0].i_lines * i_value / 512
 
838
                * p_picture->p[0].i_pitch) = 0x9f;
 
839
        *(ppp_area[1][2]
 
840
                + p_picture->p[2].i_pitch * i_index / p_effect->i_width
 
841
                + p_picture->p[2].i_lines * i_value / 512
841
842
                * p_picture->p[2].i_pitch) = 0xdd;
842
843
 
843
 
           p_sample += p_effect->i_nb_chans;
844
 
        }
845
 
        return 0;
 
844
        p_sample += p_effect->i_nb_chans;
 
845
    }
 
846
    return 0;
846
847
}
847
848
 
848
849
 
849
850
/*****************************************************************************
850
851
 * vuMeter_Run: vu meter effect
851
852
 *****************************************************************************/
852
 
int vuMeter_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
853
 
              aout_buffer_t * p_buffer , picture_t * p_picture)
 
853
int vuMeter_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
 
854
                const block_t * p_buffer , picture_t * p_picture)
854
855
{
855
 
        VLC_UNUSED(p_aout);
856
 
        int i, j;
857
 
        float i_value_l = 0;
858
 
        float i_value_r = 0;
859
 
 
860
 
        /* Compute the peack values */
861
 
        for ( i = 0 ; i < p_buffer->i_nb_samples; i++ )
862
 
        {
863
 
                const float *p_sample = (float *)p_buffer->p_buffer;
864
 
                float ch;
865
 
 
866
 
                ch = p_sample[p_effect->i_idx_left] * 256;
867
 
                if (ch > i_value_l)
868
 
                        i_value_l = ch;
869
 
 
870
 
                ch = p_sample[p_effect->i_idx_right] * 256;
871
 
                if (ch > i_value_r)
872
 
                        i_value_r = ch;
873
 
 
874
 
                p_sample += p_effect->i_nb_chans;
875
 
        }
876
 
 
877
 
        i_value_l = abs(i_value_l);
878
 
        i_value_r = abs(i_value_r);
879
 
 
880
 
        /* Stay under maximum value admited */
881
 
        if ( i_value_l > 200 * M_PI_2 )
882
 
                i_value_l = 200 * M_PI_2;
883
 
        if ( i_value_r > 200 * M_PI_2 )
884
 
                i_value_r = 200 * M_PI_2;
885
 
 
886
 
        float *i_value;
887
 
 
888
 
        if( !p_effect->p_data )
889
 
        {
890
 
                /* Allocate memory to save hand positions */
891
 
                p_effect->p_data = (void *)malloc( 2 * sizeof(float) );
892
 
                i_value = p_effect->p_data;
893
 
                i_value[0] = i_value_l;
894
 
                i_value[1] = i_value_r;
895
 
        }
896
 
        else
897
 
        {
898
 
                /* Make the hands go down slowly if the current values are slower
899
 
                than the previous */
900
 
                i_value = p_effect->p_data;
901
 
 
902
 
                if ( i_value_l > i_value[0] - 6 )
903
 
                        i_value[0] = i_value_l;
904
 
                else
905
 
                        i_value[0] = i_value[0] - 6;
906
 
 
907
 
                if ( i_value_r > i_value[1] - 6 )
908
 
                        i_value[1] = i_value_r;
909
 
                else
910
 
                        i_value[1] = i_value[1] - 6;
911
 
        }
912
 
 
913
 
        int x, y, k;
914
 
        float teta;
915
 
        float teta_grad;
916
 
 
917
 
        for ( j = 0; j < 2; j++ )
918
 
        {
919
 
                /* Draw the two scales */
920
 
                k = 0;
921
 
                teta_grad = GRAD_ANGLE_MIN;
922
 
                for ( teta = -M_PI_4; teta <= M_PI_4; teta = teta + 0.003 )
923
 
                {
924
 
                        for ( i = 140; i <= 150; i++ )
925
 
                        {
926
 
                                y = i * cos(teta) + 20;
927
 
                                x = i * sin(teta) + 150 + 240 * j;
928
 
                                /* Compute the last color for the gradation */
929
 
                                if (teta >= teta_grad + GRAD_INCR && teta_grad <= GRAD_ANGLE_MAX)
930
 
                                {
931
 
                                        teta_grad = teta_grad + GRAD_INCR;
932
 
                                        k = k + 5;
933
 
                                }
934
 
                                *(p_picture->p[0].p_pixels +
935
 
                                 (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
936
 
                                 + x ) = 0x45;
937
 
                                *(p_picture->p[1].p_pixels +
938
 
                                 (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
939
 
                                 + x / 2 ) = 0x0;
940
 
                                *(p_picture->p[2].p_pixels +
941
 
                                 (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
942
 
                                 + x / 2 ) = 0x4D + k;
943
 
                        }
944
 
                }
945
 
 
946
 
                /* Draw the two hands */
947
 
                teta = (float)i_value[j] / 200 - M_PI_4;
948
 
                for ( i = 0; i <= 150; i++ )
949
 
                {
950
 
                        y = i * cos(teta) + 20;
951
 
                        x = i * sin(teta) + 150 + 240 * j;
952
 
                        *(p_picture->p[0].p_pixels +
953
 
                         (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
954
 
                         + x ) = 0xAD;
955
 
                        *(p_picture->p[1].p_pixels +
956
 
                         (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
957
 
                         + x / 2 ) = 0xFC;
958
 
                        *(p_picture->p[2].p_pixels +
959
 
                         (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
960
 
                         + x / 2 ) = 0xAC;
961
 
                }
962
 
 
963
 
                /* Draw the hand bases */
964
 
                for ( teta = -M_PI_2; teta <= M_PI_2 + 0.01; teta = teta + 0.003 )
965
 
                {
966
 
                        for ( i = 0; i < 10; i++ )
967
 
                        {
968
 
                                y = i * cos(teta) + 20;
969
 
                                x = i * sin(teta) + 150 + 240 * j;
970
 
                                *(p_picture->p[0].p_pixels +
971
 
                                 (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
972
 
                                 + x ) = 0xFF;
973
 
                                *(p_picture->p[1].p_pixels +
974
 
                                 (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
975
 
                                 + x / 2 ) = 0x80;
976
 
                                *(p_picture->p[2].p_pixels +
977
 
                                 (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
978
 
                                 + x / 2 ) = 0x80;
979
 
                        }
980
 
                }
981
 
 
982
 
        }
983
 
 
984
 
        return 0;
 
856
    VLC_UNUSED(p_aout);
 
857
    float i_value_l = 0;
 
858
    float i_value_r = 0;
 
859
 
 
860
    /* Compute the peack values */
 
861
    for ( unsigned i = 0 ; i < p_buffer->i_nb_samples; i++ )
 
862
    {
 
863
        const float *p_sample = (float *)p_buffer->p_buffer;
 
864
        float ch;
 
865
 
 
866
        ch = p_sample[p_effect->i_idx_left] * 256;
 
867
        if (ch > i_value_l)
 
868
            i_value_l = ch;
 
869
 
 
870
        ch = p_sample[p_effect->i_idx_right] * 256;
 
871
        if (ch > i_value_r)
 
872
            i_value_r = ch;
 
873
 
 
874
        p_sample += p_effect->i_nb_chans;
 
875
    }
 
876
 
 
877
    i_value_l = abs(i_value_l);
 
878
    i_value_r = abs(i_value_r);
 
879
 
 
880
    /* Stay under maximum value admited */
 
881
    if ( i_value_l > 200 * M_PI_2 )
 
882
        i_value_l = 200 * M_PI_2;
 
883
    if ( i_value_r > 200 * M_PI_2 )
 
884
        i_value_r = 200 * M_PI_2;
 
885
 
 
886
    float *i_value;
 
887
 
 
888
    if( !p_effect->p_data )
 
889
    {
 
890
        /* Allocate memory to save hand positions */
 
891
        p_effect->p_data = malloc( 2 * sizeof(float) );
 
892
        i_value = p_effect->p_data;
 
893
        i_value[0] = i_value_l;
 
894
        i_value[1] = i_value_r;
 
895
    }
 
896
    else
 
897
    {
 
898
        /* Make the hands go down slowly if the current values are slower
 
899
           than the previous */
 
900
        i_value = p_effect->p_data;
 
901
 
 
902
        if ( i_value_l > i_value[0] - 6 )
 
903
            i_value[0] = i_value_l;
 
904
        else
 
905
            i_value[0] = i_value[0] - 6;
 
906
 
 
907
        if ( i_value_r > i_value[1] - 6 )
 
908
            i_value[1] = i_value_r;
 
909
        else
 
910
            i_value[1] = i_value[1] - 6;
 
911
    }
 
912
 
 
913
    int x, y;
 
914
    float teta;
 
915
    float teta_grad;
 
916
 
 
917
    int start_x = p_effect->i_width / 2 - 120; /* i_width.min = 532 (visual.c) */
 
918
 
 
919
    for ( int j = 0; j < 2; j++ )
 
920
    {
 
921
        /* Draw the two scales */
 
922
        int k = 0;
 
923
        teta_grad = GRAD_ANGLE_MIN;
 
924
        for ( teta = -M_PI_4; teta <= M_PI_4; teta = teta + 0.003 )
 
925
        {
 
926
            for ( unsigned i = 140; i <= 150; i++ )
 
927
            {
 
928
                y = i * cos(teta) + 20;
 
929
                x = i * sin(teta) + start_x + 240 * j;
 
930
                /* Compute the last color for the gradation */
 
931
                if (teta >= teta_grad + GRAD_INCR && teta_grad <= GRAD_ANGLE_MAX)
 
932
                {
 
933
                    teta_grad = teta_grad + GRAD_INCR;
 
934
                    k = k + 5;
 
935
                }
 
936
                *(p_picture->p[0].p_pixels +
 
937
                        (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
 
938
                        + x ) = 0x45;
 
939
                *(p_picture->p[1].p_pixels +
 
940
                        (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
 
941
                        + x / 2 ) = 0x0;
 
942
                *(p_picture->p[2].p_pixels +
 
943
                        (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
 
944
                        + x / 2 ) = 0x4D + k;
 
945
            }
 
946
        }
 
947
 
 
948
        /* Draw the two hands */
 
949
        teta = (float)i_value[j] / 200 - M_PI_4;
 
950
        for ( int i = 0; i <= 150; i++ )
 
951
        {
 
952
            y = i * cos(teta) + 20;
 
953
            x = i * sin(teta) + start_x + 240 * j;
 
954
            *(p_picture->p[0].p_pixels +
 
955
                    (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
 
956
                    + x ) = 0xAD;
 
957
            *(p_picture->p[1].p_pixels +
 
958
                    (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
 
959
                    + x / 2 ) = 0xFC;
 
960
            *(p_picture->p[2].p_pixels +
 
961
                    (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
 
962
                    + x / 2 ) = 0xAC;
 
963
        }
 
964
 
 
965
        /* Draw the hand bases */
 
966
        for ( teta = -M_PI_2; teta <= M_PI_2 + 0.01; teta = teta + 0.003 )
 
967
        {
 
968
            for ( int i = 0; i < 10; i++ )
 
969
            {
 
970
                y = i * cos(teta) + 20;
 
971
                x = i * sin(teta) + start_x + 240 * j;
 
972
                *(p_picture->p[0].p_pixels +
 
973
                        (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
 
974
                        + x ) = 0xFF;
 
975
                *(p_picture->p[1].p_pixels +
 
976
                        (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
 
977
                        + x / 2 ) = 0x80;
 
978
                *(p_picture->p[2].p_pixels +
 
979
                        (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
 
980
                        + x / 2 ) = 0x80;
 
981
            }
 
982
        }
 
983
 
 
984
    }
 
985
 
 
986
    return 0;
985
987
}