3
Copyright (C) 1999 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
14
#include "tplayPlugin.h"
16
#include "../tplay/tplayfunctions.h"
20
TplayPlugin::TplayPlugin() {
21
info=new info_struct();
23
info->progname = NULL;
25
info->in_seconds = FALSE;
26
info->speed = DEFAULT_SPEED;
27
info->bits = DEFAULT_BITS;
28
info->channels = DEFAULT_CHANNELS;
29
info->buffer_size = BUFFER_SIZE;
30
info->show_usage = FALSE;
32
info->forceraw = FALSE;
35
info->verbose = FALSE;
38
info->firstblock = NULL;
39
info->number_of_blocks = 0;
44
info->alldone = FALSE;
45
info->overflow = FALSE;
46
info->underflow = FALSE;
47
info->audioset = FALSE;
49
info->blocksize = 4096;
50
info->bytes_on_last_block = 0;
52
startStamp=new TimeStamp();
53
endStamp=new TimeStamp();
57
TplayPlugin::~TplayPlugin() {
65
void TplayPlugin::decoder_loop() {
66
int bytesread, count, stereo;
70
cout << "TplayPlugin::decoder_loop input is NULL"<<endl;
74
cout << "TplayPlugin::decoder_loop output is NULL"<<endl;
81
info->buffer = (char*) malloc(info->buffer_size * sizeof(char));
85
case _STREAM_STATE_FIRST_INIT : {
88
if (info->channels == 1)
93
info->number_of_blocks = 0;
94
bufferp = info->buffer;
95
pluginInfo->setLength(getTotalLength());
96
output->writeInfo(pluginInfo);
99
setStreamState(_STREAM_STATE_INIT);
102
case _STREAM_STATE_INIT :
103
setStreamState(_STREAM_STATE_PLAY);
104
cout << "audioSetup call"<<endl;
106
output->audioSetup(info->speed, stereo, 1, 0, info->bits);
108
case _STREAM_STATE_PLAY :
112
while ((bytesread < info->blocksize) && (count != -1) &&
113
((count = input->read(p,info->blocksize-bytesread))!=0)){
118
swap_block(bufferp, bytesread);
122
pos=input->getBytePosition();
123
stamp=input->getTimeStamp(pos-bytesread);
124
output->audioPlay(stamp,endStamp,(char *) bufferp, bytesread);
127
if (bytesread < info->blocksize) {
128
info->alldone = TRUE;
132
case _STREAM_STATE_WAIT_FOR_END:
137
cout << "unknown stream state:"<<streamState<<endl;
140
cout << "tplay exit"<<endl;
143
output->audioFlush();
147
int TplayPlugin::seek_impl(int second) {
148
int bytes_per_second;
153
bytes_per_second = info->speed * info->channels * (info->bits / 8);
157
seconds = bytes_per_second * second;
158
back=input->seek(seconds);
164
void TplayPlugin::config(const char* key,const char* value,void* user_data) {
165
DecoderPlugin::config(key,value,user_data);
169
void TplayPlugin::swap_block(char * buffer, int blocksize) {
174
for (i = 0; i < (blocksize / 2); i++) {
183
void TplayPlugin::read_header() {
184
int bytesread, count;
187
info->firstblock = (char*) malloc(info->blocksize * sizeof(char));
188
bufferp = info->firstblock;
189
if (!info->forceraw) {
193
while ((bytesread < info->blocksize) && (count != -1) &&
194
((count=input->read(p,info->blocksize-bytesread)) != 0)){
199
if (bytesread < SUN_HDRSIZE)
200
cout << "Sample size is too small"<<endl;
202
if (read_au(info,info->firstblock) && read_wav(info,info->firstblock)) {
204
printf("Playing raw data: %ld samples/s, %d bits, %d channels.\n",
205
info->speed, info->bits, info->channels);
209
swap_block(bufferp, bytesread);
211
if (bytesread < info->blocksize) {
212
info->alldone = TRUE;
213
info->bytes_on_last_block = bytesread;
217
if (info->headerskip) {
219
bytesread = info->blocksize - info->headerskip;
220
p = info->firstblock + (info->blocksize - info->headerskip);
221
while ((bytesread < info->blocksize) && (count != -1) &&
222
((count = input->read(p,info->blocksize - bytesread)) != 0)) {
233
printf("Playing raw data: %ld samples/s, %d bits, %d channels\n",
234
info->speed, info->bits, info->channels);
239
Nobody is perfect I'm too tired to fix this race
242
int TplayPlugin::getTotalLength() {
243
float wavfilesize = input->getByteLength();
247
float frequence=info->speed;
253
wavfilesize=wavfilesize/2;
255
if (info->channels==2) {
256
wavfilesize=wavfilesize/2;
258
if (frequence != 0) {
259
back=(int)(wavfilesize/frequence);