fix FS#8187 - charging breaks sleep timer. Now if the timer goes off and the player...
[Rockbox.git] / apps / plugins / rockboy / rbsound.c
blobac5a29c5179de257e720a8a4ab94d59a99b39150
1 #include "rockmacros.h"
2 #include "defs.h"
3 #include "pcm.h"
5 struct pcm pcm IBSS_ATTR;
7 #define N_BUFS 2
8 #define BUF_SIZE 2048
10 #if CONFIG_CODEC == SWCODEC
12 bool doneplay=1;
13 bool bufnum=0;
15 static unsigned short *buf=0, *hwbuf=0;
17 static bool newly_started;
19 static void get_more(unsigned char** start, size_t* size)
21 memcpy(hwbuf, &buf[pcm.len*doneplay], BUF_SIZE*sizeof(short));
22 *start = (unsigned char*)(hwbuf);
23 *size = BUF_SIZE*sizeof(short);
24 doneplay=1;
27 void pcm_init(void)
29 if(plugbuf)
30 return;
32 newly_started = true;
34 #if defined(HW_HAVE_11) && !defined(TOSHIBA_GIGABEAT_F)
35 pcm.hz = SAMPR_11;
36 #else
37 pcm.hz = SAMPR_44;
38 #endif
40 pcm.stereo = 1;
42 pcm.len = BUF_SIZE;
43 if(!buf)
45 buf = my_malloc(pcm.len * N_BUFS *sizeof(short));
46 hwbuf = my_malloc(pcm.len *sizeof(short));
48 pcm.buf = buf;
49 pcm.pos = 0;
50 memset(buf, 0, pcm.len * N_BUFS*sizeof(short));
53 rb->pcm_play_stop();
55 #if INPUT_SRC_CAPS != 0
56 /* Select playback */
57 rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
58 rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);
59 #endif
61 rb->pcm_set_frequency(pcm.hz); /* 44100 22050 11025 */
64 void pcm_close(void)
66 memset(&pcm, 0, sizeof pcm);
67 newly_started = true;
68 rb->pcm_play_stop();
69 rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
72 int pcm_submit(void)
74 if (!pcm.buf) return 0;
75 if (pcm.pos < pcm.len) return 1;
77 if(newly_started)
79 rb->pcm_play_data(&get_more,NULL,0);
80 newly_started = false;
83 while (!doneplay)
84 {rb->yield();}
86 doneplay=0;
88 pcm.pos = 0;
89 return 1;
92 #else
94 void pcm_init(void)
96 pcm.hz = 44100;
97 pcm.stereo = 1;
98 pcm.buf = NULL;
99 pcm.len = 0;
100 pcm.pos = 0;
103 void pcm_close(void)
105 memset(&pcm, 0, sizeof pcm);
108 int pcm_submit(void)
110 pcm.pos =0;
111 return 0;
114 #endif