~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_inputs/ADM_nuv/ADM_nuvAudio.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          ADM_nuvAudio.cpp  -  description
 
3
                             -------------------
 
4
 
 
5
                            Handle NUV (nuppel video) Audio track 
 
6
 
 
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
 
10
                        a/v sync problem
 
11
 
 
12
 ***************************************************************************
 
13
 
 
14
    begin                : Tue Jul 25 2002
 
15
    copyright            : (C) 2002 by mean
 
16
    email                : fixounet@free.fr
 
17
 ***************************************************************************/
 
18
 
 
19
/***************************************************************************
 
20
 *                                                                         *
 
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.                                   *
 
25
 *                                                                         *
 
26
 ***************************************************************************/
 
27
 
 
28
#include "config.h"
 
29
#include <stdio.h>
 
30
#ifdef HAVE_SYS_PARAM_H
 
31
#include <sys/param.h>
 
32
#endif
 
33
#ifdef __FreeBSD__
 
34
          #include <sys/types.h>
 
35
#endif
 
36
#include <stdlib.h>
 
37
#include <string.h>
 
38
 
 
39
#include "math.h"
 
40
#include <ADM_assert.h>
 
41
 
 
42
#include "default.h"
 
43
#include "ADM_editor/ADM_Video.h"
 
44
#include "fourcc.h"
 
45
#include "ADM_nuv/ADM_nuv.h"
 
46
 
 
47
//_______________________________________________________
 
48
//
 
49
//
 
50
//_______________________________________________________
 
51
 
 
52
nuvAudio::nuvAudio(nuvIndex *idx, uint32_t nbchunk, FILE * fd,uint32_t fq,mythHeader *hdr)
 
53
{
 
54
        _nb_chunks=nbchunk;
 
55
        _fd=fd;
 
56
        _current_index=0;
 
57
        _abs_position=0;
 
58
        _rel_position=0;
 
59
        _pos=0;
 
60
        _index=idx;
 
61
        // nuv format is fixed : PCM stero 44.1 khz
 
62
        if(!hdr|| fourCC::check(hdr->audio_fourcc,(uint8_t *)"RAWA"))
 
63
        {
 
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;
 
71
        }
 
72
        else
 
73
        {
 
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;
 
81
 
 
82
        }
 
83
        _destroyable=1; 
 
84
        strcpy(_name,"nuv audio");      
 
85
        // compute length
 
86
        _length=0;
 
87
        for(uint32_t i=0;i<_nb_chunks;i++)
 
88
                {
 
89
                        _length+=_index[i]._len;
 
90
                }
 
91
        printf("\n Nuv audio : %lu bytes (%lu chunks)\n",_length,_nb_chunks);
 
92
        if(hdr)
 
93
         if(fourCC::check(hdr->audio_fourcc,(uint8_t *)"LAME"))
 
94
       {
 
95
               _wavheader->encoding=WAV_MP3;
 
96
               uint8_t bfr[4096];
 
97
               WAVHeader hdr;
 
98
               goTo(0);
 
99
               read(4096,bfr);
 
100
                if(mpegAudioIdentify(bfr, 4090, &hdr))
 
101
                       memcpy(_wavheader,&hdr,sizeof(hdr));
 
102
                goTo(0);
 
103
 
 
104
       }
 
105
 
 
106
}
 
107
//_______________________________________________________
 
108
//
 
109
//
 
110
//_______________________________________________________
 
111
uint8_t nuvAudio::goTo(uint32_t newoffset)
 
112
{
 
113
    uint32_t len;
 
114
    len = newoffset;
 
115
    if(len>=_length)
 
116
        {
 
117
        printf("\n Out of bound !\n");
 
118
                return 0;
 
119
       }
 
120
    _current_index = 0; // start at beginning
 
121
#ifdef VERBOSE_L3
 
122
    printf("\n Stream offset : %lu\n", newoffset);
 
123
#endif
 
124
    do
 
125
      {
 
126
          if (len >= _index[_current_index]._len)       // skip whole subchunk
 
127
            {
 
128
                len -= _index[_current_index]._len;
 
129
                _current_index++;
 
130
                if(_current_index>=_nb_chunks)
 
131
                        {
 
132
                  printf("\n idx : %lu max: %lu len:%lu\n",  _current_index,_nb_chunks,len);
 
133
                  //ADM_assert(0);
 
134
                  //pos=0;
 
135
                  return 0;
 
136
                };
 
137
                _rel_position = 0;
 
138
          } else                // we got the last one
 
139
            {
 
140
                _rel_position = len;
 
141
                len = 0;
 
142
            }
 
143
          //printf("\n %lu len bytes to go",len);
 
144
      }
 
145
    while (len);
 
146
        _abs_position = _index[_current_index]._pos;
 
147
        ADM_assert(_current_index<_nb_chunks);
 
148
        _pos=newoffset;
 
149
    return 1;
 
150
}
 
151
//_______________________________________________________
 
152
//
 
153
//
 
154
//_______________________________________________________
 
155
uint32_t nuvAudio::read(uint32_t len,uint8_t *buffer)
 
156
{
 
157
    uint32_t togo;
 
158
    uint32_t avail, rd;
 
159
 
 
160
    // just to be sure....  
 
161
 
 
162
    fseeko(_fd,_abs_position+_rel_position,SEEK_SET);
 
163
 
 
164
    togo = len;
 
165
 
 
166
#ifdef VERBOSE_L3
 
167
    printf("\n ABS: %lu rel:%lu len:%lu", _abs_position, _rel_position,
 
168
           len);
 
169
#endif
 
170
 
 
171
     do
 
172
     {
 
173
          avail = _index[_current_index]._len - _rel_position;  // how much available ?
 
174
 
 
175
          if (avail > togo)     // we can grab all in one move
 
176
            {
 
177
                if(_index[_current_index]._compression=='R')
 
178
                        memset(buffer,0,togo);
 
179
                else
 
180
                        if(togo!= fread( (uint8_t *) buffer,1,togo,_fd))
 
181
                        {
 
182
                                printf("\n ***WARNING : incomplete chunk ***\n");
 
183
                        }
 
184
 
 
185
#ifdef VERBOSE_L3
 
186
 
 
187
                printf("\n REL: %lu rel:%lu len:%lu", _abs_position,
 
188
                       _rel_position, togo);
 
189
#endif
 
190
 
 
191
                _rel_position += togo;
 
192
#ifdef VERBOSE_L3
 
193
 
 
194
                printf("\n FINISH: %lu rel:%lu len:%lu", _abs_position,
 
195
                       _rel_position, togo);
 
196
#endif
 
197
 
 
198
                buffer += togo;
 
199
                togo = 0;
 
200
          } else                // read the whole subchunk and go to next one
 
201
            {
 
202
#ifdef VERBOSE_L3
 
203
 
 
204
                printf("\n CONT: %lu rel:%lu len:%lu", _abs_position,
 
205
                       _rel_position, togo);
 
206
#endif
 
207
                if(_index[_current_index]._compression=='R')
 
208
                {
 
209
                        memset(buffer,0,avail);
 
210
                        rd=avail;
 
211
                }
 
212
                else
 
213
                {
 
214
                rd = fread( buffer,1,avail,_fd);
 
215
                }
 
216
                if (rd != avail)
 
217
                  {
 
218
                      printf("\n Error : Expected :%lu bytes read :%lu \n",     rd, avail);
 
219
                      //ADM_assert(0);
 
220
                      return rd;
 
221
 
 
222
                  }
 
223
                buffer += avail;
 
224
                togo -= avail;
 
225
 
 
226
                _current_index++;
 
227
                if (_current_index>=_nb_chunks)
 
228
                  {
 
229
#ifdef VERBOSE_L3
 
230
 
 
231
                printf("\n OVR: %lu rel:%lu len:%lu", _abs_position,
 
232
                       _rel_position, togo);
 
233
#endif
 
234
                      _abs_position =_index[0]._pos ;
 
235
            _rel_position = 0;
 
236
                      ADM_assert(len >= togo);
 
237
                  _pos+=len;
 
238
            _pos-=togo;
 
239
                      return (len - togo);
 
240
 
 
241
                  }
 
242
        else
 
243
        {
 
244
#ifdef VERBOSE_L3
 
245
                printf("\n CONT: %lu rel:%lu len:%lu", _abs_position,
 
246
                       _rel_position, togo);
 
247
#endif
 
248
                _abs_position = _index[_current_index]._pos;
 
249
                _rel_position = 0;
 
250
                //_riff->goTo(_abs_position);
 
251
                fseeko(_fd,_abs_position,SEEK_SET);
 
252
            }
 
253
      }
 
254
    }
 
255
    while (togo);
 
256
    _pos+=len;
 
257
    return len;
 
258
 
 
259
}
 
260
//_______________________________________________________
 
261
//
 
262
//
 
263
//_______________________________________________________
 
264
 
 
265
 
 
266
nuvAudio::~nuvAudio()
 
267
{
 
268
        // nothing special to do...
 
269
 
 
270
}
 
271
//_______________________________________________________
 
272
uint8_t nuvAudio::getNbChunk(uint32_t *ch)
 
273
{
 
274
        *ch=_nb_chunks;
 
275
        return 1;
 
276
}