This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 27th, 2010  |  syntax: Diff  |  size: 5.64 KB  |  views: 160  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/apps/plugins/fft/fft.c b/apps/plugins/fft/fft.c
  2. index e62c919..8d21ad4 100644
  3. --- a/apps/plugins/fft/fft.c
  4. +++ b/apps/plugins/fft/fft.c
  5. @@ -18,6 +18,18 @@
  6.   * KIND, either express or implied.
  7.   *
  8.   ****************************************************************************/
  9. +
  10. +/****************************************************************************
  11. + * OVERVIEW OF THE PLUGIN
  12. + *
  13. + * There are two input modes available:
  14. + * 1) Playback mode - analyzes the currently playing track
  15. + * 2) Recording mode (if supported by hardware) - analyzes input from
  16. + *    user-selected source (mic, linein, spdif, taken from Recording Settings)
  17. + *
  18. + * Recording mode is triggered if playback is stopped.
  19. + *
  20. + ****************************************************************************/
  21.  #include "plugin.h"
  22.  
  23.  #include "lib/helper.h"
  24. @@ -228,6 +240,14 @@ GREY_INFO_STRUCT
  25.  #include "_kiss_fft_guts.h" /* sizeof(struct kiss_fft_state) */
  26.  #include "const.h"
  27.  
  28. +#if (REC_SAMPR_CAPS & SAMPR_CAP_44)
  29. +#define SAMPLE_RATE     SAMPR_44
  30. +#elif (REC_SAMPR_CAPS & SAMPR_CAP_22)
  31. +#define SAMPLE_RATE     SAMPR_22
  32. +#elif (REC_SAMPR_CAPS & SAMPR_CAP_11)
  33. +#define SAMPLE_RATE     SAMPR_11
  34. +#endif
  35. +
  36.  #if (LCD_WIDTH < LCD_HEIGHT)
  37.  #define LCD_SIZE LCD_HEIGHT
  38.  #else
  39. @@ -1072,15 +1092,65 @@ void input_thread_entry(void)
  40.         }
  41.  }
  42.  
  43. +#ifdef HAVE_RECORDING
  44. +static int recording_entry(int status)
  45. +{
  46. +    if (status >= 0)
  47. +        input_thread_has_data = true;
  48. +    else
  49. +        input_thread_has_data = false;
  50. +
  51. +    rb->pcm_stop_recording();
  52. +
  53. +    rb->logf("FFT: More data available, status: %d", status);    
  54. +    return -1;
  55. +}
  56. +
  57. +void recording_init(void)
  58. +{
  59. +    rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);  
  60. +    rb->audio_set_input_source(rb->global_settings->rec_source, SRCF_RECORDING);
  61. +
  62. +    /* set to maximum gain */
  63. +    if (rb->global_settings->rec_source == AUDIO_SRC_MIC)
  64. +        rb->audio_set_recording_gain(rb->global_settings->rec_mic_gain,
  65. +                rb->global_settings->rec_mic_gain,
  66. +                AUDIO_GAIN_MIC);
  67. +    else
  68. +        rb->audio_set_recording_gain(rb->global_settings->rec_left_gain,
  69. +                rb->global_settings->rec_right_gain,
  70. +                AUDIO_GAIN_LINEIN);
  71. +
  72. +    rb->pcm_set_frequency(SAMPLE_RATE);
  73. +    rb->pcm_apply_settings();
  74. +
  75. +    rb->pcm_init_recording();
  76. +    rb->logf("FFT: Recording initialized");
  77. +}
  78. +#endif
  79. +
  80.  
  81.  enum plugin_status plugin_start(const void* parameter)
  82.  {
  83.      (void) parameter;
  84. +
  85. +#ifdef HAVE_RECORDING
  86. +    bool recording_mode = false;
  87. +#endif
  88.      if ((rb->audio_status() & AUDIO_STATUS_PLAY) == 0)
  89.      {
  90. +#ifdef HAVE_RECORDING
  91. +        rb->splash(HZ * 2, "No track playing. Input mode.");
  92. +        recording_mode = true;
  93. +        recording_init();
  94. +#else
  95.          rb->splash(HZ * 2, "No track playing. Exiting..");
  96.          return PLUGIN_OK;
  97. +#endif
  98.      }
  99. +
  100. +    rb->lcd_clear_display();
  101. +
  102.  #ifndef HAVE_LCD_COLOR
  103.      unsigned char *gbuf;
  104.      size_t  gbuf_size = 0;
  105. @@ -1127,25 +1197,51 @@ enum plugin_status plugin_start(const void* parameter)
  106.  
  107.      if (state == 0)
  108.      {
  109. -        DEBUGF("needed data: %i", (int) size);
  110. +        DEBUGF("needed data: %l", (int) size);
  111.          return PLUGIN_ERROR;
  112.      }
  113. +    unsigned int input_thread = 0;
  114. +#ifdef HAVE_RECORDING
  115. +    if (recording_mode)
  116. +        rb->pcm_record_data(recording_entry, (void *) input,
  117. +                (size_t) ARRAYSIZE_IN * sizeof(kiss_fft_scalar));
  118. +    else
  119. +#endif
  120. +        input_thread = rb->create_thread(&input_thread_entry, thread_stack, sizeof(thread_stack), 0, "fft input thread" IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU));
  121.        
  122. -       unsigned int input_thread = rb->create_thread(&input_thread_entry, thread_stack, sizeof(thread_stack), 0, "fft input thread" IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU));
  123.         rb->yield();
  124.      while (run)
  125.      {
  126. +        if(!recording_mode)
  127.                 rb->mutex_lock(&input_mutex);
  128.                 if(!input_thread_has_data)
  129.                 {
  130.                         /* Make sure the input thread has started before doing anything else */
  131. +            if(!recording_mode)
  132.                         rb->mutex_unlock(&input_mutex);
  133. +            else
  134. +            {
  135. +                if(rb->button_get(false) == FFT_QUIT)
  136. +                {
  137. +                    rb->logf("Aborting wait-for-data cycle");
  138. +                    run = false;
  139. +                    break;
  140. +                }
  141. +            }
  142. +
  143.                         rb->yield();
  144.                         continue;
  145.                 }
  146.                 apply_window_func(graph_settings.window_func);
  147.                 FFT_FFT(state, input, output);
  148.  
  149. +        /* We're done with the input */
  150. +        if(recording_mode)
  151. +        {
  152. +            rb->logf("FFT: call pcm_record_data from main loop");
  153. +            rb->pcm_record_data(recording_entry, (void *) input, (size_t) ARRAYSIZE_IN * sizeof(kiss_fft_scalar));
  154. +        }
  155. +
  156.                 if(changed_window)
  157.                 {
  158.                         draw(window_text[graph_settings.window_func]);
  159. @@ -1155,6 +1251,7 @@ enum plugin_status plugin_start(const void* parameter)
  160.                         draw(0);
  161.  
  162.                 input_thread_has_data = false;
  163. +        if(!recording_mode)
  164.          rb->mutex_unlock(&input_mutex);
  165.                 rb->yield();
  166.  
  167. @@ -1203,11 +1300,21 @@ enum plugin_status plugin_start(const void* parameter)
  168.          }
  169.      }
  170.        
  171. +#ifdef HAVE_RECORDING
  172. +    if (recording_mode)
  173. +    {
  174. +        rb->pcm_stop_recording();
  175. +        rb->pcm_close_recording();
  176. +    }
  177. +    else
  178. +#endif
  179. +    {
  180.         /* Handle our input thread. We haven't yield()'d since our last mutex_unlock, so we know we have the mutex */
  181.         rb->mutex_lock(&input_mutex);
  182.         input_thread_run = false;
  183.         rb->mutex_unlock(&input_mutex);
  184.         rb->thread_wait(input_thread);
  185. +    }
  186.  
  187.  #ifdef HAVE_ADJUSTABLE_CPU_FREQ
  188.      rb->cpu_boost(false);
clone this paste RAW Paste Data