@@ -51,11 +51,16 @@ void audio_dma_reset(void) {
51
51
52
52
void audio_dma_convert_signed (audio_dma_t * dma , uint8_t * buffer , uint32_t buffer_length ,
53
53
uint8_t * * output_buffer , uint32_t * output_buffer_length ) {
54
+
55
+ size_t output_buffer_max_length ;
54
56
if (dma -> first_buffer_free ) {
55
57
* output_buffer = dma -> first_buffer ;
58
+ output_buffer_max_length = dma -> first_buffer_length ;
56
59
} else {
57
60
* output_buffer = dma -> second_buffer ;
61
+ output_buffer_max_length = dma -> second_buffer_length ;
58
62
}
63
+
59
64
#pragma GCC diagnostic push
60
65
#pragma GCC diagnostic ignored "-Wcast-align"
61
66
if (dma -> signed_to_unsigned ||
@@ -65,6 +70,12 @@ void audio_dma_convert_signed(audio_dma_t *dma, uint8_t *buffer, uint32_t buffer
65
70
* output_buffer_length = buffer_length / dma -> sample_spacing ;
66
71
uint32_t out_i = 0 ;
67
72
if (dma -> sample_resolution <= 8 && dma -> output_resolution > 8 ) {
73
+ // reading bytes, writing 16-bit samples
74
+ * output_buffer_length = * output_buffer_length * 2 ;
75
+ if (* output_buffer_length > output_buffer_max_length ) {
76
+ mp_raise_RuntimeError (translate ("Internal audio buffer too small" ));
77
+ }
78
+
68
79
size_t shift = dma -> output_resolution - dma -> sample_resolution ;
69
80
70
81
for (uint32_t i = 0 ; i < buffer_length ; i += dma -> sample_spacing ) {
@@ -107,6 +118,10 @@ void audio_dma_convert_signed(audio_dma_t *dma, uint8_t *buffer, uint32_t buffer
107
118
}
108
119
out_i += 1 ;
109
120
}
121
+ } else {
122
+ // (dma->sample_resolution > 8 && dma->output_resolution <= 8)
123
+ // Not currently used, but might be in the future.
124
+ mp_raise_RuntimeError (translate ("Audio conversion not implemented" ));
110
125
}
111
126
} else {
112
127
* output_buffer = buffer ;
@@ -149,7 +164,6 @@ void audio_dma_load_next_block(audio_dma_t *dma) {
149
164
// If we don't have an output buffer, save the pointer to first_buffer for use in the single
150
165
// buffer special case.
151
166
if (dma -> first_buffer == NULL ) {
152
- mp_printf (& mp_plat_print ,"no first buffer\n" );
153
167
dma -> first_buffer = output_buffer ;
154
168
}
155
169
@@ -210,8 +224,11 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
210
224
uint32_t max_buffer_length ;
211
225
audiosample_get_buffer_structure (sample , single_channel_output , & single_buffer , & samples_signed ,
212
226
& max_buffer_length , & dma -> sample_spacing );
213
-
227
+ mp_printf (& mp_plat_print , "single_buffer: %d, samples_signed: %d, max_buffer_length: %d, dma->sample_spacing: %d\n" ,
228
+ single_buffer , samples_signed , max_buffer_length , dma -> sample_spacing ); ////
214
229
// Check to see if we have to scale the resolution up.
230
+ mp_printf (& mp_plat_print , "dma->sample_resolution: %d, dma->output_resolution: %d, output_signed: %d, single_channel_output: %d\n" ,
231
+ dma -> sample_resolution , dma -> output_resolution , output_signed , single_channel_output );
215
232
if (dma -> sample_resolution <= 8 && dma -> output_resolution > 8 ) {
216
233
max_buffer_length *= 2 ;
217
234
}
@@ -222,13 +239,15 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
222
239
}
223
240
224
241
dma -> first_buffer = (uint8_t * )m_realloc (dma -> first_buffer , max_buffer_length );
242
+ dma -> first_buffer_length = max_buffer_length ;
225
243
if (dma -> first_buffer == NULL ) {
226
244
return AUDIO_DMA_MEMORY_ERROR ;
227
245
}
228
246
229
247
dma -> first_buffer_free = true;
230
248
if (!single_buffer ) {
231
249
dma -> second_buffer = (uint8_t * )m_realloc (dma -> second_buffer , max_buffer_length );
250
+ dma -> second_buffer_length = max_buffer_length ;
232
251
if (dma -> second_buffer == NULL ) {
233
252
return AUDIO_DMA_MEMORY_ERROR ;
234
253
}
0 commit comments