~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to akode/lib/audioframe.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  aKode AudioFrame
 
2
 
 
3
    Copyright (C) 2004 Allan Sandfeld Jensen <kde@carewolf.com>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Library General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Library General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to
 
17
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
    Boston, MA 02111-1307, USA.
 
19
*/
 
20
 
 
21
#ifndef _AKODE_AUDIOFRAME_H
 
22
#define _AKODE_AUDIOFRAME_H
 
23
 
 
24
#include "akodelib.h"
 
25
#include "audioconfiguration.h"
 
26
 
 
27
namespace aKode {
 
28
 
 
29
#define AKODE_POS_UNKNOWN -1
 
30
#define AKODE_POS_EOF -2
 
31
#define AKODE_POS_ERROR -3
 
32
 
 
33
//! The internal audio format
 
34
 
 
35
/*!
 
36
 * AudioFrames are used through-out akodelib as the mean of audiotransport.
 
37
 * It derives from AudioConfiguration because it caries its own interpretation
 
38
 * around with it.
 
39
 */
 
40
struct AudioFrame : public AudioConfiguration {
 
41
public:
 
42
    AudioFrame() : length(0), max(0), data(0) {};
 
43
    ~AudioFrame() { freeSpace(); }
 
44
    /*!
 
45
     * Reserves space in the frame for atleast \a iLength samples of the
 
46
     * configuration \a config.
 
47
     */
 
48
    void reserveSpace(const AudioConfiguration *config, long iLength) {
 
49
        reserveSpace(config->channels, iLength, config->sample_width);
 
50
        sample_rate = config->sample_rate;
 
51
        channel_config = config->channel_config;
 
52
        surround_config = config->surround_config;
 
53
    }
 
54
    void reserveSpace(uint8_t iChannels, long iLength, int8_t iWidth) {
 
55
        if ( data != 0 && channels == iChannels &&
 
56
             max >= iLength && sample_width == iWidth)
 
57
        {    // Fast common case
 
58
            length = iLength;
 
59
            return;
 
60
        }
 
61
        freeSpace();
 
62
        channels = iChannels;
 
63
        length = max = iLength;
 
64
        sample_width = iWidth;
 
65
        data = new int8_t*[channels+1];
 
66
        int bytes = (sample_width+7) / 8;
 
67
        if (bytes > 2) bytes = 4;
 
68
        if (bytes < 0) bytes = 4;
 
69
        for(int i=0; i<iChannels; i++)
 
70
            data[i] = new int8_t[length*bytes];
 
71
        data[iChannels] = 0;
 
72
    }
 
73
    /*!
 
74
     * Frees the space allocated for the buffer.
 
75
     */
 
76
    void freeSpace()
 
77
    {
 
78
        if (!data) return;
 
79
        int8_t** tmp = data;
 
80
        while(*tmp) {
 
81
           delete[] *tmp;
 
82
           tmp++;
 
83
        }
 
84
        delete[] data;
 
85
        pos = 0;
 
86
        data = 0;
 
87
        channels = 0;
 
88
        length = 0;
 
89
        max = 0;
 
90
    }
 
91
    /*!
 
92
     * The current position in stream (measured in milliseconds)
 
93
     * -1 if unknown
 
94
     */
 
95
    long pos;
 
96
    /*!
 
97
     * The length of the frame in samples.
 
98
     */
 
99
    long length;
 
100
    /*!
 
101
     * The maximum number of samples currently reserved in the frame.
 
102
     */
 
103
    long max;
 
104
    /*!
 
105
     * The buffer is accessed according sample-width
 
106
     * 1-8bit: int8_t, 9-16bit: int16_t, 17-32bit: int32_t
 
107
     * -32bit: float
 
108
     */
 
109
    int8_t** data;
 
110
};
 
111
 
 
112
} // namespace
 
113
 
 
114
#endif