Mercurial > mplayer.hg
annotate libmpdemux/demux_rawaudio.c @ 7488:f5393c6c0cce
some updates
author | arpi |
---|---|
date | Sun, 22 Sep 2002 19:47:34 +0000 |
parents | f0b933918a22 |
children | 3dc0b71630ff |
rev | line source |
---|---|
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
1 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
2 #include "config.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
3 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
4 #include <stdlib.h> |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
5 #include <stdio.h> |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
6 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
7 #include "../cfgparser.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
8 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
9 #include "stream.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
10 #include "demuxer.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
11 #include "stheader.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
12 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
13 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
14 int use_rawaudio = 0; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
15 static int channels = 2; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
16 static int samplerate = 44100; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
17 static int samplesize = 2; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
18 static int format = 0x1; // Raw PCM |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
19 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
20 static config_t demux_rawaudio_opts[] = { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
21 { "on", &use_rawaudio, CONF_TYPE_FLAG, 0,0, 1, NULL }, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
22 { "channels", &channels, CONF_TYPE_INT,CONF_RANGE,1,8, NULL }, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
23 { "rate", &samplerate, CONF_TYPE_INT,CONF_RANGE,1000,8*48000, NULL }, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
24 { "samplesize", &samplesize, CONF_TYPE_INT,CONF_RANGE,1,8, NULL }, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
25 { "format", &format, CONF_TYPE_INT, CONF_MIN, 0 , 0, NULL }, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
26 {NULL, NULL, 0, 0, 0, 0, NULL} |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
27 }; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
28 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
29 static config_t demux_rawaudio_conf[] = { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
30 { "rawaudio", &demux_rawaudio_opts, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
31 { NULL,NULL, 0, 0, 0, 0, NULL} |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
32 }; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
33 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
34 void demux_rwaudio_register_options(m_config_t* cfg) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
35 m_config_register_options(cfg,demux_rawaudio_conf); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
36 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
37 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
38 extern void resync_audio_stream(sh_audio_t *sh_audio); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
39 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
40 int demux_rawaudio_open(demuxer_t* demuxer) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
41 sh_audio_t* sh_audio; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
42 WAVEFORMATEX* w; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
43 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
44 sh_audio = new_sh_audio(demuxer,0); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
45 sh_audio->wf = w = (WAVEFORMATEX*)malloc(sizeof(WAVEFORMATEX)); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
46 w->wFormatTag = sh_audio->format = format; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
47 w->nChannels = sh_audio->channels = channels; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
48 w->nSamplesPerSec = sh_audio->samplerate = samplerate; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
49 w->nAvgBytesPerSec = samplerate*samplesize*channels; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
50 w->nBlockAlign = channels*samplesize; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
51 sh_audio->samplesize = samplesize; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
52 w->wBitsPerSample = 8*samplesize; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
53 w->cbSize = 0; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
54 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
55 demuxer->movi_start = demuxer->stream->start_pos; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
56 demuxer->movi_end = demuxer->stream->end_pos; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
57 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
58 demuxer->audio->sh = sh_audio; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
59 sh_audio->ds = demuxer->audio; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
60 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
61 return 1; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
62 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
63 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
64 int demux_rawaudio_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
65 sh_audio_t* sh_audio = demuxer->audio->sh; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
66 int l = sh_audio->wf->nAvgBytesPerSec; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
67 off_t spos = stream_tell(demuxer->stream); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
68 demux_packet_t* dp; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
69 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
70 if(demuxer->stream->eof) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
71 return 0; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
72 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
73 dp = new_demux_packet(l); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
74 ds->pts = spos / (float)(sh_audio->wf->nAvgBytesPerSec); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
75 ds->pos = spos; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
76 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
77 stream_read(demuxer->stream,dp->buffer,l); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
78 ds_add_packet(ds,dp); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
79 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
80 return 1; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
81 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
82 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
83 void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
84 stream_t* s = demuxer->stream; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
85 sh_audio_t* sh_audio = demuxer->audio->sh; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
86 off_t base,pos; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
87 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
88 base = (flags & 1) ? demuxer->movi_start : stream_tell(s); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
89 if(flags & 2) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
90 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
91 else |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
92 pos = base + (rel_seek_secs*sh_audio->i_bps); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
93 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
94 pos -= (pos % (sh_audio->channels * sh_audio->samplesize) ); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
95 stream_seek(s,pos); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
96 resync_audio_stream(sh_audio); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
97 } |