annotate libmpcodecs/ad_pcm.c @ 7180:28677d779205

-afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
author arpi
date Fri, 30 Aug 2002 21:44:20 +0000
parents e2f1b1b8f8b4
children 2759150cc687
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
1 #include <stdio.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
2 #include <stdlib.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
3 #include <unistd.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
4
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
5 #include "config.h"
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
6 #include "ad_internal.h"
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
7
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
8 static ad_info_t info =
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
9 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
10 "Uncompressed PCM audio decoder",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
11 "pcm",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
12 "Nick Kurshev",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
13 "A'rpi",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
14 ""
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
15 };
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
16
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
17 LIBAD_EXTERN(pcm)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
18
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
19 static int init(sh_audio_t *sh_audio)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
20 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
21 WAVEFORMATEX *h=sh_audio->wf;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
22 sh_audio->i_bps=h->nAvgBytesPerSec;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
23 sh_audio->channels=h->nChannels;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
24 sh_audio->samplerate=h->nSamplesPerSec;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
25 sh_audio->samplesize=(h->wBitsPerSample+7)/8;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
26 switch(sh_audio->format){ /* hardware formats: */
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
27 case 0x6: sh_audio->sample_format=AFMT_A_LAW;break;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
28 case 0x7: sh_audio->sample_format=AFMT_MU_LAW;break;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
29 case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
30 case 0x50: sh_audio->sample_format=AFMT_MPEG;break;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
31 /* case 0x2000: sh_audio->sample_format=AFMT_AC3; */
6233
e2f1b1b8f8b4 8bit 'twos' S8 pcm audio support - fixes MOTI1E.MOV
arpi
parents: 5827
diff changeset
32 case 0x736F7774:
e2f1b1b8f8b4 8bit 'twos' S8 pcm audio support - fixes MOTI1E.MOV
arpi
parents: 5827
diff changeset
33 if(sh_audio->samplesize==1) sh_audio->sample_format=AFMT_S8; // 'twos'
e2f1b1b8f8b4 8bit 'twos' S8 pcm audio support - fixes MOTI1E.MOV
arpi
parents: 5827
diff changeset
34 break;
5827
9907037223fb bigendian fix - thx to Rogrio Brito <linuxconsult@yahoo.com.br>
arpi
parents: 5455
diff changeset
35 default: if(sh_audio->samplesize!=2) sh_audio->sample_format=AFMT_U8;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
36 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
37 return 1;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
38 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
39
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
40 static int preinit(sh_audio_t *sh)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
41 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
42 sh->audio_out_minsize=2048;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
43 return 1;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
44 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
45
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
46 static void uninit(sh_audio_t *sh)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
47 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
48 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
49
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
50 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
51 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
52 int skip;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
53 switch(cmd)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
54 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
55 case ADCTRL_SKIP_FRAME:
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
56 skip=sh->i_bps/16;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
57 skip=skip&(~3);
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
58 demux_read_data(sh->ds,NULL,skip);
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
59 return CONTROL_TRUE;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
60 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
61 return CONTROL_UNKNOWN;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
62 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
63
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
64 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
65 {
5455
5546543ae874 cleanup
arpi
parents: 5453
diff changeset
66 int len=sh_audio->channels*sh_audio->samplesize-1;
5546543ae874 cleanup
arpi
parents: 5453
diff changeset
67 len=(minlen+len)&(~len); // sample align
5546543ae874 cleanup
arpi
parents: 5453
diff changeset
68 len=demux_read_data(sh_audio->ds,buf,len);
5827
9907037223fb bigendian fix - thx to Rogrio Brito <linuxconsult@yahoo.com.br>
arpi
parents: 5455
diff changeset
69 #ifdef WORDS_BIGENDIAN
9907037223fb bigendian fix - thx to Rogrio Brito <linuxconsult@yahoo.com.br>
arpi
parents: 5455
diff changeset
70 if(sh_audio->format!=0x736F7774){
9907037223fb bigendian fix - thx to Rogrio Brito <linuxconsult@yahoo.com.br>
arpi
parents: 5455
diff changeset
71 #else
5453
0e63c2f19ba6 twos audio fixed
arpi
parents: 5340
diff changeset
72 if(sh_audio->format==0x736F7774){ // "twos" is swapped byteorder
5827
9907037223fb bigendian fix - thx to Rogrio Brito <linuxconsult@yahoo.com.br>
arpi
parents: 5455
diff changeset
73 #endif
5455
5546543ae874 cleanup
arpi
parents: 5453
diff changeset
74 int j;
5453
0e63c2f19ba6 twos audio fixed
arpi
parents: 5340
diff changeset
75 for(j=0;j<len;j+=2){
0e63c2f19ba6 twos audio fixed
arpi
parents: 5340
diff changeset
76 char x=buf[j];
0e63c2f19ba6 twos audio fixed
arpi
parents: 5340
diff changeset
77 buf[j]=buf[j+1];
0e63c2f19ba6 twos audio fixed
arpi
parents: 5340
diff changeset
78 buf[j+1]=x;
0e63c2f19ba6 twos audio fixed
arpi
parents: 5340
diff changeset
79 }
0e63c2f19ba6 twos audio fixed
arpi
parents: 5340
diff changeset
80 }
5455
5546543ae874 cleanup
arpi
parents: 5453
diff changeset
81 return len;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
82 }