Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Anonymous
Thursday, October 23rd, 2008 at 2:48:33pm UTC 

  1. Index: apps/pcmbuf.c
  2. ===================================================================
  3. --- apps/pcmbuf.c       (revision 18859)
  4. +++ apps/pcmbuf.c       (working copy)
  5. @@ -142,6 +142,7 @@
  6.   * to the DMA.  Finally the function checks the status of the buffer and
  7.   * boosts if necessary */
  8.  static void pcmbuf_callback(unsigned char** start, size_t* size) ICODE_ATTR;
  9. +#if 0
  10.  static void pcmbuf_callback(unsigned char** start, size_t* size)
  11.  {
  12.      {
  13. @@ -189,7 +190,7 @@
  14.          }
  15.      }
  16.  }
  17. -
  18. +#endif
  19.  void pcmbuf_set_position_callback(void (*callback)(size_t size))
  20.  {
  21.      position_callback = callback;
  22. @@ -320,6 +321,7 @@
  23.  
  24.  bool pcmbuf_is_lowdata(void)
  25.  {
  26. +    return true;
  27.      if (!pcm_is_playing() || pcm_is_paused() ||
  28.              crossfade_init || crossfade_active)
  29.          return false;
  30. @@ -474,7 +476,7 @@
  31.      pcmbuf_crossfade_enable_finished();
  32.  
  33.      pcmbuf_play_stop();
  34. -
  35. +    pcm_mixer_init();
  36.      return pcmbuf_bufend - audiobuffer;
  37.  }
  38.  
  39. @@ -513,6 +515,8 @@
  40.  /* Force playback. */
  41.  void pcmbuf_play_start(void)
  42.  {
  43. +    pcm_mixer_play();
  44. +    /*
  45.      if (!pcm_is_playing() && pcmbuf_unplayed_bytes && pcmbuf_read != NULL)
  46.      {
  47.          last_chunksize = pcmbuf_read->size;
  48. @@ -520,6 +524,7 @@
  49.          pcm_play_data(pcmbuf_callback,
  50.              (unsigned char *)pcmbuf_read->addr, last_chunksize);
  51.      }
  52. +    */
  53.  }
  54.  
  55.  /**
  56. @@ -861,7 +866,7 @@
  57.  
  58.      return true;
  59.  }
  60. -
  61. +#if 0
  62.  void* pcmbuf_request_buffer(int *count)
  63.  {
  64.      if (crossfade_init)
  65. @@ -895,7 +900,7 @@
  66.          }
  67.      }
  68.  }
  69. -
  70. +#endif
  71.  void * pcmbuf_request_voice_buffer(int *count)
  72.  {
  73.      /* A get-it-to-work-for-now hack (audio status could change by
  74. @@ -927,7 +932,7 @@
  75.  {
  76.      return crossfade_active || crossfade_init;
  77.  }
  78. -
  79. +#if 0
  80.  void pcmbuf_write_complete(int count)
  81.  {
  82.      size_t length = (size_t)(unsigned int)count << 2;
  83. @@ -946,7 +951,7 @@
  84.              pcmbuf_flush_fillpos();
  85.      }
  86.  }
  87. -
  88. +#endif
  89.  #if 0
  90.  bool pcmbuf_insert_buffer(char *buf, int count)
  91.  {
  92. @@ -1114,3 +1119,154 @@
  93.  
  94.      return crossfade_enabled;
  95.  }
  96. +
  97. +/* stuff that needs reimplementing:
  98. +    pcmbuf_request_buffer() - called to get a block to write to
  99. +    pcmbuf_write_complete() - called once a pcm block has been finished writing to by the codec
  100. +    pcmbuf_callback() - called by the ISR to get some pcm to output
  101. + */
  102. +
  103. +#define PCM_BLOCK_SIZE 8*1024*2*2 /* 8K samples */
  104. +#define MAX_PCM_BLOCKS 32
  105. +struct pcm_block {
  106. +    unsigned char buf[PCM_BLOCK_SIZE];
  107. +    unsigned int size;
  108. +    struct pcm_block *next;
  109. +};
  110. +static struct pcm_block pcm_block_buffer[MAX_PCM_BLOCKS];
  111. +static int block_count = 0;
  112. +enum {
  113. +    CHANNEL_AUDIO = 0,
  114. + //  CHANNEL_VOICE,
  115. +   
  116. +    PCM_CHANNEL_COUNT,
  117. +};
  118. +struct pcm_mixer_channel {
  119. +    struct pcm_block *head;
  120. +    struct pcm_block *tail;
  121. +    bool paused;
  122. +};
  123. +struct pcm_mixer_channel channels[PCM_CHANNEL_COUNT];
  124. +
  125. +struct pcm_block *get_free_block(void)
  126. +{
  127. +    int i = 0;
  128. +    struct pcm_block *ret;
  129. +    while (i<MAX_PCM_BLOCKS)
  130. +    {
  131. +        ret = &pcm_block_buffer[i];
  132. +        if (ret->size == 0) {
  133. +         //   printf("block %d\n", i);
  134. +            return ret;
  135. +        }
  136. +        i++;
  137. +    }
  138. +    pcmbuf_play_start();
  139. +    return NULL;
  140. +}
  141. +
  142. +void pcm_mixer_init(void)
  143. +{
  144. +    int i = 0;
  145. +    for (i=0; i<PCM_CHANNEL_COUNT; i++)
  146. +    {
  147. +        channels[i].head = NULL;
  148. +        channels[i].tail = NULL;
  149. +        channels[i].paused = false;
  150. +    }
  151. +    for (i=0; i<MAX_PCM_BLOCKS; i++)
  152. +    {
  153. +        pcm_block_buffer[i].size = 0;
  154. +    }
  155. +}
  156. +
  157. +void* pcmbuf_request_buffer(int *count)
  158. +{
  159. +    struct pcm_block *block, *tail;
  160. +    int bytes = *count<<2;
  161. +    tail = channels[CHANNEL_AUDIO].tail;
  162. + //   printf("pcmbuf_request_buffer\n");
  163. +    //printf("%d: \n", PCM_BLOCK_SIZE-tail->size);
  164. +    if (tail && (PCM_BLOCK_SIZE-tail->size > 0))
  165. +    {
  166. +        bytes = MIN(bytes, (PCM_BLOCK_SIZE-tail->size));
  167. +        *count = bytes>>2;
  168. +        printf("%d %d\n", *count, bytes);
  169. +        tail->size += bytes;
  170. +        return tail->buf + tail->size;
  171. +    }
  172. +    block = get_free_block();
  173. +    if (block == NULL)
  174. +        return NULL;
  175. +    block->next = NULL;
  176. +    bytes = MIN(bytes, 512<<2);
  177. +    //printf("%d %d\n", *count, *count>>2);
  178. +    block->size = bytes;
  179. +    *count = bytes>>2;
  180. +    if (channels[CHANNEL_AUDIO].head == NULL)
  181. +        channels[CHANNEL_AUDIO].head = block;
  182. +    if (channels[CHANNEL_AUDIO].tail == NULL)
  183. +        channels[CHANNEL_AUDIO].tail = block;
  184. +    else
  185. +    {
  186. +        channels[CHANNEL_AUDIO].tail->next = block;
  187. +        channels[CHANNEL_AUDIO].tail = block;
  188. +    }
  189. +    return block->buf;
  190. +}
  191. +
  192. +void pcmbuf_write_complete(int count)
  193. +{
  194. +  //  printf("pcmbuf_write_complete, %d\n", count);
  195. +    block_count++;
  196. +    //channels[CHANNEL_AUDIO].tail->size = count;
  197. +}
  198. +static bool playing = false;
  199. +void pcm_mixer_play(void)
  200. +{
  201. +    struct pcm_mixer_channel *c = &channels[CHANNEL_AUDIO];
  202. +    if (!c->paused && c->head != NULL && !playing && block_count >  0)
  203. +    {
  204. +        if (c->head == c->tail)
  205. +            return;
  206. +        pcm_play_data(pcmbuf_callback, channels[CHANNEL_AUDIO].head->buf, channels[CHANNEL_AUDIO].head->size);
  207. +        playing = true;
  208. +    }
  209. +}
  210. +
  211. +static void pcmbuf_callback(unsigned char** start, size_t* size)
  212. +{
  213. +    struct pcm_block *block = NULL;
  214. +    {
  215. +        int last_size = channels[CHANNEL_AUDIO].head->size;
  216. +        channels[CHANNEL_AUDIO].head->size = 0;
  217. +        block = channels[CHANNEL_AUDIO].head->next;
  218. +        channels[CHANNEL_AUDIO].head = block;
  219. +        /* The buffer is finished, call the callback functions */
  220. +        CALL_IF_EXISTS(position_callback, last_size);
  221. +            CALL_IF_EXISTS(pcmbuf_event_handler);
  222. +        block_count--;
  223. +    }
  224. +    {
  225. +        /* mix all the channels that are ready */
  226. +        // ... TODO
  227. +        struct pcm_mixer_channel *c = &channels[CHANNEL_AUDIO];
  228. +        if (!c->paused && c->head != NULL)
  229. +        {
  230. +            *start = c->head->buf;
  231. +            *size = c->head->size;
  232. +        }
  233. +        else
  234. +        {
  235. +            *start = NULL;
  236. +            *size = 0;
  237. +            playing = false;
  238. +        }
  239. +    }
  240. +}
  241. +   
  242. +   
  243. +   
  244. +   
  245. +   
  246. +   
  247. \ No newline at end of file
  248. Index: apps/playback.c
  249. ===================================================================
  250. --- apps/playback.c     (revision 18860)
  251. +++ apps/playback.c     (working copy)
  252. @@ -904,7 +904,7 @@
  253.  
  254.          if (inp_count <= 0)
  255.              return true;
  256. -
  257. +       
  258.          /* Input size has grown, no error, just don't write more than length */
  259.          if (inp_count > count)
  260.              inp_count = count;

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right