Advertisement
Guest User

Untitled

a guest
Apr 27th, 2010
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.92 KB | None | 0 0
  1. diff --git a/apps/plugins/fft/fft.c b/apps/plugins/fft/fft.c
  2. index e62c919..9f84c2c 100644
  3. --- a/apps/plugins/fft/fft.c
  4. +++ b/apps/plugins/fft/fft.c
  5. @@ -228,6 +228,14 @@ GREY_INFO_STRUCT
  6.  #include "_kiss_fft_guts.h" /* sizeof(struct kiss_fft_state) */
  7.  #include "const.h"
  8.  
  9. +#if (REC_SAMPR_CAPS & SAMPR_CAP_44)
  10. +#define SAMPLE_RATE     SAMPR_44
  11. +#elif (REC_SAMPR_CAPS & SAMPR_CAP_22)
  12. +#define SAMPLE_RATE     SAMPR_22
  13. +#elif (REC_SAMPR_CAPS & SAMPR_CAP_11)
  14. +#define SAMPLE_RATE     SAMPR_11
  15. +#endif
  16. +
  17.  #if (LCD_WIDTH < LCD_HEIGHT)
  18.  #define LCD_SIZE LCD_HEIGHT
  19.  #else
  20. @@ -1072,14 +1080,59 @@ void input_thread_entry(void)
  21.     }
  22.  }
  23.  
  24. +#ifdef HAVE_RECORDING
  25. +static int recording_entry(int status)
  26. +{
  27. +    if (status >= 0)
  28. +        input_thread_has_data = true;
  29. +    else
  30. +        input_thread_has_data = false;
  31. +
  32. +    rb->logf("FFT: More data available, status: %d", status);    
  33. +    return -1;
  34. +}
  35. +
  36. +void recording_init(void)
  37. +{
  38. +    rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);  
  39. +    rb->audio_set_input_source(rb->global_settings->rec_source, SRCF_RECORDING);
  40. +
  41. +    /* set to maximum gain */
  42. +    if (rb->global_settings->rec_source == AUDIO_SRC_MIC)
  43. +        rb->audio_set_recording_gain(rb->global_settings->rec_mic_gain,
  44. +                rb->global_settings->rec_mic_gain,
  45. +                AUDIO_GAIN_MIC);
  46. +    else
  47. +        rb->audio_set_recording_gain(rb->global_settings->rec_left_gain,
  48. +                rb->global_settings->rec_right_gain,
  49. +                AUDIO_GAIN_LINEIN);
  50. +
  51. +    rb->pcm_set_frequency(SAMPLE_RATE);
  52. +    rb->pcm_apply_settings();
  53. +
  54. +    rb->pcm_init_recording();
  55. +    rb->logf("FFT: Recording initialized");
  56. +}
  57. +#endif
  58. +
  59.  
  60.  enum plugin_status plugin_start(const void* parameter)
  61.  {
  62.      (void) parameter;
  63. +
  64. +#ifdef HAVE_RECORDING
  65. +    bool recording_mode = false;
  66. +#endif
  67.      if ((rb->audio_status() & AUDIO_STATUS_PLAY) == 0)
  68.      {
  69. +#ifdef HAVE_RECORDING
  70. +        rb->splash(HZ * 2, "No track playing. Recording mode.");
  71. +        recording_mode = true;
  72. +        recording_init();
  73. +#else
  74.          rb->splash(HZ * 2, "No track playing. Exiting..");
  75.          return PLUGIN_OK;
  76. +#endif
  77.      }
  78.  #ifndef HAVE_LCD_COLOR
  79.      unsigned char *gbuf;
  80. @@ -1127,25 +1180,53 @@ enum plugin_status plugin_start(const void* parameter)
  81.  
  82.      if (state == 0)
  83.      {
  84. -        DEBUGF("needed data: %i", (int) size);
  85. +        DEBUGF("needed data: %l", (int) size);
  86.          return PLUGIN_ERROR;
  87.      }
  88. +    unsigned int input_thread = 0;
  89. +#ifdef HAVE_RECORDING
  90. +    if (recording_mode)
  91. +        rb->pcm_record_data(recording_entry, (void *) input,
  92. +                (size_t) ARRAYSIZE_IN * sizeof(kiss_fft_scalar));
  93. +    else
  94. +#endif
  95. +        input_thread = rb->create_thread(&input_thread_entry, thread_stack, sizeof(thread_stack), 0, "fft input thread" IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU));
  96.    
  97. -   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));
  98.     rb->yield();
  99.      while (run)
  100.      {
  101. +        if(!recording_mode)
  102.         rb->mutex_lock(&input_mutex);
  103.         if(!input_thread_has_data)
  104.         {
  105.             /* Make sure the input thread has started before doing anything else */
  106. +            if(!recording_mode)
  107.             rb->mutex_unlock(&input_mutex);
  108. +            else
  109. +            {
  110. +                rb->lcd_clear_display();
  111. +                rb->splash(HZ*2, "Waiting for recorded data");
  112. +                if(rb->button_get(false) == FFT_QUIT)
  113. +                {
  114. +                    rb->logf("Aborting wait-for-data cycle");
  115. +                    run = false;
  116. +                    break;
  117. +                }
  118. +            }
  119. +
  120.             rb->yield();
  121.             continue;
  122.         }
  123.         apply_window_func(graph_settings.window_func);
  124.         FFT_FFT(state, input, output);
  125.  
  126. +        /* We're done with the input */
  127. +        if(recording_mode)
  128. +        {
  129. +            rb->logf("FFT: call pcm_record_more");
  130. +            rb->pcm_record_more((void *) input, (size_t) ARRAYSIZE_IN * sizeof(kiss_fft_scalar));
  131. +        }
  132. +
  133.         if(changed_window)
  134.         {
  135.             draw(window_text[graph_settings.window_func]);
  136. @@ -1155,6 +1236,7 @@ enum plugin_status plugin_start(const void* parameter)
  137.             draw(0);
  138.  
  139.         input_thread_has_data = false;
  140. +        if(!recording_mode)
  141.          rb->mutex_unlock(&input_mutex);
  142.         rb->yield();
  143.  
  144. @@ -1203,11 +1285,21 @@ enum plugin_status plugin_start(const void* parameter)
  145.          }
  146.      }
  147.    
  148. +#ifdef HAVE_RECORDING
  149. +    if (recording_mode)
  150. +    {
  151. +        rb->pcm_stop_recording();
  152. +        rb->pcm_close_recording();
  153. +    }
  154. +    else
  155. +#endif
  156. +    {
  157.     /* Handle our input thread. We haven't yield()'d since our last mutex_unlock, so we know we have the mutex */
  158.     rb->mutex_lock(&input_mutex);
  159.     input_thread_run = false;
  160.     rb->mutex_unlock(&input_mutex);
  161.     rb->thread_wait(input_thread);
  162. +    }
  163.  
  164.  #ifdef HAVE_ADJUSTABLE_CPU_FREQ
  165.      rb->cpu_boost(false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement