Changeset def5f9e2207c9b20fc0e3c2c95b013ed63f8cc66
- Timestamp:
- 11/04/03 15:51:51 (5 years ago)
- git-parent:
- Files:
-
- modules/codec/adpcm.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/codec/adpcm.c
r7bb574f rdef5f9e 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001, 2002 VideoLAN 5 * $Id: adpcm.c,v 1.1 3 2003/09/02 20:19:25 gbazinExp $5 * $Id: adpcm.c,v 1.14 2003/11/04 14:51:51 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 27 27 * Documentation: http://www.pcisys.net/~melanson/codecs/adpcm.txt 28 28 *****************************************************************************/ 29 #include <stdlib.h> /* malloc(), free() */ 30 29 31 #include <vlc/vlc.h> 30 32 #include <vlc/aout.h> … … 32 34 #include <vlc/input.h> 33 35 34 #include <stdlib.h> /* malloc(), free() */35 #include <string.h> /* strdup() */36 36 #include "codecs.h" 37 38 /***************************************************************************** 39 * Module descriptor 40 *****************************************************************************/ 41 static int Open ( vlc_object_t * ); 42 43 vlc_module_begin(); 44 set_description( _("ADPCM audio decoder") ); 45 set_capability( "decoder", 50 ); 46 set_callbacks( Open, NULL ); 47 vlc_module_end(); 48 49 37 50 /***************************************************************************** 38 51 * Local prototypes 39 52 *****************************************************************************/ 40 41 #define ADPCM_IMA_QT 1 42 #define ADPCM_IMA_WAV 2 43 #define ADPCM_MS 3 44 #define ADPCM_DK3 4 45 #define ADPCM_DK4 5 46 47 typedef struct adec_thread_s 48 { 49 int i_codec; 50 51 WAVEFORMATEX *p_wf; 53 enum adpcm_codec_e 54 { 55 ADPCM_IMA_QT, 56 ADPCM_IMA_WAV, 57 ADPCM_MS, 58 ADPCM_DK3, 59 ADPCM_DK4 60 }; 61 62 struct decoder_sys_t 63 { 64 WAVEFORMATEX *p_wf; 65 enum adpcm_codec_e codec; 52 66 53 67 int i_block; 54 uint8_t *p_block;55 68 int i_samplesperblock; 56 69 57 uint8_t *p_buffer; /* buffer for gather pes */ \ 58 int i_buffer; /* bytes present in p_buffer */ 59 60 /* Input properties */ 61 decoder_fifo_t *p_fifo; 62 63 /* Output properties */ 70 /* audio output */ 64 71 aout_instance_t * p_aout; /* opaque */ 65 72 aout_input_t * p_aout_input; /* opaque */ … … 67 74 68 75 audio_date_t date; 69 mtime_t pts; 70 71 } adec_thread_t; 72 73 static int OpenDecoder ( vlc_object_t * ); 74 75 static int RunDecoder ( decoder_fifo_t * ); 76 static int InitThread ( adec_thread_t * ); 77 static void DecodeThread ( adec_thread_t * ); 78 static void EndThread ( adec_thread_t * ); 79 80 81 static void DecodeAdpcmMs ( adec_thread_t *, aout_buffer_t * ); 82 static void DecodeAdpcmImaWav ( adec_thread_t *, aout_buffer_t * ); 83 static void DecodeAdpcmImaQT ( adec_thread_t *, aout_buffer_t * ); 84 static void DecodeAdpcmDk4 ( adec_thread_t *, aout_buffer_t * ); 85 static void DecodeAdpcmDk3 ( adec_thread_t *, aout_buffer_t * ); 86 87 /***************************************************************************** 88 * Module descriptor 89 *****************************************************************************/ 90 91 vlc_module_begin(); 92 set_description( _("ADPCM audio decoder") ); 93 set_capability( "decoder", 50 ); 94 set_callbacks( OpenDecoder, NULL ); 95 vlc_module_end(); 96 76 }; 77 78 static int Init ( decoder_t * ); 79 static int Decode( decoder_t *, block_t * ); 80 static int End ( decoder_t * ); 81 82 83 84 static void DecodeAdpcmMs ( decoder_sys_t *, int16_t *, uint8_t * ); 85 static void DecodeAdpcmImaWav ( decoder_sys_t *, int16_t *, uint8_t * ); 86 static void DecodeAdpcmImaQT ( decoder_sys_t *, int16_t *, uint8_t * ); 87 static void DecodeAdpcmDk4 ( decoder_sys_t *, int16_t *, uint8_t * ); 88 static void DecodeAdpcmDk3 ( decoder_sys_t *, int16_t *, uint8_t * ); 97 89 98 90 static int pi_channels_maps[6] = … … 150 142 * to choose. 151 143 *****************************************************************************/ 152 static int Open Decoder( vlc_object_t *p_this )144 static int Open( vlc_object_t *p_this ) 153 145 { 154 146 decoder_t *p_dec = (decoder_t*)p_this; … … 162 154 case VLC_FOURCC('m','s',0x00,0x62): /* Duck DK3 ADPCM */ 163 155 164 p_dec->pf_run = RunDecoder; 156 p_dec->pf_init = Init; 157 p_dec->pf_decode = Decode; 158 p_dec->pf_end = End; 159 160 p_dec->p_sys = malloc( sizeof( decoder_sys_t ) ); 165 161 return VLC_SUCCESS; 166 162 … … 171 167 172 168 /***************************************************************************** 173 * RunDecoder: this function is called just after the thread is created169 * Init: 174 170 *****************************************************************************/ 175 static int RunDecoder( decoder_fifo_t *p_fifo ) 176 { 177 adec_thread_t *p_adec; 178 int b_error; 179 180 if( !( p_adec = malloc( sizeof( adec_thread_t ) ) ) ) 181 { 182 msg_Err( p_fifo, "out of memory" ); 183 DecoderError( p_fifo ); 184 return( -1 ); 185 } 186 memset( p_adec, 0, sizeof( adec_thread_t ) ); 187 188 p_adec->p_fifo = p_fifo; 189 190 if( InitThread( p_adec ) != 0 ) 191 { 192 DecoderError( p_fifo ); 193 return( -1 ); 194 } 195 196 while( ( !p_adec->p_fifo->b_die )&&( !p_adec->p_fifo->b_error ) ) 197 { 198 DecodeThread( p_adec ); 199 } 200 201 202 if( ( b_error = p_adec->p_fifo->b_error ) ) 203 { 204 DecoderError( p_adec->p_fifo ); 205 } 206 207 EndThread( p_adec ); 208 if( b_error ) 209 { 210 return( -1 ); 211 } 212 213 return( 0 ); 214 } 215 216 217 #define FREE( p ) if( p ) free( p ); p = NULL 218 219 /***************************************************************************** 220 * InitThread: initialize data before entering main loop 221 *****************************************************************************/ 222 223 static int InitThread( adec_thread_t * p_adec ) 224 { 225 if( ( p_adec->p_wf = (WAVEFORMATEX*)p_adec->p_fifo->p_waveformatex ) == NULL ) 226 { 227 msg_Err( p_adec->p_fifo, "missing format" ); 228 return( -1 ); 229 } 230 /* fourcc to codec */ 231 switch( p_adec->p_fifo->i_fourcc ) 171 static int Init ( decoder_t *p_dec ) 172 { 173 decoder_sys_t *p_sys = p_dec->p_sys; 174 175 WAVEFORMATEX *p_wf; 176 if( ( p_wf = (WAVEFORMATEX*)p_dec->p_fifo->p_waveformatex ) == NULL ) 177 { 178 msg_Err( p_dec, "unknown raw format" ); 179 return VLC_EGENERIC; 180 } 181 182 if( p_wf->nChannels < 1 || p_wf->nChannels > 2 ) 183 { 184 msg_Err( p_dec, "bad channels count(1-2)" ); 185 return VLC_EGENERIC; 186 } 187 if( p_wf->nSamplesPerSec <= 0 ) 188 { 189 msg_Err( p_dec, "bad samplerate" ); 190 return VLC_EGENERIC; 191 } 192 193 p_sys->p_wf = p_wf; 194 switch( p_dec->p_fifo->i_fourcc ) 232 195 { 233 196 case VLC_FOURCC('i','m','a', '4'): /* IMA ADPCM */ 234 p_ adec->i_codec = ADPCM_IMA_QT;197 p_sys->codec = ADPCM_IMA_QT; 235 198 break; 236 199 case VLC_FOURCC('m','s',0x00,0x11): /* IMA ADPCM */ 237 p_ adec->i_codec = ADPCM_IMA_WAV;200 p_sys->codec = ADPCM_IMA_WAV; 238 201 break; 239 202 case VLC_FOURCC('m','s',0x00,0x02): /* MS ADPCM */ 240 p_ adec->i_codec = ADPCM_MS;203 p_sys->codec = ADPCM_MS; 241 204 break; 242 205 case VLC_FOURCC('m','s',0x00,0x61): /* Duck DK4 ADPCM */ 243 p_ adec->i_codec = ADPCM_DK4;206 p_sys->codec = ADPCM_DK4; 244 207 break; 245 208 case VLC_FOURCC('m','s',0x00,0x62): /* Duck DK3 ADPCM */ 246 p_adec->i_codec = ADPCM_DK3; 247 break; 248 } 249 250 if( p_adec->p_wf->nChannels < 1 || 251 p_adec->p_wf->nChannels > 2 ) 252 { 253 msg_Err( p_adec->p_fifo, "bad channels count(1-2)" ); 254 return( -1 ); 255 } 256 if( !( p_adec->i_block = p_adec->p_wf->nBlockAlign ) ) 257 { 258 if( p_adec->i_codec == ADPCM_IMA_QT ) 259 { 260 p_adec->i_block = 34 * p_adec->p_wf->nChannels; 261 } 262 else 263 { 264 p_adec->i_block = 1024; // XXX FIXME 265 } 266 msg_Warn( p_adec->p_fifo, 267 "block size undefined, using %d default", 268 p_adec->i_block ); 269 } 270 p_adec->p_block = NULL; 209 p_sys->codec = ADPCM_DK3; 210 break; 211 } 212 213 if( ( p_sys->i_block = p_wf->nBlockAlign ) <= 0 ) 214 { 215 p_sys->i_block = p_sys->codec==ADPCM_IMA_QT ? 34*p_wf->nChannels:1024; 216 msg_Warn( p_dec, "block size undefined, -> using %d", p_sys->i_block ); 217 } 271 218 272 219 /* calculate samples per block */ 273 switch( p_ adec->i_codec )220 switch( p_sys->codec ) 274 221 { 275 222 case ADPCM_IMA_QT: 276 p_ adec->i_samplesperblock = 64;223 p_sys->i_samplesperblock = 64; 277 224 break; 278 225 case ADPCM_IMA_WAV: 279 p_adec->i_samplesperblock = 280 2 * ( p_adec->i_block - 4 * p_adec->p_wf->nChannels )/ 281 p_adec->p_wf->nChannels; 226 p_sys->i_samplesperblock = 227 2 * ( p_sys->i_block - 4 * p_wf->nChannels )/ p_wf->nChannels; 282 228 break; 283 229 case ADPCM_MS: 284 p_adec->i_samplesperblock = 285 2 * ( p_adec->i_block - 7 * p_adec->p_wf->nChannels ) / 286 p_adec->p_wf->nChannels + 2; 230 p_sys->i_samplesperblock = 231 2 * (p_sys->i_block - 7 * p_wf->nChannels)/p_wf->nChannels + 2; 287 232 break; 288 233 case ADPCM_DK4: 289 p_adec->i_samplesperblock = 290 2 * ( p_adec->i_block - 4 * p_adec->p_wf->nChannels ) / 291 p_adec->p_wf->nChannels + 1; 234 p_sys->i_samplesperblock = 235 2 * (p_sys->i_block - 4 * p_wf->nChannels)/p_wf->nChannels + 1; 292 236 break; 293 237 case ADPCM_DK3: 294 p_adec->p_wf->nChannels = 2; 295 p_adec->i_samplesperblock = ( 4 * ( p_adec->i_block - 16 ) + 2 )/ 3; 296 break; 297 default: 298 msg_Err( p_adec->p_fifo, "unknown adpcm variant" ); 299 return( -1 ); 300 } 301 302 msg_Dbg( p_adec->p_fifo, 238 p_wf->nChannels = 2; 239 p_sys->i_samplesperblock = ( 4 * ( p_sys->i_block - 16 ) + 2 )/ 3; 240 break; 241 } 242 msg_Dbg( p_dec, 303 243 "format: samplerate:%dHz channels:%d bits/sample:%d blockalign:%d samplesperblock %d", 304 p_adec->p_wf->nSamplesPerSec, 305 p_adec->p_wf->nChannels, 306 p_adec->p_wf->wBitsPerSample, 307 p_adec->p_wf->nBlockAlign, 308 p_adec->i_samplesperblock ); 309 310 //p_adec->output_format.i_format = VLC_FOURCC('s','1','6','l'); 311 /* FIXME good way ? */ 312 p_adec->output_format.i_format = AOUT_FMT_S16_NE; 313 p_adec->output_format.i_rate = p_adec->p_wf->nSamplesPerSec; 314 315 316 p_adec->output_format.i_physical_channels = 317 p_adec->output_format.i_original_channels = 318 pi_channels_maps[p_adec->p_wf->nChannels]; 319 p_adec->p_aout = NULL; 320 p_adec->p_aout_input = NULL; 321 322 /* **** Create a new audio output **** */ 323 aout_DateInit( &p_adec->date, p_adec->output_format.i_rate ); 324 p_adec->p_aout_input = aout_DecNew( p_adec->p_fifo, 325 &p_adec->p_aout, 326 &p_adec->output_format ); 327 if( !p_adec->p_aout_input ) 328 { 329 msg_Err( p_adec->p_fifo, "cannot create aout" ); 330 return( -1 ); 331 } 332 333 /* Init the BitStream */ 334 // InitBitstream( &p_adec->bit_stream, p_adec->p_fifo, 335 // NULL, NULL ); 336 337 return( 0 ); 338 } 339 340 341 static void GetPESData( uint8_t *p_buf, int i_max, pes_packet_t *p_pes ) 342 { 343 int i_copy; 344 int i_count; 345 346 data_packet_t *p_data; 347 348 i_count = 0; 349 p_data = p_pes->p_first; 350 while( p_data != NULL && i_count < i_max ) 351 { 352 353 i_copy = __MIN( p_data->p_payload_end - p_data->p_payload_start, 354 i_max - i_count ); 355 356 if( i_copy > 0 ) 244 p_wf->nSamplesPerSec, p_wf->nChannels, 245 p_wf->wBitsPerSample, p_wf->nBlockAlign, 246 p_sys->i_samplesperblock ); 247 248 p_sys->output_format.i_format = AOUT_FMT_S16_NE; 249 p_sys->output_format.i_rate = p_wf->nSamplesPerSec; 250 p_sys->output_format.i_physical_channels = 251 p_sys->output_format.i_original_channels = 252 pi_channels_maps[p_wf->nChannels]; 253 254 p_sys->p_aout = NULL; 255 p_sys->p_aout_input = aout_DecNew( p_dec, 256 &p_sys->p_aout, &p_sys->output_format); 257 if( p_sys->p_aout_input == NULL ) 258 { 259 msg_Err( p_dec, "cannot create aout" ); 260 return VLC_EGENERIC; 261 } 262 263 aout_DateInit( &p_sys->date, p_sys->output_format.i_rate ); 264 aout_DateSet( &p_sys->date, 0 ); 265 266 return VLC_SUCCESS; 267 } 268 269 /***************************************************************************** 270 * Decode: 271 *****************************************************************************/ 272 static int Decode( decoder_t *p_dec, block_t *p_block ) 273 { 274 decoder_sys_t *p_sys = p_dec->p_sys; 275 mtime_t i_pts = p_block->i_pts; 276 uint8_t *p_data = p_block->p_buffer; 277 int i_data = p_block->i_buffer; 278 279 while( i_data >= p_sys->i_block ) 280 { 281 aout_buffer_t *out; 282 283 if( i_pts != 0 && i_pts != aout_DateGet( &p_sys->date ) ) 357 284 { 358 memcpy( p_buf, 359 p_data->p_payload_start, 360 i_copy ); 285 aout_DateSet( &p_sys->date, i_pts ); 361 286 } 362 363 p_data = p_data->p_next; 364 i_count += i_copy; 365 p_buf += i_copy; 366 } 367 368 if( i_count < i_max ) 369 { 370 memset( p_buf, 0, i_max - i_count ); 371 } 372 } 373 374 /***************************************************************************** 375 * DecodeThread: decodes a frame 376 *****************************************************************************/ 377 static void DecodeThread( adec_thread_t *p_adec ) 378 { 379 aout_buffer_t *p_aout_buffer; 380 pes_packet_t *p_pes; 381 382 int i_frame_size; 383 384 /* **** Get a new frames from streams **** */ 385 do 386 { 387 input_ExtractPES( p_adec->p_fifo, &p_pes ); 388 if( !p_pes ) 287 else if( !aout_DateGet( &p_sys->date ) ) 389 288 { 390 p_adec->p_fifo->b_error = 1; 391 return; 289 return VLC_SUCCESS; 392 290 } 393 if( p_pes->i_pts != 0 ) 291 i_pts = 0; 292 293 out = aout_DecNewBuffer( p_sys->p_aout, 294 p_sys->p_aout_input, 295 p_sys->i_samplesperblock ); 296 if( out == NULL ) 394 297 { 395 p_adec->pts = p_pes->i_pts; 298 msg_Err( p_dec, "cannot get aout buffer" ); 299 return VLC_EGENERIC; 396 300 } 397 i_frame_size = p_pes->i_pes_size; 398 399 if( i_frame_size > 0 ) 400 { 401 if( p_adec->i_buffer < i_frame_size + 16 ) 402 { 403 FREE( p_adec->p_buffer ); 404 p_adec->p_buffer = malloc( i_frame_size + 16 ); 405 p_adec->i_buffer = i_frame_size + 16; 406 } 407 408 GetPESData( p_adec->p_buffer, p_adec->i_buffer, p_pes ); 409 } 410 input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes ); 411 412 } while( i_frame_size <= 0 ); 413 414 for( p_adec->p_block = p_adec->p_buffer; 415 i_frame_size >= p_adec->i_block; 416 p_adec->p_block += p_adec->i_block, i_frame_size -= p_adec->i_block ) 417 { 418 /* get output buffer */ 419 if( p_adec->pts != 0 && p_adec->pts != aout_DateGet( &p_adec->date ) ) 420 { 421 aout_DateSet( &p_adec->date, p_adec->pts ); 422 } 423 else if( !aout_DateGet( &p_adec->date ) ) 424 { 425 return; 426 } 427 p_adec->pts = 0; 428 429 p_aout_buffer = aout_DecNewBuffer( p_adec->p_aout, 430 p_adec->p_aout_input, 431 p_adec->i_samplesperblock ); 432 if( !p_aout_buffer ) 433 { 434 msg_Err( p_adec->p_fifo, "cannot get aout buffer" ); 435 p_adec->p_fifo->b_error = 1; 436 return; 437 } 438 439 p_aout_buffer->start_date = aout_DateGet( &p_adec->date ); 440 p_aout_buffer->end_date = aout_DateIncrement( &p_adec->date, 441 p_adec->i_samplesperblock ); 442 443 /* decode */ 444 445 switch( p_adec->i_codec ) 301 out->start_date = aout_DateGet( &p_sys->date ); 302 out->end_date = aout_DateIncrement( &p_sys->date, 303 p_sys->i_samplesperblock ); 304 305 switch( p_sys->codec ) 446 306 { 447 307 case ADPCM_IMA_QT: 448 DecodeAdpcmImaQT( p_ adec, p_aout_buffer);308 DecodeAdpcmImaQT( p_sys, (int16_t*)out->p_buffer, p_data ); 449 309 break; 450 310 case ADPCM_IMA_WAV: 451 DecodeAdpcmImaWav( p_ adec, p_aout_buffer);311 DecodeAdpcmImaWav( p_sys, (int16_t*)out->p_buffer, p_data ); 452 312 break; 453 313 case ADPCM_MS: 454 DecodeAdpcmMs( p_ adec, p_aout_buffer);314 DecodeAdpcmMs( p_sys, (int16_t*)out->p_buffer, p_data ); 455 315 break; 456 316 case ADPCM_DK4: 457 DecodeAdpcmDk4( p_adec, p_aout_buffer ); 317 DecodeAdpcmDk4( p_sys, (int16_t*)out->p_buffer, p_data ); 318 break; 458 319 case ADPCM_DK3: 459 DecodeAdpcmDk3( p_adec, p_aout_buffer ); 320 DecodeAdpcmDk3( p_sys, (int16_t*)out->p_buffer, p_data ); 321 break; 460 322 default: 461 323 break; 462 324 } 463 464 465 /* **** Now we can output these samples **** */ 466 aout_DecPlay( p_adec->p_aout, p_adec->p_aout_input, p_aout_buffer ); 467 } 468 } 469 325 aout_DecPlay( p_sys->p_aout, p_sys->p_aout_input, out ); 326 327 p_data += p_sys->i_block; 328 i_data -= p_sys->i_block; 329 } 330 331 return VLC_SUCCESS; 332 } 470 333 471 334 /***************************************************************************** 472 * End Thread : faad decoder thread destruction335 * End: 473 336 *****************************************************************************/ 474 static void EndThread (adec_thread_t *p_adec) 475 { 476 if( p_adec->p_aout_input ) 477 { 478 aout_DecDelete( p_adec->p_aout, p_adec->p_aout_input ); 479 } 480 481 msg_Dbg( p_adec->p_fifo, "adpcm audio decoder closed" ); 482 483 FREE( p_adec->p_buffer ); 484 free( p_adec ); 485 } 337 static int End ( decoder_t *p_dec ) 338 { 339 decoder_sys_t *p_sys = p_dec->p_sys; 340 341 if( p_sys->p_aout_input ) 342 { 343 aout_DecDelete( p_sys->p_aout, p_sys->p_aout_input ); 344 } 345 free( p_sys ); 346 347 return VLC_SUCCESS; 348 } 349 486 350 #define CLAMP( v, min, max ) \ 487 351 if( (v) < (min) ) (v) = (min); \ … … 535 399 } 536 400 537 static void DecodeAdpcmMs( adec_thread_t *p_adec, 538 aout_buffer_t *p_aout_buffer) 539 { 540 uint8_t *p_buffer; 401 static void DecodeAdpcmMs( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 402 { 541 403 adpcm_ms_channel_t channel[2]; 542 404 int i_nibbles; 543 uint16_t *p_sample;544 405 int b_stereo; 545 406 int i_block_predictor; 546 407 547 p_buffer = p_adec->p_block; 548 b_stereo = p_adec->p_wf->nChannels == 2 ? 1 : 0; 408 b_stereo = p_sys->p_wf->nChannels == 2 ? 1 : 0; 549 409 550 410 GetByte( i_block_predictor ); … … 578 438 } 579 439 580 p_sample = (int16_t*)p_aout_buffer->p_buffer; 581 582 if( b_stereo ) 583 { 584 *p_sample = channel[0].i_sample2; p_sample++; 585 *p_sample = channel[1].i_sample2; p_sample++; 586 *p_sample = channel[0].i_sample1; p_sample++; 587 *p_sample = channel[1].i_sample1; p_sample++; 440 if( b_stereo ) 441 { 442 *p_sample++ = channel[0].i_sample2; 443 *p_sample++ = channel[1].i_sample2; 444 *p_sample++ = channel[0].i_sample1; 445 *p_sample++ = channel[1].i_sample1; 588 446 } 589 447 else 590 448 { 591 *p_sample = channel[0].i_sample2; p_sample++;592 *p_sample = channel[0].i_sample1; p_sample++;593 } 594 595 for( i_nibbles = 2 *( p_ adec->i_block - 7 * p_adec->p_wf->nChannels );449 *p_sample++ = channel[0].i_sample2; 450 *p_sample++ = channel[0].i_sample1; 451 } 452 453 for( i_nibbles = 2 *( p_sys->i_block - 7 * p_sys->p_wf->nChannels ); 596 454 i_nibbles > 0; i_nibbles -= 2,p_buffer++ ) 597 455 { 598 *p_sample = AdpcmMsExpandNibble( &channel[0], (*p_buffer) >> 4); 599 p_sample++; 600 601 *p_sample = AdpcmMsExpandNibble( &channel[b_stereo ? 1 : 0], 602 (*p_buffer)&0x0f); 603 p_sample++; 604 } 605 606 456 *p_sample++ = AdpcmMsExpandNibble( &channel[0], (*p_buffer) >> 4); 457 *p_sample++ = AdpcmMsExpandNibble( &channel[b_stereo ? 1 : 0], 458 (*p_buffer)&0x0f); 459 } 607 460 } 608 461 … … 640 493 } 641 494 642 static void DecodeAdpcmImaWav( adec_thread_t *p_adec, 643 aout_buffer_t *p_aout_buffer) 644 { 645 uint8_t *p_buffer; 495 static void DecodeAdpcmImaWav( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 496 { 646 497 adpcm_ima_wav_channel_t channel[2]; 647 498 int i_nibbles; 648 uint16_t *p_sample;649 499 int b_stereo; 650 500 651 p_buffer = p_adec->p_block; 652 b_stereo = p_adec->p_wf->nChannels == 2 ? 1 : 0; 501 b_stereo = p_sys->p_wf->nChannels == 2 ? 1 : 0; 653 502 654 503 GetWord( channel[0].i_predictor ); … … 665 514 } 666 515 667 p_sample = (int16_t*)p_aout_buffer->p_buffer; 668 if( b_stereo ) 669 { 670 for( i_nibbles = 2 * (p_adec->i_block - 8); 516 if( b_stereo ) 517 { 518 for( i_nibbles = 2 * (p_sys->i_block - 8); 671 519 i_nibbles > 0; 672 520 i_nibbles -= 16 ) … … 699 547 else 700 548 { 701 for( i_nibbles = 2 * (p_ adec->i_block - 4);549 for( i_nibbles = 2 * (p_sys->i_block - 4); 702 550 i_nibbles > 0; 703 551 i_nibbles -= 2, p_buffer++ ) 704 552 { 705 *p_sample =AdpcmImaWavExpandNibble( &channel[0], (*p_buffer)&0x0f ); 706 p_sample++; 707 *p_sample =AdpcmImaWavExpandNibble( &channel[0], (*p_buffer) >> 4 ); 708 p_sample++; 553 *p_sample++ =AdpcmImaWavExpandNibble( &channel[0], (*p_buffer)&0x0f ); 554 *p_sample++ =AdpcmImaWavExpandNibble( &channel[0], (*p_buffer) >> 4 ); 709 555 } 710 556 } … … 714 560 * Ima4 in QT file 715 561 */ 716 static void DecodeAdpcmImaQT( adec_thread_t *p_adec, 717 aout_buffer_t *p_aout_buffer ) 718 { 719 uint8_t *p_buffer; 562 static void DecodeAdpcmImaQT( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 563 { 720 564 adpcm_ima_wav_channel_t channel[2]; 721 565 int i_nibbles; 722 uint16_t *p_sample;723 566 int i_ch; 724 567 int i_step; 725 568 726 p_buffer = p_adec->p_block; 727 i_step = p_adec->p_wf->nChannels; 728 729 for( i_ch = 0; i_ch < p_adec->p_wf->nChannels; i_ch++ ) 730 { 731 p_sample = ((int16_t*)p_aout_buffer->p_buffer) + i_ch; 569 i_step = p_sys->p_wf->nChannels; 570 571 for( i_ch = 0; i_ch < p_sys->p_wf->nChannels; i_ch++ ) 572 { 732 573 /* load preambule */ 733 574 channel[i_ch].i_predictor = (int16_t)((( ( p_buffer[0] << 1 )|( p_buffer[1] >> 7 ) ))<<7); … … 747 588 p_buffer++; 748 589 } 590 591 /* Next channel */ 592 p_sample += 1 - 64 * i_step; 749 593 } 750 594 } … … 754 598 */ 755 599 756 static void DecodeAdpcmDk4( adec_thread_t *p_adec, 757 aout_buffer_t *p_aout_buffer) 758 { 759 uint8_t *p_buffer; 600 static void DecodeAdpcmDk4( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 601 { 760 602 adpcm_ima_wav_channel_t channel[2]; 761 603 int i_nibbles; 762 uint16_t *p_sample;763 604 int b_stereo; 764 605 765 p_buffer = p_adec->p_block; 766 b_stereo = p_adec->p_wf->nChannels == 2 ? 1 : 0; 606 b_stereo = p_sys->p_wf->nChannels == 2 ? 1 : 0; 767 607 768 608 GetWord( channel[0].i_predictor ); … … 779 619 } 780 620 781 p_sample = (int16_t*)p_aout_buffer->p_buffer;782 783 621 /* first output predictor */ 784 622 *p_sample++ = channel[0].i_predictor; … … 789 627 790 628 for( i_nibbles = 0; 791 i_nibbles < p_ adec->i_block - 4 * (b_stereo ? 2:1 );629 i_nibbles < p_sys->i_block - 4 * (b_stereo ? 2:1 ); 792 630 i_nibbles++ ) 793 631 { … … 804 642 * Dk3 805 643 */ 806 807 static void DecodeAdpcmDk3( adec_thread_t *p_adec, 808 aout_buffer_t *p_aout_buffer) 809 { 810 uint8_t *p_buffer, *p_end; 644 static void DecodeAdpcmDk3( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 645 { 646 uint8_t *p_end = &p_buffer[p_sys->i_block]; 811 647 adpcm_ima_wav_channel_t sum; 812 648 adpcm_ima_wav_channel_t diff; 813 uint16_t *p_sample;814 649 int i_diff_value; 815 650 816 p_buffer = p_adec->p_block;817 p_end = p_buffer + p_adec->i_block;818 819 651 p_buffer += 10; 652 820 653 GetWord( sum.i_predictor ); 821 654 GetWord( diff.i_predictor ); … … 823 656 GetByte( diff.i_step_index ); 824 657 825 p_sample = (int16_t*)p_aout_buffer->p_buffer;826 658 i_diff_value = diff.i_predictor; 827 659 /* we process 6 nibbles at once */ 828 //for( i_group = 0; i_group < ( p_adec->i_block -16 ) / 3; i_group++ )829 660 while( p_buffer + 1 <= p_end ) 830 661 { … … 870 701 *p_sample++ = sum.i_predictor - i_diff_value; 871 702 } 872 873 } 874 875 } 703 } 704 } 705
