1
/***************************************************************************
2
ADM_nuvAudio.cpp - description
5
Handle NUV (nuppel video) Audio track
7
* Audio is simple : 44.1 khz, stereo, pcm
8
* Strongly derivated from avi audio lib
9
- Added buffering through _compression type R. Should get rid of
12
***************************************************************************
14
begin : Tue Jul 25 2002
15
copyright : (C) 2002 by mean
16
email : fixounet@free.fr
17
***************************************************************************/
19
/***************************************************************************
21
* This program is free software; you can redistribute it and/or modify *
22
* it under the terms of the GNU General Public License as published by *
23
* the Free Software Foundation; either version 2 of the License, or *
24
* (at your option) any later version. *
26
***************************************************************************/
30
#ifdef HAVE_SYS_PARAM_H
31
#include <sys/param.h>
34
#include <sys/types.h>
40
#include <ADM_assert.h>
43
#include "ADM_editor/ADM_Video.h"
45
#include "ADM_nuv/ADM_nuv.h"
47
//_______________________________________________________
50
//_______________________________________________________
52
nuvAudio::nuvAudio(nuvIndex *idx, uint32_t nbchunk, FILE * fd,uint32_t fq,mythHeader *hdr)
61
// nuv format is fixed : PCM stero 44.1 khz
62
if(!hdr|| fourCC::check(hdr->audio_fourcc,(uint8_t *)"RAWA"))
64
_wavheader=new WAVHeader;
65
memset(_wavheader,0,sizeof(WAVHeader));
66
_wavheader->bitspersample=16;
67
_wavheader->frequency=fq;
68
_wavheader->channels=2;
69
_wavheader->byterate=2*fq*2;
70
_wavheader->encoding=WAV_PCM;
74
_wavheader=new WAVHeader;
75
memset(_wavheader,0,sizeof(WAVHeader));
76
_wavheader->bitspersample=hdr->audio_bits_per_sample;;
77
_wavheader->frequency=hdr->audio_sample_rate;
78
_wavheader->channels=hdr->audio_channels;;
79
_wavheader->encoding=WAV_MP3; // ??
80
_wavheader->byterate=16000;
84
strcpy(_name,"nuv audio");
87
for(uint32_t i=0;i<_nb_chunks;i++)
89
_length+=_index[i]._len;
91
printf("\n Nuv audio : %lu bytes (%lu chunks)\n",_length,_nb_chunks);
93
if(fourCC::check(hdr->audio_fourcc,(uint8_t *)"LAME"))
95
_wavheader->encoding=WAV_MP3;
100
if(mpegAudioIdentify(bfr, 4090, &hdr))
101
memcpy(_wavheader,&hdr,sizeof(hdr));
107
//_______________________________________________________
110
//_______________________________________________________
111
uint8_t nuvAudio::goTo(uint32_t newoffset)
117
printf("\n Out of bound !\n");
120
_current_index = 0; // start at beginning
122
printf("\n Stream offset : %lu\n", newoffset);
126
if (len >= _index[_current_index]._len) // skip whole subchunk
128
len -= _index[_current_index]._len;
130
if(_current_index>=_nb_chunks)
132
printf("\n idx : %lu max: %lu len:%lu\n", _current_index,_nb_chunks,len);
138
} else // we got the last one
143
//printf("\n %lu len bytes to go",len);
146
_abs_position = _index[_current_index]._pos;
147
ADM_assert(_current_index<_nb_chunks);
151
//_______________________________________________________
154
//_______________________________________________________
155
uint32_t nuvAudio::read(uint32_t len,uint8_t *buffer)
160
// just to be sure....
162
fseeko(_fd,_abs_position+_rel_position,SEEK_SET);
167
printf("\n ABS: %lu rel:%lu len:%lu", _abs_position, _rel_position,
173
avail = _index[_current_index]._len - _rel_position; // how much available ?
175
if (avail > togo) // we can grab all in one move
177
if(_index[_current_index]._compression=='R')
178
memset(buffer,0,togo);
180
if(togo!= fread( (uint8_t *) buffer,1,togo,_fd))
182
printf("\n ***WARNING : incomplete chunk ***\n");
187
printf("\n REL: %lu rel:%lu len:%lu", _abs_position,
188
_rel_position, togo);
191
_rel_position += togo;
194
printf("\n FINISH: %lu rel:%lu len:%lu", _abs_position,
195
_rel_position, togo);
200
} else // read the whole subchunk and go to next one
204
printf("\n CONT: %lu rel:%lu len:%lu", _abs_position,
205
_rel_position, togo);
207
if(_index[_current_index]._compression=='R')
209
memset(buffer,0,avail);
214
rd = fread( buffer,1,avail,_fd);
218
printf("\n Error : Expected :%lu bytes read :%lu \n", rd, avail);
227
if (_current_index>=_nb_chunks)
231
printf("\n OVR: %lu rel:%lu len:%lu", _abs_position,
232
_rel_position, togo);
234
_abs_position =_index[0]._pos ;
236
ADM_assert(len >= togo);
245
printf("\n CONT: %lu rel:%lu len:%lu", _abs_position,
246
_rel_position, togo);
248
_abs_position = _index[_current_index]._pos;
250
//_riff->goTo(_abs_position);
251
fseeko(_fd,_abs_position,SEEK_SET);
260
//_______________________________________________________
263
//_______________________________________________________
266
nuvAudio::~nuvAudio()
268
// nothing special to do...
271
//_______________________________________________________
272
uint8_t nuvAudio::getNbChunk(uint32_t *ch)