comparison alt_audio_convert.c @ 347:778cee61e1be

Mono-to-stereo fixes, more fprintf debugging output.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 23 May 2002 12:37:13 +0000
parents fbbb1f25b944
children c984aa6990f7
comparison
equal deleted inserted replaced
346:b6341f628568 347:778cee61e1be
155 155
156 /*-------------------------------------------------------------------------*/ 156 /*-------------------------------------------------------------------------*/
157 static int convertMonoToStereo( AdapterC Data, int length ) 157 static int convertMonoToStereo( AdapterC Data, int length )
158 { 158 {
159 int i; 159 int i;
160 short* buffer = Data.buffer-2; 160 short* buffer = Data.buffer-1;
161 length *= 2; 161 length *= 2;
162 162
163 /* 163 /*
164 * !!! FIXME: Can we avoid the division in this loop and just keep 164 * !!! FIXME: Can we avoid the division in this loop and just keep
165 * !!! FIXME: a second index variable? --ryan. 165 * !!! FIXME: a second index variable? --ryan.
166 */ 166 */
167 for( i = length; i; i-=2 ) 167 for( i = length; i; i-=2 )
168 buffer[i] = buffer [i+1] = buffer[i/2]; 168 buffer[i] = buffer [i-1] = buffer[i/2];
169 return length*2; 169 return length;
170 } 170 }
171 171
172 /*-------------------------------------------------------------------------*/ 172 /*-------------------------------------------------------------------------*/
173 static int minus5dB( AdapterC Data, int length ) 173 static int minus5dB( AdapterC Data, int length )
174 { 174 {
349 Ratio /= SrcRate; 349 Ratio /= SrcRate;
350 350
351 if( Ratio > 1.0) 351 if( Ratio > 1.0)
352 VarPos = filter_index++; 352 VarPos = filter_index++;
353 else 353 else
354 {
355 fprintf (stderr, "Filter: minus5dB\n");
354 Data->adapter[filter_index++] = minus5dB; 356 Data->adapter[filter_index++] = minus5dB;
357 }
355 358
356 while( Ratio > 64.0/31.0) 359 while( Ratio > 64.0/31.0)
357 { 360 {
361 fprintf (stderr, "Filter: %s\n",
362 Mono ? "doubleRateMono" : "doubleRateStereo");
358 Data->adapter[filter_index++] = 363 Data->adapter[filter_index++] =
359 Mono ? doubleRateMono : doubleRateStereo; 364 Mono ? doubleRateMono : doubleRateStereo;
360 Ratio /= 2; 365 Ratio /= 2;
361 Data->len_mult *= 2; 366 Data->len_mult *= 2;
362 Data->add *= 2; 367 Data->add *= 2;
363 Data->add += _fsize; 368 Data->add += _fsize;
364 } 369 }
365 370
366 while( Ratio < 31.0/64.0 ) 371 while( Ratio < 31.0/64.0 )
367 { 372 {
373 fprintf (stderr, "Filter: %s\n",
374 Mono ? "halfRateMono" : "halfRateStereo");
368 Data->adapter[filter_index++] = 375 Data->adapter[filter_index++] =
369 Mono ? halfRateMono : halfRateStereo; 376 Mono ? halfRateMono : halfRateStereo;
370 Ratio *= 2; 377 Ratio *= 2;
371 } 378 }
372 379
373 if( Ratio > 1.0 ) 380 if( Ratio > 1.0 )
374 { 381 {
382 fprintf (stderr, "Filter: %s\n",
383 Mono ? "varRateMono" : "varRateStereo");
375 setupVarFilter( &Data->filter, Ratio, Up ); 384 setupVarFilter( &Data->filter, Ratio, Up );
376 Data->adapter[VarPos] = 385 Data->adapter[VarPos] =
377 Mono ? varRateMono : varRateStereo; 386 Mono ? varRateMono : varRateStereo;
378 Data->len_mult *= 2; 387 Data->len_mult *= 2;
379 Data->add *= 2; 388 Data->add *= 2;
380 Data->add += _fsize; 389 Data->add += _fsize;
381 } 390 }
382 else 391 else
383 { 392 {
393 fprintf (stderr, "Filter: %s\n",
394 Mono ? "varRateMono" : "varRateStereo");
384 setupVarFilter( &Data->filter, Ratio, Down ); 395 setupVarFilter( &Data->filter, Ratio, Down );
385 Data->adapter[filter_index++] = 396 Data->adapter[filter_index++] =
386 Mono ? varRateMono : varRateStereo; 397 Mono ? varRateMono : varRateStereo;
387 } 398 }
388 return 0; 399 return filter_index;
389 } 400 }
390 401
391 static int BuildAudioCVT(Sound_AudioCVT *Data, 402 static int BuildAudioCVT(Sound_AudioCVT *Data,
392 Uint16 src_format, Uint8 src_channels, int src_rate, 403 Uint16 src_format, Uint8 src_channels, int src_rate,
393 Uint16 dst_format, Uint8 dst_channels, int dst_rate) 404 Uint16 dst_format, Uint8 dst_channels, int dst_rate)
604 * order again. This is not an optimal solution. 615 * order again. This is not an optimal solution.
605 */ 616 */
606 src_format |= ( AUDIO_16WRONG | AUDIO_SIGN ); 617 src_format |= ( AUDIO_16WRONG | AUDIO_SIGN );
607 dst_format |= AUDIO_16WRONG; 618 dst_format |= AUDIO_16WRONG;
608 } /* if */ 619 } /* if */
620
621 if ( src_rate != dst_rate )
622 {
623 /*
624 * !!! FIXME !!!
625 *
626 * The audio conversion filter probably only works if the
627 * data is in system byte order. So we need to convert to
628 * system byte order, and then back to original byte
629 * order. This is not an optimal solution.
630 */
631 src_format |= AUDIO_16WRONG;
632 dst_format |= AUDIO_16WRONG;
633 }
609 } /* else if */ 634 } /* else if */
610 else if ( SIGNED(src_in_format) != SIGNED(dst_in_format) ) 635 else if ( SIGNED(src_in_format) != SIGNED(dst_in_format) )
611 { 636 {
612 src_format |= AUDIO_SIGN; 637 src_format |= AUDIO_SIGN;
613 } /* else if */ 638 } /* else if */