changeset 3875:e3caff2daa98

fixed stereo MS ADPCM decoder and reinstated opensource decoder as the default handler for MS ADPCM data
author melanson
date Sat, 29 Dec 2001 04:20:29 +0000
parents 8b76388de734
children d619260dc756
files adpcm.c adpcm.h dec_audio.c etc/codecs.conf
diffstat 4 files changed, 23 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/adpcm.c	Sat Dec 29 01:32:46 2001 +0000
+++ b/adpcm.c	Sat Dec 29 04:20:29 2001 +0000
@@ -211,7 +211,7 @@
 }
 
 int ms_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels)
+  int channels, int block_size)
 {
   int current_channel = 0;
   int idelta[2];
@@ -267,7 +267,7 @@
     SE_16BIT(sample2[1]);
   }
 
-  while (stream_ptr < MS_ADPCM_BLOCK_SIZE * channels)
+  while (stream_ptr < block_size)
   {
     // get the next nibble
     if (upper_nibble)
@@ -295,7 +295,7 @@
     current_channel ^= channels - 1;
   }
 
-  return MS_ADPCM_SAMPLES_PER_BLOCK * channels;
+  return (block_size - (MS_ADPCM_PREAMBLE_SIZE * channels)) * 2;
 }
 
 // note: This decoder assumes the format 0x62 data always comes in
--- a/adpcm.h	Sat Dec 29 01:32:46 2001 +0000
+++ b/adpcm.h	Sat Dec 29 04:20:29 2001 +0000
@@ -7,9 +7,8 @@
   ((IMA_ADPCM_BLOCK_SIZE - IMA_ADPCM_PREAMBLE_SIZE) * 2)
 
 #define MS_ADPCM_PREAMBLE_SIZE 7
-#define MS_ADPCM_BLOCK_SIZE 256
 #define MS_ADPCM_SAMPLES_PER_BLOCK \
-  ((MS_ADPCM_BLOCK_SIZE - MS_ADPCM_PREAMBLE_SIZE) * 2)
+  ((sh_audio->wf->nBlockAlign - MS_ADPCM_PREAMBLE_SIZE) * 2)
 
 // pretend there's such a thing as mono for this format
 #define FOX62_ADPCM_PREAMBLE_SIZE 8
@@ -20,7 +19,7 @@
 int ima_adpcm_decode_block(unsigned short *output, unsigned char *input,
   int channels);
 int ms_adpcm_decode_block(unsigned short *output, unsigned char *input,
-  int channels);
+  int channels, int block_size);
 int fox62_adpcm_decode_block(unsigned short *output, unsigned char *input,
   int channels);
 
--- a/dec_audio.c	Sat Dec 29 01:32:46 2001 +0000
+++ b/dec_audio.c	Sat Dec 29 04:20:29 2001 +0000
@@ -369,9 +369,9 @@
   sh_audio->ds->ss_mul=IMA_ADPCM_BLOCK_SIZE;
   break;
 case AFM_MSADPCM:
-  sh_audio->audio_out_minsize=4096;
-  sh_audio->ds->ss_div=MS_ADPCM_SAMPLES_PER_BLOCK;
-  sh_audio->ds->ss_mul=MS_ADPCM_BLOCK_SIZE;
+  sh_audio->audio_out_minsize=sh_audio->wf->nBlockAlign * 8;
+  sh_audio->ds->ss_div = MS_ADPCM_SAMPLES_PER_BLOCK;
+  sh_audio->ds->ss_mul = sh_audio->wf->nBlockAlign;
   break;
 case AFM_FOX62ADPCM:
   sh_audio->audio_out_minsize=FOX62_ADPCM_SAMPLES_PER_BLOCK * 4;
@@ -615,7 +615,7 @@
 case AFM_MSADPCM:
   sh_audio->channels=sh_audio->wf->nChannels;
   sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
-  sh_audio->i_bps=MS_ADPCM_BLOCK_SIZE*
+  sh_audio->i_bps = sh_audio->wf->nBlockAlign *
     (sh_audio->channels*sh_audio->samplerate) / MS_ADPCM_SAMPLES_PER_BLOCK;
   break;
 case AFM_FOX62ADPCM:
@@ -1034,12 +1034,17 @@
         break;
       }
       case AFM_MSADPCM:
-      { unsigned char ibuf[MS_ADPCM_BLOCK_SIZE * 2]; // bytes / stereo frame
+      { static unsigned char *ibuf = NULL;
+        if (!ibuf)
+          ibuf = (unsigned char *)malloc
+            (sh_audio->wf->nBlockAlign * sh_audio->wf->nChannels);
         if (demux_read_data(sh_audio->ds, ibuf,
-          MS_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) != 
-          MS_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) 
+          sh_audio->wf->nBlockAlign) != 
+          sh_audio->wf->nBlockAlign) 
           break; // EOF
-        len=2*ms_adpcm_decode_block((unsigned short*)buf,ibuf, sh_audio->wf->nChannels);
+        len= 2 * ms_adpcm_decode_block(
+          (unsigned short*)buf,ibuf, sh_audio->wf->nChannels,
+          sh_audio->wf->nBlockAlign);
         break;
       }
       case AFM_FOX62ADPCM:
--- a/etc/codecs.conf	Sat Dec 29 01:32:46 2001 +0000
+++ b/etc/codecs.conf	Sat Dec 29 04:20:29 2001 +0000
@@ -324,11 +324,11 @@
   format 0x34616d69  ; "ima4" (MOV files)
   driver imaadpcm
 
-;audiocodec msadpcm
-;  info "MS ADPCM"
-;  status buggy
-;  format 0x2
-;  driver msadpcm
+audiocodec msadpcm
+  info "MS ADPCM"
+  status working
+  format 0x2
+  driver msadpcm
 
 audiocodec fox62adpcm
   info "Format 0x62 ADPCM"