1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2009 Wincent Balin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include "pdbox.h"
#include "m_pd.h"
#include "s_stuff.h"
/* Sound output buffer. */
#define AUDIO_OUTPUT_BLOCKS 3
static struct pdbox_audio_block audio_output[AUDIO_OUTPUT_BLOCKS];
static unsigned int output_head;
static unsigned int output_tail;
static unsigned int output_fill;
/* Open audio. */
void rockbox_open_audio(int rate)
{
unsigned int i;
/* Initialize output buffer. */
for(i = 0; i < AUDIO_OUTPUT_BLOCKS; i++)
audio_output[i].fill = 0;
output_head = 0;
output_tail = 0;
output_fill = 0;
#if INPUT_SRC_CAPS != 0
/* Select playback */
rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);
#endif
/* Set sample rate of the audio buffer. */
rb->pcm_set_frequency(rate);
}
/* Close audio. */
void rockbox_close_audio(void)
{
/* Stop playback. */
rb->pcm_play_stop();
/* Restore default sampling rate. */
rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
}
/* Rockbox audio callback. */
void pdbox_get_more(unsigned char** start, size_t* size)
{
if(output_fill > 0)
{
/* Store output data address and size. */
*start = (unsigned char*) audio_output[output_tail].data;
*size = audio_output[output_tail].fill;
/* Advance tail index. */
audio_output[output_tail].fill = 0;
output_fill--;
if(output_tail == AUDIO_OUTPUT_BLOCKS-1)
output_tail = 0;
else
output_tail++;
}
else
{
/* Nothing to play. */
*start = NULL;
*size = 0;
return;
}
}
/* Audio I/O. */
int rockbox_send_dacs(void)
{
/* Start playback if needed and possible. */
if(output_fill > 1 &&
audio_output[output_tail].fill == PD_AUDIO_BLOCK_SIZE)
{
/* Start playback. */
rb->pcm_play_data(pdbox_get_more,
(unsigned char*) audio_output[output_tail].data,
PD_AUDIO_BLOCK_SIZE);
/* Advance tail index. */
audio_output[output_tail].fill = PD_AUDIO_BLOCK_SIZE;
output_fill--;
if(output_tail == AUDIO_OUTPUT_BLOCKS-1)
output_tail = 0;
else
output_tail++;
}
#if 0
if (sys_getrealtime() > timebefore + 0.002)
{
/* post("slept"); */
return (SENDDACS_SLEPT);
}
else
#endif
return (SENDDACS_YES);
}
/* Placeholder. */
void rockbox_listdevs(void)
{
}
#if 0
/* Scanning for devices */
void rockbox_getdevs(char *indevlist, int *nindevs,
char *outdevlist, int *noutdevs, int *canmulti,
int maxndev, int devdescsize)
{
}
#endif
|