1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*
splay player plugin
Copyright (C) 1999 Martin Vogt
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation.
For more information look at the file COPYRIGHT in this package
*/
#include "cddaPlugin.h"
#ifdef CDDA_PARANOIA
#include <sys/types.h>
#include <iostream>
using namespace std;
typedef int16_t size16;
typedef int32_t size32;
extern "C" {
#include <cdda_interface.h>
#include <cdda_paranoia.h>
}
CDDAPlugin::CDDAPlugin() {
}
CDDAPlugin::~CDDAPlugin() {
}
// here we can config our decoder with special flags
void CDDAPlugin::config(const char* key,const char* value,void* user_data) {
DecoderPlugin::config(key,value,user_data);
}
void CDDAPlugin::decoder_loop() {
if (input == NULL) {
cout << "CDDAPlugin::decoder_loop input is NULL"<<endl;
exit(0);
}
if (output == NULL) {
cout << "CDDAPlugin::decoder_loop output is NULL"<<endl;
exit(0);
}
// init decoder
output->audioInit();
TimeStamp* stamp;
char buf[CD_FRAMESIZE_RAW*4];
int len=0;
// start decoding
while(runCheck()) {
switch(streamState) {
case _STREAM_STATE_FIRST_INIT :
output->audioSetup(44100,1,0,0,16);
output->audioOpen();
setStreamState(_STREAM_STATE_PLAY);
len=getTotalLength();
pluginInfo->setLength(len);
output->writeInfo(pluginInfo);
break;
case _STREAM_STATE_INIT :
setStreamState(_STREAM_STATE_PLAY);
break;
case _STREAM_STATE_PLAY : {
// decode
int read=input->read(buf,2*CD_FRAMESIZE_RAW);
int pos=input->getBytePosition();
stamp=input->getTimeStamp(pos);
output->audioPlay(stamp,stamp,buf,read);
break;
}
case _STREAM_STATE_WAIT_FOR_END:
// exit while loop
lDecoderLoop=false;
break;
default:
cout << "unknown stream state:"<<streamState<<endl;
}
}
// remove decoder
output->audioFlush();
}
// splay can seek in streams
int CDDAPlugin::seek_impl(int second) {
int bytes_per_second;
int seconds;
int back;
float frequence=44100;
int bits=16;
int channels=2;
bytes_per_second = (int)(frequence * channels * (bits / 8));
seconds = bytes_per_second * second;
cout << "seek to :"<<seconds<<endl;
back=input->seek(seconds);
return true;
}
int CDDAPlugin::getTotalLength() {
shutdownLock();
float wavfilesize;
int back=0;
float frequence=44100;
if (input == NULL) {
shutdownUnlock();
return 0;
}
wavfilesize = input->getByteLength();
int bits=16;
int channels=2;
if (bits == 16) {
wavfilesize=wavfilesize/2;
}
if (channels==2) {
wavfilesize=wavfilesize/2;
}
if (frequence != 0) {
back=(int)(wavfilesize/frequence);
}
shutdownUnlock();
return back;
}
#endif
//CDDA_PARANOIA
|